39TEST_CASE(
"PermutationTransfer::fromLocalPermutation reverse")
41 auto mpi = worldMPI();
46 arr.InitPair(
"test_arr", mpi);
47 arr.father->Resize(
nLocal);
48 arr.father->createGlobalMapping();
50 DNDS::index myOffset = (*arr.father->pLGlobalMapping)(mpi.rank, 0);
52 arr(
i, 0) = myOffset +
i;
55 std::vector<DNDS::index> old2new(
nLocal);
61 CHECK(pt.isLocalOnly);
63 CHECK(pt.localOld2New.size() ==
static_cast<size_t>(
nLocal));
67 CHECK(pt.newGlobalIndices[
i] == myOffset + old2new[
i]);
70 pt.transferRows(arr, mpi);
80 DNDS::index expectedValue = myOffset + expectedOldSlot;
81 CHECK(arr(
j, 0) == expectedValue);
89TEST_CASE(
"PermutationTransfer::fromLocalPermutation identity")
91 auto mpi = worldMPI();
95 arr.InitPair(
"test_arr", mpi);
96 arr.father->Resize(
nLocal);
97 arr.father->createGlobalMapping();
99 DNDS::index myOffset = (*arr.father->pLGlobalMapping)(mpi.rank, 0);
101 arr(
i, 0) = 100 + myOffset +
i;
104 std::vector<DNDS::index> old2new(
nLocal);
105 std::iota(old2new.begin(), old2new.end(),
DNDS::index{0});
108 CHECK(pt.isLocalOnly);
110 pt.transferRows(arr, mpi);
113 CHECK(arr(
i, 0) == 100 + myOffset +
i);
120TEST_CASE(
"PermutationTransfer::fromPartition all-local")
122 auto mpi = worldMPI();
126 arr.InitPair(
"test_arr", mpi);
127 arr.father->Resize(
nLocal);
128 arr.father->createGlobalMapping();
130 DNDS::index myOffset = (*arr.father->pLGlobalMapping)(mpi.rank, 0);
132 arr(
i, 0) = myOffset +
i;
135 std::vector<MPI_int> partition(
nLocal, mpi.rank);
139 CHECK(pt.isLocalOnly);
143 DNDS::index newOffset = pt.newGlobalOffsets[mpi.rank];
145 CHECK(pt.newGlobalIndices[
i] == newOffset +
i);
148 pt.transferRows(arr, mpi);
150 CHECK(arr(
i, 0) == myOffset +
i);
157TEST_CASE(
"PermutationTransfer::fromPartition round-robin")
159 auto mpi = worldMPI();
166 arr.InitPair(
"test_arr", mpi);
167 arr.father->Resize(
nLocal);
168 arr.father->createGlobalMapping();
170 DNDS::index myOffset = (*arr.father->pLGlobalMapping)(mpi.rank, 0);
172 arr(
i, 0) = myOffset +
i;
175 std::vector<MPI_int> partition(
nLocal);
177 partition[
i] =
static_cast<MPI_int>(
i % mpi.size);
181 CHECK_FALSE(pt.isLocalOnly);
184 pt.transferRows(arr, mpi);
192 if (
i % mpi.size == mpi.rank)
198 if (partition[
i] == mpi.rank)
206 for (
int r = 0;
r < mpi.size;
r++)
209 if (
i % mpi.size == mpi.rank)
213 CHECK(arr.father->Size() == totalReceive);
221 CHECK(val < globalTotal);
231 auto mpi = worldMPI();
235 arr.InitPair(
"test_arr", mpi);
236 arr.father->Resize(
nLocal);
237 arr.father->createGlobalMapping();
239 DNDS::index myOffset = (*arr.father->pLGlobalMapping)(mpi.rank, 0);
242 std::vector<MPI_int> partition(
nLocal, mpi.rank);
246 std::vector<DNDS::index> pullSet;
247 for (
int r = 0;
r < mpi.size;
r++)
251 DNDS::index rOffset = (*arr.father->pLGlobalMapping)(
r, 0);
253 pullSet.push_back(rOffset +
i);
255 std::sort(pullSet.begin(), pullSet.end());
257 auto lookup = pt.buildLookup(pullSet, mpi);
264 CHECK(newGlobal == pt.newGlobalIndices[
i]);
268 for (
auto oldGlobal : pullSet)
272 CHECK(newGlobal >= 0);
273 CHECK(newGlobal < pt.newGlobalOffsets.back());
284TEST_CASE(
"PermutationTransfer distributed lookup cross-rank")
286 auto mpi = worldMPI();
293 arr.InitPair(
"test_arr", mpi);
294 arr.father->Resize(
nLocal);
295 arr.father->createGlobalMapping();
297 DNDS::index myOffset = (*arr.father->pLGlobalMapping)(mpi.rank, 0);
300 MPI_int targetRank = (mpi.rank + 1) % mpi.size;
301 std::vector<MPI_int> partition(
nLocal, targetRank);
304 CHECK_FALSE(pt.isLocalOnly);
307 MPI_int sourceRank = (mpi.rank - 1 + mpi.size) % mpi.size;
308 DNDS::index sourceOffset = (*arr.father->pLGlobalMapping)(sourceRank, 0);
309 std::vector<DNDS::index> pullSet;
311 pullSet.push_back(sourceOffset +
i);
312 std::sort(pullSet.begin(), pullSet.end());
314 auto lookup = pt.buildLookup(pullSet, mpi);
322 CHECK(newGlobal >= pt.newGlobalOffsets[targetRank]);
323 CHECK(newGlobal < pt.newGlobalOffsets[targetRank + 1]);
327 for (
auto oldGlobal : pullSet)
331 CHECK(newGlobal >= pt.newGlobalOffsets[mpi.rank]);
332 CHECK(newGlobal < pt.newGlobalOffsets[mpi.rank + 1]);
340TEST_CASE(
"PermutationTransfer::transferRows CSR local permutation")
342 auto mpi = worldMPI();
347 arr.InitPair(
"test_csr", mpi);
348 arr.father->Resize(
nLocal);
350 arr.father->ResizeRow(
i,
static_cast<rowsize>(
i + 1));
351 arr.father->Compress();
352 arr.father->createGlobalMapping();
356 for (
rowsize j = 0;
j < arr.father->RowSize(
i);
j++)
357 arr(
i,
j) =
i * 100 +
j;
360 std::vector<DNDS::index> old2new(
nLocal);
365 pt.transferRows(arr, mpi);
372 CHECK(arr.father->RowSize(
j) == expectedRowSize);
373 for (
rowsize k = 0; k < expectedRowSize; k++)
374 CHECK(arr(
j, k) == oldSlot * 100 + k);