Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
test_suite.cxx
Go to the documentation of this file.
1 /*Copyright (c) 2011, Edgar Solomonik, all rights reserved.*/
2 #include <vector>
3 #include <numeric>
4 #include <ctf.hpp>
5 
6 #define TEST_SUITE
7 #include "weigh_4D.cxx"
8 #include "gemm_4D.cxx"
9 #include "scalar.cxx"
10 #include "diag_sym.cxx"
11 #include "diag_ctr.cxx"
12 #include "dft.cxx"
13 #include "ccsdt_t3_to_t2.cxx"
14 #include "readwrite_test.cxx"
15 #include "readall_test.cxx"
16 #include "subworld_gemm.cxx"
17 #include "multi_tsr_sym.cxx"
18 #include "repack.cxx"
19 #include "sy_times_ns.cxx"
20 #include "speye.cxx"
21 #include "sptensor_sum.cxx"
22 #include "endomorphism.cxx"
23 #include "endomorphism_cust.cxx"
24 #include "endomorphism_cust_sp.cxx"
25 #include "univar_function.cxx"
26 #include "bivar_function.cxx"
27 #include "bivar_transform.cxx"
28 
29 #include "../examples/trace.cxx"
30 #include "../examples/dft_3D.cxx"
31 #include "../examples/strassen.cxx"
32 #include "../examples/recursive_matmul.cxx"
33 #include "../examples/force_integration.cxx"
34 #include "../examples/force_integration_sparse.cxx"
35 #include "../examples/particle_interaction.cxx"
36 #include "../examples/spmv.cxx"
37 #include "../examples/jacobi.cxx"
38 #include "../examples/sssp.cxx"
39 #include "../examples/apsp.cxx"
40 #include "../examples/btwn_central.cxx"
41 #include "../examples/sparse_mp3.cxx"
42 #include "../examples/bitonic_sort.cxx"
43 #include "../examples/matmul.cxx"
44 
45 #include "../studies/fast_sym.cxx"
46 #include "../studies/fast_sym_4D.cxx"
47 
48 #ifdef USE_SCALAPACK
49 #include "../scalapack_tests/qr.cxx"
50 #include "../scalapack_tests/svd.cxx"
51 #endif
52 
53 
54 using namespace CTF;
55 
56 namespace CTF_int{
57  int64_t proc_bytes_used();
58 }
59 
60 char* getCmdOption(char ** begin,
61  char ** end,
62  const std::string & option){
63  char ** itr = std::find(begin, end, option);
64  if (itr != end && ++itr != end){
65  return *itr;
66  }
67  return 0;
68 }
69 
70 
71 int main(int argc, char ** argv){
72  int rank, np, n;
73  int in_num = argc;
74  char ** input_str = argv;
75 
76  //int nt;
77  //MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &nt);
78  MPI_Init(&argc, &argv);
79  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
80  MPI_Comm_size(MPI_COMM_WORLD, &np);
81 
82  if (getCmdOption(input_str, input_str+in_num, "-n")){
83  n = atoi(getCmdOption(input_str, input_str+in_num, "-n"));
84  if (n < 2) n = 6;
85  } else n = 6;
86 
87  if (rank == 0){
88  printf("Testing Cyclops Tensor Framework using %d processors\n",np);
89  }
90 
91  std::vector<int> pass;
92 
93  {
94  World dw(MPI_COMM_WORLD, argc, argv);
95 
96  if (rank == 0)
97  printf("Testing non-symmetric: NS = NS*NS weigh with n = %d:\n",n);
98  pass.push_back(weigh_4D(n, NS, dw));
99 
100  if (rank == 0)
101  printf("Testing symmetric: SY = SY*SY weigh with n = %d:\n",n);
102  pass.push_back(weigh_4D(n, SY, dw));
103 
104  if (rank == 0)
105  printf("Testing (anti-)skew-symmetric: AS = AS*AS weigh with n = %d:\n",n);
106  pass.push_back(weigh_4D(n, AS, dw));
107 
108  if (rank == 0)
109  printf("Testing symmetric-hollow: SH = SH*SH weigh with n = %d:\n",n);
110  pass.push_back(weigh_4D(n, SH, dw));
111 
112  if (rank == 0)
113  printf("Testing CCSDT T3->T2 with n= %d, m = %d:\n",n,n+1);
114  pass.push_back(ccsdt_t3_to_t2(n, n+1, dw));
115 
116  if (rank == 0)
117  printf("Testing non-symmetric: NS = NS*NS matmul with n = %d:\n",n*n);
118  pass.push_back(matmul(n*n, n*n, n*n, dw));
119 
120  if (rank == 0)
121  printf("Testing symmetric: SY = SY*SY matmul with n = %d:\n",n*n);
122  pass.push_back(matmul(n*n, n*n, n*n, dw, SY, SY, SY));
123 
124  if (rank == 0)
125  printf("Testing (anti-)skew-symmetric: AS = AS*AS matmul with n = %d:\n",n*n);
126  pass.push_back(matmul(n*n, n*n, n*n, dw, AS, AS, AS));
127 
128  if (rank == 0)
129  printf("Testing symmetric-hollow: SH = SH*SH matmul with n = %d:\n",n*n);
130  pass.push_back(matmul(n*n, n*n, n*n, dw, SH, SH, SH));
131 
132  if (rank == 0)
133  printf("Testing non-symmetric: NS = NS*NS 4D gemm with n = %d:\n",n);
134  pass.push_back(gemm_4D(n, NS, 1, dw));
135 
136  if (rank == 0)
137  printf("Testing symmetric: SY = SY*SY 4D gemm with n = %d:\n",n);
138  pass.push_back(gemm_4D(n, SY, 1, dw));
139 
140  if (rank == 0)
141  printf("Testing (anti-)skew-symmetric: AS = AS*AS 4D gemm with n = %d:\n",n);
142  pass.push_back(gemm_4D(n, AS, 1, dw));
143 
144  if (rank == 0)
145  printf("Testing symmetric-hollow: SH = SH*SH 4D gemm with n = %d:\n",n);
146  pass.push_back(gemm_4D(n, SH, 1, dw));
147 
148  if (rank == 0)
149  printf("Testing scalar operations\n");
150  pass.push_back(scalar(dw));
151 
152  if (rank == 0)
153  printf("Testing a 2D trace operation with n = %d:\n",n);
154  pass.push_back(trace(n, dw));
155 
156  if (rank == 0)
157  printf("Testing a diag sym operation with n = %d:\n",n);
158  pass.push_back(diag_sym(n, dw));
159 
160  if (rank == 0)
161  printf("Testing a diag ctr operation with n = %d m = %d:\n",n,n*n);
162  pass.push_back(diag_ctr(n, n*n, dw));
163 
164  if (rank == 0)
165  printf("Testing fast symmetric multiplication operation with n = %d:\n",n*n);
166  pass.push_back(fast_sym(n*n, dw));
167 
168  if (rank == 0)
169  printf("Testing 4D fast symmetric contraction operation with n = %d:\n",n);
170  pass.push_back(fast_sym_4D(n, dw));
171 
172  if (rank == 0)
173  printf("Testing multi-tensor symmetric contraction with m = %d n = %d:\n",n*n,n);
174  pass.push_back(multi_tsr_sym(n^2,n, dw));
175 
176  if (rank == 0)
177  printf("Testing gemm on subworld algorithm with n,m,k = %d div = 3:\n",n*n);
178  pass.push_back(test_subworld_gemm(n*n, n*n, n*n, 3, dw));
179 
180  if (rank == 0)
181  printf("Testing non-symmetric Strassen's algorithm with n = %d:\n", 2*n*n);
182  pass.push_back(strassen(2*n*n, NS, dw));
183 
184  if (rank == 0)
185  printf("Testing diagonal write with n = %d:\n",n);
186  pass.push_back(readwrite_test(n, dw));
187 
188  if (rank == 0)
189  printf("Testing readall test with n = %d m = %d:\n",n,n*n);
190  pass.push_back(readall_test(n, n*n, dw));
191 
192  if (rank == 0)
193  printf("Testing repack with n = %d:\n",n);
194  pass.push_back(repack(n,dw));
195 
196  if (rank == 0)
197  printf("Testing SY times NS with n = %d:\n",n);
198  pass.push_back(sy_times_ns(n,dw));
199 
200 #ifdef USE_SCALAPACK
201  if (rank == 0)
202  printf("Testing QR with m = %d n = %d:\n",n*n,n);
203  pass.push_back(test_qr(n*n,n,dw));
204 
205  if (rank == 0)
206  printf("Testing SVD with m = %d n = %d k=%d:\n",n*n,n+1,n+1);
207  pass.push_back(test_svd(n*n,n+1,n+1,dw));
208 
209 #endif
210  if (np == 1<<(int)log2(np)){
211  if (rank == 0)
212  printf("Testing non-symmetric sliced GEMM algorithm with (%d %d %d):\n",16,32,8);
213  pass.push_back(test_recursive_matmul(16, 32, 8, dw));
214  }
215  if (rank == 0)
216  printf("Testing 1D DFT with n = %d:\n",n*n);
217  pass.push_back(test_dft(n*n, dw));
218 //#ifdef __clang__
219  //if (rank == 0)
220  // printf("WARNING: Skipping dft_3D test, due to known issue with Clang and optimizations -Ox for x>0\n");
221 //#else
222  if (rank == 0)
223  printf("Testing 3D DFT with n = %d:\n",n);
224  pass.push_back(test_dft_3D(n, dw));
225 //#endif
226 
227  if (rank == 0)
228  printf("Testing sparse summation with n = %d:\n",n);
229  pass.push_back(sptensor_sum(n,dw));
230 
231  if (rank == 0)
232  printf("Testing sparse identity with n = %d order = %d:\n",n,11);
233  pass.push_back(speye(n,11,dw));
234 
235  if (rank == 0)
236  printf("Testing endomorphism A_ijkl = A_ijkl^3 with n = %d:\n",n);
237  pass.push_back(endomorphism(n,dw));
238 
239  if (rank == 0)
240  printf("Testing endomorphism with custom function on a monoid A_ijkl = f(A_ijkl) with n = %d:\n",n);
241  pass.push_back(endomorphism_cust(n,dw));
242 
243  if (rank == 0)
244  printf("Testing endomorphism with custom function on a sparse set A_ijkl = f(A_ijkl) with n = %d:\n",n);
245  pass.push_back(endomorphism_cust_sp(n,dw));
246 
247  if (rank == 0)
248  printf("Testing univar_function .5*A_ijkl = .5*A_ijkl^4 with n = %d:\n",n);
249  pass.push_back(univar_function(n,dw));
250 
251  if (rank == 0)
252  printf("Testing force_integration integrates forces to particles with n = %d:\n",n);
253  pass.push_back(force_integration(n,dw));
254 
255  if (rank == 0)
256  printf("Testing force_integration_sparse integrates sparse forces to particles with n = %d:\n",n);
257  pass.push_back(force_integration_sparse(n,dw));
258 
259  if (rank == 0)
260  printf("Testing bivar_function A_ijkl = f2(A_ijkl, B_ijkl) with n = %d:\n",n);
261  pass.push_back(bivar_function(n,dw));
262 
263  if (rank == 0)
264  printf("Testing custom bivar_function F[\"i\"] += f(P[\"i\"],P[\"j\"] with n = %d:\n",n);
265  pass.push_back(particle_interaction(n,dw));
266 
267  if (rank == 0)
268  printf("Testing bivar_transform 3(A_ijkl, B_ijkl, C_ijkl) with n = %d:\n",n);
269  pass.push_back(bivar_transform(n,dw));
270 
271  if (rank == 0)
272  printf("Testing sparse-matrix times vector with n=%d:\n",n);
273  pass.push_back(spmv(n,dw));
274 
275  if (rank == 0)
276  printf("Testing sparse-matrix times matrix with n=%d k=%d:\n",n*n,n);
277  pass.push_back(matmul(n*n,n,n*n,dw,NS,NS,NS,.3));
278 
279  if (rank == 0)
280  printf("Testing sparse-matrix times sparse-matrix with m=%d n=%d k=%d:\n",n,n*n,n+1);
281  pass.push_back(matmul(n,n*n,n+1,dw,NS,NS,NS,.3,.3));
282 
283  if (rank == 0)
284  printf("Testing sparse=sparse*sparse (spgemm) with m=%d n=%d k=%d:\n",n,n*n,n+1);
285  pass.push_back(matmul(n,n*n,n+1,dw,NS,NS,NS,.3,.3,.3));
286 
287  if (rank == 0)
288  printf("Testing Jacobi iteration with n=%d:\n",n);
289  pass.push_back(jacobi(n,dw));
290 
291  if (rank == 0)
292  printf("Testing SSSP via the Bellman-Ford algorithm n=%d:\n",n*n);
293  pass.push_back(sssp(n*n,dw));
294 
295  if (rank == 0)
296  printf("Testing APSP via path doubling with n=%d:\n",n*n);
297  pass.push_back(apsp(n*n,dw));
298 
299  if (rank == 0)
300  printf("Testing betweenness centrality with n=%d:\n",n);
301  pass.push_back(btwn_cnt(n,dw,.2,2,1,1,1,1));
302 
303  if (rank == 0)
304  printf("Testing MP3 calculation using sparse*dense with %d occupied and %d virtual orbitals:\n",n,2*n);
305  pass.push_back(sparse_mp3(2*n,n,dw,.8,1,0,0,0,0));
306 
307  if (rank == 0)
308  printf("Testing MP3 calculation using sparse*sparse with %d occupied and %d virtual orbitals:\n",n,2*n);
309  pass.push_back(sparse_mp3(2*n,n,dw,.8,1,0,0,0,1));
310 
311  /*int logn = log2(n)+1;
312  if (rank == 0)
313  printf("Testing bitonic sorting with %d elements:\n",1<<logn);
314  pass.push_back(bitonic(logn,dw));*/
315  }
316  int num_pass = std::accumulate(pass.begin(), pass.end(), 0);
317  if (rank == 0)
318  printf("Testing completed, %d/%zu tests passed\n", num_pass, pass.size());
319  int64_t tot_mem_used = std::fabs(CTF_int::proc_bytes_used());
320  int64_t max_tot_mem_used;
321  MPI_Reduce(&tot_mem_used, &max_tot_mem_used, 1, MPI_INT64_T, MPI_MAX, 0, MPI_COMM_WORLD);
322  if (rank == 0 && max_tot_mem_used > 0)
323  printf("Warning: CTF memory accounting thinks %1.2E bytes have been left allocated, memory leak or bug possible\n", (double)max_tot_mem_used);
324 
325  MPI_Finalize();
326  return 0;
327 }
328 
int test_dft_3D(int n, World &wrld)
Definition: dft_3D.cxx:15
int diag_ctr(int n, int m, World &dw)
Definition: diag_ctr.cxx:13
char * getCmdOption(char **begin, char **end, const std::string &option)
Definition: test_suite.cxx:60
int jacobi(int n, World &dw)
Definition: jacobi.cxx:19
int weigh_4D(int const n, int const sym, World &dw)
Definition: weigh_4D.cxx:17
def rank(self)
Definition: core.pyx:312
int spmv(int n, World &dw)
Definition: spmv.cxx:11
int sparse_mp3(int nv, int no, World &dw, double sp=.8, bool test=1, int niter=0, bool bnd=1, bool bns=1, bool sparse_T=1)
Definition: sparse_mp3.cxx:96
int main(int argc, char **argv)
Definition: test_suite.cxx:71
int bivar_function(int n, World &dw)
int trace(int const n, World &dw)
Definition: trace.cxx:12
Definition: common.h:37
int bivar_transform(int n, World &dw)
int btwn_cnt(int n, World &dw, double sp=.20, int bsize=2, int nbatches=1, int test=0, bool sp_B=1, bool sp_C=1)
int force_integration_sparse(int n, World &dw)
int endomorphism_cust(int n, World &dw)
an instance of the CTF library (world) on a MPI communicator
Definition: world.h:19
int64_t tot_mem_used
Definition: memcontrol.cxx:77
string
Definition: core.pyx:456
int particle_interaction(int n, World &dw)
int endomorphism_cust_sp(int n, World &dw)
int scalar(CTF::World &dw)
Definition: test/scalar.cxx:12
int test_subworld_gemm(int n, int m, int k, int div_, World &dw)
int endomorphism(int n, World &dw)
int gemm_4D(int const n, int const sym, int const niter, World &dw)
Definition: gemm_4D.cxx:11
int readwrite_test(int n, World &dw)
int sptensor_sum(int n, World &dw)
int matmul(int m, int n, int k, World &dw, int sym_A=NS, int sym_B=NS, int sym_C=NS, double sp_A=1., double sp_B=1., double sp_C=1., bool test=true, bool bench=false, int niter=10)
(if test) tests and (if bench) benchmarks m*n*k matrix multiplication with matrices of specified symm...
Definition: matmul.cxx:28
int force_integration(int n, World &dw)
int diag_sym(int n, World &dw)
Definition: diag_sym.cxx:14
bool test_svd(int m, int n, int k, World dw)
Definition: svd.cxx:70
int speye(int n, int order, World &dw)
Definition: speye.cxx:11
int sssp(int n, World &dw)
Definition: sssp.cxx:33
int readall_test(int n, int m, World &dw)
int64_t proc_bytes_used()
gives total memory used on this MPI process
Definition: memcontrol.cxx:538
int fast_sym_4D(int const n, World &ctf)
Definition: fast_sym_4D.cxx:12
int multi_tsr_sym(int m, int n, World &dw)
int ccsdt_t3_to_t2(int n, int m, World &dw)
int fast_sym(int const n, World &ctf)
Definition: fast_sym.cxx:12
int univar_function(int n, World &dw)
Definition: apsp.cxx:17
int strassen(int const n, int const sym, World &dw)
Definition: strassen.cxx:13
int test_dft(int64_t n, World &wrld)
Definition: dft.cxx:13
Definition: common.h:37
bool test_qr(int m, int n, World dw)
Definition: qr.cxx:54
int repack(int n, World &dw)
Definition: repack.cxx:14
int sy_times_ns(int n, World &dw)
Definition: sy_times_ns.cxx:14
Definition: common.h:37
int test_recursive_matmul(int n, int m, int k, World &dw)
Definition: common.h:37
int apsp(int n, World &dw, int niter=0)
Definition: apsp.cxx:24
def np(self)
Definition: core.pyx:315