OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
grid_dist_id_HDF5_chckpnt_restart_test.cpp
1 /*
2  * grid_dist_id_HDF5_chckpnt_restart_test.hpp
3  *
4  * Created on: Nov 9, 2016
5  * Author: Yaroslav Zaluzhnyi
6  */
7 
8 #define BOOST_TEST_DYN_LINK
9 #include <boost/test/unit_test.hpp>
10 
11 #include "Grid/grid_dist_id.hpp"
12 
13 BOOST_AUTO_TEST_SUITE( gd_hdf5_chckpnt_rstrt_test )
14 
15 BOOST_AUTO_TEST_CASE( grid_dist_id_hdf5_save_test )
16 {
17 
18  // Input data
19  size_t k = 2400;
20 
21  float ghost_part = 0.0;
22 
23  // Domain
24  Box<2,float> domain({0.0,0.0},{1.0,1.0});
25 
26  Vcluster & v_cl = create_vcluster();
27 
28  // Skip this test on big scale
29  if (v_cl.getProcessingUnits() >= 32)
30  return;
31 
32  // grid size
33  size_t sz[2];
34  sz[0] = k;
35  sz[1] = k;
36 
37  // Ghost
38  Ghost<2,float> g(ghost_part);
39 
40  // Distributed grid with id decomposition
42 
43  // get the decomposition
44  auto & dec = g_dist.getDecomposition();
45 
46  // check the consistency of the decomposition
47  bool val = dec.check_consistency();
48  BOOST_REQUIRE_EQUAL(val,true);
49 
50  size_t count = 0;
51 
52  auto it = g_dist.getDomainIterator();
53 
54  while (it.isNext())
55  {
56  //key
57  auto key = it.get();
58 
59  auto keyg = g_dist.getGKey(key);
60 
61  g_dist.template get<0>(key) = keyg.get(0);
62 
63  ++it;
64  count++;
65  }
66 
67  openfpm::vector<size_t> count_total;
68  v_cl.allGather(count,count_total);
69  v_cl.execute();
70 
71  size_t sum = 0;
72 
73  for (size_t i = 0; i < count_total.size(); i++)
74  {sum += count_total.get(i);}
75 
76  timer t;
77  t.start();
78  // Save the grid
79  g_dist.save("grid_dist_id.h5" + std::to_string(v_cl.getProcessingUnits()));
80  t.stop();
81 }
82 
83 BOOST_AUTO_TEST_CASE( grid_dist_id_hdf5_load_test )
84 {
85 
86  // Input data
87  size_t k = 2400;
88 
89  float ghost_part = 0.0;
90 
91  // Domain
92  Box<2,float> domain({0.0,0.0},{1.0,1.0});
93 
94  Vcluster & v_cl = create_vcluster();
95 
96  // Skip this test on big scale
97  if (v_cl.getProcessingUnits() >= 32)
98  return;
99 
100  // grid size
101  size_t sz[2];
102  sz[0] = k;
103  sz[1] = k;
104 
105  // Ghost
106  Ghost<2,float> g(ghost_part);
107 
108  // Distributed grid with id decomposition
110 
111  g_dist.load("grid_dist_id.h5" + std::to_string(v_cl.getProcessingUnits()));
112 
113  auto it = g_dist.getDomainIterator();
114 
115  size_t count = 0;
116 
117  bool match = true;
118  while (it.isNext())
119  {
120  //key
121  auto key = it.get();
122 
123  //BOOST_CHECK_CLOSE(g_dist.template get<0>(key),1,0.0001);
124  //std::cout << "Element: " << g_dist.template get<0>(key) << std::endl;
125 
126  auto keyg = g_dist.getGKey(key);
127 
128  match &= g_dist.template get<0>(key) == keyg.get(0);
129 
130  ++it;
131  count++;
132  }
133 
134  openfpm::vector<size_t> count_total;
135  v_cl.allGather(count,count_total);
136  v_cl.execute();
137 
138  size_t sum = 0;
139 
140  for (size_t i = 0; i < count_total.size(); i++)
141  sum += count_total.get(i);
142 
143  BOOST_REQUIRE_EQUAL(sum, (size_t)k*k);
144  BOOST_REQUIRE_EQUAL(match,true);
145 }
146 
147 
148 BOOST_AUTO_TEST_SUITE_END()
149 
size_t size()
Stub size.
Definition: map_vector.hpp:70
Definition: Ghost.hpp:39
Implementation of VCluster class.
Definition: VCluster.hpp:36
This class decompose a space into sub-sub-domains and distribute them across processors.
This is a distributed grid.
void start()
Start the timer.
Definition: timer.hpp:73
This class represent an N-dimensional box.
Definition: Box.hpp:56
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
It model an expression expr1 + ... exprn.
Definition: sum.hpp:92
Class for cpu time benchmarking.
Definition: timer.hpp:25
void stop()
Stop the timer.
Definition: timer.hpp:97