Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
endomorphism_cust_sp.cxx
Go to the documentation of this file.
1 /*Copyright (c) 2011, Edgar Solomonik, all rights reserved.*/
2 
10 #include <ctf.hpp>
11 using namespace CTF;
12 
13 struct cust_sp_type {
14  char name[256];
15  int len_name;
16 };
17 
19  a.len_name = strlen(a.name);
20 }
21 
23  World & dw){
24 
25  int shapeN4[] = {NS,NS,NS,NS};
26  int sizeN4[] = {n+1,n,n+2,n+3};
27 
29 
30  Tensor<cust_sp_type> A(4, true, sizeN4, shapeN4, dw, s);
31 
32  if (dw.rank < n*n*n*n){
33  srand48(dw.rank);
34  int str_len = drand48()*255;
35 
36  cust_sp_type my_obj;
37  std::fill(my_obj.name, my_obj.name+str_len, 'a');
38  my_obj.name[str_len]='\0';
39 
40  int64_t idx = dw.rank;
41  A.write(1, &idx, &my_obj);
42  } else
43  A.write(0, NULL, NULL);
44 
46  // below is equivalent to A.scale(NULL, "ijkl", endo);
47  endo(A["ijkl"]);
48 
49  int64_t * indices;
50  cust_sp_type * loc_data;
51  int64_t nloc;
52  A.get_local_data(&nloc, &indices, &loc_data, true);
53 
54  int pass = 1;
55  if (pass){
56  for (int64_t i=0; i<nloc; i++){
57  if ((int)strlen(loc_data[i].name) != loc_data[i].len_name) pass = 0;
58  }
59  }
60  MPI_Allreduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
61 
62  if (dw.rank == 0){
63  if (pass){
64  printf("{ A[\"ijkl\"] = comp_len(A[\"ijkl\"]) } passed\n");
65  } else {
66  printf("{ A[\"ijkl\"] = comp_len(A[\"ijkl\"]) } failed\n");
67  }
68  }
69 
70  free(indices);
71  delete [] loc_data;
72 
73  return pass;
74 }
75 
76 
77 #ifndef TEST_SUITE
78 
79 char* getCmdOption(char ** begin,
80  char ** end,
81  const std::string & option){
82  char ** itr = std::find(begin, end, option);
83  if (itr != end && ++itr != end){
84  return *itr;
85  }
86  return 0;
87 }
88 
89 
90 int main(int argc, char ** argv){
91  int rank, np, n;
92  int const in_num = argc;
93  char ** input_str = argv;
94 
95  MPI_Init(&argc, &argv);
96  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
97  MPI_Comm_size(MPI_COMM_WORLD, &np);
98 
99  if (getCmdOption(input_str, input_str+in_num, "-n")){
100  n = atoi(getCmdOption(input_str, input_str+in_num, "-n"));
101  if (n < 0) n = 5;
102  } else n = 5;
103 
104 
105  {
106  World dw(MPI_COMM_WORLD, argc, argv);
107 
108  if (rank == 0){
109  printf("Computing user-defined endomorphism on a tensor over a set, A_ijkl = f(A_ijkl)\n");
110  }
111  endomorphism_cust_sp(n, dw);
112  }
113 
114 
115  MPI_Finalize();
116  return 0;
117 }
118 
124 #endif
Set class defined by a datatype and a min/max function (if it is partially ordered i...
Definition: set.h:280
char * getCmdOption(char **begin, char **end, const std::string &option)
def rank(self)
Definition: core.pyx:312
Definition: common.h:37
an instance of the CTF library (world) on a MPI communicator
Definition: world.h:19
string
Definition: core.pyx:456
int endomorphism_cust_sp(int n, World &dw)
int rank
rank of local processor
Definition: world.h:24
int main(int argc, char **argv)
Definition: apsp.cxx:17
an instance of a tensor within a CTF world
Definition: tensor.h:74
void comp_len(cust_sp_type &a)
def np(self)
Definition: core.pyx:315