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

Test 8b (Bench Read Parallel): Support Variable encoding, Fix Bugs #1131

Merged
merged 15 commits into from
Oct 27, 2021
Merged
146 changes: 88 additions & 58 deletions examples/8b_benchmark_read_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class MemoryProfiler
m_Name = "/proc/self/status";
Display(tag);
#else
(void)tag;
m_Name = "";
#endif
}
Expand Down Expand Up @@ -127,6 +128,7 @@ class Timer
//MemoryProfiler (rank, tag);
}
~Timer() {
MPI_Barrier(MPI_COMM_WORLD);
std::string tt = "~"+m_Tag;
//MemoryProfiler (m_Rank, tt.c_str());
m_End = std::chrono::system_clock::now();
Expand Down Expand Up @@ -187,9 +189,13 @@ std::vector<std::string> getBackends() {
#if openPMD_HAVE_ADIOS2
if( auxiliary::getEnvString( "OPENPMD_BP_BACKEND", "NOT_SET" ) != "ADIOS1" )
res.emplace_back(".bp");
if( auxiliary::getEnvString( "OPENPMD_BENCHMARK_USE_BACKEND", "NOT_SET" ) == "ADIOS" )
guj marked this conversation as resolved.
Show resolved Hide resolved
return res;
#endif

#if openPMD_HAVE_HDF5
if( auxiliary::getEnvString( "OPENPMD_BENCHMARK_USE_BACKEND", "NOT_SET" ) == "HDF5" )
res.clear();
res.emplace_back(".h5");
#endif
return res;
Expand All @@ -210,30 +216,22 @@ class TestInput
* Run the read tests
* assumes both GroupBased and fileBased series of this prefix exist.
* @ param prefix file prefix
* e.g. abc.bp (for group/variable based encoding)
* abc (for file based encoding)
*
*/
void run(const std::string& prefix)
{
{ // file based
std::ostringstream s;
s <<prefix<<"_%07T"<<m_Backend;

std::string filename = s.str();

read(filename);
}

return; // not doing group based..yet
/*
{ // group based
std::ostringstream s;
s <<prefix<<m_Backend;

std::string filename = s.str();

read(filename);
}
*/
if (prefix.find(m_Backend) == std::string::npos) {
// file based, default to %07T
std::ostringstream s;
s <<prefix<<"_%07T"<<m_Backend;
guj marked this conversation as resolved.
Show resolved Hide resolved
std::string filename = s.str();
read(filename);
} else {
// group or variable based, or filebased with fullname
read(prefix);
}
} // run


Expand All @@ -244,7 +242,7 @@ class TestInput
*
*/
void
read(std::string& filename)
read(const std::string& filename)
{
try {
std::string tag = "Reading: "+filename ;
Expand All @@ -254,16 +252,22 @@ class TestInput
int numIterations = series.iterations.size();

if ( 0 == m_MPIRank )
std::cout<<"\n\t Num Iterations in " << filename<<" : " << numIterations<<std::endl;
{
std::cout<<" "<<series.iterationEncoding()<<std::endl;
std::cout<<" Num Iterations in " << filename<<" : " << numIterations<<std::endl<<std::endl;
guj marked this conversation as resolved.
Show resolved Hide resolved
}

{
int counter = 1;
for ( auto const& i : series.iterations )
for ( auto i : series.readIterations() )
{
if ( (1 == counter) || (numIterations == counter) )
readStep(series, i.first);
if ( counter % 5 == 1 )
readStep(series, i, counter - 1);
counter ++;
}
}
if ( 0 == m_MPIRank )
std::cout<<" Total Num iterations read: "<<(counter - 1)<<std::endl<<std::endl;
guj marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (std::exception& ex)
{}
}
Expand Down Expand Up @@ -388,6 +392,7 @@ class TestInput
bool atCenter = ( (m_Pattern % 10 == 0) || (fractionOnDim == 1) );
bool atTopLeft = ( (m_Pattern % 10 == 1) && (fractionOnDim > 1) );
bool atBottomRight = ( (m_Pattern % 10 == 2) && (fractionOnDim > 1) );
bool overlay = ( (m_Pattern % 10 == 3) && (fractionOnDim > 1) );

bool rankZeroOnly = ( alongDim == 4);
bool diagnalBlocks = ( alongDim > meshExtent.size() ) && !rankZeroOnly;
Expand All @@ -403,6 +408,8 @@ class TestInput
s <<" topleft ";
else if (atBottomRight)
s <<" bottomRight ";
else if (overlay)
s << " near center ";
} else if ( diagnalBlocks )
s <<" blockStyle = diagnal";
else
Expand All @@ -422,12 +429,14 @@ class TestInput

if ( rankZeroOnly )
{
if ( atCenter )
if ( atTopLeft )
off[i] = 0; // top corner
else if ( atTopLeft )
else if ( atBottomRight )
off[i] = (meshExtent[i]-blob); // bottom corner
else if (atBottomRight)
else if (atCenter)
off[i] = (fractionOnDim/2) * blob; // middle corner
else if (overlay)
off[i] = (fractionOnDim/2) * blob - blob/3; // near middle corner
}
else
{
Expand Down Expand Up @@ -455,7 +464,7 @@ class TestInput
auto slice_data = rho.loadChunk<double>(off, ext);
series.flush();

std::cout<<"Rank: "<<m_MPIRank;
std::cout<<" Rank: "<<m_MPIRank;
guj marked this conversation as resolved.
Show resolved Hide resolved

prettyLambda(off,ext);
}
Expand Down Expand Up @@ -505,7 +514,7 @@ class TestInput
}

std::ostringstream so, sc;
so <<"Rank: "<<m_MPIRank<<" offset [ "; sc<<" count[ ";
so <<" Rank: "<<m_MPIRank<<" offset [ "; sc<<" count[ ";
guj marked this conversation as resolved.
Show resolved Hide resolved
for ( unsigned int i=0; i<meshExtent.size(); i++ )
{
so <<off[i]<<" ";
guj marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -572,7 +581,8 @@ class TestInput
* @param series openPMD series
*/
void
sliceField( Series& series, int ts )
sliceField(Series& series, IndexedIteration& iter)
//sliceField( Series& series, int ts )
guj marked this conversation as resolved.
Show resolved Hide resolved
{
if ( m_Pattern >= 100 )
return;
Expand All @@ -591,7 +601,7 @@ class TestInput
return;
whichDim -= 5;

MeshRecordComponent bx = series.iterations[ts].meshes["B"]["x"];
MeshRecordComponent bx = iter.meshes["B"]["x"];
Extent meshExtent = bx.getExtent();

if ( bx.getExtent().size() != 3) {
Expand All @@ -600,15 +610,15 @@ class TestInput
return;
}

MeshRecordComponent by = series.iterations[ts].meshes["B"]["y"];
MeshRecordComponent bz = series.iterations[ts].meshes["B"]["z"];
MeshRecordComponent by = iter.meshes["B"]["y"];
MeshRecordComponent bz = iter.meshes["B"]["z"];


Offset off(meshExtent.size(),0);
Extent ext(meshExtent.size(),1);

std::ostringstream s;
s<<" Eletrict Field slice: ";
s<<" Electric Field slice: ";
guj marked this conversation as resolved.
Show resolved Hide resolved
if (!getSlice(meshExtent, whichDim, rankZeroOnly, off, ext, s))
return;

Expand All @@ -625,52 +635,71 @@ class TestInput
* Read an iteration step, mesh & particles
*
* @param Series openPMD series
* @param iter iteration (actual iteration step may not equal to ts)
* @param ts timestep
*
*/
void
readStep( Series& series, int ts )
readStep( Series& series, IndexedIteration& iter, int ts )
guj marked this conversation as resolved.
Show resolved Hide resolved
{
std::string comp_name = openPMD::MeshRecordComponent::SCALAR;

MeshRecordComponent rho = series.iterations[ts].meshes["rho"][comp_name];

MeshRecordComponent rho = iter.meshes["rho"][comp_name];
Extent meshExtent = rho.getExtent();

if ( 0 == m_MPIRank )
{
std::cout<<"... rho meshExtent : ts="<<ts<<" [";
std::cout<<"===> rho meshExtent : ts="<<ts<<" [";
guj marked this conversation as resolved.
Show resolved Hide resolved
for (unsigned long i : meshExtent)
std::cout<<i<<" ";
std::cout<<"]"<<std::endl;
}

sliceMe(series, rho);
block(series, rho);
fullscan(series, rho);
std::vector<int> currPatterns;
if (m_Pattern > 0)
guj marked this conversation as resolved.
Show resolved Hide resolved
currPatterns.push_back(m_Pattern);
else
currPatterns.insert(currPatterns.end(), { 1, 5, 15, 25, 55, 65, 75, 440, 441, 442, 443, 7 });

sliceField(series, ts);
for(int i : currPatterns) {
m_Pattern = i;
sliceMe(series, rho);
block(series, rho);
fullscan(series, rho);

// read particles
if ( m_Pattern == 7 )
{
openPMD::ParticleSpecies electrons =
series.iterations[ts].particles["ion"];
RecordComponent charge = electrons["charge"][RecordComponent::SCALAR];
sliceParticles(series, charge);
}
sliceField(series, iter);

sliceParticles(series, iter);
}
if (currPatterns.size() > 1)
m_Pattern = 0;
}

/*
* Read a slice of particles
* Read a slice of id of the first particle
*
* @param series openPMD Series
* @param charge Particle record
* @param iter current iteration
*
*/
void sliceParticles(Series& series, RecordComponent& charge)
void sliceParticles(Series& series, IndexedIteration& iter)
{
Extent pExtent = charge.getExtent();
// read id of the first particle found
if ( m_Pattern != 7 )
return;

if ( 0 == iter.particles.size() )
{
if ( 0 == m_MPIRank )
std::cerr<<" No Particles found. Skipping particle slicing. "<<std::endl;
guj marked this conversation as resolved.
Show resolved Hide resolved
return;
}

openPMD::ParticleSpecies p = iter.particles.begin()->second;
RecordComponent idVal = p["id"][RecordComponent::SCALAR];
//sliceParticles(series, val);
guj marked this conversation as resolved.
Show resolved Hide resolved

Extent pExtent = idVal.getExtent();

auto blob = pExtent[0]/(10*m_MPISize);
if (0 == blob)
Expand All @@ -688,7 +717,7 @@ class TestInput

Offset colOff = {m_MPIRank*blob};
Extent colExt = {blob};
auto col_data = charge.loadChunk<double>(colOff, colExt);
auto col_data = idVal.loadChunk<uint64_t>(colOff, colExt);
series.flush();
}

Expand Down Expand Up @@ -724,6 +753,7 @@ main( int argc, char *argv[] )
return 0;
}

{
Timer g( " Main ", input.m_MPIRank );

std::string prefix = argv[1];
Expand Down Expand Up @@ -758,7 +788,7 @@ main( int argc, char *argv[] )
input.m_Backend = which;
input.run(prefix);
}

} // Timer g
MPI_Finalize();

return 0;
Expand Down