Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang-Tidy changes in Src/Extern #3472

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 38 additions & 27 deletions Src/Extern/HDF5/AMReX_ParticleHDF5.H
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
AMREX_ASSERT( int_comp_names.size() == NStructInt + NumIntComps() );

Vector<int> write_real_comp;
for (int i = 0; i < NStructReal + NumRealComps(); ++i) write_real_comp.push_back(1);
for (int i = 0; i < NStructReal + NumRealComps(); ++i) { write_real_comp.push_back(1); }

Vector<int> write_int_comp;
for (int i = 0; i < NStructInt + NumIntComps(); ++i) write_int_comp.push_back(1);
for (int i = 0; i < NStructInt + NumIntComps(); ++i) { write_int_comp.push_back(1); }

WriteHDF5ParticleData(dir, name,
write_real_comp, write_int_comp,
Expand Down Expand Up @@ -312,10 +312,10 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
AMREX_ASSERT( int_comp_names.size() == NStructInt + NArrayInt );

Vector<int> write_real_comp;
for (int i = 0; i < NStructReal + NumRealComps(); ++i) write_real_comp.push_back(1);
for (int i = 0; i < NStructReal + NumRealComps(); ++i) { write_real_comp.push_back(1); }

Vector<int> write_int_comp;
for (int i = 0; i < NStructInt + NumIntComps(); ++i) write_int_comp.push_back(1);
for (int i = 0; i < NStructInt + NumIntComps(); ++i) { write_int_comp.push_back(1); }

WriteHDF5ParticleData(dir, name,
write_real_comp, write_int_comp,
Expand All @@ -335,10 +335,10 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
AMREX_ASSERT(real_comp_names.size() == NStructReal + NumRealComps());

Vector<int> write_real_comp;
for (int i = 0; i < NStructReal + NumRealComps(); ++i) write_real_comp.push_back(1);
for (int i = 0; i < NStructReal + NumRealComps(); ++i) { write_real_comp.push_back(1); }

Vector<int> write_int_comp;
for (int i = 0; i < NStructInt + NumIntComps(); ++i) write_int_comp.push_back(1);
for (int i = 0; i < NStructInt + NumIntComps(); ++i) { write_int_comp.push_back(1); }

Vector<std::string> int_comp_names;
for (int i = 0; i < NStructInt + NumIntComps(); ++i )
Expand Down Expand Up @@ -604,8 +604,9 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
hsize_t chunk_dim = 1024;

chunk_env = getenv("HDF5_CHUNK_SIZE");
if (chunk_env != NULL)
if (chunk_env != NULL) {
chunk_dim = atoi(chunk_env);
}

H5Pset_chunk(dcpl_int, 1, &chunk_dim);
H5Pset_chunk(dcpl_real, 1, &chunk_dim);
Expand All @@ -626,7 +627,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
pos = compression.find("ZFP");
if (pos != std::string::npos) {
ret = H5Z_zfp_initialize();
if (ret < 0) amrex::Abort("ZFP initialize failed!");
if (ret < 0) { amrex::Abort("ZFP initialize failed!"); }
}
#endif

Expand Down Expand Up @@ -815,22 +816,25 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
H5Sclose(real_dset_space);

real_file_offset = 0;
for (int i = 0; i < ParallelDescriptor::MyProc(); i++)
for (int i = 0; i < ParallelDescriptor::MyProc(); i++) {
real_file_offset += all_mfi_real_total_size[i];
}
my_real_offset = real_file_offset;
my_real_count = 0;

int max_mfi_count = 0, write_count = 0;
for (int i = 0; i < ParallelDescriptor::MyProc(); i++)
if (max_mfi_count < all_mfi_cnt[i])
for (int i = 0; i < ParallelDescriptor::MyProc(); i++) {
if (max_mfi_count < all_mfi_cnt[i]) {
max_mfi_count = all_mfi_cnt[i];
}
}


for (MFIter mfi(state); mfi.isValid(); ++mfi)
{
const int grid = mfi.index();

if (count[grid] == 0) continue;
if (count[grid] == 0) { continue; }

Vector<int> istuff;
Vector<ParticleReal> rstuff;
Expand All @@ -851,7 +855,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
#else
ret = H5Dwrite(int_dset_id, H5T_NATIVE_INT, int_mem_space, int_dset_space, dxpl_col, istuff.dataPtr());
#endif
if (ret < 0) amrex::Abort("H5Dwrite int_dset failed!");
if (ret < 0) { amrex::Abort("H5Dwrite int_dset failed!"); }

H5Sclose(int_dset_space);
H5Sclose(int_mem_space);
Expand All @@ -864,20 +868,21 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
/* my_real_offset << ", my_real_count = " << my_real_count << ", total_real_size = " << total_real_size << '\n'; */
real_dset_space = H5Screate_simple(1, &total_real_size, NULL);
H5Sselect_hyperslab (real_dset_space, H5S_SELECT_SET, &my_real_offset, NULL, &my_real_count, NULL);
if (sizeof(typename ParticleType::RealType) == 4)
if (sizeof(typename ParticleType::RealType) == 4) {
#ifdef AMREX_USE_HDF5_ASYNC
ret = H5Dwrite_async(real_dset_id, H5T_NATIVE_FLOAT, real_mem_space, real_dset_space, dxpl_col, rstuff.dataPtr(), es_par_g);
#else
ret = H5Dwrite(real_dset_id, H5T_NATIVE_FLOAT, real_mem_space, real_dset_space, dxpl_col, rstuff.dataPtr());
#endif
else
} else {
#ifdef AMREX_USE_HDF5_ASYNC
ret = H5Dwrite_async(real_dset_id, H5T_NATIVE_DOUBLE, real_mem_space, real_dset_space, dxpl_col, rstuff.dataPtr(), es_par_g);
#else
ret = H5Dwrite(real_dset_id, H5T_NATIVE_DOUBLE, real_mem_space, real_dset_space, dxpl_col, rstuff.dataPtr());
#endif
}

if (ret < 0) amrex::Abort("H5Dwrite real_dset failed!");
if (ret < 0) { amrex::Abort("H5Dwrite real_dset failed!"); }

H5Sclose(real_mem_space);
H5Sclose(real_dset_space);
Expand All @@ -896,16 +901,18 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>

#ifdef AMREX_USE_HDF5_ASYNC
H5Dwrite_async(int_dset_id, H5T_NATIVE_INT, int_dset_space, int_dset_space, dxpl_col, NULL, es_par_g);
if (sizeof(typename ParticleType::RealType) == 4)
if (sizeof(typename ParticleType::RealType) == 4) {
H5Dwrite_async(real_dset_id, H5T_NATIVE_FLOAT, real_dset_space, real_dset_space, dxpl_col, NULL, es_par_g);
else
} else {
H5Dwrite_async(real_dset_id, H5T_NATIVE_DOUBLE, real_dset_space, real_dset_space, dxpl_col, NULL, es_par_g);
}
#else
H5Dwrite(int_dset_id, H5T_NATIVE_INT, int_dset_space, int_dset_space, dxpl_col, NULL);
if (sizeof(typename ParticleType::RealType) == 4)
if (sizeof(typename ParticleType::RealType) == 4) {
H5Dwrite(real_dset_id, H5T_NATIVE_FLOAT, real_dset_space, real_dset_space, dxpl_col, NULL);
else
} else {
H5Dwrite(real_dset_id, H5T_NATIVE_DOUBLE, real_dset_space, real_dset_space, dxpl_col, NULL);
}
#endif

H5Sclose(int_dset_space);
Expand All @@ -931,8 +938,9 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
#endif

my_int_offset = 0;
for (int i = 0; i < ParallelDescriptor::MyProc(); i++)
for (int i = 0; i < ParallelDescriptor::MyProc(); i++) {
my_int_offset += all_mfi_cnt[i];
}
my_int_count = my_mfi_cnt;
int_mem_space = H5Screate_simple(1, &my_int_count, NULL);
/* std::cout << "Rank " << ParallelDescriptor::MyProc() << ": my_int_offset = " << */
Expand All @@ -944,7 +952,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
#else
ret = H5Dwrite(offset_id, H5T_NATIVE_INT, int_mem_space, offset_space, dxpl_col, &(my_nparticles[0]));
#endif
if (ret < 0) amrex::Abort("H5Dwrite offset failed!");
if (ret < 0) { amrex::Abort("H5Dwrite offset failed!"); }

H5Pclose(dcpl_int);
H5Pclose(dcpl_real);
Expand Down Expand Up @@ -986,8 +994,9 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
const auto strttime = amrex::second();

std::string fullname = dir;
if (!fullname.empty() && fullname[fullname.size()-1] != '/')
if (!fullname.empty() && fullname[fullname.size()-1] != '/') {
fullname += '/';
}

fullname += file;
fullname += ".h5";
Expand Down Expand Up @@ -1097,8 +1106,9 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
msg += aname;
amrex::Abort(msg.c_str());
}
if (ni != NStructInt + NumIntComps())
if (ni != NStructInt + NumIntComps()) {
amrex::Abort("ParticleContainer::Restart(): ni != NStructInt");
}

aname = "nparticles";
Long nparticles;
Expand Down Expand Up @@ -1285,7 +1295,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>

const int rank = ParallelDescriptor::MyProc();
const int NReaders = MaxReaders();
if (rank >= NReaders) return;
if (rank >= NReaders) { return; }

const int Navg = ngrids[lev] / NReaders;
const int Nleft = ngrids[lev] - Navg * NReaders;
Expand Down Expand Up @@ -1378,10 +1388,11 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
hsize_t real_offset = offset*rChunkSize;
real_dspace = H5Screate_simple(1, &real_cnt, NULL);
H5Sselect_hyperslab (real_fspace, H5S_SELECT_SET, &real_offset, NULL, &real_cnt, NULL);
if (sizeof(RTYPE) == 4)
if (sizeof(RTYPE) == 4) {
H5Dread(real_dset, H5T_NATIVE_FLOAT, real_dspace, real_fspace, H5P_DEFAULT, rstuff.dataPtr());
else
} else {
H5Dread(real_dset, H5T_NATIVE_DOUBLE, real_dspace, real_fspace, H5P_DEFAULT, rstuff.dataPtr());
}

H5Sclose(real_fspace);
H5Sclose(real_dspace);
Expand Down
20 changes: 11 additions & 9 deletions Src/Extern/HDF5/AMReX_PlotFileUtilHDF5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void WriteMultiLevelPlotfileHDF5SingleDset (const std::string& plotfilename,
pos = compression.find("ZFP");
if (pos != std::string::npos) {
ret = H5Z_zfp_initialize();
if (ret < 0) amrex::Abort("ZFP initialize failed!");
if (ret < 0) { amrex::Abort("ZFP initialize failed!"); }
}
#endif

Expand Down Expand Up @@ -912,15 +912,15 @@ void WriteMultiLevelPlotfileHDF5MultiDset (const std::string& plotfilename,
pos = compression.find("ZFP");
if (pos != std::string::npos) {
ret = H5Z_zfp_initialize();
if (ret < 0) amrex::Abort("ZFP initialize failed!");
if (ret < 0) { amrex::Abort("ZFP initialize failed!"); }
}
#endif

#ifdef AMREX_USE_HDF5_SZ
pos = compression.find("SZ");
if (pos != std::string::npos) {
ret = H5Z_SZ_Init((char*)value_env.c_str());
if (ret < 0) amrex::Abort("ZFP initialize failed, check SZ config file!");
if (ret < 0) { amrex::Abort("ZFP initialize failed, check SZ config file!"); }
}
#endif

Expand Down Expand Up @@ -1161,24 +1161,26 @@ void WriteMultiLevelPlotfileHDF5MultiDset (const std::string& plotfilename,
snprintf(dataname, sizeof dataname, "data:datatype=%d", jj);
#ifdef AMREX_USE_HDF5_ASYNC
dataset = H5Dcreate_async(grp, dataname, H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT, es_id_g);
if(dataset < 0) std::cout << ParallelDescriptor::MyProc() << "create data failed! ret = " << dataset << std::endl;
if(dataset < 0) { std::cout << ParallelDescriptor::MyProc() << "create data failed! ret = " << dataset << std::endl; }

if (hs_procsize[0] == 0)
if (hs_procsize[0] == 0) {
H5Sselect_none(dataspace);
else
} else {
H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, ch_offset, NULL, hs_procsize, NULL);
}

ret = H5Dwrite_async(dataset, H5T_NATIVE_DOUBLE, memdataspace, dataspace, dxpl_col, a_buffer_ind.dataPtr(), es_id_g);
if(ret < 0) { std::cout << ParallelDescriptor::MyProc() << "Write data failed! ret = " << ret << std::endl; break; }
H5Dclose_async(dataset, es_id_g);
#else
dataset = H5Dcreate(grp, dataname, H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT);
if(dataset < 0) std::cout << ParallelDescriptor::MyProc() << "create data failed! ret = " << dataset << std::endl;
if(dataset < 0) { std::cout << ParallelDescriptor::MyProc() << "create data failed! ret = " << dataset << std::endl; }

if (hs_procsize[0] == 0)
if (hs_procsize[0] == 0) {
H5Sselect_none(dataspace);
else
} else {
H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, ch_offset, NULL, hs_procsize, NULL);
}

ret = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, memdataspace, dataspace, dxpl_col, a_buffer_ind.dataPtr());
if(ret < 0) { std::cout << ParallelDescriptor::MyProc() << "Write data failed! ret = " << ret << std::endl; break; }
Expand Down
30 changes: 18 additions & 12 deletions Src/Extern/HDF5/AMReX_WriteBinaryParticleDataHDF5.H
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void WriteHDF5ParticleDataSync (PC const& pc,
#endif

std::string pdir = dir;
if ( ! pdir.empty() && pdir[pdir.size()-1] != '/') pdir += '/';
if ( ! pdir.empty() && pdir[pdir.size()-1] != '/') { pdir += '/'; }
pdir += name;

if ( ! pc.GetLevelDirectoriesCreated()) {
Expand Down Expand Up @@ -250,7 +250,7 @@ void WriteHDF5ParticleDataSync (PC const& pc,
}

fid = H5Fcreate(HDF5FileName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if (fid < 0) amrex::FileOpenFailed(HDF5FileName.c_str());
if (fid < 0) { amrex::FileOpenFailed(HDF5FileName.c_str()); }

//
// First thing written is our Checkpoint/Restart version string.
Expand All @@ -259,20 +259,23 @@ void WriteHDF5ParticleDataSync (PC const& pc,
// particles so that we can Restart from the checkpoint files.
//
std::string versionName = is_checkpoint ? PC::CheckpointVersion() : PC::PlotfileVersion();
if (sizeof(typename PC::ParticleType::RealType) == 4)
if (sizeof(typename PC::ParticleType::RealType) == 4) {
versionName += "_single";
else
} else {
versionName += "_double";
}

CreateWriteHDF5AttrString(fid, "version_name", versionName.c_str());

int num_output_real = 0;
for (int i = 0; i < pc.NumRealComps() + NStructReal; ++i)
if (write_real_comp[i]) ++num_output_real;
for (int i = 0; i < pc.NumRealComps() + NStructReal; ++i) {
if (write_real_comp[i]) { ++num_output_real; }
}

int num_output_int = 0;
for (int i = 0; i < pc.NumIntComps() + NStructInt; ++i)
if (write_int_comp[i]) ++num_output_int;
for (int i = 0; i < pc.NumIntComps() + NStructInt; ++i) {
if (write_int_comp[i]) { ++num_output_int; }
}

// AMREX_SPACEDIM and N for sanity checking.
int ndim = AMREX_SPACEDIM;
Expand Down Expand Up @@ -392,8 +395,9 @@ void WriteHDF5ParticleDataSync (PC const& pc,
#else
fid = H5Fopen(HDF5FileName.c_str(), H5F_ACC_RDWR, fapl);
#endif
if (fid < 0)
if (fid < 0) {
FileOpenFailed(HDF5FileName.c_str());
}

char level_name[64];
for (int lev = 0; lev <= pc.finestLevel(); lev++)
Expand All @@ -406,10 +410,11 @@ void WriteHDF5ParticleDataSync (PC const& pc,
#endif

bool gotsome;
if(pc.usePrePost)
if(pc.usePrePost) {
gotsome = (pc.nParticlesAtLevelPrePost[lev] > 0);
else
} else {
gotsome = (pc.NumberOfParticlesAtLevel(lev) > 0);
}

MFInfo info;
info.SetAlloc(false);
Expand All @@ -423,8 +428,9 @@ void WriteHDF5ParticleDataSync (PC const& pc,
Vector<int > count(state.size(),0);
Vector<Long> where(state.size(),0);

if(pc.usePrePost)
if(pc.usePrePost) {
pc.filePrefixPrePost[lev] = HDF5FileName;
}

if (gotsome)
{
Expand Down
Loading
Loading