16 int np,
rank, nprow, npcol, rrow, rcol, nrow, ncol, pass;
17 int64_t i, nvals, row_pfx, col_pfx;
20 int * perm_row, * perm_col;
23 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24 MPI_Comm_size(MPI_COMM_WORLD, &np);
28 if (np%i == 0 && i > nprow && i <= np/i){
39 row_pfx += std::min(n%nprow, rrow);
40 if (rrow < n%nprow) nrow++;
43 col_pfx += std::min(n%npcol, rcol);
44 if (rcol < n%npcol) ncol++;
46 perms = (
int**)malloc(
sizeof(
int*)*2);
47 perm_row = (
int*)malloc(
sizeof(
int)*nrow);
48 perm_col = (
int*)malloc(
sizeof(
int)*ncol);
53 for (i=0; i<nrow; i++){
54 perm_row[i] = row_pfx+i;
56 for (i=0; i<ncol; i++){
57 perm_col[i] = col_pfx+i;
63 for (i=0; i<nvals; i++){
64 data[i] = (double)indices[i];
67 A.
write(nvals, indices, data);
71 World id_world(MPI_COMM_SELF);
74 if (rrow == rcol) Bsym = sym;
77 if (sym !=
NS && rrow > rcol){
82 Matrix<> B(nrow, ncol, Bsym, id_world);
91 for (i=0; i<nvals; i++){
92 if (data[i] != (
double)((indices[i]/nrow + col_pfx)*n + (indices[i]%nrow)+row_pfx)){
97 MPI_Allreduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
102 printf(
"{ permuted-read among multiple worlds } passed\n");
104 printf(
"{ permuted-read among multiple worlds } failed\n");
112 for (i=0; i<nvals; i++){
113 data[i] = n*n-((indices[i]/nrow + col_pfx)*n + (indices[i]%nrow)+row_pfx);
118 if (sym !=
NS && rrow > rcol){
120 A.permute(1.0, B, perms, 1.0);
123 Matrix<> B(nrow, ncol, Bsym, id_world);
124 B.
write(nvals,indices,data);
125 A.permute(1.0, B, perms, 1.0);
133 A.get_local_data(&nvals, &indices, &data);
136 for (i=0; i<nvals; i++){
137 if (
abs(data[i] - (
double)(n*n-indices[i])) >= 1.E-9){
141 MPI_Allreduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
145 printf(
"{ permuted read and write among multiple worlds } passed\n");
147 printf(
"{ permuted read and write among multiple worlds } failed\n");
160 char ** itr = std::find(begin, end, option);
161 if (itr != end && ++itr != end){
167 int main(
int argc,
char ** argv){
169 int const in_num = argc;
170 char ** input_str = argv;
172 MPI_Init(&argc, &argv);
173 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
174 MPI_Comm_size(MPI_COMM_WORLD, &np);
177 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
182 World dw(MPI_COMM_WORLD, argc, argv);
185 printf(
"Testing nonsymmetric multiworld permutation with n=%d\n",n);
189 if (np == sqrt(np)*sqrt(np)){
191 printf(
"Testing symmetric multiworld permutation with n=%d\n",n);
196 printf(
"Testing skew-symmetric multiworld permutation with n=%d\n",n);
201 printf(
"Testing asymmetric multiworld permutation with n=%d\n",n);
Matrix class which encapsulates a 2D tensor.
void permute(dtype beta, CTF_int::tensor &A, int *const *perms_A, dtype alpha)
Apply permutation to matrix, potentially extracting a slice B[i,j,...] = beta*B[...] + alpha*A[perms_A[0][i],perms_A[1][j],...].
int permute_multiworld(int n, int sym, World &dw)
an instance of the CTF library (world) on a MPI communicator
Scalar class which encapsulates a 0D tensor.
void get_local_data(int64_t *npair, int64_t **global_idx, dtype **data, bool nonzeros_only=false, bool unpack_sym=false) const
Gives the global indices and values associated with the local data.
int main(int argc, char **argv)
char * getCmdOption(char **begin, char **end, const std::string &option)
void write(int64_t npair, int64_t const *global_idx, dtype const *data)
writes in values associated with any set of indices The sparse data is defined in coordinate format...