| 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 |
| 41 | grid_dist_id<2, float, aggregate<float>, CartDecomposition<2,float>> g_dist(sz,domain,g); |
| 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 |
| 109 | grid_dist_id<2, float, aggregate<float>, CartDecomposition<2,float>> g_dist(sz,domain,g); |
| 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_CASE( grid_dist_id_hdf5_copy_test ) |
| 149 | { |
| 150 | |
| 151 | // Input data |
| 152 | size_t k = 2400; |
| 153 | |
| 154 | float ghost_part = 0.0; |
| 155 | |
| 156 | // Domain |
| 157 | Box<2,float> domain({0.0,0.0},{1.0,1.0}); |
| 158 | |
| 159 | Vcluster<> & v_cl = create_vcluster(); |
| 160 | |
| 161 | // Skip this test on big scale |
| 162 | if (v_cl.getProcessingUnits() >= 32) |
| 163 | return; |
| 164 | |
| 165 | // grid size |
| 166 | size_t sz[2]; |
| 167 | sz[0] = k; |
| 168 | sz[1] = k; |
| 169 | |
| 170 | // Ghost |
| 171 | Ghost<2,float> g(ghost_part); |
| 172 | |
| 173 | // Distributed grid with id decomposition |
| 174 | grid_dist_id<2, float, aggregate<float>, CartDecomposition<2,float>> g_dist(sz,domain,g); |
| 175 | grid_dist_id<2, float, aggregate<float>, CartDecomposition<2,float>> g_dist_copy(g_dist.getDecomposition(),sz,g); |
| 176 | |
| 177 | g_dist.load("test_data/test_data_three.h5" ); |
| 178 | |
| 179 | // Copy |
| 180 | |
| 181 | auto dom_sc = g_dist.getDomainIterator(); |
| 182 | auto dom_ds = g_dist_copy.getDomainIterator(); |
| 183 | while (dom_sc.isNext()) |
| 184 | { |
| 185 | auto key_sc = dom_sc.get(); |
| 186 | auto key_ds = dom_ds.get(); |
| 187 | g_dist_copy.template get<0>(key_ds) = g_dist.template get<0>(key_sc); |
| 188 | ++dom_sc; |
| 189 | ++dom_ds; |
| 190 | } |
| 191 | |
| 192 | |
| 193 | auto it = g_dist_copy.getDomainIterator(); |
| 194 | |
| 195 | size_t count = 0; |
| 196 | |
| 197 | bool match = true; |
| 198 | while (it.isNext()) |
| 199 | { |
| 200 | //key |
| 201 | auto key = it.get(); |
| 202 | |
| 203 | //BOOST_CHECK_CLOSE(g_dist.template get<0>(key),1,0.0001); |
| 204 | //std::cout << "Element: " << g_dist.template get<0>(key) << std::endl; |
| 205 | |
| 206 | auto keyg = g_dist_copy.getGKey(key); |
| 207 | |
| 208 | match &= g_dist_copy.template get<0>(key) == keyg.get(0); |
| 209 | |
| 210 | ++it; |
| 211 | count++; |
| 212 | } |
| 213 | |
| 214 | openfpm::vector<size_t> count_total; |
| 215 | v_cl.allGather(count,count_total); |
| 216 | v_cl.execute(); |
| 217 | |
| 218 | size_t sum = 0; |
| 219 | |
| 220 | for (size_t i = 0; i < count_total.size(); i++) |
| 221 | sum += count_total.get(i); |
| 222 | |
| 223 | BOOST_REQUIRE_EQUAL(sum, (size_t)k*k); |
| 224 | BOOST_REQUIRE_EQUAL(match,true); |
| 225 | } |
| 226 | |
| 227 | BOOST_AUTO_TEST_CASE( grid_dist_id_hdf5_load_test_diff_proc ) |
| 228 | { |
| 229 | |
| 230 | // Input data |
| 231 | size_t k = 200; |
| 232 | |
| 233 | float ghost_part = 0.0; |
| 234 | |
| 235 | // Domain |
| 236 | Box<2,float> domain({0.0,0.0},{1.0,1.0}); |
| 237 | |
| 238 | Vcluster<> & v_cl = create_vcluster(); |
| 239 | |
| 240 | // Skip this test on big scale |
| 241 | if (v_cl.getProcessingUnits() >= 32) |
| 242 | return; |
| 243 | |
| 244 | // grid size |
| 245 | size_t sz[2]; |
| 246 | sz[0] = k; |
| 247 | sz[1] = k; |
| 248 | |
| 249 | // Ghost |
| 250 | Ghost<2,float> g(3); |
| 251 | |
| 252 | // Distributed grid with id decomposition |
| 253 | grid_dist_id<2, float, aggregate<float>> g_dist(sz,domain,g); |
| 254 | |
| 255 | g_dist.load("test_data/test_data_single.h5" ); |
| 256 | |
| 257 | auto it = g_dist.getDomainIterator(); |
| 258 | |
| 259 | size_t count = 0; |
| 260 | |
| 261 | bool match = true; |
| 262 | while (it.isNext()) |
| 263 | { |
| 264 | //key |
| 265 | auto key = it.get(); |
| 266 | |
| 267 | //BOOST_CHECK_CLOSE(g_dist.template get<0>(key),1,0.0001); |
| 268 | //std::cout << "Element: " << g_dist.template get<0>(key) << std::endl; |
| 269 | |
| 270 | auto keyg = g_dist.getGKey(key); |
| 271 | |
| 272 | match &= g_dist.template get<0>(key) == keyg.get(0); |
| 273 | |
| 274 | ++it; |
| 275 | count++; |
| 276 | } |
| 277 | |
| 278 | v_cl.sum(count); |
| 279 | v_cl.execute(); |
| 280 | |
| 281 | BOOST_REQUIRE_EQUAL(count, (size_t)k*k); |
| 282 | BOOST_REQUIRE_EQUAL(match,true); |
| 283 | } |
| 284 | |
| 285 | BOOST_AUTO_TEST_CASE( grid_dist_id_hdf5_2GB_save_test ) |
| 286 | { |
| 287 | float ghost_part = 0.0; |
| 288 | |
| 289 | // Domain |
| 290 | Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0}); |
| 291 | |
| 292 | Vcluster<> & v_cl = create_vcluster(); |
| 293 | |
| 294 | // Skip this test on big scale |
| 295 | if (v_cl.getProcessingUnits() != 1) |
| 296 | return; |
| 297 | |
| 298 | // grid size |
| 299 | size_t sz[3]; |
| 300 | sz[0] = 970; |
| 301 | sz[1] = 650; |
| 302 | sz[2] = 512; |
| 303 | |
| 304 | // Ghost |
| 305 | Ghost<3,float> g(ghost_part); |
| 306 | |
| 307 | // Distributed grid with id decomposition |
| 308 | grid_dist_id<3, float, aggregate<double>> g_dist(sz,domain,g); |
| 309 | |
| 310 | // get the decomposition |
| 311 | auto & dec = g_dist.getDecomposition(); |
| 312 | |
| 313 | // check the consistency of the decomposition |
| 314 | bool val = dec.check_consistency(); |
| 315 | BOOST_REQUIRE_EQUAL(val,true); |
| 316 | |
| 317 | size_t count = 0; |
| 318 | |
| 319 | auto it = g_dist.getDomainIterator(); |
| 320 | |
| 321 | while (it.isNext()) |
| 322 | { |
| 323 | //key |
| 324 | auto key = it.get(); |
| 325 | |
| 326 | auto keyg = g_dist.getGKey(key); |
| 327 | |
| 328 | g_dist.template get<0>(key) = keyg.get(0); |
| 329 | |
| 330 | ++it; |
| 331 | count++; |
| 332 | } |
| 333 | |
| 334 | openfpm::vector<size_t> count_total; |
| 335 | v_cl.allGather(count,count_total); |
| 336 | v_cl.execute(); |
| 337 | |
| 338 | size_t sum = 0; |
| 339 | |
| 340 | for (size_t i = 0; i < count_total.size(); i++) |
| 341 | {sum += count_total.get(i);} |
| 342 | |
| 343 | timer t; |
| 344 | t.start(); |
| 345 | // Save the grid |
| 346 | g_dist.save("grid_dist_2GB_id.h5" + std::to_string(v_cl.getProcessingUnits())); |
| 347 | t.stop(); |
| 348 | } |
| 349 | |
| 350 | BOOST_AUTO_TEST_CASE( grid_dist_id_hdf5_2GB_load_test ) |
| 351 | { |
| 352 | float ghost_part = 0.0; |
| 353 | |
| 354 | // Domain |
| 355 | Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1,0}); |
| 356 | |
| 357 | Vcluster<> & v_cl = create_vcluster(); |
| 358 | |
| 359 | // Skip this test on big scale |
| 360 | if (v_cl.getProcessingUnits() != 1) |
| 361 | return; |
| 362 | |
| 363 | // grid size |
| 364 | size_t sz[3]; |
| 365 | sz[0] = 970; |
| 366 | sz[1] = 650; |
| 367 | sz[2] = 512; |
| 368 | |
| 369 | // Ghost |
| 370 | Ghost<3,float> g(ghost_part); |
| 371 | |
| 372 | // Distributed grid with id decomposition |
| 373 | grid_dist_id<3, float, aggregate<double>> g_dist(sz,domain,g); |
| 374 | |
| 375 | g_dist.load("grid_dist_2GB_id.h5" + std::to_string(v_cl.getProcessingUnits())); |
| 376 | |
| 377 | auto it = g_dist.getDomainIterator(); |
| 378 | |
| 379 | size_t count = 0; |
| 380 | |
| 381 | bool match = true; |
| 382 | while (it.isNext()) |
| 383 | { |
| 384 | //key |
| 385 | auto key = it.get(); |
| 386 | |
| 387 | //BOOST_CHECK_CLOSE(g_dist.template get<0>(key),1,0.0001); |
| 388 | //std::cout << "Element: " << g_dist.template get<0>(key) << std::endl; |
| 389 | |
| 390 | auto keyg = g_dist.getGKey(key); |
| 391 | |
| 392 | match &= g_dist.template get<0>(key) == keyg.get(0); |
| 393 | |
| 394 | ++it; |
| 395 | count++; |
| 396 | } |
| 397 | |
| 398 | openfpm::vector<size_t> count_total; |
| 399 | v_cl.allGather(count,count_total); |
| 400 | v_cl.execute(); |
| 401 | |
| 402 | size_t sum = 0; |
| 403 | |
| 404 | for (size_t i = 0; i < count_total.size(); i++) |
| 405 | sum += count_total.get(i); |
| 406 | |
| 407 | BOOST_REQUIRE_EQUAL(sum, (size_t)970*650*512); |
| 408 | BOOST_REQUIRE_EQUAL(match,true); |
| 409 | } |
| 410 | |
| 411 | BOOST_AUTO_TEST_SUITE_END() |
| 412 | |
| 413 | |