5from numpy.random
import MT19937
6from numpy.random
import RandomState, SeedSequence
10 arrayRU = DNDS.Array_d_I_I_N()
11 rsize = np.linspace(3, 10, 32, dtype=np.int32)
12 arrayRU.Resize(32, rsize)
13 arrayRU_rstart = arrayRU.getRowStart()
17 np.concatenate((np.array([0]), rsize.cumsum())),
22 scalarBuf = np.zeros((), dtype=np.int64)
25 assert scalarBuf == mpi.size
31 print(f
"arrayR3 is {type(arrayR3)}")
32 print(arrayR3.getRowStart().shape)
35 np.array(d, copy=
False)[:] = 1.335
39 arrayR3Trans.setFatherSon(arrayR3, arrayR3son)
40 arrayR3Trans.createFatherGlobalMapping()
41 global_size = arrayR3.getLGlobalMapping().
globalSize()
42 pullIdx = range(global_size)
44 pullIdx = np.array([0, 1, 2, 3], dtype=np.int64)
45 rank_pull = (mpi.rank - 1) % mpi.size
46 np.vectorize(
lambda x: arrayR3.getLGlobalMapping()(rank_pull, x))(pullIdx)
48 arrayR3Trans.createGhostMapping(pullIdx)
49 arrayR3Trans.createMPITypes()
50 arrayR3Trans.pullOnce()
52 print(f
"arrayR3son.size is {arrayR3son.Size()}")
53 assert arrayR3son.Size() == len(pullIdx)
54 assert np.all(np.array(arrayR3son.data()) == 1.335)
58 arrayR3Trans_1.setFatherSon(arrayR3, arrayR3son_1)
59 arrayR3Trans_1.BorrowGGIndexing(arrayR3Trans)
60 arrayR3Trans_1.createMPITypes()
61 arrayR3Trans_1.pullOnce()
63 assert arrayR3son_1.Size() == len(pullIdx)
64 assert np.all(np.array(arrayR3son_1.data()) == 1.335)
68 arrayIIPair = DNDS.ParArrayPair(
"q",
"I")
70 arrayIIPair.father =
DNDS.ParArray(
"q",
"I", init_args=(mpi,))
72 arrayIIPair.TransAttach()
73 arrayIIPair.father.Resize(44)
74 for iRow
in range(arrayIIPair.father.Size()):
75 arrayIIPair.father.ResizeRow(iRow, iRow % 4 + 2)
76 for j
in range(arrayIIPair.father.Rowsize(iRow)):
77 arrayIIPair.father[iRow, j] = 123123
78 arrayIIPair.father.Compress()
79 arrayIIPair.trans.createFatherGlobalMapping()
80 global_size = arrayIIPair.trans.LGlobalMapping.globalSize()
81 pullIdx = range(global_size)
82 arrayIIPair.trans.createGhostMapping(pullIdx)
83 arrayIIPair.trans.createMPITypes()
84 arrayIIPair.trans.pullOnce()
85 assert arrayIIPair.son.Size() == len(pullIdx)
86 assert (np.array(arrayIIPair.son.data()) == 123123).all()
90 arrayRU = DNDS.Array_d_I_I_N()
92 rsize = np.linspace(3, 10, 32, dtype=np.int32)
93 arrayRU.Resize(32, rsize)
96 assert not (np.diff(np.array(arrayRU.getRowStart())) - rsize).any()
98 for i
in range(arrayRU.Size()):
99 for j
in range(arrayRU.Rowsize(i)):
100 arrayRU[i, j] = i + j
101 arrayRUdata = np.array(arrayRU.data(), copy=
False)
104 print(arrayRUdata.shape)
105 for i
in range(arrayRU.Size()):
106 for j
in range(arrayRU.Rowsize(i)):
107 assert arrayRU[i, j] == i + j + 1
111 gt - arrayRU_rstart_ret
114 print(arrayRU_rstart_ret.shape)
115 arrayRU_rstart_ret_np = np.array(arrayRU_rstart_ret, copy=
False)
116 del arrayRU_rstart_ret
119 f
"if corrupted: { np.any(gt - arrayRU_rstart_ret_np)}"
126 for irow
in range(adj.Size()):
127 adj.ResizeRow(irow, irow % 3 + 1)
128 rowdata = np.array(adj[irow], copy=
False)
132 assert not np.any(np.array(adj.data()) - 3343)
135 transT = adj.getTrans()
137 adj_trans.setFatherSon(adj, adj_son)
138 adj_trans.createFatherGlobalMapping()
139 gsize = adj_trans.LGlobalMapping.globalSize()
140 pullIdx = range(gsize)
141 adj_trans.createGhostMapping(pullIdx)
142 adj_trans.createMPITypes()
144 assert adj_son.Size() == len(pullIdx)
145 assert np.all(np.array(adj_son.data()) == 3343)
152 val0 = np.array([1, 4, 5, 1, 3.2], dtype=np.float64)
153 for irow
in range(arr.Size()):
156 arrTrans = DNDS.ArrayTransformerFromParArray(arr)
157 arrTrans.setFatherSon(arr, arr_son)
158 arrTrans.createFatherGlobalMapping()
159 gsize = arrTrans.LGlobalMapping.globalSize()
160 pullIdx = range(gsize)
161 arrTrans.createGhostMapping(pullIdx)
162 arrTrans.createMPITypes()
165 assert arr_son.Size() == len(pullIdx)
166 for irow
in range(arr_son.Size()):
167 assert (np.array(arr_son[irow]) == val0).all()
174 mat0 = np.eye(3, 4, dtype=np.float64)
175 for irow
in range(arr.Size()):
178 arrTrans = DNDS.ArrayTransformerFromParArray(arr)
179 arrTrans.setFatherSon(arr, arr_son)
180 arrTrans.createFatherGlobalMapping()
181 gsize = arrTrans.LGlobalMapping.globalSize()
182 pullIdx = range(gsize)
183 arrTrans.createGhostMapping(pullIdx)
184 arrTrans.createMPITypes()
186 assert arr_son.Size() == len(pullIdx)
187 for irow
in range(arr_son.Size()):
188 assert (np.array(arr_son[irow]) == mat0).all()
196 rs = RandomState(MT19937(SeedSequence(123456789)))
199 val2 = rs.rand(65535, 1)
200 rowList = [val0, val1, val2]
202 for irow
in range(arr.Size()):
203 rowSiz = irow % 3 + 1
204 arr.InitializeWriteRow(irow, rowList[0:rowSiz])
207 arrTrans = DNDS.ArrayTransformerFromParArray(arr)
208 arrTrans.setFatherSon(arr, arr_son)
209 arrTrans.createFatherGlobalMapping()
210 gsize = arrTrans.LGlobalMapping.globalSize()
211 pullIdx = range(gsize)
212 arrTrans.createGhostMapping(pullIdx)
213 arrTrans.createMPITypes()
216 assert arr_son.Size() == len(pullIdx)
217 for irow
in range(arr_son.Size()):
218 for iMat
in range(arr_son.BatchSize(irow)):
219 assert (np.array(arr_son[irow, iMat]) == rowList[iMat]).all()
227 arr_son.Resize(0, 4, 5)
228 rs = RandomState(MT19937(SeedSequence(123456789)))
231 for irow
in range(arr.Size()):
232 arr.ResizeRow(irow, irow % 3 + 1)
233 cDat = np.concatenate((val0.reshape((1, 4, 5)),) * arr.BatchSize(irow), axis=0)
237 arrTrans = DNDS.ArrayTransformerFromParArray(arr)
238 arrTrans.setFatherSon(arr, arr_son)
239 arrTrans.createFatherGlobalMapping()
240 gsize = arrTrans.LGlobalMapping.globalSize()
241 pullIdx = range(gsize)
242 arrTrans.createGhostMapping(pullIdx)
243 arrTrans.createMPITypes()
246 assert arr_son.Size() == len(pullIdx)
251 for irow
in range(arr_son.Size()):
252 for iMat
in range(arr_son.BatchSize(irow)):
253 assert (np.array(arr_son[irow, iMat]) == val0).all()
257if __name__ ==
"__main__":
265 print(f
"is debugged == {DNDS.Debug.IsDebugged()}")
278 print(f
"{mpiC.rank} / {mpiC.size}, {mpiC.comm():x}")
Mesh-connectivity array: ParArray<index> whose operator[] yields an AdjacencyRow typed view.
CSR array storing a variable-sized batch of Eigen matrices per row.
ParArray<real> whose operator[] returns an Eigen::Map<Matrix<real, Ni, Nj>>.
CSR array whose rows store a batch of identically-sized Eigen matrices.
ParArray<real, N> whose operator[] returns an Eigen::Map<Vector>.
MPI-aware Array: adds a communicator, rank, and global index mapping.
MPI_int Allreduce(const void *sendbuf, void *recvbuf, MPI_int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
Wrapper over MPI_Allreduce.
test_arrayRU(DNDS.MPIInfo mpi)
test_adj(DNDS.MPIInfo mpi)
test_ArrayEigenMatrix(DNDS.MPIInfo mpi)
test_ArrayEigenUniMatrixBatch(DNDS.MPIInfo mpi)
test_ArrayEigenVector(DNDS.MPIInfo mpi)
test_ParArrayPair(DNDS.MPIInfo mpi)
test_ArrayEigenMatrixBatch(DNDS.MPIInfo mpi)
test_array_trans(DNDS.MPIInfo mpi, str mode="global")
test_all_reduce_scalar(DNDS.MPIInfo mpi)
Lightweight bundle of an MPI communicator and the calling rank's coordinates.