88 H5Pset_fapl_mpio(fapl, comm, MPI_INFO_NULL);
91 int alignment = 16 * 1024 * 1024;
92 int blocksize = 4 * 1024 * 1024;
93 H5Pset_alignment(fapl, alignment, alignment);
94 H5Pset_meta_block_size(fapl, blocksize);
97 H5Pset_coll_metadata_write(fapl,
true);
98 H5Pset_all_coll_metadata_ops(fapl,
true);
101 H5AC_cache_config_t cache_config;
102 cache_config.version = H5AC__CURR_CACHE_CONFIG_VERSION;
103 H5Pget_mdc_config(fapl, &cache_config);
104 cache_config.set_initial_size = 1;
105 cache_config.initial_size = 16 * 1024 * 1024;
106 cache_config.evictions_enabled = 0;
107 cache_config.incr_mode = H5C_incr__off;
108 cache_config.flash_incr_mode = H5C_flash_incr__off;
109 cache_config.decr_mode = H5C_decr__off;
110 H5Pset_mdc_config (fapl, &cache_config);
112 H5Pset_fapl_sec2(fapl);
118 const std::string& dir,
const std::string& name,
123 const std::string& compression,
124 F&& f,
bool is_checkpoint)
129 AMREX_ASSERT(
sizeof(
typename PC::ParticleType::RealType) == 4 ||
130 sizeof(
typename PC::ParticleType::RealType) == 8);
132 constexpr int NStructReal = PC::NStructReal;
133 constexpr int NStructInt = PC::NStructInt;
141#ifdef AMREX_USE_HDF5_ASYNC
144 async_vol_es_wait_particle();
147 es_par_g = H5EScreate();
151 std::string pdir = dir;
152 if ( ! pdir.empty() && pdir[pdir.size()-1] !=
'/') { pdir +=
'/'; }
155 if ( ! pc.GetLevelDirectoriesCreated()) {
167 hid_t fid, grp, fapl, comp_dtype;
173 comp_dtype = H5Tcreate (H5T_COMPOUND, 2 * AMREX_SPACEDIM *
sizeof(
int));
174 if (1 == AMREX_SPACEDIM) {
175 H5Tinsert (comp_dtype,
"lo_i", 0 *
sizeof(
int), H5T_NATIVE_INT);
176 H5Tinsert (comp_dtype,
"hi_i", 1 *
sizeof(
int), H5T_NATIVE_INT);
178 else if (2 == AMREX_SPACEDIM) {
179 H5Tinsert (comp_dtype,
"lo_i", 0 *
sizeof(
int), H5T_NATIVE_INT);
180 H5Tinsert (comp_dtype,
"lo_j", 1 *
sizeof(
int), H5T_NATIVE_INT);
181 H5Tinsert (comp_dtype,
"hi_i", 2 *
sizeof(
int), H5T_NATIVE_INT);
182 H5Tinsert (comp_dtype,
"hi_j", 3 *
sizeof(
int), H5T_NATIVE_INT);
184 else if (3 == AMREX_SPACEDIM) {
185 H5Tinsert (comp_dtype,
"lo_i", 0 *
sizeof(
int), H5T_NATIVE_INT);
186 H5Tinsert (comp_dtype,
"lo_j", 1 *
sizeof(
int), H5T_NATIVE_INT);
187 H5Tinsert (comp_dtype,
"lo_k", 2 *
sizeof(
int), H5T_NATIVE_INT);
188 H5Tinsert (comp_dtype,
"hi_i", 3 *
sizeof(
int), H5T_NATIVE_INT);
189 H5Tinsert (comp_dtype,
"hi_j", 4 *
sizeof(
int), H5T_NATIVE_INT);
190 H5Tinsert (comp_dtype,
"hi_k", 5 *
sizeof(
int), H5T_NATIVE_INT);
195 particle_io_flags(pc.GetParticles().size());
196 for (
int lev = 0; lev < pc.GetParticles().size(); lev++)
198 const auto& pmap = pc.GetParticles(lev);
199 for (
const auto& kv : pmap)
201 auto& flags = particle_io_flags[lev][kv.first];
208 if(pc.GetUsePrePost())
210 nparticles = pc.GetNParticlesPrePost();
211 maxnextid = pc.GetMaxNextIDPrePost();
216 maxnextid = PC::ParticleType::NextID();
218 PC::ParticleType::NextID(maxnextid);
222 std::string HDF5FileName = pdir;
223 if ( ! HDF5FileName.empty() && HDF5FileName[HDF5FileName.size()-1] !=
'/')
226 HDF5FileName += name;
227 HDF5FileName +=
".h5";
228 pc.HdrFileNamePrePost = HDF5FileName;
235 char setstripe[1024];
236 int stripe_count = 128;
238 char *stripe_count_str = getenv(
"HDF5_STRIPE_COUNT");
239 char *stripe_size_str = getenv(
"HDF5_STRIPE_SIZE");
240 if (stripe_count_str) {
241 stripe_count = atoi(stripe_count_str);
244 if (stripe_size_str) {
245 stripe_size = atoi(stripe_size_str);
248 if (set_stripe == 1) {
249 snprintf(setstripe,
sizeof setstripe,
"lfs setstripe -c %d -S %dm %s", stripe_count, stripe_size, pdir.c_str());
250 std::cout <<
"Setting stripe parameters for HDF5 output: " << setstripe << std::endl;
254 fid = H5Fcreate(HDF5FileName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
263 std::string versionName = is_checkpoint ? PC::CheckpointVersion() : PC::PlotfileVersion();
264 if (
sizeof(
typename PC::ParticleType::RealType) == 4) {
265 versionName +=
"_single";
267 versionName +=
"_double";
272 int num_output_real = 0;
273 for (
int i = 0; i < pc.NumRealComps() + NStructReal; ++i) {
274 if (write_real_comp[i]) { ++num_output_real; }
277 int num_output_int = 0;
278 for (
int i = 0; i < pc.NumIntComps() + NStructInt; ++i) {
279 if (write_int_comp[i]) { ++num_output_int; }
283 int ndim = AMREX_SPACEDIM;
284 grp = H5Gcreate(fid,
"Chombo_global", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
289 int ncomp = num_output_real + num_output_int;
296 int real_comp_count = AMREX_SPACEDIM;
298 for (
int i = 0; i < NStructReal + pc.NumRealComps(); ++i ) {
299 if (write_real_comp[i]) {
301 snprintf(comp_name,
sizeof comp_name,
"real_component_%d", real_comp_count);
311 int int_comp_count = 2;
313 for (
int i = 0; i < NStructInt + pc.NumIntComps(); ++i ) {
314 if (write_int_comp[i]) {
315 snprintf(comp_name,
sizeof comp_name,
"int_component_%d", int_comp_count);
328 int finest_level = pc.finestLevel();
331 char level_name[128];
334 hid_t dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
335 H5Pset_fill_time(dcpl_id, H5D_FILL_TIME_NEVER);
337 for (
int lev = 0; lev <= finest_level; ++lev) {
338 snprintf(level_name,
sizeof level_name,
"level_%d", lev);
340 grp = H5Gcreate(fid, level_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
342 std::cout <<
"H5Gcreate [" << level_name <<
"] failed!" << std::endl;
347 ngrids = pc.ParticleBoxArray(lev).size();
353 int mfs_size = 2 * AMREX_SPACEDIM;
354 hsize_t mfs_dim = (hsize_t)ngrids;
356 hid_t mfs_dset_space = H5Screate_simple(1, &mfs_dim, NULL);
357 hid_t mfs_dset= H5Dcreate(grp,
"boxes", comp_dtype, mfs_dset_space, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
360 for(
int j = 0; j < pc.ParticleBoxArray(lev).size(); ++j) {
361 for(
int i = 0; i < AMREX_SPACEDIM; ++i) {
362 vbox[(j * mfs_size) + i] = pc.ParticleBoxArray(lev)[j].smallEnd(i);
363 vbox[(j * mfs_size) + i + AMREX_SPACEDIM] = pc.ParticleBoxArray(lev)[j].bigEnd(i);
367 status = H5Dwrite(mfs_dset, comp_dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &(vbox[0]));
369 std::string msg(
"ParticleContainer::WriteHDF5ParticleDataSync(): unable to write boxes dataset");
373 H5Sclose(mfs_dset_space);
390 pp.
query(
"particles_nfiles",nOutFiles);
391 if(nOutFiles == -1) nOutFiles = NProcs;
393 pc.nOutFilesPrePost = nOutFiles;
395 fapl = H5Pcreate (H5P_FILE_ACCESS);
402#ifdef AMREX_USE_HDF5_ASYNC
403 fid = H5Fopen_async(HDF5FileName.c_str(), H5F_ACC_RDWR, fapl, es_par_g);
405 fid = H5Fopen(HDF5FileName.c_str(), H5F_ACC_RDWR, fapl);
412 for (
int lev = 0; lev <= pc.finestLevel(); lev++)
414 snprintf(level_name,
sizeof level_name,
"level_%d", lev);
415#ifdef AMREX_USE_HDF5_ASYNC
416 grp = H5Gopen_async(fid, level_name, H5P_DEFAULT, es_par_g);
418 grp = H5Gopen(fid, level_name, H5P_DEFAULT);
423 gotsome = (pc.nParticlesAtLevelPrePost[lev] > 0);
425 gotsome = (pc.NumberOfParticlesAtLevel(lev) > 0);
430 MultiFab state(pc.ParticleBoxArray(lev),
431 pc.ParticleDistributionMap(lev),
441 pc.filePrefixPrePost[lev] = HDF5FileName;
446 pc.WriteParticlesHDF5(lev, grp, which, count, where,
447 write_real_comp, write_int_comp,
449 particle_io_flags, is_checkpoint);
452 pc.whichPrePost[lev] = which;
453 pc.countPrePost[lev] = count;
454 pc.wherePrePost[lev] = where;
462#ifdef AMREX_USE_HDF5_ASYNC
463 H5Gclose_async(grp, es_par_g);
469 H5Tclose(comp_dtype);
472#ifdef AMREX_USE_HDF5_ASYNC
473 H5Fclose_async(fid, es_par_g);
std::enable_if_t< RunOnGpu< typename Container< int, Allocator >::allocator_type >::value > fillFlags(Container< int, Allocator > &pflags, const PTile &ptile, F const &f)
Definition AMReX_WriteBinaryParticleData.H:36
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