ReadPortal().Get(idx) is slow in a loop.

This commit is contained in:
NAThompson 2020-05-08 11:30:59 -04:00
parent dcf5ecdd36
commit 46faf574fa
23 changed files with 296 additions and 166 deletions

@ -0,0 +1,18 @@
# `ReadPortal().Get(idx)`
Calling `ReadPortal()` in a tight loop is an antipattern.
A call to `ReadPortal()` causes the array to be copied back to the control environment,
and hence code like
```cpp
for (vtkm::Id i = 0; i < array.GetNumberOfValues(); ++i) {
vtkm::FloatDefault x = array.ReadPortal().Get(i);
}
```
is a quadratic-scaling loop.
We have remove *almost* all internal uses of the `ReadPortal().Get` antipattern,
with the exception of 4 API calls into which the pattern is baked in:
`CellSetExplicit::GetCellShape`, `CellSetPermutation::GetNumberOfPointsInCell`, `CellSetPermutation::GetCellShape`, and `CellSetPermutation::GetCellPointIds`.
We expect these will need to be deprecated in the future.

@ -179,6 +179,8 @@ VTKM_CONT
vtkm::UInt8 CellSetExplicit<SST, CST, OST>
::GetCellShape(vtkm::Id cellid) const
{
// Looping over GetCellShape(cellid) is a performance bug.
// Don't know quite what to do about it right now.
return this->Data->CellPointIds.Shapes.ReadPortal().Get(cellid);
}

@ -349,17 +349,20 @@ public:
VTKM_CONT
vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id cellIndex) const override
{
// Looping over GetNumberOfPointsInCell is a performance bug.
return this->FullCellSet.GetNumberOfPointsInCell(
this->ValidCellIds.ReadPortal().Get(cellIndex));
}
vtkm::UInt8 GetCellShape(vtkm::Id id) const override
{
// Looping over GetCellShape is a performance bug.
return this->FullCellSet.GetCellShape(this->ValidCellIds.ReadPortal().Get(id));
}
void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const override
{
// Looping over GetCellPointsIdx is a performance bug.
return this->FullCellSet.GetCellPointIds(this->ValidCellIds.ReadPortal().Get(id), ptids);
}

@ -92,9 +92,10 @@ public:
{
this->GetRangeImpl(TypeList());
const vtkm::Id length = this->Range.GetNumberOfValues();
auto portal = this->Range.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
range[i] = this->Range.ReadPortal().Get(i);
range[i] = portal.Get(i);
}
}

@ -149,10 +149,11 @@ struct TryWholeArrayType
token.DetachFromAll();
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Array size wrong?");
auto portal = array.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
T expectedValue = TestValue(index, T()) + T(OFFSET);
T retrievedValue = array.ReadPortal().Get(index);
T retrievedValue = portal.Get(index);
VTKM_TEST_ASSERT(test_equal(expectedValue, retrievedValue),
"In/Out array not set correctly.");
}

@ -103,9 +103,10 @@ private:
c1.Allocate(length);
c2.Allocate(length);
c3.Allocate(length);
auto portal = a1.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
auto p = a1.ReadPortal().Get(i);
auto p = portal.Get(i);
c1.WritePortal().Set(i, p[0]);
c2.WritePortal().Set(i, p[1]);
c3.WritePortal().Set(i, p[2]);

