22 double * pairs, * post_pairs_C, * pairs_A;
23 int64_t * indices, * indices_A;
25 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26 MPI_Comm_size(MPI_COMM_WORLD, &num_pes);
28 int shapeN4[] = {sym,
NS,sym,NS};
29 int sizeN4[] = {n,n,n,n};
38 for (i=0; i<np_A; i++ ) pairs_A[i] = drand48()-.5;
39 A.
write(np_A, indices_A, pairs_A);
41 for (i=0; i<
np; i++ ) pairs[i] = drand48()-.5;
42 B.
write(np, indices, pairs);
46 for (i=0; i<
np; i++ ) pairs[i] = drand48()-.5;
47 C.
write(np, indices, pairs);
51 C[
"ijkl"] = A[
"ijkl"]*B[
"klij"];
55 C.
contract(1.0, C,
"ijkl", B,
"klij", 0.0,
"ijkl", fctr);
57 post_pairs_C = (
double*)malloc(np_A*
sizeof(
double));
58 C.
read(np_A, indices_A, post_pairs_C);
61 for (i=0; i<np_A; i++){
62 if (fabs(pairs_A[i]) > 1.E-10 &&
63 fabs((
double)post_pairs_C[i]-(
double)pairs_A[i])/(
double)pairs_A[i]>1.E-10){
68 MPI_Reduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
70 printf(
"{ C[\"ijkl\"] = A[\"ijkl\"]*B[\"ijkl\"] } passed\n");
72 printf(
"{ C[\"ijkl\"] = A[\"ijkl\"]*B[\"ijkl\"] } failed\n");
75 MPI_Reduce(&pass, MPI_IN_PLACE, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
89 char ** itr = std::find(begin, end, option);
90 if (itr != end && ++itr != end){
97 int main(
int argc,
char ** argv){
99 int const in_num = argc;
100 char ** input_str = argv;
102 MPI_Init(&argc, &argv);
103 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
104 MPI_Comm_size(MPI_COMM_WORLD, &np);
107 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
113 World dw(MPI_COMM_WORLD, argc, argv);
116 printf(
"Computing C_ijkl = A_ijkl*B_kilj\n");
117 printf(
"Non-symmetric: NS = NS*NS weigh:\n");
121 printf(
"Symmetric: SY = SY*SY weigh:\n");
125 printf(
"(Anti-)Skew-symmetric: AS = AS*AS weigh:\n");
void contract(dtype alpha, CTF_int::tensor &A, char const *idx_A, CTF_int::tensor &B, char const *idx_B, dtype beta, char const *idx_C)
contracts C[idx_C] = beta*C[idx_C] + alpha*A[idx_A]*B[idx_B]
double divide(double a, double b)
int weigh_4D(int const n, int const sym, World &dw)
int main(int argc, char **argv)
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.
an instance of a tensor within a CTF world
void read(int64_t npair, Pair< dtype > *pairs)
Gives the values associated with any set of indices.
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...