16 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
17 MPI_Comm_size(MPI_COMM_WORLD, &num_pes);
30 Tensor<> A_rep(3, len3, YYN, ctf,
"B_rep");
31 Tensor<> B_rep(3, len3, YYN, ctf,
"A_rep");
44 for (i=0; i<size; i++){
45 values[i] = drand48();
47 A.
write(size, indices, values);
51 for (i=0; i<size; i++){
52 values[i] = drand48();
54 B.
write(size, indices, values);
58 C_ans[
"ij"] = A[
"ik"]*B[
"kj"];
59 A_rep[
"ijk"] += A[
"ij"];
60 B_rep[
"ijk"] += B[
"ij"];
61 Z[
"ijk"] += A_rep[
"ijk"]*B_rep[
"ijk"];
63 Cs[
"i"] += A[
"ik"]*B[
"ik"];
66 C[
"ij"] -= ((double)n)*A[
"ij"]*B[
"ij"];
68 C[
"ij"] -= As[
"i"]*B[
"ij"];
69 C[
"ij"] -= A[
"ij"]*Bs[
"j"];
94 if (rank == 0) printf(
"A:\n");
96 if (rank == 0) printf(
"B:\n");
98 if (rank == 0) printf(
"C_ans:\n");
100 if (rank == 0) printf(
"C:\n");
104 Diff[
"ij"] += C[
"ij"];
105 Diff[
"ij"] -= C_ans[
"ij"];
106 double nrm = sqrt((
double)(Diff[
"ij"]*Diff[
"ij"]));
107 int pass = (nrm <=1.E-10);
108 if (nrm > 1.E-10 && rank == 0) printf(
"nrm = %lf\n",nrm);
111 MPI_Reduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
112 if (pass) printf(
"{ C[\"(ij)\"] = A[\"(ik)\"]*B[\"(kj)\"] } passed\n");
113 else printf(
"{ C[\"(ij)\"] = A[\"(ik)\"]*B[\"(kj)\"] } failed\n");
115 MPI_Reduce(&pass, MPI_IN_PLACE, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
123 char ** itr = std::find(begin, end, option);
124 if (itr != end && ++itr != end){
131 int main(
int argc,
char ** argv){
133 int const in_num = argc;
134 char ** input_str = argv;
136 MPI_Init(&argc, &argv);
137 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
138 MPI_Comm_size(MPI_COMM_WORLD, &np);
141 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
146 World dw(MPI_COMM_WORLD, argc, argv);
148 printf(
"Computing C_(ij) = A_(ik)*B_(kj)\n");
Matrix class which encapsulates a 2D tensor.
Vector class which encapsulates a 1D tensor.
an instance of the CTF library (world) on a MPI communicator
int main(int argc, char **argv)
char * getCmdOption(char **begin, char **end, const std::string &option)
void print(FILE *fp, dtype cutoff) const
prints tensor data to file using process 0 (modify print(...) overload in set.h if you would like a d...
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 fast_sym(int const n, World &ctf)
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...