1#ifndef AMREX_PARTICLEHDF5_H
2#define AMREX_PARTICLEHDF5_H
4#include <AMReX_Config.H>
11#ifdef AMREX_USE_HDF5_ZFP
12#include "H5Zzfp_lib.h"
13#include "H5Zzfp_props.h"
16#ifdef AMREX_USE_HDF5_SZ
22template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
23 template<
class>
class Allocator,
class CellAssignor>
25ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
26::CheckpointHDF5 (
const std::string& dir,
27 const std::string& name,
bool ,
28 const Vector<std::string>& real_comp_names,
29 const Vector<std::string>& int_comp_names,
30 const std::string& compression)
const
32 Vector<int> write_real_comp;
33 Vector<std::string> tmp_real_comp_names;
34 for (
int i = 0; i < NStructReal + NumRealComps(); ++i )
36 write_real_comp.push_back(1);
37 if (real_comp_names.size() == 0)
40 ss <<
"real_comp" << i;
41 tmp_real_comp_names.push_back(ss.str());
45 tmp_real_comp_names.push_back(real_comp_names[i]);
49 Vector<int> write_int_comp;
50 Vector<std::string> tmp_int_comp_names;
51 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
53 write_int_comp.push_back(1);
54 if (int_comp_names.size() == 0)
57 ss <<
"int_comp" << i;
58 tmp_int_comp_names.push_back(ss.str());
62 tmp_int_comp_names.push_back(int_comp_names[i]);
67 tmp_real_comp_names, tmp_int_comp_names,
75template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
76 template<
class>
class Allocator,
class CellAssignor>
78ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
79::CheckpointHDF5 (
const std::string& dir,
const std::string& name,
80 const std::string& compression)
const
82 Vector<int> write_real_comp;
83 Vector<std::string> real_comp_names;
84 for (
int i = 0; i < NStructReal + NumRealComps(); ++i )
86 write_real_comp.push_back(1);
88 ss <<
"real_comp" << i;
89 real_comp_names.push_back(ss.str());
92 Vector<int> write_int_comp;
93 Vector<std::string> int_comp_names;
94 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
96 write_int_comp.push_back(1);
98 ss <<
"int_comp" << i;
99 int_comp_names.push_back(ss.str());
103 real_comp_names, int_comp_names,
111template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
112 template<
class>
class Allocator,
class CellAssignor>
114ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
115::WritePlotFileHDF5 (
const std::string& dir,
const std::string& name,
116 const std::string& compression)
const
118 Vector<int> write_real_comp;
119 Vector<std::string> real_comp_names;
120 for (
int i = 0; i < NStructReal + NumRealComps(); ++i )
122 write_real_comp.push_back(1);
123 std::stringstream ss;
124 ss <<
"real_comp" << i;
125 real_comp_names.push_back(ss.str());
128 Vector<int> write_int_comp;
129 Vector<std::string> int_comp_names;
130 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
132 write_int_comp.push_back(1);
133 std::stringstream ss;
134 ss <<
"int_comp" << i;
135 int_comp_names.push_back(ss.str());
139 real_comp_names, int_comp_names,
147template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
148 template<
class>
class Allocator,
class CellAssignor>
150ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
151::WritePlotFileHDF5 (
const std::string& dir,
const std::string& name,
152 const Vector<std::string>& real_comp_names,
153 const Vector<std::string>& int_comp_names,
154 const std::string& compression)
const
156 AMREX_ASSERT(real_comp_names.size() == NStructReal + NumRealComps());
157 AMREX_ASSERT( int_comp_names.size() == NStructInt + NumIntComps() );
159 Vector<int> write_real_comp;
160 for (
int i = 0; i < NStructReal + NumRealComps(); ++i) { write_real_comp.push_back(1); }
162 Vector<int> write_int_comp;
163 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) { write_int_comp.push_back(1); }
166 write_real_comp, write_int_comp,
167 real_comp_names, int_comp_names,
175template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
176 template<
class>
class Allocator,
class CellAssignor>
178ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
179::WritePlotFileHDF5 (
const std::string& dir,
const std::string& name,
180 const Vector<std::string>& real_comp_names,
181 const std::string& compression)
const
183 AMREX_ASSERT(real_comp_names.size() == NStructReal + NumRealComps());
185 Vector<int> write_real_comp;
186 for (
int i = 0; i < NStructReal + NumRealComps(); ++i) write_real_comp.push_back(1);
188 Vector<int> write_int_comp;
189 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) write_int_comp.push_back(1);
191 Vector<std::string> int_comp_names;
192 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
194 std::stringstream ss;
195 ss <<
"int_comp" << i;
196 int_comp_names.push_back(ss.str());
200 write_real_comp, write_int_comp,
201 real_comp_names, int_comp_names,
209template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
210 template<
class>
class Allocator,
class CellAssignor>
212ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
213::WritePlotFileHDF5 (
const std::string& dir,
214 const std::string& name,
215 const Vector<int>& write_real_comp,
216 const Vector<int>& write_int_comp,
217 const std::string& compression)
const
219 AMREX_ASSERT(write_real_comp.size() == NStructReal + NumRealComps());
220 AMREX_ASSERT(write_int_comp.size() == NStructInt + NArrayInt );
222 Vector<std::string> real_comp_names;
223 for (
int i = 0; i < NStructReal + NumRealComps(); ++i )
225 std::stringstream ss;
226 ss <<
"real_comp" << i;
227 real_comp_names.push_back(ss.str());
230 Vector<std::string> int_comp_names;
231 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
233 std::stringstream ss;
234 ss <<
"int_comp" << i;
235 int_comp_names.push_back(ss.str());
239 real_comp_names, int_comp_names,
247template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
248 template<
class>
class Allocator,
class CellAssignor>
250ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::
251WritePlotFileHDF5 (
const std::string& dir,
const std::string& name,
252 const Vector<int>& write_real_comp,
253 const Vector<int>& write_int_comp,
254 const Vector<std::string>& real_comp_names,
255 const Vector<std::string>& int_comp_names,
256 const std::string& compression)
const
258 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
261 write_real_comp, write_int_comp,
262 real_comp_names, int_comp_names,
270template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
271 template<
class>
class Allocator,
class CellAssignor>
272template <
class F, std::enable_if_t<!std::is_same_v<F, Vector<std::
string>>>*>
274ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
275::WritePlotFileHDF5 (
const std::string& dir,
const std::string& name,
276 const std::string& compression,
F&& f)
const
278 Vector<int> write_real_comp;
279 Vector<std::string> real_comp_names;
280 for (
int i = 0; i < NStructReal + NumRealComps(); ++i )
282 write_real_comp.push_back(1);
283 std::stringstream ss;
284 ss <<
"real_comp" << i;
285 real_comp_names.push_back(ss.str());
288 Vector<int> write_int_comp;
289 Vector<std::string> int_comp_names;
290 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
292 write_int_comp.push_back(1);
293 std::stringstream ss;
294 ss <<
"int_comp" << i;
295 int_comp_names.push_back(ss.str());
299 real_comp_names, int_comp_names, compression,
303template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
304 template<
class>
class Allocator,
class CellAssignor>
307ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
308::WritePlotFileHDF5 (
const std::string& dir,
const std::string& name,
309 const Vector<std::string>& real_comp_names,
310 const Vector<std::string>& int_comp_names,
311 const std::string& compression,
F&& f)
const
313 AMREX_ASSERT(real_comp_names.size() == NStructReal + NumRealComps());
314 AMREX_ASSERT( int_comp_names.size() == NStructInt + NArrayInt );
316 Vector<int> write_real_comp;
317 for (
int i = 0; i < NStructReal + NumRealComps(); ++i) { write_real_comp.push_back(1); }
319 Vector<int> write_int_comp;
320 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) { write_int_comp.push_back(1); }
323 write_real_comp, write_int_comp,
324 real_comp_names, int_comp_names,
325 compression, std::forward<F>(f));
328template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
329 template<
class>
class Allocator,
class CellAssignor>
330template <
class F, std::enable_if_t<!std::is_same_v<F, Vector<std::
string>>>*>
332ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
333::WritePlotFileHDF5 (
const std::string& dir,
const std::string& name,
334 const Vector<std::string>& real_comp_names,
335 const std::string& compression,
F&& f)
const
337 AMREX_ASSERT(real_comp_names.size() == NStructReal + NumRealComps());
339 Vector<int> write_real_comp;
340 for (
int i = 0; i < NStructReal + NumRealComps(); ++i) { write_real_comp.push_back(1); }
342 Vector<int> write_int_comp;
343 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) { write_int_comp.push_back(1); }
345 Vector<std::string> int_comp_names;
346 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
348 std::stringstream ss;
349 ss <<
"int_comp" << i;
350 int_comp_names.push_back(ss.str());
354 write_real_comp, write_int_comp,
355 real_comp_names, int_comp_names,
356 compression, std::forward<F>(f));
359template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
360 template<
class>
class Allocator,
class CellAssignor>
363ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
364::WritePlotFileHDF5 (
const std::string& dir,
365 const std::string& name,
366 const Vector<int>& write_real_comp,
367 const Vector<int>& write_int_comp,
368 const std::string& compression,
F&& f)
const
370 AMREX_ASSERT(write_real_comp.size() == NStructReal + NumRealComps());
371 AMREX_ASSERT(write_int_comp.size() == NStructInt + NumIntComps() );
373 Vector<std::string> real_comp_names;
374 for (
int i = 0; i < NStructReal + NumRealComps(); ++i )
376 std::stringstream ss;
377 ss <<
"real_comp" << i;
378 real_comp_names.push_back(ss.str());
381 Vector<std::string> int_comp_names;
382 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
384 std::stringstream ss;
385 ss <<
"int_comp" << i;
386 int_comp_names.push_back(ss.str());
390 real_comp_names, int_comp_names,
391 compression, std::forward<F>(f));
394template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
395 template<
class>
class Allocator,
class CellAssignor>
398ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::
399WritePlotFileHDF5 (
const std::string& dir,
const std::string& name,
400 const Vector<int>& write_real_comp,
401 const Vector<int>& write_int_comp,
402 const Vector<std::string>& real_comp_names,
403 const Vector<std::string>& int_comp_names,
404 const std::string& compression,
F&& f)
const
406 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
409 write_real_comp, write_int_comp,
410 real_comp_names, int_comp_names,
411 compression, std::forward<F>(f));
414template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
415 template<
class>
class Allocator,
class CellAssignor>
418ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
419::WriteHDF5ParticleData (
const std::string& dir,
const std::string& name,
420 const Vector<int>& write_real_comp,
421 const Vector<int>& write_int_comp,
422 const Vector<std::string>& real_comp_names,
423 const Vector<std::string>& int_comp_names,
424 const std::string& compression,
425 F&& f,
bool is_checkpoint)
const
435 write_real_comp, write_int_comp,
436 real_comp_names, int_comp_names,
438 std::forward<F>(f), is_checkpoint);
442template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
443 template<
class>
class Allocator,
class CellAssignor>
445ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
446::CheckpointPreHDF5 ()
452 BL_PROFILE(
"ParticleContainer::CheckpointPre()");
456 Long maxnextid = ParticleType::NextID();
458 for (
int lev = 0; lev < m_particles.size(); lev++) {
459 const auto& pmap = m_particles[lev];
460 for (
const auto& kv : pmap) {
461 const auto& aos = kv.second.GetArrayOfStructs();
462 for (
int k = 0; k < aos.numParticles(); ++k) {
463 const ParticleType& p = aos[k];
475 ParticleType::NextID(maxnextid);
478 nparticlesPrePost = nparticles;
479 maxnextidPrePost = maxnextid;
481 nParticlesAtLevelPrePost.clear();
482 nParticlesAtLevelPrePost.resize(finestLevel() + 1, 0);
483 for(
int lev(0); lev <= finestLevel(); ++lev) {
484 nParticlesAtLevelPrePost[lev] = NumberOfParticlesAtLevel(lev);
487 whichPrePost.clear();
488 whichPrePost.resize(finestLevel() + 1);
489 countPrePost.clear();
490 countPrePost.resize(finestLevel() + 1);
491 wherePrePost.clear();
492 wherePrePost.resize(finestLevel() + 1);
494 filePrefixPrePost.clear();
495 filePrefixPrePost.resize(finestLevel() + 1);
499template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
500 template<
class>
class Allocator,
class CellAssignor>
502ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
503::CheckpointPostHDF5 ()
509 BL_PROFILE(
"ParticleContainer::CheckpointPostHDF5()");
512 std::ofstream HdrFile;
513 HdrFile.open(HdrFileNamePrePost.c_str(), std::ios::out | std::ios::app);
515 for(
int lev(0); lev <= finestLevel(); ++lev) {
522 for(
int j(0); j < whichPrePost[lev].size(); ++j) {
523 HdrFile << whichPrePost[lev][j] <<
' ' << countPrePost[lev][j] <<
' ' << wherePrePost[lev][j] <<
'\n';
526 const bool gotsome = (nParticlesAtLevelPrePost[lev] > 0);
527 if(gotsome && doUnlink) {
530 Vector<Long> cnt(nOutFilesPrePost,0);
532 for(
int i(0), N = countPrePost[lev].
size(); i < N; ++i) {
533 cnt[whichPrePost[lev][i]] += countPrePost[lev][i];
536 for(
int i(0), N = cnt.size(); i < N; ++i) {
549 if( ! HdrFile.good()) {
550 amrex::Abort(
"ParticleContainer::CheckpointPostHDF5(): problem writing HdrFile");
555template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
556 template<
class>
class Allocator,
class CellAssignor>
558ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
559::WritePlotFilePreHDF5 ()
565template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
566 template<
class>
class Allocator,
class CellAssignor>
568ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
569::WritePlotFilePostHDF5 ()
575template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
576 template<
class>
class Allocator,
class CellAssignor>
578ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
579::WriteParticlesHDF5 (
int lev, hid_t grp,
580 Vector<int>& which, Vector<int>& count, Vector<Long>& where,
581 const Vector<int>& write_real_comp,
582 const Vector<int>& write_int_comp,
583 const std::string& compression,
584 const Vector<std::map<std::pair<int, int>, IntVector>>& particle_io_flags,
585 bool is_checkpoint)
const
587 BL_PROFILE(
"ParticleContainer::WriteParticlesHDF5()");
590 std::map<int, Vector<int> > tile_map;
593 hid_t dxpl_col, dxpl_ind, dcpl_int, dcpl_real;
594 dxpl_col = H5Pcreate(H5P_DATASET_XFER);
595 dxpl_ind = H5Pcreate(H5P_DATASET_XFER);
597 H5Pset_dxpl_mpio(dxpl_col, H5FD_MPIO_COLLECTIVE);
599 dcpl_int = H5Pcreate(H5P_DATASET_CREATE);
600 dcpl_real = H5Pcreate(H5P_DATASET_CREATE);
602 std::string mode_env, value_env;
603 double comp_value = -1.0;
604 std::string::size_type pos = compression.find(
'@');
605 if (pos != std::string::npos) {
606 mode_env = compression.substr(0, pos);
607 value_env = compression.substr(pos+1);
608 if (!value_env.empty()) {
609 comp_value = atof(value_env.c_str());
613 H5Pset_alloc_time(dcpl_int, H5D_ALLOC_TIME_LATE);
614 H5Pset_alloc_time(dcpl_real, H5D_ALLOC_TIME_LATE);
616 if (!mode_env.empty() && mode_env !=
"None") {
617 const char *chunk_env = NULL;
618 hsize_t chunk_dim = 1024;
619 chunk_env = getenv(
"HDF5_CHUNK_SIZE");
620 if (chunk_env != NULL) {
621 chunk_dim = atoi(chunk_env);
624 H5Pset_chunk(dcpl_int, 1, &chunk_dim);
625 H5Pset_chunk(dcpl_real, 1, &chunk_dim);
627#ifdef AMREX_USE_HDF5_ZFP
628 pos = mode_env.find(
"ZFP");
629 if (pos != std::string::npos) {
630 ret = H5Z_zfp_initialize();
631 if (ret < 0) {
amrex::Abort(
"ZFP initialize failed!"); }
635 if (mode_env ==
"ZLIB") {
636 H5Pset_shuffle(dcpl_int);
637 H5Pset_shuffle(dcpl_real);
638 H5Pset_deflate(dcpl_int, (
int)comp_value);
639 H5Pset_deflate(dcpl_real, (
int)comp_value);
641#ifdef AMREX_USE_HDF5_SZ
642 else if (mode_env ==
"SZ") {
643 ret = H5Z_SZ_Init((
char*)value_env.c_str());
645 std::cout <<
"SZ config file:" << value_env.c_str() << std::endl;
646 amrex::Abort(
"SZ initialize failed, check SZ config file!");
650#ifdef AMREX_USE_HDF5_ZFP
651 else if (mode_env ==
"ZFP_RATE") {
652 H5Pset_zfp_rate(dcpl_int, comp_value);
653 H5Pset_zfp_rate(dcpl_real, comp_value);
655 else if (mode_env ==
"ZFP_PRECISION") {
656 H5Pset_zfp_precision(dcpl_int, (
unsigned int)comp_value);
657 H5Pset_zfp_precision(dcpl_real, (
unsigned int)comp_value);
659 else if (mode_env ==
"ZFP_ACCURACY") {
660 H5Pset_zfp_accuracy(dcpl_int, comp_value);
661 H5Pset_zfp_accuracy(dcpl_real, comp_value);
663 else if (mode_env ==
"ZFP_REVERSIBLE") {
664 H5Pset_zfp_reversible(dcpl_int);
665 H5Pset_zfp_reversible(dcpl_real);
669 std::cout <<
"\nHDF5 particle checkpoint using " << mode_env <<
", " <<
670 value_env <<
", " << chunk_dim << std::endl;
674 for (
const auto& kv : m_particles[lev])
676 const int grid = kv.first.first;
677 const int tile = kv.first.second;
678 tile_map[grid].push_back(tile);
679 const auto& pflags = particle_io_flags[lev].at(kv.first);
686 info.SetAlloc(
false);
687 MultiFab state(ParticleBoxArray(lev), ParticleDistributionMap(lev), 1,0,info);
690 ULong my_mfi_int_total_size = 0, my_mfi_real_total_size = 0, int_size, real_size;
692 Vector<int> my_mfi_real_size;
693 Vector<int> my_mfi_int_size;
694 Vector<int> my_nparticles;
697 hid_t offset_id, offset_space, real_mem_space, real_dset_space, real_dset_id;
698 hid_t int_mem_space, int_dset_id, int_dset_space;
699 hsize_t total_mfi = 0, total_real_size = 0, total_int_size = 0, real_file_offset = 0, int_file_offset = 0;
700 hsize_t my_int_offset, my_int_count, my_real_offset, my_real_count;
703 int real_comp_count = AMREX_SPACEDIM;
705 for (
int i = 0; i < NStructReal + NumRealComps(); ++i ) {
706 if (write_real_comp[i]) { ++real_comp_count; }
709 int int_comp_count = 2;
711 for (
int i = 0; i < NStructInt + NumIntComps(); ++i ) {
712 if (write_int_comp[i]) { ++int_comp_count; }
716 for (MFIter mfi(state); mfi.isValid(); ++mfi) {
717 const int grid = mfi.index();
718 if (count[grid] == 0)
721 int_size = count[grid] * int_comp_count;
722 my_mfi_int_size.push_back(int_size);
723 my_nparticles.push_back(count[grid]);
724 my_mfi_int_total_size += int_size;
727 real_size = count[grid] * real_comp_count;
728 my_mfi_real_size.push_back(real_size);
729 my_mfi_real_total_size += real_size;
739 total_mfi += all_mfi_cnt[i];
745 all_mfi_cnt[0] = my_mfi_cnt;
746 all_mfi_int_total_size[0] = my_mfi_int_total_size;
751 int_file_offset += all_mfi_int_total_size[i];
752 my_int_offset = int_file_offset;
756 total_int_size += all_mfi_int_total_size[i];
770 if (H5Pget_layout(dcpl_int) == H5D_CHUNKED) {
771 if (H5Pget_chunk(dcpl_int, 1, &chunk_size) > -1) {
772 if (chunk_size > total_int_size) {
773 H5Pset_chunk(dcpl_int, 1, &total_int_size);
778 int_dset_space = H5Screate_simple(1, &total_int_size, NULL);
779#ifdef AMREX_USE_HDF5_ASYNC
780 int_dset_id = H5Dcreate_async(grp,
"data:datatype=0", H5T_NATIVE_INT, int_dset_space, H5P_DEFAULT, dcpl_int, H5P_DEFAULT, es_par_g);
782 int_dset_id = H5Dcreate(grp,
"data:datatype=0", H5T_NATIVE_INT, int_dset_space, H5P_DEFAULT, dcpl_int, H5P_DEFAULT);
785 H5Sclose(int_dset_space);
792 all_mfi_real_total_size[0] = my_mfi_real_total_size;
796 total_real_size += all_mfi_real_total_size[i];
798#ifdef AMREX_USE_HDF5_SZ
799 if (mode_env ==
"SZ") {
801 unsigned int* cd_values = NULL;
802 unsigned filter_config;
803 if (
sizeof(
typename ParticleType::RealType) == 4) {
804 SZ_metaDataToCdArray(&cd_nelmts, &cd_values, SZ_FLOAT, 0, 0, 0, 0, total_real_size);
805 H5Pset_filter(dcpl_real, H5Z_FILTER_SZ, H5Z_FLAG_MANDATORY, cd_nelmts, cd_values);
808 SZ_metaDataToCdArray(&cd_nelmts, &cd_values, SZ_DOUBLE, 0, 0, 0, 0, total_real_size);
809 H5Pset_filter(dcpl_real, H5Z_FILTER_SZ, H5Z_FLAG_MANDATORY, cd_nelmts, cd_values);
814 if (H5Pget_layout(dcpl_real) == H5D_CHUNKED) {
815 if (H5Pget_chunk(dcpl_real, 1, &chunk_size) > -1) {
816 if (chunk_size > total_real_size) {
817 H5Pset_chunk(dcpl_real, 1, &total_real_size);
822 real_dset_space = H5Screate_simple(1, &total_real_size, NULL);
823 if (
sizeof(
typename ParticleType::RealType) == 4) {
824#ifdef AMREX_USE_HDF5_ASYNC
825 real_dset_id = H5Dcreate_async(grp,
"data:datatype=1", H5T_NATIVE_FLOAT, real_dset_space,
826 H5P_DEFAULT, dcpl_real, H5P_DEFAULT, es_par_g);
828 real_dset_id = H5Dcreate(grp,
"data:datatype=1", H5T_NATIVE_FLOAT, real_dset_space,
829 H5P_DEFAULT, dcpl_real, H5P_DEFAULT);
833#ifdef AMREX_USE_HDF5_ASYNC
834 real_dset_id = H5Dcreate_async(grp,
"data:datatype=1", H5T_NATIVE_DOUBLE, real_dset_space,
835 H5P_DEFAULT, dcpl_real, H5P_DEFAULT, es_par_g);
837 real_dset_id = H5Dcreate(grp,
"data:datatype=1", H5T_NATIVE_DOUBLE, real_dset_space,
838 H5P_DEFAULT, dcpl_real, H5P_DEFAULT);
841 H5Sclose(real_dset_space);
843 real_file_offset = 0;
845 real_file_offset += all_mfi_real_total_size[i];
847 my_real_offset = real_file_offset;
850 int max_mfi_count = 0, write_count = 0;
852 if (max_mfi_count < all_mfi_cnt[i]) {
853 max_mfi_count = all_mfi_cnt[i];
858 for (MFIter mfi(state); mfi.isValid(); ++mfi)
860 const int grid = mfi.index();
862 if (count[grid] == 0) {
continue; }
865 Vector<ParticleReal> rstuff;
867 write_real_comp, write_int_comp,
868 particle_io_flags, tile_map[grid], count[grid],
871 my_int_count = istuff.size();
872 int_mem_space = H5Screate_simple(1, &my_int_count, NULL);
875 int_dset_space = H5Screate_simple(1, &total_int_size, NULL);
876 H5Sselect_hyperslab (int_dset_space, H5S_SELECT_SET, &my_int_offset, NULL, &my_int_count, NULL);
878#ifdef AMREX_USE_HDF5_ASYNC
879 ret = H5Dwrite_async(int_dset_id, H5T_NATIVE_INT, int_mem_space, int_dset_space, dxpl_col, istuff.dataPtr(), es_par_g);
881 ret = H5Dwrite(int_dset_id, H5T_NATIVE_INT, int_mem_space, int_dset_space, dxpl_col, istuff.dataPtr());
883 if (ret < 0) {
amrex::Abort(
"H5Dwrite int_dset failed!"); }
885 H5Sclose(int_dset_space);
886 H5Sclose(int_mem_space);
888 my_int_offset += my_int_count;
890 my_real_count = rstuff.size();
891 real_mem_space = H5Screate_simple(1, &my_real_count, NULL);
894 real_dset_space = H5Screate_simple(1, &total_real_size, NULL);
895 H5Sselect_hyperslab (real_dset_space, H5S_SELECT_SET, &my_real_offset, NULL, &my_real_count, NULL);
896 if (
sizeof(
typename ParticleType::RealType) == 4) {
897#ifdef AMREX_USE_HDF5_ASYNC
898 ret = H5Dwrite_async(real_dset_id, H5T_NATIVE_FLOAT, real_mem_space, real_dset_space, dxpl_col, rstuff.dataPtr(), es_par_g);
900 ret = H5Dwrite(real_dset_id, H5T_NATIVE_FLOAT, real_mem_space, real_dset_space, dxpl_col, rstuff.dataPtr());
903#ifdef AMREX_USE_HDF5_ASYNC
904 ret = H5Dwrite_async(real_dset_id, H5T_NATIVE_DOUBLE, real_mem_space, real_dset_space, dxpl_col, rstuff.dataPtr(), es_par_g);
906 ret = H5Dwrite(real_dset_id, H5T_NATIVE_DOUBLE, real_mem_space, real_dset_space, dxpl_col, rstuff.dataPtr());
910 if (ret < 0) {
amrex::Abort(
"H5Dwrite real_dset failed!"); }
912 H5Sclose(real_mem_space);
913 H5Sclose(real_dset_space);
915 my_real_offset += my_real_count;
921 while (write_count < max_mfi_count) {
922 int_dset_space = H5Screate_simple(1, &total_int_size, NULL);
923 real_dset_space = H5Screate_simple(1, &total_real_size, NULL);
924 H5Sselect_none(int_dset_space);
925 H5Sselect_none(real_dset_space);
927#ifdef AMREX_USE_HDF5_ASYNC
928 H5Dwrite_async(int_dset_id, H5T_NATIVE_INT, int_dset_space, int_dset_space, dxpl_col, NULL, es_par_g);
929 if (
sizeof(
typename ParticleType::RealType) == 4) {
930 H5Dwrite_async(real_dset_id, H5T_NATIVE_FLOAT, real_dset_space, real_dset_space, dxpl_col, NULL, es_par_g);
932 H5Dwrite_async(real_dset_id, H5T_NATIVE_DOUBLE, real_dset_space, real_dset_space, dxpl_col, NULL, es_par_g);
935 H5Dwrite(int_dset_id, H5T_NATIVE_INT, int_dset_space, int_dset_space, dxpl_col, NULL);
936 if (
sizeof(
typename ParticleType::RealType) == 4) {
937 H5Dwrite(real_dset_id, H5T_NATIVE_FLOAT, real_dset_space, real_dset_space, dxpl_col, NULL);
939 H5Dwrite(real_dset_id, H5T_NATIVE_DOUBLE, real_dset_space, real_dset_space, dxpl_col, NULL);
943 H5Sclose(int_dset_space);
944 H5Sclose(real_dset_space);
949#ifdef AMREX_USE_HDF5_ASYNC
950 H5Dclose_async(real_dset_id, es_par_g);
951 H5Dclose_async(int_dset_id, es_par_g);
953 H5Dclose(real_dset_id);
954 H5Dclose(int_dset_id);
958 offset_space = H5Screate_simple(1, &total_mfi, NULL);
959#ifdef AMREX_USE_HDF5_ASYNC
960 offset_id = H5Dcreate_async(grp,
"nparticles_grid", H5T_NATIVE_INT, offset_space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT, es_par_g);
962 offset_id = H5Dcreate(grp,
"nparticles_grid", H5T_NATIVE_INT, offset_space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
967 my_int_offset += all_mfi_cnt[i];
969 my_int_count = my_mfi_cnt;
970 int_mem_space = H5Screate_simple(1, &my_int_count, NULL);
973 H5Sselect_hyperslab (offset_space, H5S_SELECT_SET, &my_int_offset, NULL, &my_int_count, NULL);
975#ifdef AMREX_USE_HDF5_ASYNC
976 ret = H5Dwrite_async(offset_id, H5T_NATIVE_INT, int_mem_space, offset_space, dxpl_col, &(my_nparticles[0]), es_par_g);
978 ret = H5Dwrite(offset_id, H5T_NATIVE_INT, int_mem_space, offset_space, dxpl_col, &(my_nparticles[0]));
980 if (ret < 0) {
amrex::Abort(
"H5Dwrite offset failed!"); }
987 H5Sclose(int_mem_space);
988 H5Sclose(offset_space);
990#ifdef AMREX_USE_HDF5_ASYNC
991 H5Dclose_async(offset_id, es_par_g);
1000template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1001 template<
class>
class Allocator,
class CellAssignor>
1003ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1004::RestartHDF5 (
const std::string& dir,
const std::string& file,
bool )
1009template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1010 template<
class>
class Allocator,
class CellAssignor>
1012ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1013::RestartHDF5 (
const std::string& dir,
const std::string& file)
1015 BL_PROFILE(
"ParticleContainer::RestartHDF5()");
1021 std::string fullname = dir;
1022 if (!fullname.empty() && fullname[fullname.size()-1] !=
'/') {
1029 hid_t fid, dset, grp, fapl, attr, atype, dspace, int_dset, real_dset;
1032 fapl = H5Pcreate (H5P_FILE_ACCESS);
1039 fid = H5Fopen(fullname.c_str(), H5F_ACC_RDONLY, fapl);
1041 std::string msg(
"ParticleContainer::RestartHDF5(): unable to open file: ");
1046 attr = H5Aopen(fid,
"version_name", H5P_DEFAULT);
1048 std::string msg(
"ParticleContainer::RestartHDF5(): unable to open version attribute ");
1052 atype = H5Aget_type(attr);
1054 std::string msg(
"ParticleContainer::RestartHDF5(): unable to get type of attribute ");
1058 size_t attr_len = H5Tget_size(atype);
1059 if (attr_len == 0) {
1060 std::string msg(
"ParticleContainer::RestartHDF5(): unable to get size of attribute ");
1064 std::string version;
1065 version.resize(attr_len+1);
1067 ret = H5Aread(attr, atype, &version[0]);
1082 bool convert_ids =
false;
1083 if (version.find(
"Version_Two_Dot_One") != std::string::npos) {
1086 if (version.find(
"_single") != std::string::npos) {
1089 else if (version.find(
"_double") != std::string::npos) {
1093 std::string msg(
"ParticleContainer::Restart(): bad version string: ");
1098 std::string gname =
"Chombo_global";
1099 std::string aname =
"SpaceDim";
1101 grp = H5Gopen(fid, gname.c_str(), H5P_DEFAULT);
1103 std::string msg(
"ParticleContainer::RestartHDF5(): unable to open group ");
1107 ret =
ReadHDF5Attr(grp, aname.c_str(), &dm, H5T_NATIVE_INT);
1109 std::string msg(
"ParticleContainer::RestartHDF5(): unable to read attribute ");
1115 aname =
"num_component_real";
1117 ret =
ReadHDF5Attr(fid, aname.c_str(), &nr, H5T_NATIVE_INT);
1119 std::string msg(
"ParticleContainer::RestartHDF5(): unable to read attribute ");
1123 if (nr != NStructReal + NumRealComps())
1124 amrex::Abort(
"ParticleContainer::Restart(): nr != NStructReal + NumRealComps()");
1126 aname =
"num_component_int";
1128 ret =
ReadHDF5Attr(fid, aname.c_str(), &ni, H5T_NATIVE_INT);
1130 std::string msg(
"ParticleContainer::RestartHDF5(): unable to read attribute ");
1134 if (ni != NStructInt + NumIntComps()) {
1135 amrex::Abort(
"ParticleContainer::Restart(): ni != NStructInt");
1138 aname =
"nparticles";
1140 ret =
ReadHDF5Attr(fid, aname.c_str(), &nparticles, H5T_NATIVE_LLONG);
1142 std::string msg(
"ParticleContainer::RestartHDF5(): unable to read attribute ");
1148 aname =
"maxnextid";
1150 ret =
ReadHDF5Attr(fid, aname.c_str(), &maxnextid, H5T_NATIVE_LLONG);
1152 std::string msg(
"ParticleContainer::RestartHDF5(): unable to read attribute ");
1157 ParticleType::NextID(maxnextid);
1159 aname =
"finest_level";
1160 int finest_level_in_file;
1161 ret =
ReadHDF5Attr(fid, aname.c_str(), &finest_level_in_file, H5T_NATIVE_INT);
1163 std::string msg(
"ParticleContainer::RestartHDF5(): unable to read attribute ");
1169 hid_t comp_dtype = H5Tcreate (H5T_COMPOUND, 2 * AMREX_SPACEDIM *
sizeof(
int));
1170 if (1 == AMREX_SPACEDIM) {
1171 H5Tinsert (comp_dtype,
"lo_i", 0 *
sizeof(
int), H5T_NATIVE_INT);
1172 H5Tinsert (comp_dtype,
"hi_i", 1 *
sizeof(
int), H5T_NATIVE_INT);
1174 else if (2 == AMREX_SPACEDIM) {
1175 H5Tinsert (comp_dtype,
"lo_i", 0 *
sizeof(
int), H5T_NATIVE_INT);
1176 H5Tinsert (comp_dtype,
"lo_j", 1 *
sizeof(
int), H5T_NATIVE_INT);
1177 H5Tinsert (comp_dtype,
"hi_i", 2 *
sizeof(
int), H5T_NATIVE_INT);
1178 H5Tinsert (comp_dtype,
"hi_j", 3 *
sizeof(
int), H5T_NATIVE_INT);
1180 else if (3 == AMREX_SPACEDIM) {
1181 H5Tinsert (comp_dtype,
"lo_i", 0 *
sizeof(
int), H5T_NATIVE_INT);
1182 H5Tinsert (comp_dtype,
"lo_j", 1 *
sizeof(
int), H5T_NATIVE_INT);
1183 H5Tinsert (comp_dtype,
"lo_k", 2 *
sizeof(
int), H5T_NATIVE_INT);
1184 H5Tinsert (comp_dtype,
"hi_i", 3 *
sizeof(
int), H5T_NATIVE_INT);
1185 H5Tinsert (comp_dtype,
"hi_j", 4 *
sizeof(
int), H5T_NATIVE_INT);
1186 H5Tinsert (comp_dtype,
"hi_k", 5 *
sizeof(
int), H5T_NATIVE_INT);
1190 Vector<BoxArray> particle_box_arrays(finest_level_in_file + 1);
1191 bool dual_grid =
false;
1193 for (
int lev = 0; lev <= finest_level_in_file; lev++)
1195 if (lev > finestLevel())
1201 gname =
"level_" + std::to_string(lev);
1202 grp = H5Gopen(fid, gname.c_str(), H5P_DEFAULT);
1204 std::string msg(
"ParticleContainer::RestartHDF5(): unable to open group ");
1209 dset = H5Dopen(grp,
"boxes", H5P_DEFAULT);
1210 dspace = H5Dget_space(dset);
1212 H5Sget_simple_extent_dims(dspace, &ngrid, NULL);
1214 Vector<int> boxes(ngrid*AMREX_SPACEDIM*2);
1215 ret = H5Dread(dset, comp_dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &(boxes[0]));
1217 std::string msg(
"ParticleContainer::RestartHDF5(): unable to read nparticles_grid dataset");
1225 particle_box_arrays[lev] = ParticleBoxArray(lev);
1226 for (
int i = 0; i < (
int)ngrid; i++) {
1227 Box tmp (
IntVect{
AMREX_D_DECL(boxes[i*AMREX_SPACEDIM], boxes[i*AMREX_SPACEDIM+1], boxes[i*AMREX_SPACEDIM+2])},
1228 IntVect{
AMREX_D_DECL(boxes[i*AMREX_SPACEDIM*2], boxes[i*AMREX_SPACEDIM*2+1], boxes[i*AMREX_SPACEDIM*2+2])});
1229 particle_box_arrays[lev][i] = tmp;
1232 if (! particle_box_arrays[lev].CellEqual(ParticleBoxArray(lev)))
1237 for (
int lev = 0; lev <= finestLevel(); lev++) {
1238 SetParticleBoxArray(lev, particle_box_arrays[lev]);
1239 DistributionMapping pdm(particle_box_arrays[lev]);
1240 SetParticleDistributionMap(lev, pdm);
1244 Vector<int> ngrids(finest_level_in_file+1);
1245 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
1246 gname =
"level_" + std::to_string(lev);
1247 grp = H5Gopen(fid, gname.c_str(), H5P_DEFAULT);
1249 std::string msg(
"ParticleContainer::RestartHDF5(): unable to open group ");
1255 ret =
ReadHDF5Attr(grp, aname.c_str(), &ngrids[lev], H5T_NATIVE_INT);
1257 std::string msg(
"ParticleContainer::RestartHDF5(): unable to read attribute ");
1263 if (lev <= finestLevel()) {
1272 if (finest_level_in_file > finestLevel()) {
1273 m_particles.resize(finest_level_in_file+1);
1276 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
1278 gname =
"level_" + std::to_string(lev);
1279 grp = H5Gopen(fid, gname.c_str(), H5P_DEFAULT);
1281 std::string msg(
"ParticleContainer::RestartHDF5(): unable to open group ");
1286 dset = H5Dopen(grp,
"nparticles_grid", H5P_DEFAULT);
1287 Vector<int> count(ngrids[lev]);
1288 ret = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &(count[0]));
1290 std::string msg(
"ParticleContainer::RestartHDF5(): unable to read nparticles_grid dataset");
1295 Vector<hsize_t>
offset(ngrids[lev]);
1297 for (
int i = 1; i < ngrids[lev]; i++) {
1301 int_dset = H5Dopen(grp,
"data:datatype=0", H5P_DEFAULT);
1303 std::string msg(
"ParticleContainer::RestartHDF5(): unable to open int dataset");
1306 real_dset = H5Dopen(grp,
"data:datatype=1", H5P_DEFAULT);
1307 if (real_dset < 0) {
1308 std::string msg(
"ParticleContainer::RestartHDF5(): unable to open int dataset");
1312 Vector<int> grids_to_read;
1313 if (lev <= finestLevel()) {
1314 for (MFIter mfi(*m_dummy_mf[lev]); mfi.isValid(); ++mfi) {
1315 grids_to_read.push_back(mfi.index());
1323 const int NReaders = MaxReaders();
1324 if (rank >= NReaders) {
return; }
1326 const int Navg = ngrids[lev] / NReaders;
1327 const int Nleft = ngrids[lev] - Navg * NReaders;
1331 lo = rank*(Navg + 1);
1335 lo = rank * Navg + Nleft;
1339 for (
int i = lo; i < hi; ++i) {
1340 grids_to_read.push_back(i);
1344 for(
int igrid = 0; igrid < static_cast<int>(grids_to_read.size()); ++igrid) {
1345 const int grid = grids_to_read[igrid];
1347 if (how ==
"single") {
1348 ReadParticlesHDF5<float>(
offset[grid], count[grid], grid, lev, int_dset, real_dset, finest_level_in_file, convert_ids);
1350 else if (how ==
"double") {
1351 ReadParticlesHDF5<double>(
offset[grid], count[grid], grid, lev, int_dset, real_dset, finest_level_in_file, convert_ids);
1354 std::string msg(
"ParticleContainer::Restart(): bad parameter: ");
1361 H5Dclose(real_dset);
1371 if (m_verbose > 1) {
1374 amrex::Print() <<
"ParticleContainer::Restart() time: " << stoptime <<
'\n';
1379template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1380 template<
class>
class Allocator,
class CellAssignor>
1381template <
class RTYPE>
1383ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1384::ReadParticlesHDF5 (hsize_t
offset, hsize_t cnt,
int grd,
int lev,
1385 hid_t int_dset, hid_t real_dset,
int finest_level_in_file,
1388 BL_PROFILE(
"ParticleContainer::ReadParticlesHDF5()");
1392 hid_t int_dspace, int_fspace, real_dspace, real_fspace;
1397 const int iChunkSize = 2 + NStructInt + NumIntComps();
1398 Vector<int> istuff(cnt*iChunkSize);
1399 int_fspace = H5Dget_space(int_dset);
1400 hsize_t int_cnt = cnt*iChunkSize;
1401 hsize_t int_offset =
offset*iChunkSize;
1402 int_dspace = H5Screate_simple(1, &int_cnt, NULL);
1403 H5Sselect_hyperslab (int_fspace, H5S_SELECT_SET, &int_offset, NULL, &int_cnt, NULL);
1404 H5Dread(int_dset, H5T_NATIVE_INT, int_dspace, int_fspace, H5P_DEFAULT, istuff.dataPtr());
1406 H5Sclose(int_fspace);
1407 H5Sclose(int_dspace);
1410 const int rChunkSize = AMREX_SPACEDIM + NStructReal + NumRealComps();
1411 Vector<RTYPE> rstuff(cnt*rChunkSize);
1412 real_fspace = H5Dget_space(real_dset);
1413 hsize_t real_cnt = cnt*rChunkSize;
1414 hsize_t real_offset =
offset*rChunkSize;
1415 real_dspace = H5Screate_simple(1, &real_cnt, NULL);
1416 H5Sselect_hyperslab (real_fspace, H5S_SELECT_SET, &real_offset, NULL, &real_cnt, NULL);
1417 if (
sizeof(RTYPE) == 4) {
1418 H5Dread(real_dset, H5T_NATIVE_FLOAT, real_dspace, real_fspace, H5P_DEFAULT, rstuff.dataPtr());
1420 H5Dread(real_dset, H5T_NATIVE_DOUBLE, real_dspace, real_fspace, H5P_DEFAULT, rstuff.dataPtr());
1423 H5Sclose(real_fspace);
1424 H5Sclose(real_dspace);
1427 int* iptr = istuff.dataPtr();
1428 RTYPE* rptr = rstuff.dataPtr();
1431 ParticleLocData pld;
1433 Vector<std::map<std::pair<int, int>, Gpu::HostVector<ParticleType> > > host_particles;
1434 host_particles.reserve(15);
1435 host_particles.resize(finest_level_in_file+1);
1437 Vector<std::map<std::pair<int, int>,
1438 std::vector<Gpu::HostVector<ParticleReal> > > > host_real_attribs;
1439 host_real_attribs.reserve(15);
1440 host_real_attribs.resize(finest_level_in_file+1);
1442 Vector<std::map<std::pair<int, int>,
1443 std::vector<Gpu::HostVector<int> > > > host_int_attribs;
1444 host_int_attribs.reserve(15);
1445 host_int_attribs.resize(finest_level_in_file+1);
1447 for (hsize_t i = 0; i < cnt; i++) {
1449 std::int32_t xi, yi;
1450 std::uint32_t xu, yu;
1453 std::memcpy(&xu, &xi,
sizeof(xi));
1454 std::memcpy(&yu, &yi,
sizeof(yi));
1455 p.m_idcpu = ((std::uint64_t)xu) << 32 | yu;
1462 for (
int j = 0; j < NStructInt; j++)
1471 p.pos(1) = ParticleReal(rptr[1]);,
1472 p.pos(2) = ParticleReal(rptr[2]););
1474 rptr += AMREX_SPACEDIM;
1476 for (
int j = 0; j < NStructReal; j++)
1478 p.rdata(j) = ParticleReal(*rptr);
1482 locateParticle(p, pld, 0, finestLevel(), 0);
1484 std::pair<int, int> ind(grd, pld.m_tile);
1486 host_real_attribs[lev][ind].resize(NumRealComps());
1487 host_int_attribs[lev][ind].resize(NumIntComps());
1490 host_particles[lev][ind].push_back(p);
1493 for (
int icomp = 0; icomp < NumRealComps(); icomp++) {
1494 host_real_attribs[lev][ind][icomp].push_back(ParticleReal(*rptr));
1499 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1500 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1505 for (
int host_lev = 0; host_lev < static_cast<int>(host_particles.size()); ++host_lev)
1507 for (
auto& kv : host_particles[host_lev]) {
1508 auto grid = kv.first.first;
1509 auto tile = kv.first.second;
1510 const auto& src_tile = kv.second;
1512 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
1513 auto old_size = dst_tile.GetArrayOfStructs().size();
1514 auto new_size = old_size + src_tile.size();
1515 dst_tile.resize(new_size);
1518 dst_tile.GetArrayOfStructs().begin() + old_size);
1520 for (
int i = 0; i < NumRealComps(); ++i) {
1522 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1523 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1524 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1527 for (
int i = 0; i < NumIntComps(); ++i) {
1529 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1530 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1531 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:551
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1089
void RestartHDF5(const std::string &dir, const std::string &file)
Restart from checkpoint.
void WriteHDF5ParticleData(const std::string &dir, const std::string &name, const Vector< int > &write_real_comp, const Vector< int > &write_int_comp, const Vector< std::string > &real_comp_names, const Vector< std::string > &int_comp_names, const std::string &compression, F &&f, bool is_checkpoint=false) const
Writes particle data to disk in the HDF5 format.
void CheckpointPostHDF5()
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:129
const std::string & FileName() const
Definition AMReX_NFiles.H:160
This class provides the user with a few print options.
Definition AMReX_Print.H:35
bool Remove(std::string const &filename)
Definition AMReX_FileSystem.cpp:190
AMREX_GPU_HOST_DEVICE Long size(T const &b) noexcept
integer version
Definition AMReX_GpuRange.H:26
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition AMReX_GpuContainers.H:233
static constexpr HostToDevice hostToDevice
Definition AMReX_GpuContainers.H:98
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:237
MPI_Comm Communicator() noexcept
Definition AMReX_ParallelDescriptor.H:210
void ReduceIntSum(int &)
Integer sum reduction.
Definition AMReX_ParallelDescriptor.cpp:1255
int MyProc() noexcept
return the rank number local to the current Parallel Context
Definition AMReX_ParallelDescriptor.H:125
void ReduceLongMax(Long &)
Long max reduction.
Definition AMReX_ParallelDescriptor.cpp:1227
void ReduceLongSum(Long &)
Long sum reduction.
Definition AMReX_ParallelDescriptor.cpp:1226
int NProcs() noexcept
return the number of MPI ranks local to the current Parallel Context
Definition AMReX_ParallelDescriptor.H:243
int IOProcessorNumber() noexcept
Definition AMReX_ParallelDescriptor.H:266
bool IOProcessor() noexcept
Is this CPU the I/O Processor? To get the rank number, call IOProcessorNumber()
Definition AMReX_ParallelDescriptor.H:275
void ReduceRealMax(Vector< std::reference_wrapper< Real > > const &)
Definition AMReX_ParallelDescriptor.cpp:1218
std::enable_if_t< RunOnGpu< typename PC::template AllocatorType< int > >::value, void > packIOData(Vector< int > &idata, Vector< ParticleReal > &rdata, const PC &pc, int lev, int grid, const Vector< int > &write_real_comp, const Vector< int > &write_int_comp, const Vector< std::map< std::pair< int, int >, typename PC::IntVector > > &particle_io_flags, const Vector< int > &tiles, int np, bool is_checkpoint)
Definition AMReX_WriteBinaryParticleData.H:173
std::enable_if_t< RunOnGpu< typename Container< int, Allocator >::allocator_type >::value, amrex::Long > countFlags(const Vector< std::map< std::pair< int, int >, Container< int, Allocator > > > &particle_io_flags, const PC &pc)
Definition AMReX_WriteBinaryParticleData.H:78
Definition AMReX_Amr.cpp:49
BoxND< AMREX_SPACEDIM > Box
Definition AMReX_BaseFwd.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 end(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1890
double second() noexcept
Definition AMReX_Utility.cpp:922
IntVectND< AMREX_SPACEDIM > IntVect
Definition AMReX_BaseFwd.H:30
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:224
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 begin(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1881
static void SetHDF5fapl(hid_t fapl, MPI_Comm comm)
Definition AMReX_PlotFileUtilHDF5.cpp:111
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
const int[]
Definition AMReX_BLProfiler.cpp:1664
void WriteHDF5ParticleDataSync(PC const &pc, const std::string &dir, const std::string &name, const Vector< int > &write_real_comp, const Vector< int > &write_int_comp, const Vector< std::string > &real_comp_names, const Vector< std::string > &int_comp_names, const std::string &compression, F &&f, bool is_checkpoint)
Definition AMReX_WriteBinaryParticleDataHDF5.H:117
static int ReadHDF5Attr(hid_t loc, const char *name, void *data, hid_t dtype)
Definition AMReX_WriteBinaryParticleDataHDF5.H:61
static MPI_Datatype type()