OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
grid_unit_tests.hpp
1 #ifndef GRID_UNIT_TEST_HPP
2 #define GRID_UNIT_TEST_HPP
3 
4 #include "map_grid.hpp"
5 #include "Point_test.hpp"
6 #include "Space/Shape/HyperCube.hpp"
7 #include "timer.hpp"
8 #include "grid_util_test.hpp"
9 
10 #ifdef TEST_COVERAGE_MODE
11 #define GS_SIZE 8
12 #else
13 #define GS_SIZE 128
14 #endif
15 
16 template<unsigned int dim, typename g> void test_layout_gridNd(g & c3, size_t sz);
17 template<unsigned int dim, typename g> void test_layout_gridObjNd(g & c3, size_t sz);
18 template<typename g> void test_layout_grid3d(g & c3, size_t sz);
19 
26 template<unsigned int dim> void test_all_grid(size_t sz)
27 {
28  std::vector<size_t> szz;
29  szz.clear();
30 
31  for (size_t i = 0 ; i < dim ; i++)
32  {szz.push_back(sz);}
33 
34 #ifdef CUDA_GPU
35 
37  c3.template setMemory();
38  test_layout_gridNd<dim>(c3,sz);}
39 
41  c3.template setMemory();
42  test_layout_gridObjNd<dim>(c3,sz);}
43 
45  c3.template setMemory();
46  test_layout_gridNd<dim>(c3,sz);}
47 
49  c3.template setMemory();
50  test_layout_gridObjNd<dim>(c3,sz);}
51 
52 #endif
53 
55  c3.template setMemory();
56  test_layout_gridObjNd<dim>(c3,sz);}
57 
59  c3.template setMemory();
60  test_layout_gridNd<dim>(c3,sz);}
61 
63  c3.template setMemory();
64  test_layout_gridNd<dim>(c3,sz);}
65 
67  c3.template setMemory();
68  test_layout_gridObjNd<dim>(c3,sz);}
69 }
70 
71 
72 
73 template<typename g> void test_layout_grid3d(g & c3, size_t sz)
74 {
75 
76 #ifdef VERBOSE_TEST
77  std::cout << "3D Array with grid_key (without redundant dimension): " << "\n";
78 #endif
79 
81  typedef Point_test<float> P;
82 
83  timer t;
84  t.start();
85 
86  grid_key_dx<3> kk;
87 
88  for (size_t i = 0 ; i < sz ; i++)
89  {
90  for (size_t j = 0 ; j < sz ; j++)
91  {
92  for (size_t k = 0 ; k < sz ; k++)
93  {
94 
95  kk.set(i,j,k);
96 
97  c3.template get<P::x>(kk) = 1.1f;
98  c3.template get<P::y>(kk) = 1.2f;
99  c3.template get<P::z>(kk) = 1.3f;
100  c3.template get<P::s>(kk) = 1.0f;
101 
102  c3.template get<P::v>(kk)[0] = 1.0f;
103  c3.template get<P::v>(kk)[1] = 2.0f;
104  c3.template get<P::v>(kk)[2] = 3.0f;
105 
106  c3.template get<P::t>(kk)[0][0] = 1.0f;
107  c3.template get<P::t>(kk)[0][1] = 2.0f;
108  c3.template get<P::t>(kk)[0][2] = 3.0f;
109  c3.template get<P::t>(kk)[1][0] = 4.0f;
110  c3.template get<P::t>(kk)[1][1] = 5.0f;
111  c3.template get<P::t>(kk)[1][2] = 6.0f;
112  c3.template get<P::t>(kk)[2][0] = 7.0f;
113  c3.template get<P::t>(kk)[2][1] = 8.0f;
114  c3.template get<P::t>(kk)[2][2] = 9.0f;
115 
116  }
117  }
118  }
119 
121 
122 #ifdef VERBOSE_TEST
123  t.stop();
124 
125  std::cout << "End : " << sz*sz*sz*16*4 << " Byte " << " Bandwidth: " << sz*sz*sz*16*4/1024/1024/t.getwct() << " MB/s ";
126 #endif
127 
129 
130  bool passed = true;
131 
132  for (size_t i = 0 ; i < sz ; i++)
133  {
134  for (size_t j = 0 ; j < sz ; j++)
135  {
136  for (size_t k = 0 ; k < sz ; k++)
137  {
138  kk.set(i,j,k);
139 
140  c3.template get<P::x>(kk) = i;
141  c3.template get<P::y>(kk) = j;
142  c3.template get<P::z>(kk) = k;
143  c3.template get<P::s>(kk) = i+j+k;
144 
145  c3.template get<P::v>(kk)[0] = i;
146  c3.template get<P::v>(kk)[1] = j;
147  c3.template get<P::v>(kk)[2] = k;
148 
149  c3.template get<P::t>(kk)[0][0] = i+i;
150  c3.template get<P::t>(kk)[0][1] = i+j;
151  c3.template get<P::t>(kk)[0][2] = i+k;
152  c3.template get<P::t>(kk)[1][0] = j+i;
153  c3.template get<P::t>(kk)[1][1] = j+j;
154  c3.template get<P::t>(kk)[1][2] = j+k;
155  c3.template get<P::t>(kk)[2][0] = k+i;
156  c3.template get<P::t>(kk)[2][1] = k+j;
157  c3.template get<P::t>(kk)[2][2] = k+k;
158  }
159  }
160  }
161 
162  for (size_t i = 0 ; i < sz ; i++)
163  {
164  for (size_t j = 0 ; j < sz ; j++)
165  {
166  for (size_t k = 0 ; k < sz ; k++)
167  {
168  kk.set(i,j,k);
169 
170  if (c3.template get<P::x>(kk) != i) passed = false;
171  if (c3.template get<P::y>(kk) != j) passed = false;
172  if (c3.template get<P::z>(kk) != k) passed = false;
173  if (c3.template get<P::s>(kk) != i+j+k) passed = false;
174 
175  if (c3.template get<P::v>(kk)[0] != i) passed = false;
176  if (c3.template get<P::v>(kk)[1] != j) passed = false;
177  if (c3.template get<P::v>(kk)[2] != k) passed = false;
178 
179  if (c3.template get<P::t>(kk)[0][0] != i+i) passed = false;
180  if (c3.template get<P::t>(kk)[0][1] != i+j) passed = false;
181  if (c3.template get<P::t>(kk)[0][2] != i+k) passed = false;
182  if (c3.template get<P::t>(kk)[1][0] != j+i) passed = false;
183  if (c3.template get<P::t>(kk)[1][1] != j+j) passed = false;
184  if (c3.template get<P::t>(kk)[1][2] != j+k) passed = false;
185  if (c3.template get<P::t>(kk)[2][0] != k+i) passed = false;
186  if (c3.template get<P::t>(kk)[2][1] != k+j) passed = false;
187  if (c3.template get<P::t>(kk)[2][2] != k+k) passed = false;
188  }
189  }
190  }
191 
192  BOOST_REQUIRE_EQUAL(passed,true);
193 }
194 
195 template<unsigned int dim, typename g> void test_layout_gridObjNd(g & c3, size_t sz)
196 {
197 #ifdef VERBOSE_TEST
198  std::cout << dim << "D Array with grid_key (without redundant dimension): " << "\n";
199 
200  timer t;
201  t.start();
202 #endif
203 
205 
206  typedef Point_test<float> P;
207 
208  grid_key_dx_iterator<dim> key_it = c3.getIterator();
209 
210  while (key_it.isNext())
211  {
212  grid_key_dx<dim> kk = key_it.get();
213 
214  // Here we get a reference to the object, in reality we get an encapsulated object reference encapc
215  auto v = c3.get_o(kk);
216 
217  // An encapsulated object can be accessed like that
218  // (this will change the value in the grid)
219  v.template get<P::x>() = 1.1f;
220  v.template get<P::y>() = 1.2f;
221  v.template get<P::z>() = 1.3f;
222  v.template get<P::s>() = 1.0f;
223 
224  v.template get<P::v>()[0] = 1.0f;
225  v.template get<P::v>()[1] = 2.0f;
226  v.template get<P::v>()[2] = 3.0f;
227 
228  v.template get<P::t>()[0][0] = 1.0f;
229  v.template get<P::t>()[0][1] = 2.0f;
230  v.template get<P::t>()[0][2] = 3.0f;
231  v.template get<P::t>()[1][0] = 4.0f;
232  v.template get<P::t>()[1][1] = 5.0f;
233  v.template get<P::t>()[1][2] = 6.0f;
234  v.template get<P::t>()[2][0] = 7.0f;
235  v.template get<P::t>()[2][1] = 8.0f;
236  v.template get<P::t>()[2][2] = 9.0f;
237 
238  // From an encapsulated reference object you can create
239  // an object
240  Point_test<float> obj = c3.get_o(kk);
241 
242  // And do some operation
243  obj.fill();
244 
245  // Note change obj does not change the grid
246 
247  ++key_it;
248 
249  }
250 
252 
253 #ifdef VERBOSE_TEST
254  t.stop();
255 
256  std::cout << "End : " << pow(sz,dim)*16*4/1024/1024 << " MB " << " Bandwidth: " << pow(sz,dim)*16*4/1024/1024/t.getect() << " MB/s " << "\n";
257 #endif
258 
260 
261  bool passed = true;
262 
264  fill_grid<dim>(c3);
265 
266  key_it = c3.getIterator();
267 
268  while (key_it.isNext())
269  {
270  grid_key_dx<dim> kk = key_it.get();
271 
272  if (c3.template get<P::x>(kk) != c3.getGrid().LinId(kk)) passed = false;
273  if (c3.template get<P::y>(kk) != c3.getGrid().LinId(kk)+1) passed = false;
274  if (c3.template get<P::z>(kk) != c3.getGrid().LinId(kk)+2) passed = false;
275  if (c3.template get<P::s>(kk) != c3.getGrid().LinId(kk)+3) passed = false;
276 
277  if (c3.template get<P::v>(kk)[0] != c3.getGrid().LinId(kk)+123) passed = false;
278  if (c3.template get<P::v>(kk)[1] != c3.getGrid().LinId(kk)+124) passed = false;
279  if (c3.template get<P::v>(kk)[2] != c3.getGrid().LinId(kk)+125) passed = false;
280 
281  if (c3.template get<P::t>(kk)[0][0] != c3.getGrid().LinId(kk)+567) passed = false;
282  if (c3.template get<P::t>(kk)[0][1] != c3.getGrid().LinId(kk)+568) passed = false;
283  if (c3.template get<P::t>(kk)[0][2] != c3.getGrid().LinId(kk)+569) passed = false;
284  if (c3.template get<P::t>(kk)[1][0] != c3.getGrid().LinId(kk)+570) passed = false;
285  if (c3.template get<P::t>(kk)[1][1] != c3.getGrid().LinId(kk)+571) passed = false;
286  if (c3.template get<P::t>(kk)[1][2] != c3.getGrid().LinId(kk)+572) passed = false;
287  if (c3.template get<P::t>(kk)[2][0] != c3.getGrid().LinId(kk)+573) passed = false;
288  if (c3.template get<P::t>(kk)[2][1] != c3.getGrid().LinId(kk)+574) passed = false;
289  if (c3.template get<P::t>(kk)[2][2] != c3.getGrid().LinId(kk)+575) passed = false;
290 
291  ++key_it;
292  }
293 
294  BOOST_REQUIRE_EQUAL(passed,true);
295 }
296 
297 template<unsigned int dim, typename g> void test_layout_gridNd(g & c3, size_t sz)
298 {
299 #ifdef VERBOSE_TEST
300  std::cout << dim << "D Array with grid_key (without redundant dimension): " << "\n";
301 
302  timer t;
303  t.start();
304 #endif
305 
307  typedef Point_test<float> P;
308 
309  grid_key_dx_iterator<dim> key_it = c3.getIterator();
310 
311  while (key_it.isNext())
312  {
313  grid_key_dx<dim> kk = key_it.get();
314 
315  c3.template get<P::x>(kk) = 1.1f;
316  c3.template get<P::y>(kk) = 1.2f;
317  c3.template get<P::z>(kk) = 1.3f;
318  c3.template get<P::s>(kk) = 1.0f;
319 
320  c3.template get<P::v>(kk)[0] = 1.0f;
321  c3.template get<P::v>(kk)[1] = 2.0f;
322  c3.template get<P::v>(kk)[2] = 3.0f;
323 
324  c3.template get<P::t>(kk)[0][0] = 1.0f;
325  c3.template get<P::t>(kk)[0][1] = 2.0f;
326  c3.template get<P::t>(kk)[0][2] = 3.0f;
327  c3.template get<P::t>(kk)[1][0] = 4.0f;
328  c3.template get<P::t>(kk)[1][1] = 5.0f;
329  c3.template get<P::t>(kk)[1][2] = 6.0f;
330  c3.template get<P::t>(kk)[2][0] = 7.0f;
331  c3.template get<P::t>(kk)[2][1] = 8.0f;
332  c3.template get<P::t>(kk)[2][2] = 9.0f;
333 
334  ++key_it;
335 
336  }
338 
339 #ifdef VERBOSE_TEST
340  t.stop();
341 
342  std::cout << "End : " << pow(sz,dim)*16*4/1024/1024 << " MB " << " Bandwidth: " << pow(sz,dim)*16*4/1024/1024/t.getwct() << " MB/s " << "\n";
343 #endif
344 
346 
347  bool passed = true;
348 
349  key_it = c3.getIterator();
350 
351  while (key_it.isNext())
352  {
353  grid_key_dx<dim> kk = key_it.get();
354 
355  c3.template get<P::x>(kk) = c3.getGrid().LinId(kk);
356  c3.template get<P::y>(kk) = c3.getGrid().LinId(kk)+1;
357  c3.template get<P::z>(kk) = c3.getGrid().LinId(kk)+2;
358  c3.template get<P::s>(kk) = c3.getGrid().LinId(kk)+3;
359 
360  c3.template get<P::v>(kk)[0] = c3.getGrid().LinId(kk)+123;
361  c3.template get<P::v>(kk)[1] = c3.getGrid().LinId(kk)+124;
362  c3.template get<P::v>(kk)[2] = c3.getGrid().LinId(kk)+125;
363 
364  c3.template get<P::t>(kk)[0][0] = c3.getGrid().LinId(kk)+567;
365  c3.template get<P::t>(kk)[0][1] = c3.getGrid().LinId(kk)+568;
366  c3.template get<P::t>(kk)[0][2] = c3.getGrid().LinId(kk)+569;
367  c3.template get<P::t>(kk)[1][0] = c3.getGrid().LinId(kk)+570;
368  c3.template get<P::t>(kk)[1][1] = c3.getGrid().LinId(kk)+571;
369  c3.template get<P::t>(kk)[1][2] = c3.getGrid().LinId(kk)+572;
370  c3.template get<P::t>(kk)[2][0] = c3.getGrid().LinId(kk)+573;
371  c3.template get<P::t>(kk)[2][1] = c3.getGrid().LinId(kk)+574;
372  c3.template get<P::t>(kk)[2][2] = c3.getGrid().LinId(kk)+575;
373 
374  ++key_it;
375  }
376 
377 
378  key_it = c3.getIterator();
379 
380  while (key_it.isNext())
381  {
382  grid_key_dx<dim> kk = key_it.get();
383 
384  if (c3.template get<P::x>(kk) != c3.getGrid().LinId(kk)) passed = false;
385  if (c3.template get<P::y>(kk) != c3.getGrid().LinId(kk)+1) passed = false;
386  if (c3.template get<P::z>(kk) != c3.getGrid().LinId(kk)+2) passed = false;
387  if (c3.template get<P::s>(kk) != c3.getGrid().LinId(kk)+3) passed = false;
388 
389  if (c3.template get<P::v>(kk)[0] != c3.getGrid().LinId(kk)+123) passed = false;
390  if (c3.template get<P::v>(kk)[1] != c3.getGrid().LinId(kk)+124) passed = false;
391  if (c3.template get<P::v>(kk)[2] != c3.getGrid().LinId(kk)+125) passed = false;
392 
393  if (c3.template get<P::t>(kk)[0][0] != c3.getGrid().LinId(kk)+567) passed = false;
394  if (c3.template get<P::t>(kk)[0][1] != c3.getGrid().LinId(kk)+568) passed = false;
395  if (c3.template get<P::t>(kk)[0][2] != c3.getGrid().LinId(kk)+569) passed = false;
396  if (c3.template get<P::t>(kk)[1][0] != c3.getGrid().LinId(kk)+570) passed = false;
397  if (c3.template get<P::t>(kk)[1][1] != c3.getGrid().LinId(kk)+571) passed = false;
398  if (c3.template get<P::t>(kk)[1][2] != c3.getGrid().LinId(kk)+572) passed = false;
399  if (c3.template get<P::t>(kk)[2][0] != c3.getGrid().LinId(kk)+573) passed = false;
400  if (c3.template get<P::t>(kk)[2][1] != c3.getGrid().LinId(kk)+574) passed = false;
401  if (c3.template get<P::t>(kk)[2][2] != c3.getGrid().LinId(kk)+575) passed = false;
402 
403  ++key_it;
404  }
405 
406  BOOST_REQUIRE_EQUAL(passed,true);
407 
408  // Check sub iterator
409 
410  /*
411  * Basically we first fill the interior part of the grid than the borders
412  * creating sub iterator always of smaller dimension
413  *
414  * Example:
415  *
416  * 2D
417  *
418  * if we have a square grid 16x16 we first will with 1 the interior 14x14 grid
419  *
420  * than the 4 line borders 14x1 with one
421  * than the 4 point borders 1x1
422  *
423  * We check that
424  *
425  * 1) The number of points for each sub-grid correspond
426  * 2) No point is filled more than one time
427  * 3) All point are filled
428  *
429  * we use the property x of c3
430  *
431  */
432 
433  // Erase the property x
434 
435  key_it = c3.getIterator();
436 
437  while (key_it.isNext())
438  {
439  grid_key_dx<dim> kk = key_it.get();
440 
441  c3.template get<P::x>(kk) = 0.0;
442 
443  ++key_it;
444  }
445 
446  for(size_t i = 0 ; i <= dim ; i++)
447  {
448  // get the combination of dimension dim-i
449  std::vector<comb<dim>> combs = HyperCube<dim>::getCombinations_R(dim-i);
450 
451  // For each combination create a sub iterator
452 
453  for (size_t j = 0 ; j < combs.size() ; j++)
454  {
455  // Grid key of the sub-iterator
456 
457  grid_key_dx<dim> start;
458  grid_key_dx<dim> stop;
459 
460  // sub iterator
461 
462  for (size_t k = 0 ; k < dim ; k++)
463  {
464  // if combination is 0 the hyper-cube
465 
466  if (combs[j].c[k] == -1)
467  {
468  start.set_d(k,0);
469  stop.set_d(k,0);
470  }
471  else if (combs[j].c[k] == 1)
472  {
473  start.set_d(k,c3.getGrid().size(k)-1);
474  stop.set_d(k,c3.getGrid().size(k)-1);
475  }
476  else
477  {
478  start.set_d(k,1);
479  stop.set_d(k,c3.getGrid().size(k)-2);
480  }
481  }
482 
483  auto key_it = c3.getSubIterator(start,stop);
484 
485  while (key_it.isNext())
486  {
487  grid_key_dx<dim> kk = key_it.get();
488 
489  BOOST_REQUIRE_EQUAL(c3.template get<P::x>(kk),0.0);
490 
491  c3.template get<P::x>(kk) = 1.0;
492 
493  ++key_it;
494  }
495  }
496  }
497 
498  // Check that everything is 1.0
499 
500  key_it = c3.getIterator();
501 
502  while (key_it.isNext())
503  {
504  grid_key_dx<dim> kk = key_it.get();
505 
506  BOOST_REQUIRE_EQUAL(c3.template get<P::x>(kk),1.0);
507 
508  ++key_it;
509  }
510 }
511 
512 BOOST_AUTO_TEST_SUITE( grid_test )
513 
514 BOOST_AUTO_TEST_CASE( grid_iterator_test_use)
515 {
516  {
518  size_t count = 0;
519 
520  // Subdivisions
521  size_t div[3] = {16,16,16};
522 
523  // grid info
524  grid_sm<3,void> g_info(div);
525 
526  // Create a grid iterator
527  grid_key_dx_iterator<3> g_it(g_info);
528 
529  // Iterate on all the elements
530  while (g_it.isNext())
531  {
532  grid_key_dx<3> key = g_it.get();
533 
534  // set the grid key to zero without any reason ( to avoid warning compilations )
535  key.zero();
536 
537  count++;
538 
539  ++g_it;
540  }
541 
542  BOOST_REQUIRE_EQUAL(count, (size_t)16*16*16);
544  }
545 
546  {
547  size_t count = 0;
548  // Iterate only on the internal elements
549 
551  // Subdivisions
552  size_t div[3] = {16,16,16};
553 
554  // grid info
555  grid_sm<3,void> g_info(div);
556 
557  grid_key_dx<3> start(1,1,1);
558  grid_key_dx<3> stop(14,14,14);
559 
560  // Create a grid iterator (start and stop included)
561  grid_key_dx_iterator_sub<3> g_it(g_info,start,stop);
562 
563  // Iterate on all the elements
564  while (g_it.isNext())
565  {
566  grid_key_dx<3> key = g_it.get();
567 
568  // set the grid key to zero without any reason ( to avoid warning compilations )
569  key.zero();
570 
571  count++;
572 
573  ++g_it;
574  }
575 
576  BOOST_REQUIRE_EQUAL(count, (size_t)14*14*14);
577 
579 
580  // reset the iterator and check that it start from gk_start
581  g_it.reset();
582 
583  bool val = g_it.get() == start;
584 
585  BOOST_REQUIRE_EQUAL(val,true);
586  }
587 }
588 
589 BOOST_AUTO_TEST_CASE( grid_sub_iterator_test )
590 {
592  // Subdivisions
593  size_t count = 0;
594  typedef Point_test<float> p;
595 
596  size_t div[3] = {16,16,16};
597 
598  // grid info
600  g.setMemory();
601 
602  grid_key_dx<3> start(1,1,1);
603  grid_key_dx<3> stop(14,14,14);
604 
605  // Create a grid iterator (start and stop included)
606  auto g_it = g.getIterator(start,stop);
607 
608  // Iterate on all the elements
609  while (g_it.isNext())
610  {
611  grid_key_dx<3> key = g_it.get();
612 
613  // set the x value
614  g.template get<p::x>(key) = 1.0;
615 
616  count++;
617 
618  ++g_it;
619  }
620 
621  BOOST_REQUIRE_EQUAL(count, (size_t)14*14*14);
622 
624 }
625 
627 
628 grid_cpu<3,scalar<float>> & test_error()
629 {
630  size_t sz[] = {16,16,16};
631 
633 
634  return g;
635 }
636 
638 
639 BOOST_AUTO_TEST_CASE( grid_safety_check )
640 {
641 #if defined(SE_CLASS1) && defined (THROW_ON_ERROR)
642 
643  bool error = false;
644 
645  typedef Point_test<float> p;
646 
647  size_t sz[] = {16,16,16};
648 
649  // Create a grid
650 
653 
654  // try to access uninitialized grid
655  grid_key_dx<3> keyOut(23,1,1);
656  grid_key_dx<3> keyGood(15,1,1);
657  grid_key_dx<3> keyNeg(-1,0,0);
658 
659  error = false;
660  try
661  {g.template get<p::x>(keyOut);}
662  catch (size_t e)
663  {
664  error = true;
665  BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
666  BOOST_REQUIRE_EQUAL(g.getLastError(),1001);
667  }
668  BOOST_REQUIRE_EQUAL(error,true);
669 
670  error = false;
671  g.setMemory();
672  try
673  {g.template get<p::x>(keyOut);}
674  catch (size_t e)
675  {
676  error = true;
677  BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
678  BOOST_REQUIRE_EQUAL(g.getLastError(),1002);
679  }
680  BOOST_REQUIRE_EQUAL(error,true);
681 
682  error = false;
684  try
685  {g.set(keyOut,t);}
686  catch (size_t e)
687  {
688  error = true;
689  BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
690  BOOST_REQUIRE_EQUAL(g.getLastError(),1002);
691  }
692  BOOST_REQUIRE_EQUAL(error,true);
693 
694  error = false;
695  try
696  {g.set(keyGood,g2,keyOut);}
697  catch (size_t e)
698  {
699  error = true;
700  BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
701  BOOST_REQUIRE_EQUAL(g.getLastError(),1004);
702  }
703  BOOST_REQUIRE_EQUAL(error,true);
704 
706 
707  error = false;
708  try
709  {g.template get<p::x>(keyNeg);}
710  catch (size_t e)
711  {
712  error = true;
713  BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
714  BOOST_REQUIRE_EQUAL(g.getLastError(),1003);
715  }
716  BOOST_REQUIRE_EQUAL(error,true);
717 
718  error = false;
720  try
721  {g.set(keyNeg,t2);}
722  catch (size_t e)
723  {
724  error = true;
725  BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
726  BOOST_REQUIRE_EQUAL(g.getLastError(),1003);
727  }
728  BOOST_REQUIRE_EQUAL(error,true);
729 
730  error = false;
731  try
732  {g.set(keyGood,g2,keyNeg);}
733  catch (size_t e)
734  {
735  error = true;
736  BOOST_REQUIRE_EQUAL(e,GRID_ERROR);
737  BOOST_REQUIRE_EQUAL(g.getLastError(),1005);
738  }
739  BOOST_REQUIRE_EQUAL(error,true);
740 
741  #if defined(SE_CLASS2) && defined (THROW_ON_ERROR)
742 
743  error = false;
744 
745  // Create a grid
746 
748  delete gp;
749 
750  // Try to access the class
751 
752  try
753  {gp->size();}
754  catch (size_t e)
755  {
756  error = true;
757  BOOST_REQUIRE_EQUAL(e,MEM_ERROR);
758  }
759  BOOST_REQUIRE_EQUAL(error,true);
760 
761  error = false;
762  try
763  {grid_cpu<3,scalar<float>> gr = test_error();}
764  catch (size_t e)
765  {
766  error = true;
767  BOOST_REQUIRE_EQUAL(e,MEM_ERROR);
768  }
769  BOOST_REQUIRE_EQUAL(error,true);
770 
771  #endif
772 
773 #endif
774 }
775 
776 BOOST_AUTO_TEST_CASE( grid_use)
777 {
778  /* tensor<int,3,3,3> c;
779  tensor<tensor<int,3,3,3>,3,3,3> c2;*/
780 
781  std::cout << "Grid unit test start" << "\n";
782 
783  std::vector<size_t> sz;
784  sz.push_back(GS_SIZE);
785  sz.push_back(GS_SIZE);
786  sz.push_back(GS_SIZE);
787 
788  // test the grid from dimensionality 1 to 8 with several size non multiple of two
789  // Dimension 8-1
790 
791  // With test coverage reduce the test size
792 
793 #ifndef TEST_COVERAGE_MODE
794  test_all_grid<8>(4);
795  test_all_grid<7>(8);
796  test_all_grid<6>(9);
797  test_all_grid<5>(18);
798  test_all_grid<4>(37);
799  test_all_grid<3>(126);
800  test_all_grid<2>(1414);
801  test_all_grid<1>(2000000);
802 
803 
804  // Special case grid of size 0
805  test_all_grid<8>(0);
806  test_all_grid<7>(0);
807  test_all_grid<6>(0);
808  test_all_grid<5>(0);
809  test_all_grid<4>(0);
810  test_all_grid<3>(0);
811  test_all_grid<2>(0);
812  test_all_grid<1>(0);
813 #else
814  test_all_grid<4>(4);
815  test_all_grid<3>(8);
816  test_all_grid<2>(16);
817  test_all_grid<1>(256);
818 #endif
819 
820  // Test the 3d gpu grid with CudaMemory and HeapMemory with different size
821 
822  for (int i = 0 ; i <= GS_SIZE ; i++)
823  {
824  sz.clear();
825  sz.push_back(i);
826  sz.push_back(i);
827  sz.push_back(i);
828 
829 #ifdef CUDA_GPU
830 
831  {
834  c3.setMemory();
836  test_layout_grid3d(c3,i);
837  }
838 
840  c3.setMemory();
841  test_layout_grid3d(c3,i);}
842 
843 #endif
844 
845  {
848  c3.setMemory();
850  test_layout_grid3d(c3,i);}
851 
852  // Test the 3d cpu grid with Cudamemory and HeapMemory
853 
855  c3.setMemory();
856  test_layout_grid3d(c3,i);}
857 
858  }
859 
860  std::cout << "Grid unit test end" << "\n";
861 }
862 
863 BOOST_AUTO_TEST_CASE( grid_iterator_sp_test )
864 {
865  size_t sz[3] = {16,16,16};
866 
868  c3.setMemory();
869 
870  grid_key_dx<3> start(2,2,2);
871  grid_key_dx<3> stop(10,10,10);
872 
873  auto info = c3.getGrid();
874 
875  grid_key_dx_iterator_sp<3> it(info,info.LinId(start),info.LinId(stop));
876 
877  size_t count = 0;
878 
879  while (it.isNext())
880  {
881  count++;
882 
883  ++it;
884  }
885 
886  BOOST_REQUIRE_EQUAL(count,2185ul);
887 }
888 
889 /* \brief This is an ordinary test simple 3D with plain C array
890  *
891  * This is an ordinary test simple 3D with plain C array
892  *
893  */
894 
895 BOOST_AUTO_TEST_CASE( C_array_test )
896 {
897  // Testing the grids
898 
899 #ifdef VERBOSE_TEST
900  std::cout << "Grid size known at runtime" << "\n";
901  std::cout << "1D Array with index calculation: " << "\n";
902 #endif
903 
904  Point_orig<float> * pA = new Point_orig<float>[GS_SIZE*GS_SIZE*GS_SIZE];
905 
906  int gs_sq = GS_SIZE*GS_SIZE;
907  int gs = GS_SIZE;
908 
909 #ifdef VERBOSE_TEST
910  timer t;
911  t.start();
912 #endif
913 
914  for (int i = 0 ; i < GS_SIZE ; i++)
915  {
916  for (int j = 0 ; j < GS_SIZE ; j++)
917  {
918  for (int k = 0 ; k < GS_SIZE ; k++)
919  {
920  pA[i*gs_sq+j*gs+k].x = 1.1f;
921  pA[i*gs_sq+j*gs+k].y = 1.2f;
922  pA[i*gs_sq+j*gs+k].z = 1.3f;
923  pA[i*gs_sq+j*gs+k].s = 1.0f;
924 
925  pA[i*gs_sq+j*gs+k].v[0] = 1.0f;
926  pA[i*gs_sq+j*gs+k].v[1] = 2.0f;
927  pA[i*gs_sq+j*gs+k].v[2] = 3.0f;
928 
929  pA[i*gs_sq+j*gs+k].t[0][0] = 1.0f;
930  pA[i*gs_sq+j*gs+k].t[0][1] = 2.0f;
931  pA[i*gs_sq+j*gs+k].t[0][2] = 3.0f;
932  pA[i*gs_sq+j*gs+k].t[1][0] = 4.0f;
933  pA[i*gs_sq+j*gs+k].t[1][1] = 5.0f;
934  pA[i*gs_sq+j*gs+k].t[1][2] = 6.0f;
935  pA[i*gs_sq+j*gs+k].t[2][0] = 7.0f;
936  pA[i*gs_sq+j*gs+k].t[2][1] = 8.0f;
937  pA[i*gs_sq+j*gs+k].t[2][2] = 9.0f;
938  }
939  }
940  }
941 
942  delete [] pA;
943 
944 #ifdef VERBOSE_TEST
945  t.stop();
946 
947  std::cout << "End : " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024 << " MB " << " Bandwidth: " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024/t.getcputime() << " MB/s \n";
948 #endif
949 }
950 
951 BOOST_AUTO_TEST_CASE(grid_operator_equal)
952 {
954 
955  size_t sz[] = {16,16};
956 
957  typedef Box<2,float> b;
958 
959  grid_cpu<2,Box<2,float>> g1(sz);
960  g1.setMemory();
961 
962  auto it = g1.getIterator();
963 
964  while (it.isNext())
965  {
966  auto key = it.get();
967 
968  g1.template get<b::p1>(key)[0] = key.get(0);
969  g1.template get<b::p2>(key)[1] = key.get(1);
970 
971  ++it;
972  }
973 
975  g2 = g1;
976 
978 
979  bool ret = (g2 == g1);
980 
981  BOOST_REQUIRE_EQUAL(ret,true);
982 }
983 
991 void fill_2_grid_data(grid_cpu<2,Box<2,float>> & g1, grid_cpu<2,Box<2,float>> & g2)
992 {
993  typedef Box<2,float> b;
994 
995  auto it1 = g1.getIterator();
996 
997  while (it1.isNext())
998  {
999  auto key = it1.get();
1000 
1001  g1.template get<b::p1>(key)[0] = key.get(0);
1002  g1.template get<b::p2>(key)[1] = key.get(1);
1003 
1004  ++it1;
1005  }
1006 
1007  auto it2 = g2.getIterator();
1008 
1009  while (it2.isNext())
1010  {
1011  auto key = it2.get();
1012 
1013  g2.template get<b::p1>(key)[0] = key.get(0);
1014  g2.template get<b::p2>(key)[1] = key.get(1);
1015 
1016  ++it2;
1017  }
1018 
1019 
1020 }
1021 
1022 BOOST_AUTO_TEST_CASE(grid_operator_swap)
1023 {
1024  size_t sz1[] = {16,16};
1025  size_t sz2[] = {5,5};
1026 
1027  typedef Box<2,float> b;
1028 
1029  grid_cpu<2,Box<2,float>> g1_old(sz1);
1030  g1_old.setMemory();
1031  grid_cpu<2,Box<2,float>> g2_old(sz2);
1032  g2_old.setMemory();
1033  grid_cpu<2,Box<2,float>> g1(sz1);
1034  g1.setMemory();
1035  grid_cpu<2,Box<2,float>> g2(sz2);
1036  g2.setMemory();
1037 
1038  fill_2_grid_data(g1_old,g2_old);
1039  fill_2_grid_data(g1,g2);
1040 
1042 
1043  g2.swap(g1);
1044 
1046 
1047  bool ret = (g2 == g1_old);
1048  BOOST_REQUIRE_EQUAL(ret,true);
1049  ret = (g1 == g2_old);
1050  BOOST_REQUIRE_EQUAL(ret,true);
1051 }
1052 
1053 BOOST_AUTO_TEST_SUITE_END()
1054 
1055 #endif
size_t size() const
return the size of the grid
Definition: map_grid.hpp:1122
This is an N-dimensional grid or an N-dimensional array with memory_traits_inte layout.
Definition: grid_gpu.hpp:28
static std::vector< comb< dim > > getCombinations_R(size_t d)
Definition: HyperCube.hpp:97
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
double getwct()
Return the elapsed real time.
Definition: timer.hpp:102
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:302
double getcputime()
Return the cpu time.
Definition: timer.hpp:114
void fill()
fill
Definition: Point_test.hpp:227
bool isNext()
Check if there is the next element.
void start()
Start the timer.
Definition: timer.hpp:67
This class represent an N-dimensional box.
Definition: Box.hpp:56
const grid_key_dx< dim > & get()
Get the actual key.
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:202
void set(a v, T...t)
set the grid key from a list of numbers
Definition: grid_key.hpp:227
Definition of a class Point in plain C++ and boost::vector for testing purpose.
Definition: Point_orig.hpp:19
class that store the information of the grid like number of point on each direction and define the in...
Definition: grid_sm.hpp:69
void set_d(size_t i, mem_id id)
Set the i index.
Definition: grid_key.hpp:315
Test structure used for several test.
Definition: Point_test.hpp:72
Class for cpu time benchmarking.
Definition: timer.hpp:25
void stop()
Stop the timer.
Definition: timer.hpp:91