Skip to content
Snippets Groups Projects
Commit c50e6c3b authored by Podhorszki, Norbert's avatar Podhorszki, Norbert
Browse files

updates to groupless examples

parent 19412c7b
No related branches found
No related tags found
1 merge request!8Integrate groupless
......@@ -46,9 +46,16 @@ int main( int argc, char* argv [] )
// this would just open with a default transport, which is "BP"
auto bpReader = adios.Open( "myNumbers.bp", "r", bpReaderSettings );
// All the above is same as default use:
//auto bpReader = adios.Open( "myNumbers.bp", "r");
if( bpReader == nullptr )
throw std::ios_base::failure( "ERROR: failed to open ADIOS bpReader\n" );
/* Variable names are available as a vector of strings */
std::cout << "List of variables in file: " << bpReader->VariableNames << "\n";
/* NX */
bpReader->Read<unsigned int>( "NX", &Nx ); // read a Global scalar which has a single value in a step
......@@ -63,9 +70,15 @@ int main( int argc, char* argv [] )
// 1D array of Nwriters values.
if( rank < Nwriters )
{
std::shared_ptr<adios::Variable<void> > varNparts = bpReader.InquiryVariable("Nparts");
std::unique_ptr<adios::Selection> selNparts = adios.SelectionBoundingBox( {1}, {rank} );
bpReader->Read<int>( "Nparts", selNparts, &Nparts );
varNparts->SetSelection( selNparts );
bpReader->Read<int>( varNparts, &Nparts );
}
// or we could just read the whole array by every process
std::vector<int> partsV( Nwriters );
bpReader->Read<int>( "Nparts", &partsV ); // read with string name, no selection => read whole array
/* Nice */
......@@ -89,7 +102,8 @@ int main( int argc, char* argv [] )
// Make a 1D selection to describe the local dimensions of the variable we READ and
// its offsets in the global spaces
std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( {ldim}, {offs} ); // local dims and offsets; both as list
bpReader->Read<double>( "Nice", bbsel, NiceArray.data() ); // Base class Engine own the Read<T> that will call overloaded Read from Derived
varNice->SetSelection( bbsel );
bpReader->Read<double>( varNice, NiceArray.data() );
......@@ -112,30 +126,22 @@ int main( int argc, char* argv [] )
RaggedArray.resize( ldim );
std::unique_ptr<adios::Selection> wbsel = adios.SelectionWriteblock( rank );
bpReader->Read<float>( "Ragged", wbsel, RaggedArray.data() );
varRagged->SetSelection( wbsel );
bpReader->Read<float>( varRagged, RaggedArray.data() );
// We can use bounding box selection as well
std::unique_ptr<adios::Selection> rbbsel = adios.SelectionBoundingBox( {1,ldim}, {rank,0} );
bpReader->Read<float>( "Ragged", rbbsel, RaggedArray.data() );
varRagged->SetSelection( rbbsel );
bpReader->Read<float>( varRagged, RaggedArray.data() );
}
/* Extra help to process Ragged */
int maxRaggedDim = varRagged->GetMaxGlobalDimensions(1); // contains the largest
vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions(1); // contains all individual sizes in that dimension
// promise to not read more from this step
bpReader->Release();
// want to move on to the next available step
//bpReader->Advance(adios::NextImmediateStep);
//bpReader->Advance(adios::NextAvailableStep);
bpReader->Advance(); // default is adios::NextAvailableStep
std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions(1); // contains all individual sizes in that dimension
// Close file/stream
bpReader->Close( );
bpReader->Close();
}
catch( std::invalid_argument& e )
{
......
......@@ -25,7 +25,7 @@ int main( int argc, char* argv [] )
//Application variable
std::vector<double> NiceArray;
std::vector<float> RaggedArray;
unsigned int Nx;
int Nparts;
int Nwriters;
int Nsteps;
......@@ -49,26 +49,55 @@ int main( int argc, char* argv [] )
// this would just open with a default transport, which is "BP"
auto bpReader = adios.Open( "myNumbers.bp", "r", bpReaderSettings );
// All the above is same as default use:
//auto bpReader = adios.Open( "myNumbers.bp", "r");
if( bpReader == nullptr )
throw std::ios_base::failure( "ERROR: failed to open ADIOS bpReader\n" );
/* Note: there is no global number of steps. Each variable has its own number of steps */
/* NX */
/* There is a single value for each step. We can read all into a 1D array with a step selection.
* We can also just conveniently get the first with a simple read statement.
* Steps are not automatically presented as an array dimension and read does not read it as array.
*/
unsigned int Nx;
bpReader->Read<unsigned int>( "NX", &Nx ); // read a Global scalar which has a single value in a step
std::shared_ptr<adios::Variable<void> > varNx = bpReader.InquiryVariable("Nx");
std::vector<int> Nxs( varNx->nsteps() ); // number of steps available
// make a StepSelection to select multiple steps. Args: From, #of consecutive steps
std::unique_ptr<adios::StepSelection> stepsNx = adios.StepSelection( 0, varNx->nsteps() );
// ? How do we make a selection for an arbitrary list of steps ?
varNX.SetStepSelection( stepsNx );
bpReader->Read<unsigned int>( varNx, Nxs.data() );
auto itmax = std::max_element(std::begin(Nxs), std::end(Nxs));
auto itmin = std::min_element(std::begin(Nxs), std::end(Nxs));
if (*itmin != *itmax)
{
throw std::ios_base::failure( "ERROR: NX is not the same at all steps!\n" );
}
/* nproc */
bpReader->Read<int>( "nproc", &Nwriters ); // also a global scalar
/* Nparts */
// Nparts local scalar is presented as a 1D array of Nwriters elements.
// We need to read a specific value the same way as reading from any 1D array.
// Make a single-value selection to describe our rank's position in the
// 1D array of Nwriters values.
if( rank < Nwriters )
{
std::unique_ptr<adios::Selection> selNparts = adios.SelectionBoundingBox( {1}, {rank} );
bpReader->Read<int>( "Nparts", selNparts, &Nparts );
}
// We can read all steps into a 2D array of nproc * Nwriters
std::shared_ptr<adios::Variable<void> > varNparts = bpReader.InquiryVariable("Nparts");
std::vector<int> partsV( Nproc*Nwriters );
varNparts->SetStepSelection(
adios.StepSelection( 0, varNparts->nsteps() )
);
bpReader->Read<int>( varNparts, partsV.data() ); // missing spatial selection = whole array at each step
/* Nice */
......@@ -124,20 +153,14 @@ int main( int argc, char* argv [] )
/* Extra help to process Ragged */
int maxRaggedDim = varRagged->GetMaxGlobalDimensions(1); // contains the largest
vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions(1); // contains all individual sizes in that dimension
std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions(1); // contains all individual sizes in that dimension
// promise to not read more from this step
bpReader->Release();
// want to move on to the next available step
//bpReader->Advance(adios::NextImmediateStep);
//bpReader->Advance(adios::NextAvailableStep);
bpReader->Advance(); // default is adios::NextAvailableStep
// Close file/stream
bpReader->Close( );
bpReader->Close();
}
catch( std::invalid_argument& e )
......
......@@ -50,104 +50,110 @@ int main( int argc, char* argv [] )
{
auto bpReader = adios.Open( "myNumbers.bp", "r", bpReaderSettings );
while (true)
{
/* NX */
bpReader->Read<unsigned int>( "NX", &Nx ); // read a Global scalar which has a single value in a step
while (true)
{
/* NX */
bpReader->Read<unsigned int>( "NX", &Nx ); // read a Global scalar which has a single value in a step
/* nproc */
bpReader->Read<int>( "nproc", &Nwriters ); // also a global scalar
/* nproc */
bpReader->Read<int>( "nproc", &Nwriters ); // also a global scalar
/* Nparts */
// Nparts local scalar is presented as a 1D array of Nwriters elements.
// We need to read a specific value the same way as reading from any 1D array.
// Make a single-value selection to describe our rank's position in the
// 1D array of Nwriters values.
if( rank < Nwriters )
{
std::unique_ptr<adios::Selection> selNparts = adios.SelectionBoundingBox( {1}, {rank} );
bpReader->Read<int>( "Nparts", selNparts, &Nparts );
}
/* Nparts */
// Nparts local scalar is presented as a 1D array of Nwriters elements.
// We can read all as a 1D array
std::vector<int> partsV( Nwriters );
bpReader->Read<int>( "Nparts", &partsV ); // read with string name, no selection => read whole array
/* Nice */
// inquiry about a variable, whose name we know
std::shared_ptr<adios::Variable<void> > varNice = bpReader.InquiryVariable("Nice");
/* Nice */
// inquiry about a variable, whose name we know
std::shared_ptr<adios::Variable<void> > varNice = bpReader.InquiryVariable("Nice");
if( varNice == nullptr )
throw std::ios_base::failure( "ERROR: failed to find variable 'myDoubles' in input file\n" );
if( varNice == nullptr )
throw std::ios_base::failure( "ERROR: failed to find variable 'myDoubles' in input file\n" );
// ? how do we know about the type? std::string varNice->m_Type
unsigned long long int gdim = varMyDoubles->m_GlobalDimensions[0]; // ?member var or member func?
unsigned long long int ldim = gdim / nproc;
unsigned long long int offs = rank * ldim;
if( rank == nproc-1 )
{
ldim = gdim - (ldim * gdim);
}
NiceArray.reserve(ldim);
// ? how do we know about the type? std::string varNice->m_Type
unsigned long long int gdim = varMyDoubles->m_GlobalDimensions[0]; // ?member var or member func?
unsigned long long int ldim = gdim / nproc;
unsigned long long int offs = rank * ldim;
if( rank == nproc-1 )
{
ldim = gdim - (ldim * gdim);
}
// Make a 1D selection to describe the local dimensions of the variable we READ and
// its offsets in the global spaces
std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( {ldim}, {offs} ); // local dims and offsets; both as list
bpReader->Read<double>( "Nice", bbsel, NiceArray.data() ); // Base class Engine own the Read<T> that will call overloaded Read from Derived
NiceArray.reserve(ldim);
// Make a 1D selection to describe the local dimensions of the variable we READ and
// its offsets in the global spaces
std::unique_ptr<adios::Selection> bbsel = adios.SelectionBoundingBox( {ldim}, {offs} ); // local dims and offsets; both as list
varNice->SetSelection( bbsel );
bpReader->Read<double>( varNice, NiceArray.data() );
/* Ragged */
// inquiry about a variable, whose name we know
std::shared_ptr<adios::Variable<void> > varRagged = bpReader.InquiryVariable("Ragged");
if( varRagged->m_GlobalDimensions[1] != adios::VARYING_DIMENSION)
{
throw std::ios_base::failure( "Unexpected condition: Ragged array's fast dimension "
"is supposed to be VARYING_DIMENSION\n" );
}
// We have here varRagged->sum_nblocks, nsteps, nblocks[], global
if( rank < varRagged->nblocks[0] ) // same as rank < Nwriters in this example
{
// get per-writer size information
varRagged->InquiryBlocks();
// now we have the dimensions per block
/* Ragged */
// inquiry about a variable, whose name we know
std::shared_ptr<adios::Variable<void> > varRagged = bpReader.InquiryVariable("Ragged");
if( varRagged->m_GlobalDimensions[1] != adios::VARYING_DIMENSION)
{
throw std::ios_base::failure( "Unexpected condition: Ragged array's fast dimension "
"is supposed to be VARYING_DIMENSION\n" );
}
// We have here varRagged->sum_nblocks, nsteps, nblocks[], global
if( rank < varRagged->nblocks[0] ) // same as rank < Nwriters in this example
{
// get per-writer size information
varRagged->InquiryBlocks();
// now we have the dimensions per block
unsigned long long int ldim = varRagged->blockinfo[rank].m_Dimensions[0];
RaggedArray.resize( ldim );
unsigned long long int ldim = varRagged->blockinfo[rank].m_Dimensions[0];
RaggedArray.resize( ldim );
std::unique_ptr<adios::Selection> wbsel = adios.SelectionWriteblock( rank );
bpReader->Read<float>( "Ragged", wbsel, RaggedArray.data() );
std::unique_ptr<adios::Selection> wbsel = adios.SelectionWriteblock( rank );
varRagged->SetSelection( wbsel );
bpReader->Read<float>( varRagged, RaggedArray.data() );
// We can use bounding box selection as well
std::unique_ptr<adios::Selection> rbbsel = adios.SelectionBoundingBox( {1,ldim}, {rank,0} );
bpReader->Read<float>( "Ragged", rbbsel, RaggedArray.data() );
}
// We can use bounding box selection as well
std::unique_ptr<adios::Selection> rbbsel = adios.SelectionBoundingBox( {1,ldim}, {rank,0} );
varRagged->SetSelection( rbbsel );
bpReader->Read<float>( varRagged, RaggedArray.data() );
}
/* Extra help to process Ragged */
int maxRaggedDim = varRagged->GetMaxGlobalDimensions(1); // contains the largest
vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions(1); // contains all individual sizes in that dimension
/* Extra help to process Ragged */
int maxRaggedDim = varRagged->GetMaxGlobalDimensions(1); // contains the largest
std::vector<int> raggedDims = varRagged->GetVaryingGlobalDimensions(1); // contains all individual sizes in that dimension
// promise to not read more from this step
bpReader->Release();
// promise to not read more from this step
bpReader->Release();
// want to move on to the next available step
//bpReader->Advance(adios::NextImmediateStep);
//bpReader->Advance(adios::NextAvailableStep);
bpReader->Advance(); // default is adios::NextAvailableStep
// want to move on to the next available step
//bpReader->Advance(adios::NextStep);
//bpReader->Advance(adios::LatestStep);
bpReader->Advance(); // default is adios::NextStep
}
}
// Close file/stream
bpReader->Close( );
// Close file/stream
bpReader->Close();
}
catch( adios::end_of_stream& e )
{
if( rank == 0 )
{
std::cout << "Reached end of stream, end processing loop.\n";
}
// Close file/stream
bpReader->Close();
}
catch( adios::file_not_found& e )
{
if( rank == 0 )
{
std::cout << "File/stream does not exist, quit.\n";
}
}
}
catch( std::invalid_argument& e )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment