29   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    30   MPI_Comm_size(MPI_COMM_WORLD, &np);
    32   perms = (
int**)malloc(
sizeof(
int*)*2);
    39   perm = (
int*)malloc(
sizeof(
int)*bi);
    50         if (perm[i] == perm[j]) cont = 1;
    57   World id_world(MPI_COMM_SELF);
    59   Matrix<> B(bi, bi, sym, id_world, 
"B");
    64   for (i=0; i<nvals; i++){
    67   B.
write(nvals, indices, data);
    81     printf(
"permute took %lf sec\n", t_stp-t_str);
    88   int lens_Arep[3] = {n,n,np};
    89   int symm[3] = {sym,
NS,NS};
    90   int lens_B3[3] = {bi,bi,1};
    92   Tensor<> A_rep(3, lens_Arep, symm, dw, 
"A_rep");
    93   Tensor<> B3(3, lens_B3, symm, id_world, 
"B3");
   100   perms_rep = (
int**)malloc(
sizeof(
int*)*3);
   104   perms_rep[2] = &
rank;
   107   A_rep.
permute(1.0, B3, perms_rep, 1.0);
   109   Tensor<> callback_B3(3, lens_B3, symm, id_world, 
"cB3");
   110   callback_B3.
permute(perms_rep, 1.0, A_rep, 1.0);
   114   callback_B3[
"ij"] = callback_B3[
"ij"] - B[
"ij"];
   117   pass = callback_B3.
norm2() < 1.E-10;
   121       printf(
"Callback from permuted write returned incorrect values\n");
   122       printf(
"{ sparse permuted slice among multiple worlds } failed\n");
   130   ERR[
"ij"] = A_rep[
"ijk"] - A[
"ij"];
   132   pass = ERR.
norm2() < 1.E-10;
   134   MPI_Allreduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
   138       printf(
"{ sparse permuted slice among multiple worlds } passed\n");
   140       printf(
"{ sparse permuted slice among multiple worlds } failed\n");
   150   char ** itr = std::find(begin, end, option);
   151   if (itr != end && ++itr != end){
   157 int main(
int argc, 
char ** argv){
   159   int const in_num = argc;
   160   char ** input_str = argv;
   162   MPI_Init(&argc, &argv);
   163   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   164   MPI_Comm_size(MPI_COMM_WORLD, &np);
   167     n = atoi(
getCmdOption(input_str, input_str+in_num, 
"-n"));
   172     b = atoi(
getCmdOption(input_str, input_str+in_num, 
"-b"));
   177     World dw(MPI_COMM_WORLD, argc, argv);
   180       printf(
"Testing nonsymmetric multiworld permutation with n=%d\n",n);
   185       printf(
"Testing symmetric multiworld permutation with n=%d\n",n);
   190       printf(
"Testing symmetric-hollow multiworld permutation with n=%d\n",n);
   195       printf(
"Testing asymmetric multiworld permutation with n=%d\n",n);
 int sparse_permuted_slice(int n, int b, int sym, World &dw)
tests sparse remote global write via permute function 
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],...]. 
an instance of the CTF library (world) on a MPI communicator 
dtype norm2()
computes the frobenius norm of the tensor (needs sqrt()!) 
char * getCmdOption(char **begin, char **end, const std::string &option)
int main(int argc, char **argv)
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. 
an instance of a tensor within a CTF world 
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...