17   double tr1, tr2, tr3, tr4;
    20   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    21   MPI_Comm_size(MPI_COMM_WORLD, &num_pes);
    36   for (i=0; i<
np; i++ ) pairs[i] = drand48();;
    37   A.
write(np, indices, pairs);
    41   for (i=0; i<
np; i++ ) pairs[i] = drand48();
    42   B.
write(np, indices, pairs);
    46   for (i=0; i<
np; i++ ) pairs[i] = drand48();
    47   C.
write(np, indices, pairs);
    51   for (i=0; i<
np; i++ ) pairs[i] = drand48();
    52   D.
write(np, indices, pairs);
    57   C1[
"ij"] = A[
"ia"]*B[
"ab"]*C[
"bc"]*D[
"cj"];
    58   C2[
"ij"] = D[
"ia"]*A[
"ab"]*B[
"bc"]*C[
"cj"];
    59   C3[
"ij"] = C[
"ia"]*D[
"ab"]*A[
"bc"]*B[
"cj"];
    60   C4[
"ij"] = B[
"ia"]*C[
"ab"]*D[
"bc"]*A[
"cj"];
    75     MPI_Reduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
    78     if (fabs(tr1-tr2)/tr1>1.E-10 || fabs(tr2-tr3)/tr2>1.E-10 || fabs(tr3-tr4)/tr3>1.E-10){
    82       printf(
"{ tr(ABCD) = tr(DABC) = tr(CDAB) = tr(BCDA) } failed\n");
    84       printf(
"{ tr(ABCD) = tr(DABC) = tr(CDAB) = tr(BCDA) } passed\n");
    87     MPI_Reduce(&pass, MPI_IN_PLACE, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
    97   char ** itr = std::find(begin, end, option);
    98   if (itr != end && ++itr != end){
   105 int main(
int argc, 
char ** argv){
   107   int const in_num = argc;
   108   char ** input_str = argv;
   110   MPI_Init(&argc, &argv);
   111   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   112   MPI_Comm_size(MPI_COMM_WORLD, &np);
   115     n = atoi(
getCmdOption(input_str, input_str+in_num, 
"-n"));
   121     World dw(MPI_COMM_WORLD, argc, argv);
   123       printf(
"Checking trace calculation n = %d, p = %d:\n",n,np);
   125     int pass = 
trace(n,dw);
 
Matrix class which encapsulates a 2D tensor. 
Vector class which encapsulates a 1D tensor. 
dtype reduce(OP op)
performs a reduction on the tensor 
int trace(int const n, World &dw)
an instance of the CTF library (world) on a MPI communicator 
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. 
char * getCmdOption(char **begin, char **end, const std::string &option)
int main(int argc, char **argv)
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...