@ -45,9 +45,10 @@ private:
return false;
}
auto portal = ah.ReadPortal();
for (vtkm::Id i = 0; i < size; ++i)
{
if (ah.ReadPortal().Get(i) != expected[i])
if (portal.Get(i) != expected[i])
{
return false;
}
@ -128,9 +129,10 @@ private:
dispatcher.Invoke(cellset, dataSet.GetField("pointvar"), result);
vtkm::Float32 expected[3] = { 20.1333f, 30.1667f, 40.2333f };
auto portal = result.ReadPortal();
for (int i = 0; i < 3; ++i)
{
VTKM_TEST_ASSERT(test_equal(result.ReadPortal().Get(i), expected[i]),
VTKM_TEST_ASSERT(test_equal(portal.Get(i), expected[i]),
"Wrong result for CellAverage worklet on explicit single type cellset data");
}
}

@ -55,7 +55,7 @@ namespace testing
{
#define ERROR_MESSAGE "Got an error."
#define ARRAY_SIZE 100000
#define ARRAY_SIZE 10000
#define OFFSET 1000
#define DIM_SIZE 128
@ -672,9 +672,10 @@ private:
}
std::cout << "Checking results." << std::endl;
auto portal = handle.ReadPortal();
for (vtkm::Id index = 0; index < 1; index++)
{
vtkm::Id value = handle.ReadPortal().Get(index);
vtkm::Id value = portal.Get(index);
VTKM_TEST_ASSERT(value == index + OFFSET,
"Got bad value for single value scheduled kernel.");
}
@ -703,9 +704,10 @@ private:
}
std::cout << "Checking results." << std::endl;
auto portal = handle.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
vtkm::Id value = handle.ReadPortal().Get(index);
vtkm::Id value = portal.Get(index);
VTKM_TEST_ASSERT(value == index + OFFSET, "Got bad value for scheduled kernels.");
}
} //release memory
@ -741,10 +743,11 @@ private:
std::default_random_engine generator(static_cast<unsigned int>(std::time(nullptr)));
std::uniform_int_distribution<vtkm::Id> distribution(0, size - 1);
vtkm::Id numberOfSamples = size / 100;
auto portal = handle.ReadPortal();
for (vtkm::Id i = 0; i < numberOfSamples; ++i)
{
vtkm::Id randomIndex = distribution(generator);
vtkm::Id value = handle.ReadPortal().Get(randomIndex);
vtkm::Id value = portal.Get(randomIndex);
VTKM_TEST_ASSERT(value == randomIndex + OFFSET, "Got bad value for scheduled kernels.");
}
} //release memory
@ -777,9 +780,10 @@ private:
std::cout << "Checking results." << std::endl;
const vtkm::Id maxId = DIM_SIZE * DIM_SIZE * DIM_SIZE;
auto portal = handle.ReadPortal();
for (vtkm::Id index = 0; index < maxId; index++)
{
vtkm::Id value = handle.ReadPortal().Get(index);
vtkm::Id value = portal.Get(index);
VTKM_TEST_ASSERT(value == index + OFFSET, "Got bad value for scheduled vtkm::Id3 kernels.");
}
} //release memory
@ -897,9 +901,10 @@ private:
VTKM_TEST_ASSERT(result.GetNumberOfValues() == array.GetNumberOfValues() / 2,
"result of CopyIf has an incorrect size");
auto portal = result.ReadPortal();
for (vtkm::Id index = 0; index < result.GetNumberOfValues(); index++)
{
const vtkm::Id value = result.ReadPortal().Get(index);
const vtkm::Id value = portal.Get(index);
VTKM_TEST_ASSERT(value == (OFFSET + (index * 2) + 1), "Incorrect value in CopyIf result.");
}
@ -912,9 +917,10 @@ private:
VTKM_TEST_ASSERT(result.GetNumberOfValues() == array.GetNumberOfValues() / 2,
"result of CopyIf has an incorrect size");
portal = result.ReadPortal();
for (vtkm::Id index = 0; index < result.GetNumberOfValues(); index++)
{
const vtkm::Id value = result.ReadPortal().Get(index);
const vtkm::Id value = portal.Get(index);
VTKM_TEST_ASSERT(value == (OFFSET + (index * 2) + 1), "Incorrect value in CopyIf result.");
}
@ -958,10 +964,12 @@ private:
VTKM_TEST_ASSERT(temp.GetNumberOfValues() == 50,
"Unique did not resize array (or size did not copy to control).");
auto portal = handle.ReadPortal();
auto portal1 = handle1.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Id value = handle.ReadPortal().Get(i);
vtkm::Id value1 = handle1.ReadPortal().Get(i);
vtkm::Id value = portal.Get(i);
vtkm::Id value1 = portal1.Get(i);
VTKM_TEST_ASSERT(value == i % 50, "Got bad value (LowerBounds)");
VTKM_TEST_ASSERT(value1 >= i % 50, "Got bad value (UpperBounds)");
}
@ -1033,10 +1041,11 @@ private:
//Validate the standard inplace sort is correct
Algorithm::Sort(sorted);
auto portal = sorted.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE - 1; ++i)
{
vtkm::Id sorted1 = sorted.ReadPortal().Get(i);
vtkm::Id sorted2 = sorted.ReadPortal().Get(i + 1);
vtkm::Id sorted1 = portal.Get(i);
vtkm::Id sorted2 = portal.Get(i + 1);
VTKM_TEST_ASSERT(sorted1 <= sorted2, "Values not properly sorted.");
}
@ -1066,19 +1075,22 @@ private:
Algorithm::Sort(comp_sorted, vtkm::SortGreater());
//Validate that sorted and comp_sorted are sorted in the opposite directions
auto sorted_portal = sorted.ReadPortal();
auto comp_sorted_portal = comp_sorted.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Id sorted1 = sorted.ReadPortal().Get(i);
vtkm::Id sorted2 = comp_sorted.ReadPortal().Get(ARRAY_SIZE - (i + 1));
vtkm::Id sorted1 = sorted_portal.Get(i);
vtkm::Id sorted2 = comp_sorted_portal.Get(ARRAY_SIZE - (i + 1));
VTKM_TEST_ASSERT(sorted1 == sorted2, "Got bad sort values when using SortGreater");
}
//validate that sorted and comp_sorted are now equal
Algorithm::Sort(comp_sorted, vtkm::SortLess());
comp_sorted_portal = comp_sorted.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Id sorted1 = sorted.ReadPortal().Get(i);
vtkm::Id sorted2 = comp_sorted.ReadPortal().Get(i);
vtkm::Id sorted1 = sorted_portal.Get(i);
vtkm::Id sorted2 = comp_sorted_portal.Get(i);
VTKM_TEST_ASSERT(sorted1 == sorted2, "Got bad sort values when using SortLess");
}
}
@ -1105,9 +1117,10 @@ private:
Algorithm::Sort(zipped, vtkm::SortGreater());
Algorithm::Sort(zipped);
auto portal = zipped.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Pair<vtkm::Id, vtkm::Id> kv_sorted = zipped.ReadPortal().Get(i);
vtkm::Pair<vtkm::Id, vtkm::Id> kv_sorted = portal.Get(i);
VTKM_TEST_ASSERT((OFFSET + (i / (ARRAY_SIZE / 50))) == kv_sorted.first,
"ArrayZipHandle improperly sorted");
}
@ -1122,18 +1135,20 @@ private:
//verify we can use a custom operator sort with permutation handle
Algorithm::Sort(perm, vtkm::SortGreater());
auto perm_portal = perm.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Id sorted_value = perm.ReadPortal().Get(i);
vtkm::Id sorted_value = perm_portal.Get(i);
VTKM_TEST_ASSERT((OFFSET + ((ARRAY_SIZE - (i + 1)) / (ARRAY_SIZE / 50))) == sorted_value,
"ArrayZipPermutation improperly sorted");
}
//verify we can use the default sort with permutation handle
Algorithm::Sort(perm);
perm_portal = perm.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Id sorted_value = perm.ReadPortal().Get(i);
vtkm::Id sorted_value = perm_portal.Get(i);
VTKM_TEST_ASSERT((OFFSET + (i / (ARRAY_SIZE / 50))) == sorted_value,
"ArrayZipPermutation improperly sorted");
}
@ -1162,12 +1177,14 @@ private:
Algorithm::SortByKey(keys, values);
auto values_portal = values.ReadPortal();
auto keys_portal = keys.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
//keys should be sorted from 1 to ARRAY_SIZE
//values should be sorted from (ARRAY_SIZE-1) to 0
Vec3 sorted_value = values.ReadPortal().Get(i);
vtkm::Id sorted_key = keys.ReadPortal().Get(i);
Vec3 sorted_value = values_portal.Get(i);
vtkm::Id sorted_key = keys_portal.Get(i);
VTKM_TEST_ASSERT((sorted_key == (i + 1)), "Got bad SortByKeys key");
VTKM_TEST_ASSERT(test_equal(sorted_value, TestValue(ARRAY_SIZE - 1 - i, Vec3())),
@ -1176,12 +1193,14 @@ private:
// this will return everything back to what it was before sorting
Algorithm::SortByKey(keys, values, vtkm::SortGreater());
values_portal = values.ReadPortal();
keys_portal = keys.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
//keys should be sorted from ARRAY_SIZE to 1
//values should be sorted from 0 to (ARRAY_SIZE-1)
Vec3 sorted_value = values.ReadPortal().Get(i);
vtkm::Id sorted_key = keys.ReadPortal().Get(i);
Vec3 sorted_value = values_portal.Get(i);
vtkm::Id sorted_key = keys_portal.Get(i);
VTKM_TEST_ASSERT((sorted_key == (ARRAY_SIZE - i)), "Got bad SortByKeys key");
VTKM_TEST_ASSERT(test_equal(sorted_value, TestValue(i, Vec3())), "Got bad SortByKeys value");
@ -1189,12 +1208,14 @@ private:
//this is here to verify we can sort by vtkm::Vec
Algorithm::SortByKey(values, keys);
values_portal = values.ReadPortal();
keys_portal = keys.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
//keys should be sorted from ARRAY_SIZE to 1
//values should be sorted from 0 to (ARRAY_SIZE-1)
Vec3 sorted_value = values.ReadPortal().Get(i);
vtkm::Id sorted_key = keys.ReadPortal().Get(i);
Vec3 sorted_value = values_portal.Get(i);
vtkm::Id sorted_key = keys_portal.Get(i);
VTKM_TEST_ASSERT((sorted_key == (ARRAY_SIZE - i)), "Got bad SortByKeys key");
VTKM_TEST_ASSERT(test_equal(sorted_value, TestValue(i, Vec3())), "Got bad SortByKeys value");
@ -1229,10 +1250,10 @@ private:
temp.ReleaseResourcesExecution(); // Make sure not counting on execution.
VTKM_TEST_ASSERT(temp.GetNumberOfValues() == 50,
"Unique did not resize array (or size did not copy to control).");
auto portal = handle.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Id value = handle.ReadPortal().Get(i);
vtkm::Id value = portal.Get(i);
VTKM_TEST_ASSERT(value == i % 50, "Got bad LowerBounds value with SortLess");
}
}
@ -1266,9 +1287,10 @@ private:
VTKM_TEST_ASSERT(temp.GetNumberOfValues() == 50,
"Unique did not resize array (or size did not copy to control).");
auto portal = handle.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Id value = handle.ReadPortal().Get(i);
vtkm::Id value = portal.Get(i);
VTKM_TEST_ASSERT(value == (i % 50) + 1, "Got bad UpperBounds value with SortLess");
}
}
@ -1490,10 +1512,12 @@ private:
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto keys_portal = keysOut.ReadPortal();
auto values_portal = valuesOut.ReadPortal();
for (vtkm::Id i = 0; i < expectedLength; ++i)
{
const vtkm::Id k = keysOut.ReadPortal().Get(i);
const vtkm::Id v = valuesOut.ReadPortal().Get(i);
const vtkm::Id k = keys_portal.Get(i);
const vtkm::Id v = values_portal.Get(i);
VTKM_TEST_ASSERT(expectedKeys[i] == k, "Incorrect reduced key");
VTKM_TEST_ASSERT(expectedValues[i] == v, "Incorrect reduced value");
}
@ -1528,10 +1552,12 @@ private:
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto keys_portal = keysOut.ReadPortal();
auto values_portal = valuesOut.ReadPortal();
for (vtkm::Id i = 0; i < expectedLength; ++i)
{
const vtkm::Id k = keysOut.ReadPortal().Get(i);
const vtkm::Vec3f_64 v = valuesOut.ReadPortal().Get(i);
const vtkm::Id k = keys_portal.Get(i);
const vtkm::Vec3f_64 v = values_portal.Get(i);
VTKM_TEST_ASSERT(expectedKeys[i] == k, "Incorrect reduced key");
VTKM_TEST_ASSERT(expectedValues[i] == v, "Incorrect reduced vale");
}
@ -1564,11 +1590,12 @@ private:
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto keys_portal = keysOut.ReadPortal();
auto values_portal = valuesOut.ReadPortal();
for (vtkm::Id i = 0; i < expectedLength; ++i)
{
const vtkm::Id k = keysOut.ReadPortal().Get(i);
const vtkm::Id v = valuesOut.ReadPortal().Get(i);
const vtkm::Id k = keys_portal.Get(i);
const vtkm::Id v = values_portal.Get(i);
VTKM_TEST_ASSERT(expectedKeys[i] == k, "Incorrect reduced key");
VTKM_TEST_ASSERT(expectedValues[i] == v, "Incorrect reduced value");
}
@ -1619,9 +1646,10 @@ private:
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto values_portal = valuesOut.ReadPortal();
for (vtkm::Id i = 0; i < expectedLength; i++)
{
const vtkm::Id v = valuesOut.ReadPortal().Get(i);
const vtkm::Id v = values_portal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
}
}
@ -1661,9 +1689,10 @@ private:
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto values_portal = valuesOut.ReadPortal();
for (auto i = 0; i < expectedLength; i++)
{
const vtkm::Id v = valuesOut.ReadPortal().Get(i);
const vtkm::Id v = values_portal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
}
}
@ -1687,9 +1716,10 @@ private:
Algorithm::ScanInclusiveByKey(keys, values, valuesOut);
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto valuesPortal = valuesOut.ReadPortal();
for (auto i = 0; i < expectedLength; i++)
{
const vtkm::Id v = valuesOut.ReadPortal().Get(i);
const vtkm::Id v = valuesPortal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
}
}
@ -1712,9 +1742,10 @@ private:
Algorithm::ScanInclusiveByKey(keys, values, values);
VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto valuesPortal = values.ReadPortal();
for (auto i = 0; i < expectedLength; i++)
{
const vtkm::Id v = values.ReadPortal().Get(i);
const vtkm::Id v = valuesPortal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
}
}
@ -1738,9 +1769,10 @@ private:
Algorithm::ScanInclusiveByKey(keys, castValues, castValues);
VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto valuesPortal = values.ReadPortal();
for (auto i = 0; i < expectedLength; i++)
{
const vtkm::Id v = values.ReadPortal().Get(i);
const vtkm::Id v = valuesPortal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
}
}
@ -1792,9 +1824,10 @@ private:
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto valuesPortal = valuesOut.ReadPortal();
for (auto i = 0; i < expectedLength; i++)
{
const vtkm::Id v = valuesOut.ReadPortal().Get(i);
const vtkm::Id v = valuesPortal.Get(i);
VTKM_TEST_ASSERT(expectedValues[i] == v, "Incorrect scanned value");
}
}
@ -1835,9 +1868,10 @@ private:
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto valuesPortal = valuesOut.ReadPortal();
for (vtkm::Id i = 0; i < expectedLength; i++)
{
const vtkm::Id v = valuesOut.ReadPortal().Get(i);
const vtkm::Id v = valuesPortal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
}
}
@ -1864,9 +1898,10 @@ private:
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto valuesPortal = valuesOut.ReadPortal();
for (vtkm::Id i = 0; i < expectedLength; i++)
{
const vtkm::Id v = valuesOut.ReadPortal().Get(i);
const vtkm::Id v = valuesPortal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
}
}
@ -1890,9 +1925,10 @@ private:
Algorithm::ScanExclusiveByKey(keys, values, values, init, vtkm::Add());
VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto valuesPortal = values.ReadPortal();
for (auto i = 0; i < expectedLength; i++)
{
const vtkm::Id v = values.ReadPortal().Get(i);
const vtkm::Id v = valuesPortal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
}
}
@ -1917,9 +1953,10 @@ private:
Algorithm::ScanExclusiveByKey(keys, castValues, castValues, init, vtkm::Add());
VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength,
"Got wrong number of output values");
auto valuesPortal = values.ReadPortal();
for (auto i = 0; i < expectedLength; i++)
{
const vtkm::Id v = values.ReadPortal().Get(i);
const vtkm::Id v = valuesPortal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
}
}
@ -1945,9 +1982,10 @@ private:
vtkm::Id sum = Algorithm::ScanInclusive(array, array);
VTKM_TEST_ASSERT(sum == OFFSET * ARRAY_SIZE, "Got bad sum from Inclusive Scan");
auto portal = array.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
const vtkm::Id value = array.ReadPortal().Get(i);
const vtkm::Id value = portal.Get(i);
VTKM_TEST_ASSERT(value == (i + 1) * OFFSET, "Incorrect partial sum");
}
@ -1982,18 +2020,18 @@ private:
vtkm::Float64 product = Algorithm::ScanInclusive(array, array, vtkm::Multiply());
VTKM_TEST_ASSERT(product == 0.0f, "ScanInclusive product result not 0.0");
auto portal = array.ReadPortal();
for (std::size_t i = 0; i < mid; ++i)
{
vtkm::Id index = static_cast<vtkm::Id>(i);
vtkm::Float64 expected = pow(1.01, static_cast<vtkm::Float64>(i + 1));
vtkm::Float64 got = array.ReadPortal().Get(index);
vtkm::Float64 got = portal.Get(index);
VTKM_TEST_ASSERT(test_equal(got, expected), "Incorrect results for ScanInclusive");
}
for (std::size_t i = mid; i < ARRAY_SIZE; ++i)
{
vtkm::Id index = static_cast<vtkm::Id>(i);
VTKM_TEST_ASSERT(array.ReadPortal().Get(index) == 0.0f,
"Incorrect results for ScanInclusive");
VTKM_TEST_ASSERT(portal.Get(index) == 0.0f, "Incorrect results for ScanInclusive");
}
}
@ -2042,10 +2080,12 @@ private:
VTKM_TEST_ASSERT(sum == OFFSET + (ARRAY_SIZE - 1),
"Got bad sum from Inclusive Scan with comparison object");
auto array_portal = array.ReadPortal();
auto result_portal = result.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
const vtkm::Id input_value = array.ReadPortal().Get(i);
const vtkm::Id result_value = result.ReadPortal().Get(i);
const vtkm::Id input_value = array_portal.Get(i);
const vtkm::Id result_value = result_portal.Get(i);
VTKM_TEST_ASSERT(input_value == result_value, "Incorrect partial sum");
}
@ -2053,11 +2093,11 @@ private:
sum = Algorithm::ScanInclusive(array, array, vtkm::Maximum());
VTKM_TEST_ASSERT(sum == OFFSET + (ARRAY_SIZE - 1),
"Got bad sum from Inclusive Scan with comparison object");
array_portal = array.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
const vtkm::Id input_value = array.ReadPortal().Get(i);
const vtkm::Id result_value = result.ReadPortal().Get(i);
const vtkm::Id input_value = array_portal.Get(i);
const vtkm::Id result_value = result_portal.Get(i);
VTKM_TEST_ASSERT(input_value == result_value, "Incorrect partial sum");
}
}
@ -2084,9 +2124,10 @@ private:
std::cout << " Sum that was returned " << sum << std::endl;
VTKM_TEST_ASSERT(sum == (OFFSET * ARRAY_SIZE), "Got bad sum from Exclusive Scan");
auto portal = array.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
const vtkm::Id value = array.ReadPortal().Get(i);
const vtkm::Id value = portal.Get(i);
VTKM_TEST_ASSERT(value == i * OFFSET, "Incorrect partial sum");
}
@ -2127,18 +2168,18 @@ private:
VTKM_TEST_ASSERT(product == 0.0f, "ScanExclusive product result not 0.0");
VTKM_TEST_ASSERT(array.ReadPortal().Get(0) == initialValue,
"ScanExclusive result's first value != initialValue");
auto portal = array.ReadPortal();
for (std::size_t i = 1; i <= mid; ++i)
{
vtkm::Id index = static_cast<vtkm::Id>(i);
vtkm::Float64 expected = pow(1.01, static_cast<vtkm::Float64>(i)) * initialValue;
vtkm::Float64 got = array.ReadPortal().Get(index);
vtkm::Float64 got = portal.Get(index);
VTKM_TEST_ASSERT(test_equal(got, expected), "Incorrect results for ScanExclusive");
}
for (std::size_t i = mid + 1; i < ARRAY_SIZE; ++i)
{
vtkm::Id index = static_cast<vtkm::Id>(i);
VTKM_TEST_ASSERT(array.ReadPortal().Get(index) == 0.0f,
"Incorrect results for ScanExclusive");
VTKM_TEST_ASSERT(portal.Get(index) == 0.0f, "Incorrect results for ScanExclusive");
}
}
@ -2472,10 +2513,11 @@ private:
std::uniform_int_distribution<vtkm::Id> distribution(0, COPY_ARRAY_SIZE - 100 - 1);
vtkm::Id numberOfSamples = (COPY_ARRAY_SIZE - 100) / 100;
auto outputPortal = output.ReadPortal();
for (vtkm::Id i = 0; i < numberOfSamples; ++i)
{
vtkm::Id randomIndex = distribution(generator);
T value = output.ReadPortal().Get(randomIndex);
T value = outputPortal.Get(randomIndex);
VTKM_TEST_ASSERT(value == testData[static_cast<size_t>(randomIndex) + 100],
"Got bad value (CopySubRange 2)");
}
@ -2492,13 +2534,14 @@ private:
std::uniform_int_distribution<vtkm::Id> distribution(0, COPY_ARRAY_SIZE - 1);
vtkm::Id numberOfSamples = COPY_ARRAY_SIZE / 50;
auto portal = output.ReadPortal();
for (vtkm::Id i = 0; i < numberOfSamples; ++i)
{
vtkm::Id randomIndex = distribution(generator);
T value = output.ReadPortal().Get(randomIndex);
T value = portal.Get(randomIndex);
VTKM_TEST_ASSERT(value == testData[static_cast<size_t>(randomIndex)],
"Got bad value (CopySubRange 5)");
value = output.ReadPortal().Get(COPY_ARRAY_SIZE + randomIndex);
value = portal.Get(COPY_ARRAY_SIZE + randomIndex);
VTKM_TEST_ASSERT(value == testData[static_cast<size_t>(randomIndex)],
"Got bad value (CopySubRange 5)");
}
@ -2515,13 +2558,14 @@ private:
"CopySubRange needs too resize Array");
std::uniform_int_distribution<vtkm::Id> distribution(0, COPY_ARRAY_SIZE - 1);
vtkm::Id numberOfSamples = COPY_ARRAY_SIZE / 50;
auto portal = output.ReadPortal();
for (vtkm::Id i = 0; i < numberOfSamples; ++i)
{
vtkm::Id randomIndex = distribution(generator);
T value = output.ReadPortal().Get(randomIndex);
T value = portal.Get(randomIndex);
VTKM_TEST_ASSERT(value == testData[static_cast<size_t>(randomIndex)],
"Got bad value (CopySubRange 6)");
value = output.ReadPortal().Get(COPY_ARRAY_SIZE + randomIndex);
value = portal.Get(COPY_ARRAY_SIZE + randomIndex);
VTKM_TEST_ASSERT(value == testData[static_cast<size_t>(randomIndex)],
"Got bad value (CopySubRange 6)");
}
@ -2608,9 +2652,10 @@ private:
Algorithm::Copy(input, temp);
std::vector<vtkm::Id>::const_iterator c = testData.begin();
auto portal = temp.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i, ++c)
{
vtkm::Float64 value = temp.ReadPortal().Get(i);
vtkm::Float64 value = portal.Get(i);
VTKM_TEST_ASSERT(value == static_cast<vtkm::Float64>(*c), "Got bad value (Copy)");
}
}

