OpenFPM_pdata  1.0.0
Project that contain the implementation of distributed structures
 All Data Structures Functions Variables Typedefs Enumerations Friends Pages
grid_dist_id_HDF5_chckpnt_restart_test.hpp
1 /*
2  * grid_dist_id_HDF5_chckpnt_restart_test.hpp
3  *
4  * Created on: Nov 9, 2016
5  * Author: Yaroslav Zaluzhnyi
6  */
7 
8 #ifndef SRC_GRID_GRID_DIST_ID_HDF5_CHCKPNT_RESTART_TEST_HPP_
9 #define SRC_GRID_GRID_DIST_ID_HDF5_CHCKPNT_RESTART_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");
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.getDecomposition().write("Before_load_grid_decomposition");
112  g_dist.write("Before_Loaded_grid");
113 
114  timer t;
115  t.start();
116  // Save the grid
117  g_dist.load("grid_dist_id.h5");
118  t.stop();
119 
120  g_dist.write("Loaded_grid");
121  g_dist.getDecomposition().write("Loaded_grid_decomposition");
122 
123  auto it = g_dist.getDomainIterator();
124 
125  size_t count = 0;
126 
127  while (it.isNext())
128  {
129  //key
130  auto key = it.get();
131 
132  //BOOST_CHECK_CLOSE(g_dist.template get<0>(key),1,0.0001);
133  //std::cout << "Element: " << g_dist.template get<0>(key) << std::endl;
134 
135  auto keyg = g_dist.getGKey(key);
136 
137  BOOST_REQUIRE_EQUAL(g_dist.template get<0>(key), keyg.get(0));
138 
139  ++it;
140  count++;
141  }
142 
143  openfpm::vector<size_t> count_total;
144  v_cl.allGather(count,count_total);
145  v_cl.execute();
146 
147  size_t sum = 0;
148 
149  for (size_t i = 0; i < count_total.size(); i++)
150  sum += count_total.get(i);
151 
152  BOOST_REQUIRE_EQUAL(sum, (size_t)k*k);
153 }
154 
155 
156 BOOST_AUTO_TEST_SUITE_END()
157 
158 #endif /* SRC_GRID_GRID_DIST_ID_HDF5_CHCKPNT_RESTART_TEST_HPP_ */
size_t size()
Stub size.
Definition: map_vector.hpp:70
Definition: Ghost.hpp:37
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