diff --git a/examples/solidfluid/solidfluid_read.cpp b/examples/solidfluid/solidfluid_read.cpp index 7d94ad22ff743c0ff0df52322f3aa75526b4332f..38f0e528737fbc8abf36e0577e9f9900961d6ee0 100644 --- a/examples/solidfluid/solidfluid_read.cpp +++ b/examples/solidfluid/solidfluid_read.cpp @@ -12,7 +12,7 @@ #include <string> #include <vector> -#include "public/ADIOS.h" +#include "ADIOS.h" struct MYDATA { @@ -26,26 +26,27 @@ struct MYDATA solid, fluid; MPI_Comm comm=MPI_COMM_WORLD; int rank, size; -void read_ckpt (struct MYDATA &solid, struct MYDATA &fluid) +void read_ckpt (adios::ADIOS adios, struct MYDATA &solid, struct MYDATA &fluid) { try { // Open an input which was written with an expected Method - // The writing transport method is associated with the group in the XML + // The write transport is associated with the group in the XML // ADIOS pairs that with the corresponding read transport // "r" is required to indicate we are reading - adios::ADIOS_INPUT ckptfile( comm, "r", "checkpoint"); - ckptfile.Open("ckpt.bp"); + int ckptfile = adios.Open("checkpoint.bp", "checkpoint", "r", comm); + // We can also manually set the read transport + //int ckptfile = adios.Open("checkpoint.bp", adios::READ_METHOD_BP, "r", comm); // Note: we only see a single step in the input but the checkpoint has // only one step anyway. This makes this code simple // simple immediate read of a scalar - ckptfile.ReadScalar ("solid/NX", &solid.NX); + adios.ReadScalar (ckptfile, "solid/NX", &solid.NX); // solid.NX is filled at this point // scheduled version of read of another scalar - ckptfile.ScheduleRead ("fluid/NX", &fluid.NX); - ckptfile.Read(); // perform reading now + adios.ScheduleRead (ckptfile, "fluid/NX", &fluid.NX); + adios.Read(ckptfile); // perform reading now // fluid.NX is filled at this point solid.t = new double(solid.NX); @@ -55,13 +56,13 @@ void read_ckpt (struct MYDATA &solid, struct MYDATA &fluid) fluid.p = std::vector<double>(fluid.NX); adios::ADIOS_SELECTION_WRITEBLOCK sel(rank); - ckptfile.ScheduleRead (sel, "solid/temperature", solid.t); - ckptfile.ScheduleRead (sel, "solid/pressure", solid.p); - ckptfile.ScheduleRead (sel, "fluid/temperature", fluid.t); + adios.ScheduleRead (ckptfile, sel, "solid/temperature", solid.t); + adios.ScheduleRead (ckptfile, sel, "solid/pressure", solid.p); + adios.ScheduleRead (ckptfile, sel, "fluid/temperature", fluid.t); // force checking if the allocated space equals to the size of the selection: - ckptfile.ScheduleRead (sel, "fluid/pressure", fluid.p, fluid.NX*sizeof(double)); - ckptfile.Read(true); // true: blocking read - ckptfile.Close(); // Should this do Read() if user misses or should we complain? + adios.ScheduleRead (ckptfile, sel, "fluid/pressure", fluid.p, fluid.NX*sizeof(double)); + adios.Read(ckptfile, true); // true: blocking read, which is also default + adios.Close(ckptfile); // Should this do Read() if user misses or should we complain? } catch ( std::exception& e ) //need to think carefully how to handle C++ exceptions with MPI to avoid deadlocking { @@ -72,21 +73,20 @@ void read_ckpt (struct MYDATA &solid, struct MYDATA &fluid) } } -void read_solid (struct MYDATA &solid) +void read_solid (adios::ADIOS adios, struct MYDATA &solid) { float timeout_sec = 1.0; int retval = 0; - // Open a file for input, no group defined - // A reading transport should be defined if not file based - // "r" is required to indicate we are reading - adios::ADIOS_INPUT solidfile( comm, "r"); try { - solidfile.Open("solid.bp"); //, ADIOS_LOCKMODE_NONE, timeout_sec); - + // Open a file for input, no group defined + // A reading transport should be defined if not file based + // "r" is required to indicate we are reading + int solidfile = adios.Open("solid.bp", "r", comm); //, ADIOS_LOCKMODE_NONE, timeout_sec); + //int solidfile = adios.Open("solid.bp", adios::READ_METHOD_BP, "r", comm); /* process file here... */ - const adios::ADIOS_VARINFO &v = solidfile.InqVar ("temperature"); + const adios::ADIOS_VARINFO &v = adios.InqVar (solidfile, "temperature"); v.GetBlockInfo(); printf ("ndim = %d\n", v.ndim); @@ -103,7 +103,7 @@ void read_solid (struct MYDATA &solid) start[1] = 0; count[1] = v.dims[1]; - data = malloc (slice_size * v.dims[1] * 8); + auto data = std::make_unique<double[]>(slice_size * v.dims[1] * 8); adios::ADIOS_SELECTION_BOUNDINGBOX sel(v.ndim, start, count); @@ -161,7 +161,7 @@ void read_solid (struct MYDATA &solid) } } -void read_fluid (struct MYDATA &fluid) +void read_fluid (adios::ADIOS adios, struct MYDATA &fluid) { float timeout_sec = 1.0; int retval = 0; @@ -273,11 +273,11 @@ int main (int argc, char ** argv) // ADIOS manager object creation. MPI must be initialized adios::ADIOS adios( "globalArrayXML.xml", comm, true ); - read_ckpt(solid, fluid); + read_ckpt(adios, solid, fluid); - read_solid(solid); + read_solid(adios, solid); - read_fluid(fluid); + read_fluid(adios, fluid); } catch( std::exception& e ) //need to think carefully how to handle C++ exceptions with MPI to avoid deadlocking { diff --git a/examples/solidfluid/solidfluid_write.cpp b/examples/solidfluid/solidfluid_write.cpp index 915061b0f294ba4ec66673ddb06aa5d4d271a414..bf38af63321fbf024c19003b0e36d23e2c9c3a7a 100644 --- a/examples/solidfluid/solidfluid_write.cpp +++ b/examples/solidfluid/solidfluid_write.cpp @@ -12,7 +12,7 @@ #include <string> #include <vector> -#include "public/ADIOS.h" +#include "ADIOS.h" struct MYDATA { @@ -27,7 +27,7 @@ MPI_Comm comm=MPI_COMM_WORLD; int rank, size; -void write_data (adios::ADIOS adios, struct MYDATA &data, ADIOS_OUTPUT &outfile) +void write_data (adios::ADIOS adios, struct MYDATA &data, unsigned int outfile) { adios.Write (outfile, "NX", &data.NX); adios.Write (outfile, "rank", &rank); @@ -38,27 +38,27 @@ void write_data (adios::ADIOS adios, struct MYDATA &data, ADIOS_OUTPUT &outfile) adios.Write (outfile); } -void write_ckpt (struct MYDATA &solid, struct MYDATA &fluid, adios::ADIOS_OUTPUT &ckptfile) +void write_checkpoint (adios::ADIOS adios, struct MYDATA &solid, struct MYDATA &fluid) { try { // Open an output for a Group // a transport or an engine should be associated with the group - ckptfile.Open("ckpt.bp"); - - ckptfile.ScheduleWrite ("solid/NX", &solid.NX); - ckptfile.ScheduleWrite ("solid/rank", &rank); - ckptfile.ScheduleWrite ("solid/size", &size); - ckptfile.ScheduleWrite ("solid/temperature", solid.t); - ckptfile.ScheduleWrite ("solid/pressure", solid.p); - - ckptfile.ScheduleWrite ("fluid/NX", &fluid.NX); - ckptfile.ScheduleWrite ("fluid/rank", &rank); - ckptfile.ScheduleWrite ("fluid/size", &size); - ckptfile.ScheduleWrite ("fluid/temperature", fluid.t); - ckptfile.ScheduleWrite ("fluid/pressure", fluid.p); - - ckptfile.Write(); - ckptfile.Close(); // Should this do Write() if user misses or should we complain? + int ckptfile = adios.Open("checkpoint.bp", "checkpoint", "w", comm); + + adios.Write (ckptfile, "solid/NX", &solid.NX); + adios.Write (ckptfile, "solid/rank", &rank); + adios.Write (ckptfile, "solid/size", &size); + adios.Write (ckptfile, "solid/temperature", solid.t); + adios.Write (ckptfile, "solid/pressure", solid.p); + + adios.Write (ckptfile, "fluid/NX", &fluid.NX); + adios.Write (ckptfile, "fluid/rank", &rank); + adios.Write (ckptfile, "fluid/size", &size); + adios.Write (ckptfile, "fluid/temperature", fluid.t); + adios.Write (ckptfile, "fluid/pressure", fluid.p); + + adios.Write(ckptfile); + adios.Close(ckptfile); // Should this do Write() if user misses or should we complain? } catch ( std::exception& e ) //need to think carefully how to handle C++ exceptions with MPI to avoid deadlocking { @@ -69,7 +69,7 @@ void write_ckpt (struct MYDATA &solid, struct MYDATA &fluid, adios::ADIOS_OUTPUT } } -void write_viz (struct MYDATA &solid, struct MYDATA &fluid, ADIOS_OUTPUT &vizstream) +void write_viz (adios::ADIOS adios, struct MYDATA &solid, struct MYDATA &fluid, unsigned int vizstream) { // This stream is not associated with a group, so we must say for each write which group to use // The output variable is re-defined inside as <groupname>/<varname>, unless given as third string argument @@ -87,11 +87,11 @@ void write_viz (struct MYDATA &solid, struct MYDATA &fluid, ADIOS_OUTPUT &vizstr adios.Write (vizstream, "fluid", "temperature", "temperature", fluid.t); - vizstream.Write(); + adios.Write(vizstream); // flushes all data to disk; required operation vizstream.AdvanceStep(); } -void compute (struct MYDATA &solid, struct MYDATA &fluid) +void compute (int it, struct MYDATA &solid, struct MYDATA &fluid) { for (int i = 0; i < solid.NX; i++) { @@ -129,7 +129,7 @@ int main( int argc, char* argv [] ) // Multiple writes to the same file work as append in this application run // FIXME: how do we support Update to same step? - int solidfile = adios.Open("solid", "solid.bp", "a", comm); // "solid" is a method but incidentally also a group + int solidfile = adios.Open("solid.bp", "solid", "a", comm); // "solid" is a method but incidentally also a group // Constructor only creates an object and what is needed there but does not open a stream/file // It can be used to initialize a staging connection if not declared before // FIXME: which argument can be post-poned into Open() instead of constructor? @@ -141,15 +141,14 @@ int main( int argc, char* argv [] ) // "a" will append to an already existing file, "w" would create a new file // Multiple writes to the same file work as append in this application run // FIXME: how do we support Update to same step? - int fluidfile = adios.Open("fluid.bp", "fluid", - adios::ACCESS_MODE::APPEND, comm); + int fluidfile = adios.Open("fluid.bp", "fluid", "a", comm); - int ckptfile = adios.Open("checkpoint.bp", "checkpoint", "w", comm); + //int ckptfile = adios.Open("checkpoint.bp", "checkpoint", "w", comm); // we do not open this here, but every time when needed in a function // Another output not associated with a single group, so that we can mix variables to it //adios:handle vizstream = adios.Open( "stream.bp", comm, "w", "STAGING", "options to staging method"); - adios::handle vizstream = adios.Open( "stream.bp", comm, "w", "groupless"); + int vizstream = adios.Open( "stream.bp", comm, "w", "groupless"); // This creates an empty group inside, and we can write all kinds of variables to it @@ -159,16 +158,16 @@ int main( int argc, char* argv [] ) for (int it = 1; it <= 100; it++) { - compute (solid, fluid); + compute (it, solid, fluid); - write_data(solid, solidfile); - write_data(fluid, fluidfile); + write_data(adios, solid, solidfile); + write_data(adios, fluid, fluidfile); if (it%10 == 0) { - write_checkpoint (solid, fluid); + write_checkpoint (adios, solid, fluid); } - write_viz(solid, fluid, vizstream); + write_viz(adios, solid, fluid, vizstream); MPI_Barrier (comm); if (rank==0) printf("Timestep %d written\n", it);