@ -450,13 +450,15 @@ private:
dispatcher.Invoke(composite, result);
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto compositePortal = composite.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
const vtkm::Vec<ValueType, 3> result_v = result.ReadPortal().Get(i);
const vtkm::Vec<ValueType, 3> result_v = resultPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, vtkm::Vec<ValueType, 3>(value)),
"CompositeVector Handle Failed");
const vtkm::Vec<ValueType, 3> result_c = composite.ReadPortal().Get(i);
const vtkm::Vec<ValueType, 3> result_c = compositePortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_c, vtkm::Vec<ValueType, 3>(value)),
"CompositeVector Handle Failed");
}
@ -481,10 +483,12 @@ private:
std::cout << std::endl;
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto constantPortal = constant.ReadPortal();
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
const ValueType result_v = result.ReadPortal().Get(i);
const ValueType control_value = constant.ReadPortal().Get(i);
const ValueType result_v = resultPortal.Get(i);
const ValueType control_value = constantPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, value), "Counting Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value), "Counting Handle Control Failed");
}
@ -516,11 +520,13 @@ private:
std::cout << std::endl;
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto countingPortal = counting.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
const ValueType result_v = result.ReadPortal().Get(i);
const ValueType result_v = resultPortal.Get(i);
const ValueType correct_value = ValueType(component_value);
const ValueType control_value = counting.ReadPortal().Get(i);
const ValueType control_value = countingPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Counting Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value), "Counting Handle Control Failed");
component_value = ComponentType(component_value + ComponentType(1));
@ -549,11 +555,13 @@ private:
dispatcher.Invoke(implicit, result);
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto implicitPortal = implicit.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
const ValueType result_v = result.ReadPortal().Get(i);
const ValueType result_v = resultPortal.Get(i);
const ValueType correct_value = functor(i);
const ValueType control_value = implicit.ReadPortal().Get(i);
const ValueType control_value = implicitPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Implicit Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value), "Implicit Handle Failed");
}
@ -602,15 +610,19 @@ private:
dispatcher.Invoke(concatenate, result);
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto implicitPortal = implicit.ReadPortal();
auto basicPortal = basic.ReadPortal();
auto concatPortal = concatenate.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
const ValueType result_v = result.ReadPortal().Get(i);
const ValueType result_v = resultPortal.Get(i);
ValueType correct_value;
if (i < implicitLen)
correct_value = implicit.ReadPortal().Get(i);
correct_value = implicitPortal.Get(i);
else
correct_value = basic.ReadPortal().Get(i - implicitLen);
const ValueType control_value = concatenate.ReadPortal().Get(i);
correct_value = basicPortal.Get(i - implicitLen);
const ValueType control_value = concatPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
"ArrayHandleConcatenate as Input Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
@ -656,14 +668,17 @@ private:
dispatcher.Invoke(permutation, result);
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto implicitPortal = implicit.ReadPortal();
auto permutationPortal = permutation.ReadPortal();
for (vtkm::Id i = 0; i < counting_length; ++i)
{
const vtkm::Id value_index = i;
const vtkm::Id key_index = start_pos + i;
const ValueType result_v = result.ReadPortal().Get(value_index);
const ValueType correct_value = implicit.ReadPortal().Get(key_index);
const ValueType control_value = permutation.ReadPortal().Get(value_index);
const ValueType result_v = resultPortal.Get(value_index);
const ValueType correct_value = implicitPortal.Get(key_index);
const ValueType control_value = permutationPortal.Get(value_index);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Implicit Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value), "Implicit Handle Failed");
}
@ -702,14 +717,17 @@ private:
dispatcher.Invoke(view, result);
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto implicitPortal = implicit.ReadPortal();
auto viewPortal = view.ReadPortal();
for (vtkm::Id i = 0; i < counting_length; ++i)
{
const vtkm::Id value_index = i;
const vtkm::Id key_index = start_pos + i;
const ValueType result_v = result.ReadPortal().Get(value_index);
const ValueType correct_value = implicit.ReadPortal().Get(key_index);
const ValueType control_value = view.ReadPortal().Get(value_index);
const ValueType result_v = resultPortal.Get(value_index);
const ValueType correct_value = implicitPortal.Get(key_index);
const ValueType control_value = viewPortal.Get(value_index);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Implicit Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value), "Implicit Handle Failed");
}
@ -743,11 +761,13 @@ private:
dispatcher.Invoke(transformed, result);
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto transformedPortal = transformed.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
const ValueType result_v = result.ReadPortal().Get(i);
const ValueType result_v = resultPortal.Get(i);
const ValueType correct_value = functor(TestValue(i, ValueType()));
const ValueType control_value = transformed.ReadPortal().Get(i);
const ValueType control_value = transformedPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Transform Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value), "Transform Handle Control Failed");
}
@ -781,11 +801,13 @@ private:
dispatcher.Invoke(transformed, result);
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto transformedPortal = transformed.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
const ValueType result_v = result.ReadPortal().Get(i);
const ValueType result_v = resultPortal.Get(i);
const ValueType correct_value = functor(TestValue(i, ValueType()));
const ValueType control_value = transformed.ReadPortal().Get(i);
const ValueType control_value = transformedPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Transform Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value), "Transform Handle Control Failed");
}
@ -823,11 +845,13 @@ private:
dispatcher.Invoke(countingTransformed, result);
//verify that the control portal works
auto resultPortal = result.ReadPortal();
auto countingPortal = countingTransformed.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
const OutputValueType result_v = result.ReadPortal().Get(i);
const OutputValueType result_v = resultPortal.Get(i);
const OutputValueType correct_value = functor(ValueType(component_value));
const OutputValueType control_value = countingTransformed.ReadPortal().Get(i);
const OutputValueType control_value = countingPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Transform Counting Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
"Transform Counting Handle Control Failed");
@ -856,10 +880,11 @@ private:
// verify results
vtkm::Id length = ARRAY_SIZE;
auto resultPortal = result.ReadPortal();
auto inputPortal = input.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
VTKM_TEST_ASSERT(result.ReadPortal().Get(i) ==
static_cast<CastToType>(input.ReadPortal().Get(i)),
VTKM_TEST_ASSERT(resultPortal.Get(i) == static_cast<CastToType>(inputPortal.Get(i)),
"Casting ArrayHandle Failed");
}
}
@ -887,10 +912,11 @@ private:
// verify results
vtkm::Id length = ARRAY_SIZE;
auto inputPortal = input.ReadPortal();
auto resultPortal = result.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
VTKM_TEST_ASSERT(input.ReadPortal().Get(i) ==
static_cast<vtkm::Id>(result.ReadPortal().Get(i)),
VTKM_TEST_ASSERT(inputPortal.Get(i) == static_cast<vtkm::Id>(resultPortal.Get(i)),
"Casting ArrayHandle Failed");
}
}
@ -986,9 +1012,10 @@ private:
//verify that the control portal works
vtkm::Id totalIndex = 0;
auto resultPortal = resultArray.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
{
const ValueType result = resultArray.ReadPortal().Get(index);
const ValueType result = resultPortal.Get(index);
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS;
componentIndex++)
{
@ -1034,13 +1061,14 @@ private:
//verify that the control portal works
vtkm::Id totalIndex = 0;
auto resultPortal = resultArray.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
{
const ValueType expectedValue = TestValue(index, ValueType());
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS;
componentIndex++)
{
const ComponentType result = resultArray.ReadPortal().Get(totalIndex);
const ComponentType result = resultPortal.Get(totalIndex);
VTKM_TEST_ASSERT(test_equal(result, expectedValue[componentIndex]),
"Result array got wrong value.");
totalIndex++;
@ -1199,9 +1227,10 @@ private:
dispatcher.Invoke(zip, result);
//verify that the control portal works
auto resultPortal = result.ReadPortal();
for (int i = 0; i < ARRAY_SIZE; ++i)
{
const PairType result_v = result.ReadPortal().Get(i);
const PairType result_v = resultPortal.Get(i);
const PairType correct_value(KeyType(static_cast<KeyComponentType>(ARRAY_SIZE - i)),
ValueType(static_cast<ValueComponentType>(i)));
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "ArrayHandleZip Failed as input");
@ -1320,11 +1349,13 @@ private:
std::cout << std::endl;
//verify that the control portal works
auto outputPortal = output.ReadPortal();
auto transformedPortal = transformed.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
const ValueType result_v = output.ReadPortal().Get(i);
const ValueType result_v = outputPortal.Get(i);
const ValueType correct_value = inverseFunctor(TestValue(i, ValueType()));
const ValueType control_value = transformed.ReadPortal().Get(i);
const ValueType control_value = transformedPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Transform Handle Failed");
VTKM_TEST_ASSERT(test_equal(functor(result_v), control_value),
"Transform Handle Control Failed");
@ -1364,11 +1395,13 @@ private:
std::cout << std::endl;
//verify that the control portal works
auto outputPortal = output.ReadPortal();
auto transformedPortal = transformed.ReadPortal();
for (vtkm::Id i = 0; i < length; ++i)
{
const ValueType result_v = output.ReadPortal().Get(i);
const ValueType result_v = outputPortal.Get(i);
const ValueType correct_value = inverseFunctor(TestValue(i, ValueType()));
const ValueType control_value = transformed.ReadPortal().Get(i);
const ValueType control_value = transformedPortal.Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value), "Transform Handle Failed");
VTKM_TEST_ASSERT(test_equal(functor(result_v), control_value),
"Transform Handle Control Failed");
@ -1407,10 +1440,12 @@ private:
std::cout << std::endl;
//now the two arrays we have zipped should have data inside them
auto keysPortal = result_keys.ReadPortal();
auto valsPortal = result_values.ReadPortal();
for (int i = 0; i < ARRAY_SIZE; ++i)
{
const KeyType result_key = result_keys.ReadPortal().Get(i);
const ValueType result_value = result_values.ReadPortal().Get(i);
const KeyType result_key = keysPortal.Get(i);
const ValueType result_value = valsPortal.Get(i);
VTKM_TEST_ASSERT(
test_equal(result_key, KeyType(static_cast<KeyComponentType>(ARRAY_SIZE - i))),

@ -168,12 +168,14 @@ public:
///// verify search result /////
bool passTest = true;
auto nnPortal = nnDis_Handle.ReadPortal();
auto bfPortal = bfnnDis_Handle.ReadPortal();
for (vtkm::Int32 i = 0; i < nTestingPoint; i++)
{
vtkm::Id workletIdx = nnId_Handle.WritePortal().Get(i);
vtkm::FloatDefault workletDis = nnDis_Handle.ReadPortal().Get(i);
vtkm::FloatDefault workletDis = nnPortal.Get(i);
vtkm::Id bfworkletIdx = bfnnId_Handle.WritePortal().Get(i);
vtkm::FloatDefault bfworkletDis = bfnnDis_Handle.ReadPortal().Get(i);
vtkm::FloatDefault bfworkletDis = bfPortal.Get(i);
if (workletIdx != bfworkletIdx)
{

@ -44,15 +44,18 @@ void ArrayHandleCPBasic(vtkm::cont::ArrayHandle<T> x,
//Make sure the values are correct.
vtkm::Vec<T, 3> val;
auto xPortal = x.ReadPortal();
auto yPortal = y.ReadPortal();
auto zPortal = z.ReadPortal();
auto cpPortal = cpArray.ReadPortal();
for (vtkm::Id i = 0; i < n; i++)
{
vtkm::Id idx0 = (i % (nx * ny)) % nx;
vtkm::Id idx1 = (i % (nx * ny)) / nx;
vtkm::Id idx2 = i / (nx * ny);
val =
vtkm::Vec<T, 3>(x.ReadPortal().Get(idx0), y.ReadPortal().Get(idx1), z.ReadPortal().Get(idx2));
VTKM_TEST_ASSERT(test_equal(cpArray.ReadPortal().Get(i), val), "Wrong value in array");
val = vtkm::Vec<T, 3>(xPortal.Get(idx0), yPortal.Get(idx1), zPortal.Get(idx2));
VTKM_TEST_ASSERT(test_equal(cpPortal.Get(i), val), "Wrong value in array");
}
}

@ -21,10 +21,10 @@ void TestArrayHandleIndex()
{
vtkm::cont::ArrayHandleIndex array(ARRAY_SIZE);
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Bad size.");
auto portal = array.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
VTKM_TEST_ASSERT(array.ReadPortal().Get(index) == index, "Index array has unexpected value.");
VTKM_TEST_ASSERT(portal.Get(index) == index, "Index array has unexpected value.");
}
}

@ -24,17 +24,19 @@ void TestArrayHandleReverseRead()
vtkm::cont::ArrayHandleIndex array(ARRAY_SIZE);
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Bad size.");
auto portal = array.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
VTKM_TEST_ASSERT(array.ReadPortal().Get(index) == index, "Index array has unexpected value.");
VTKM_TEST_ASSERT(portal.Get(index) == index, "Index array has unexpected value.");
}
vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandleIndex> reverse =
vtkm::cont::make_ArrayHandleReverse(array);
auto reversedPortal = reverse.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
VTKM_TEST_ASSERT(reverse.ReadPortal().Get(index) == array.ReadPortal().Get(9 - index),
VTKM_TEST_ASSERT(reversedPortal.Get(index) == portal.Get(9 - index),
"ArrayHandleReverse does not reverse array");
}
}
@ -52,10 +54,10 @@ void TestArrayHandleReverseWrite()
reverse.WritePortal().Set(index, index);
}
auto portal = handle.ReadPortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
VTKM_TEST_ASSERT(handle.ReadPortal().Get(index) == (9 - index),
"ArrayHandleReverse does not reverse array");
VTKM_TEST_ASSERT(portal.Get(index) == (9 - index), "ArrayHandleReverse does not reverse array");
}
}
@ -76,9 +78,11 @@ void TestArrayHandleReverseScanInclusiveByKey()
vtkm::Id expected[] = { 0, 1, 3, 6, 4, 9, 6, 7, 15, 9 };
vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<vtkm::Id>> expected_reversed =
vtkm::cont::make_ArrayHandleReverse(vtkm::cont::make_ArrayHandle(expected, 10));
auto outputPortal = output.ReadPortal();
auto reversePortal = expected_reversed.ReadPortal();
for (int i = 0; i < 10; i++)
{
VTKM_TEST_ASSERT(output.ReadPortal().Get(i) == expected_reversed.ReadPortal().Get(i),
VTKM_TEST_ASSERT(outputPortal.Get(i) == reversePortal.Get(i),
"ArrayHandleReverse as output of ScanInclusiveByKey");
}
std::cout << std::endl;

@ -103,10 +103,10 @@ void TestCellSetExplicit()
VTKM_TEST_ASSERT(result.GetNumberOfValues() == cellset.GetNumberOfCells(),
"result length not equal to number of cells");
auto portal = result.ReadPortal();
for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i)
{
VTKM_TEST_ASSERT(result.ReadPortal().Get(i) == cellset.GetNumberOfPointsInCell(i),
"incorrect result");
VTKM_TEST_ASSERT(portal.Get(i) == cellset.GetNumberOfPointsInCell(i), "incorrect result");
}
std::cout << "\tTesting CellToPoint\n";
@ -116,9 +116,10 @@ void TestCellSetExplicit()
"result length not equal to number of points");
vtkm::Id expected1[] = { 1, 2, 2, 1, 2, 4, 4, 2, 2, 1, 2 };
portal = result.ReadPortal();
for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i)
{
VTKM_TEST_ASSERT(result.ReadPortal().Get(i) == expected1[i], "incorrect result");
VTKM_TEST_ASSERT(portal.Get(i) == expected1[i], "incorrect result");
}
std::cout << "----------------------------------------------------\n";
@ -130,10 +131,10 @@ void TestCellSetExplicit()
VTKM_TEST_ASSERT(result.GetNumberOfValues() == cellset.GetNumberOfCells(),
"result length not equal to number of cells");
portal = result.ReadPortal();
for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i)
{
VTKM_TEST_ASSERT(result.ReadPortal().Get(i) == cellset.GetNumberOfPointsInCell(i),
"incorrect result");
VTKM_TEST_ASSERT(portal.Get(i) == cellset.GetNumberOfPointsInCell(i), "incorrect result");
}
std::cout << "\tTesting CellToPoint\n";
@ -143,9 +144,10 @@ void TestCellSetExplicit()
"result length not equal to number of points");
vtkm::Id expected2[] = { 0, 1, 1, 0, 0, 2, 2, 0, 2, 0, 1 };
portal = result.ReadPortal();
for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i)
{
VTKM_TEST_ASSERT(result.ReadPortal().Get(i) == expected2[i], "incorrect result at ", i);
VTKM_TEST_ASSERT(portal.Get(i) == expected2[i], "incorrect result at ", i);
}
std::cout << "----------------------------------------------------\n";

@ -81,20 +81,24 @@ std::vector<vtkm::Id> ComputeCellToPointExpected(const CellSetType& cellset,
vtkm::worklet::DispatcherMapTopology<CellsOfPoint>().Invoke(cellset, indexOffsets, connectivity);
std::vector<bool> permutationMask(static_cast<std::size_t>(cellset.GetNumberOfCells()), false);
auto permPortal = permutation.ReadPortal();
for (vtkm::Id i = 0; i < permutation.GetNumberOfValues(); ++i)
{
permutationMask[static_cast<std::size_t>(permutation.ReadPortal().Get(i))] = true;
permutationMask[static_cast<std::size_t>(permPortal.Get(i))] = true;
}
vtkm::Id numberOfPoints = cellset.GetNumberOfPoints();
std::vector<vtkm::Id> expected(static_cast<std::size_t>(numberOfPoints), 0);
auto indexPortal = indexOffsets.ReadPortal();
auto numPortal = numIndices.ReadPortal();
auto connPortal = connectivity.ReadPortal();
for (vtkm::Id i = 0; i < numberOfPoints; ++i)
{
vtkm::Id offset = indexOffsets.ReadPortal().Get(i);
vtkm::Id count = numIndices.ReadPortal().Get(i);
vtkm::Id offset = indexPortal.Get(i);
vtkm::Id count = numPortal.Get(i);
for (vtkm::Id j = 0; j < count; ++j)
{
vtkm::Id cellId = connectivity.ReadPortal().Get(offset++);
vtkm::Id cellId = connPortal.Get(offset++);
if (permutationMask[static_cast<std::size_t>(cellId)])
{
++expected[static_cast<std::size_t>(i)];
@ -119,10 +123,11 @@ vtkm::cont::CellSetPermutation<CellSetType, vtkm::cont::ArrayHandleCounting<vtkm
VTKM_TEST_ASSERT(result.GetNumberOfValues() == numberOfCells,
"result length not equal to number of cells");
auto resultPortal = result.ReadPortal();
auto permPortal = permutation.ReadPortal();
for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i)
{
VTKM_TEST_ASSERT(result.ReadPortal().Get(i) ==
cellset.GetNumberOfPointsInCell(permutation.ReadPortal().Get(i)),
VTKM_TEST_ASSERT(resultPortal.Get(i) == cellset.GetNumberOfPointsInCell(permPortal.Get(i)),
"incorrect result");
}
@ -132,9 +137,10 @@ vtkm::cont::CellSetPermutation<CellSetType, vtkm::cont::ArrayHandleCounting<vtkm
VTKM_TEST_ASSERT(result.GetNumberOfValues() == cellset.GetNumberOfPoints(),
"result length not equal to number of points");
auto expected = ComputeCellToPointExpected(cellset, permutation);
resultPortal = result.ReadPortal();
for (vtkm::Id i = 0; i < result.GetNumberOfValues(); ++i)
{
VTKM_TEST_ASSERT(result.ReadPortal().Get(i) == expected[static_cast<std::size_t>(i)],
VTKM_TEST_ASSERT(resultPortal.Get(i) == expected[static_cast<std::size_t>(i)],
"incorrect result");
}
std::cout << "Testing resource releasing in CellSetPermutation:\n";

@ -20,8 +20,8 @@ namespace
void DoWork()
{
VTKM_LOG_SCOPE_FUNCTION(vtkm::cont::LogLevel::Info);
VTKM_LOG_F(vtkm::cont::LogLevel::Info, "Sleeping for half a second...");
std::this_thread::sleep_for(std::chrono::milliseconds{ 500 });
VTKM_LOG_F(vtkm::cont::LogLevel::Info, "Sleeping for 5 milliseconds...");
std::this_thread::sleep_for(std::chrono::milliseconds{ 5 });
}
void Scopes(int level = 0)

@ -23,7 +23,7 @@ namespace
using TimerTestDevices =
vtkm::ListAppend<VTKM_DEFAULT_DEVICE_ADAPTER_LIST, vtkm::List<vtkm::cont::DeviceAdapterTagAny>>;
constexpr long long waitTimeMilliseconds = 250;
constexpr long long waitTimeMilliseconds = 25;
constexpr vtkm::Float64 waitTimeSeconds = vtkm::Float64(waitTimeMilliseconds) / 1000;
struct Waiter

@ -751,6 +751,11 @@ VTKM_CONT void ContourTreeAugmented::DoPostExecute(
// We need to augment at least with the boundary vertices when running in parallel, even if the user requested at the end only the unaugmented contour tree
unsigned int compRegularStruct =
(this->ComputeRegularStructure > 0) ? this->ComputeRegularStructure : 2;
auto localBlocksOriginPortal =
this->MultiBlockTreeHelper->MultiBlockSpatialDecomposition.LocalBlockOrigins.ReadPortal();
auto localBlocksSizesPortal =
this->MultiBlockTreeHelper->MultiBlockSpatialDecomposition.LocalBlockSizes.ReadPortal();
for (std::size_t bi = 0; bi < static_cast<std::size_t>(input.GetNumberOfPartitions()); bi++)
{
// create the local contour tree mesh
@ -763,10 +768,8 @@ VTKM_CONT void ContourTreeAugmented::DoPostExecute(
vtkm::cont::ArrayCopy(currField.GetData().template AsVirtual<T>(), fieldData);
auto currContourTreeMesh =
vtkm::filter::detail::MultiBlockContourTreeHelper::ComputeLocalContourTreeMesh<T>(
this->MultiBlockTreeHelper->MultiBlockSpatialDecomposition.LocalBlockOrigins.ReadPortal()
.Get(static_cast<vtkm::Id>(bi)),
this->MultiBlockTreeHelper->MultiBlockSpatialDecomposition.LocalBlockSizes.ReadPortal().Get(
static_cast<vtkm::Id>(bi)),
localBlocksOriginPortal.Get(static_cast<vtkm::Id>(bi)),
localBlocksSizesPortal.Get(static_cast<vtkm::Id>(bi)),
this->MultiBlockTreeHelper->MultiBlockSpatialDecomposition.GlobalSize,
fieldData,
MultiBlockTreeHelper->LocalContourTrees[bi],
@ -782,12 +785,8 @@ VTKM_CONT void ContourTreeAugmented::DoPostExecute(
localDataBlocks[bi]->Neighbours = currContourTreeMesh->Neighbours;
localDataBlocks[bi]->FirstNeighbour = currContourTreeMesh->FirstNeighbour;
localDataBlocks[bi]->MaxNeighbours = currContourTreeMesh->MaxNeighbours;
localDataBlocks[bi]->BlockOrigin =
this->MultiBlockTreeHelper->MultiBlockSpatialDecomposition.LocalBlockOrigins.ReadPortal().Get(
static_cast<vtkm::Id>(bi));
localDataBlocks[bi]->BlockSize =
this->MultiBlockTreeHelper->MultiBlockSpatialDecomposition.LocalBlockSizes.ReadPortal().Get(
static_cast<vtkm::Id>(bi));
localDataBlocks[bi]->BlockOrigin = localBlocksOriginPortal.Get(static_cast<vtkm::Id>(bi));
localDataBlocks[bi]->BlockSize = localBlocksSizesPortal.Get(static_cast<vtkm::Id>(bi));
localDataBlocks[bi]->GlobalSize =
this->MultiBlockTreeHelper->MultiBlockSpatialDecomposition.GlobalSize;
// We need to augment at least with the boundary vertices when running in parallel

@ -46,11 +46,13 @@ inline void FixupCellSet(vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
std::vector<vtkm::Id> permutationVec;
vtkm::Id connIdx = 0;
auto shapesPortal = shapes.ReadPortal();
auto indicesPortal = numIndices.ReadPortal();
auto connPortal = connectivity.ReadPortal();
for (vtkm::Id i = 0; i < shapes.GetNumberOfValues(); ++i)
{
vtkm::UInt8 shape = shapes.ReadPortal().Get(i);
vtkm::IdComponent numInds = numIndices.ReadPortal().Get(i);
auto connPortal = connectivity.ReadPortal();
vtkm::UInt8 shape = shapesPortal.Get(i);
vtkm::IdComponent numInds = indicesPortal.Get(i);
switch (shape)
{
case vtkm::CELL_SHAPE_VERTEX:

@ -86,9 +86,10 @@ void OutputArrayDebug(const vtkm::cont::ArrayHandle<vtkm::Vec<T, S>>& outputArra
PortalConstType readPortal = outputArray.ReadPortal();
vtkm::cont::ArrayPortalToIterators<PortalConstType> iterators(readPortal);
std::cout << name.c_str() << " " << outputArray.GetNumberOfValues() << "\n";
auto portal = outputArray.ReadPortal();
for (int i = 0; i < outputArray.GetNumberOfValues(); ++i)
{
std::cout << outputArray.ReadPortal().Get(i);
std::cout << portal.Get(i);
}
std::cout << std::endl;
}
@ -104,9 +105,10 @@ void OutputArrayDebug(
PortalConstType readPortal = outputArray.ReadPortal();
vtkm::cont::ArrayPortalToIterators<PortalConstType> iterators(readPortal);
std::cout << name.c_str() << " " << outputArray.GetNumberOfValues() << "\n";
auto outputPortal = outputArray.ReadPortal();
for (int i = 0; i < outputArray.GetNumberOfValues(); ++i)
{
std::cout << outputArray.ReadPortal().Get(i);
std::cout << outputPortal.Get(i);
}
std::cout << std::endl;
}

@ -514,12 +514,12 @@ void ValidateParticleAdvectionResult(const vtkm::worklet::ParticleAdvectionResul
{
VTKM_TEST_ASSERT(res.Particles.GetNumberOfValues() == nSeeds,
"Number of output particles does not match input.");
auto portal = res.Particles.ReadPortal();
for (vtkm::Id i = 0; i < nSeeds; i++)
{
VTKM_TEST_ASSERT(res.Particles.ReadPortal().Get(i).NumSteps <= maxSteps,
VTKM_TEST_ASSERT(portal.Get(i).NumSteps <= maxSteps,
"Too many steps taken in particle advection");
VTKM_TEST_ASSERT(res.Particles.ReadPortal().Get(i).Status.CheckOk(),
"Bad status in particle advection");
VTKM_TEST_ASSERT(portal.Get(i).Status.CheckOk(), "Bad status in particle advection");
}
}
@ -529,13 +529,11 @@ void ValidateStreamlineResult(const vtkm::worklet::StreamlineResult& res,
{
VTKM_TEST_ASSERT(res.PolyLines.GetNumberOfCells() == nSeeds,
"Number of output streamlines does not match input.");
auto portal = res.Particles.ReadPortal();
for (vtkm::Id i = 0; i < nSeeds; i++)
{
VTKM_TEST_ASSERT(res.Particles.ReadPortal().Get(i).NumSteps <= maxSteps,
"Too many steps taken in streamline");
VTKM_TEST_ASSERT(res.Particles.ReadPortal().Get(i).Status.CheckOk(),
"Bad status in streamline");
VTKM_TEST_ASSERT(portal.Get(i).NumSteps <= maxSteps, "Too many steps taken in streamline");
VTKM_TEST_ASSERT(portal.Get(i).Status.CheckOk(), "Bad status in streamline");
}
VTKM_TEST_ASSERT(res.Particles.GetNumberOfValues() == nSeeds,
"Number of output particles does not match input.");

@ -229,11 +229,12 @@ void TestDecomposeReconstruct3D(vtkm::Float64 cratio)
compressor.EvaluateReconstruction(inputArray, reconstructArray);
timer.Start();
auto reconstructPortal = reconstructArray.ReadPortal();
auto inputPortal = inputArray.ReadPortal();
for (vtkm::Id i = 0; i < reconstructArray.GetNumberOfValues(); i++)
{
VTKM_TEST_ASSERT(
test_equal(reconstructArray.ReadPortal().Get(i), inputArray.ReadPortal().Get(i)),
"WaveletCompressor 3D failed...");
VTKM_TEST_ASSERT(test_equal(reconstructPortal.Get(i), inputPortal.Get(i)),
"WaveletCompressor 3D failed...");
}
elapsedTime1 = timer.GetElapsedTime();
std::cout << "Verification time = " << elapsedTime1 << std::endl;
@ -296,11 +297,12 @@ void TestDecomposeReconstruct2D(vtkm::Float64 cratio)
compressor.EvaluateReconstruction(inputArray, reconstructArray);
timer.Start();
auto reconstructPortal = reconstructArray.ReadPortal();
auto inputPortal = inputArray.ReadPortal();
for (vtkm::Id i = 0; i < reconstructArray.GetNumberOfValues(); i++)
{
VTKM_TEST_ASSERT(
test_equal(reconstructArray.ReadPortal().Get(i), inputArray.ReadPortal().Get(i)),
"WaveletCompressor 2D failed...");
VTKM_TEST_ASSERT(test_equal(reconstructPortal.Get(i), inputPortal.Get(i)),
"WaveletCompressor 2D failed...");
}
elapsedTime1 = timer.GetElapsedTime();
std::cout << "Verification time = " << elapsedTime1 << std::endl;
@ -357,11 +359,12 @@ void TestDecomposeReconstruct1D(vtkm::Float64 cratio)
compressor.EvaluateReconstruction(inputArray, reconstructArray);
timer.Start();
auto reconstructPortal = reconstructArray.ReadPortal();
auto inputPortal = inputArray.ReadPortal();
for (vtkm::Id i = 0; i < reconstructArray.GetNumberOfValues(); i++)
{
VTKM_TEST_ASSERT(
test_equal(reconstructArray.ReadPortal().Get(i), inputArray.ReadPortal().Get(i)),
"WaveletCompressor 1D failed...");
VTKM_TEST_ASSERT(test_equal(reconstructPortal.Get(i), inputPortal.Get(i)),
"WaveletCompressor 1D failed...");
}
elapsedTime = timer.GetElapsedTime();
std::cout << "Verification time = " << elapsedTime << std::endl;

@ -314,9 +314,10 @@ public:
void Print2DArray(const std::string& str, const ArrayType& arr, vtkm::Id dimX)
{
std::cerr << str << std::endl;
auto portal = arr.ReadPortal();
for (vtkm::Id i = 0; i < arr.GetNumberOfValues(); i++)
{
std::cerr << arr.ReadPortal().Get(i) << " ";
std::cerr << portal.Get(i) << " ";
if (i % dimX == dimX - 1)
{
std::cerr << std::endl;