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

Updated heatTransfer write part: common handling filename argument; uses...

Updated heatTransfer write part: common handling filename argument; uses PutDeferred and skips PerformPuts
parent 4e694406
No related branches found
No related tags found
1 merge request!338Heat
...@@ -8,8 +8,8 @@ an application to the ADIOS2 library for its IO. ...@@ -8,8 +8,8 @@ an application to the ADIOS2 library for its IO.
1. write: illustrates the Write API as well as has implementations of other IO libraries 1. write: illustrates the Write API as well as has implementations of other IO libraries
* adios 1.x * adios 1.x
* hdf5 * hdf5 sequential, separate file per process per step
* phdf5 * phdf5 parallel, steps appended to the same one file
2. read: illustrates the Read API that allows running the reader either as 2. read: illustrates the Read API that allows running the reader either as
...@@ -38,7 +38,11 @@ Writer usage: heatTransfer config output N M nx ny steps iterations ...@@ -38,7 +38,11 @@ Writer usage: heatTransfer config output N M nx ny steps iterations
steps: the total number of steps to output steps: the total number of steps to output
iterations: one step consist of this many iterations iterations: one step consist of this many iterations
$ mpirun -np 12 ./bin/heatTransfer_write_adios2 ../examples/heatTransfer/heat.xml heat 4 3 5 10 10 10 The ADIOS2 executable needs an XML config file to select the Engine used for the output. The engines are: BPFile, ADIOS1 and HDF5, the corresponding XML config files are in the examples/heatTransfer/ directory.
The adios1, ph5 and hdf5 versions of the example do not use XML config files, so just type "none" for the config argument.
$ mpirun -np 12 ./bin/heatTransfer_write_adios2 ../examples/heatTransfer/heat_bpfile.xml heat 4 3 5 10 10 10
2. Read the output step-by-step and print data into text files (data.<rank> per reader process) 2. Read the output step-by-step and print data into text files (data.<rank> per reader process)
......
...@@ -14,15 +14,24 @@ if(ADIOS2_HAVE_MPI) ...@@ -14,15 +14,24 @@ if(ADIOS2_HAVE_MPI)
adios2 MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} adios2 MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}
) )
add_executable(heatTransfer_write_ascii
main.cpp
HeatTransfer.cpp
Settings.cpp
IO_ascii.cpp
)
target_link_libraries(heatTransfer_write_ascii
MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}
)
if(ADIOS2_HAVE_ADIOS1) if(ADIOS2_HAVE_ADIOS1)
add_executable(heatTransfer_write_adios1 add_executable(heatTransfer_write_adios1.x
main.cpp main.cpp
HeatTransfer.cpp HeatTransfer.cpp
Settings.cpp Settings.cpp
IO_adios1.cpp IO_adios1.x.cpp
) )
target_link_libraries(heatTransfer_write_adios1 target_link_libraries(heatTransfer_write_adios1.x
adios1::adios MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} adios1::adios MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}
) )
endif() endif()
......
...@@ -26,6 +26,50 @@ public: ...@@ -26,6 +26,50 @@ public:
private: private:
std::string m_outputfilename; std::string m_outputfilename;
// Generate a file name from the outputfile string and the arguments
// default is add suffix if not already there
// if rank and step is specified, it will create a unique file name for that
// rank and step
std::string MakeFilename(const std::string &outputfile,
const std::string &suffix, int rank = -1,
int step = -1)
{
std::string name;
int ss = outputfile.size();
if (rank == -1 && step == -1)
{
// add suffix if not present already
name = outputfile;
if ((ss > suffix.size()) &&
outputfile.find(suffix) != ss - suffix.size())
{
name += suffix;
}
}
else
{
// we need a unique name here
name = outputfile;
if ((ss > suffix.size()) &&
outputfile.find(suffix) == ss - suffix.size())
{
name = outputfile.substr(0, ss - suffix.size());
}
if (rank >= 0)
{
std::string rs = std::to_string(rank);
name += "." + rs;
}
if (step >= 0)
{
std::string ts = std::to_string(step);
name += "." + ts;
}
name += suffix;
}
return name;
}
}; };
#endif /* IO_H_ */ #endif /* IO_H_ */
...@@ -27,7 +27,8 @@ static int rank_saved; ...@@ -27,7 +27,8 @@ static int rank_saved;
IO::IO(const Settings &s, MPI_Comm comm) IO::IO(const Settings &s, MPI_Comm comm)
{ {
rank_saved = s.rank; rank_saved = s.rank;
m_outputfilename = s.outputfile + ".bp"; m_outputfilename = MakeFilename(s.outputfile, ".bp");
adios_init_noxml(comm); adios_init_noxml(comm);
adios_declare_group(&group, "heat", "", adios_stat_default); adios_declare_group(&group, "heat", "", adios_stat_default);
adios_select_method(group, "POSIX", "", ""); adios_select_method(group, "POSIX", "", "");
......
...@@ -21,25 +21,18 @@ adios2::Variable<unsigned int> *varGndx = nullptr; ...@@ -21,25 +21,18 @@ adios2::Variable<unsigned int> *varGndx = nullptr;
IO::IO(const Settings &s, MPI_Comm comm) IO::IO(const Settings &s, MPI_Comm comm)
{ {
m_outputfilename = s.outputfile + ".bp"; m_outputfilename = MakeFilename(s.outputfile, ".bp");
ad = new adios2::ADIOS(s.configfile, comm, adios2::DebugON);
// Define method for engine creation ad = new adios2::ADIOS(s.configfile, comm, adios2::DebugON);
adios2::IO &bpio = ad->DeclareIO("writer"); adios2::IO &bpio = ad->DeclareIO("writer");
if (!bpio.InConfigFile()) if (!bpio.InConfigFile())
{ {
// if not defined by user, we can change the default settings // if not defined by user, we can change the default settings
// BPFileWriter is the default engine // BPFileWriter is the default engine
// Allow an extra thread for data processing
// ISO-POSIX file is the default transport // ISO-POSIX file is the default transport
// Passing parameters to the transport
} }
varGndx = &bpio.DefineVariable<unsigned int>("gndx");
bpio.DefineVariable<unsigned int>("gndy");
// define T as 2D global array // define T as 2D global array
varT = &bpio.DefineVariable<double>( varT = &bpio.DefineVariable<double>(
"T", "T",
...@@ -50,11 +43,6 @@ IO::IO(const Settings &s, MPI_Comm comm) ...@@ -50,11 +43,6 @@ IO::IO(const Settings &s, MPI_Comm comm)
// local size, could be defined later using SetSelection() // local size, could be defined later using SetSelection()
{s.ndx, s.ndy}); {s.ndx, s.ndy});
// add transform to variable
// adios2::Transform tr = adios2::transform::BZIP2( );
// varT.AddTransform( tr, "" );
// varT.AddTransform( tr,"accuracy=0.001" ); // for ZFP
bpWriter = &bpio.Open(m_outputfilename, adios2::Mode::Write, comm); bpWriter = &bpio.Open(m_outputfilename, adios2::Mode::Write, comm);
} }
...@@ -68,26 +56,11 @@ void IO::write(int step, const HeatTransfer &ht, const Settings &s, ...@@ -68,26 +56,11 @@ void IO::write(int step, const HeatTransfer &ht, const Settings &s,
MPI_Comm comm) MPI_Comm comm)
{ {
bpWriter->BeginStep(); bpWriter->BeginStep();
/* This selection is redundant and not required, since we defined // using PutDeferred() you promise the pointer to the data will be intact
* the selection already in DefineVariable(). It is here just as an example. // until the end of the output step.
*/ // We need to have the vector object here not to destruct here until the end
// Make a selection to describe the local dimensions of the variable we // of function.
// write and its offsets in the global spaces. This could have been done in std::vector<double> v = ht.data_noghost();
// adios.DefineVariable() bpWriter->PutDeferred<double>(*varT, v.data());
varT->SetSelection(
adios2::Box<adios2::Dims>({s.offsx, s.offsy}, {s.ndx, s.ndy}));
if (!step)
{
int rank;
MPI_Comm_rank(comm, &rank);
if (!rank)
{
bpWriter->PutSync<unsigned int>(*varGndx, s.gndx);
bpWriter->PutSync<unsigned int>("gndy", s.gndy);
}
}
bpWriter->PutSync<double>(*varT, ht.data_noghost().data());
// bpWriter->PerformPuts();
bpWriter->EndStep(); bpWriter->EndStep();
} }
...@@ -27,10 +27,8 @@ IO::IO(const Settings &s, MPI_Comm comm) ...@@ -27,10 +27,8 @@ IO::IO(const Settings &s, MPI_Comm comm)
} }
else else
{ {
int rank; m_outputfilename = MakeFilename(s.outputfile, ".txt", s.rank);
MPI_Comm_rank(comm, &rank); of.open(m_outputfilename);
std::string rs = std::to_string(rank);
of.open(m_outputfilename + rs + ".txt");
buf = of.rdbuf(); buf = of.rdbuf();
} }
} }
...@@ -67,12 +65,13 @@ void IO::write(int step, const HeatTransfer &ht, const Settings &s, ...@@ -67,12 +65,13 @@ void IO::write(int step, const HeatTransfer &ht, const Settings &s,
out << std::endl; out << std::endl;
} }
out << std::fixed;
for (int i = 1; i <= s.ndx; ++i) for (int i = 1; i <= s.ndx; ++i)
{ {
out << std::setw(5) << step << std::setw(5) << s.offsx + i - 1; out << std::setw(5) << step << std::setw(5) << s.offsx + i - 1;
for (int j = 1; j <= s.ndy; ++j) for (int j = 1; j <= s.ndy; ++j)
{ {
out << std::setw(9) << ht.T(i, j); out << std::setw(9) << std::setprecision(5) << ht.T(i, j);
} }
out << std::endl; out << std::endl;
} }
......
...@@ -33,15 +33,7 @@ IO::IO(const Settings &s, MPI_Comm comm) ...@@ -33,15 +33,7 @@ IO::IO(const Settings &s, MPI_Comm comm)
{ {
rank_saved = s.rank; rank_saved = s.rank;
m_outputfilename = s.outputfile; m_outputfilename = MakeFilename(s.outputfile, ".h5");
std::string suffix = ".h5";
int ss = s.outputfile.size();
if ((ss > suffix.size()) && s.outputfile.find(suffix) != ss - suffix.size())
{
// Your code here
m_outputfilename += suffix;
}
/*ad = new adios2::ADIOS(std::string(DEFAULT_CONFIG_STR), comm, /*ad = new adios2::ADIOS(std::string(DEFAULT_CONFIG_STR), comm,
adios2::DebugON); adios2::DebugON);
......
...@@ -27,9 +27,7 @@ IO::~IO() {} ...@@ -27,9 +27,7 @@ IO::~IO() {}
void IO::write(int step, const HeatTransfer &ht, const Settings &s, void IO::write(int step, const HeatTransfer &ht, const Settings &s,
MPI_Comm comm) MPI_Comm comm)
{ {
std::string rs = std::to_string(s.rank); m_outputfilename = MakeFilename(s.outputfile, ".h5", s.rank, step);
std::string ts = std::to_string(step);
std::string fname = s.outputfile + "." + rs + "." + ts + ".h5";
// for time measurements, let's synchronize the processes // for time measurements, let's synchronize the processes
MPI_Barrier(comm); MPI_Barrier(comm);
...@@ -39,8 +37,8 @@ void IO::write(int step, const HeatTransfer &ht, const Settings &s, ...@@ -39,8 +37,8 @@ void IO::write(int step, const HeatTransfer &ht, const Settings &s,
static_cast<hsize_t>(s.ndy)}; static_cast<hsize_t>(s.ndy)};
hid_t space = H5Screate_simple(2, dims, NULL); hid_t space = H5Screate_simple(2, dims, NULL);
hid_t file = hid_t file = H5Fcreate(m_outputfilename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,
H5Fcreate(fname.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); H5P_DEFAULT);
hid_t dset = H5Dcreate(file, "T", H5T_NATIVE_DOUBLE, space, H5P_DEFAULT, hid_t dset = H5Dcreate(file, "T", H5T_NATIVE_DOUBLE, space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT); H5P_DEFAULT, H5P_DEFAULT);
......
...@@ -276,18 +276,7 @@ std::shared_ptr<HDF5NativeWriter> h5writer; ...@@ -276,18 +276,7 @@ std::shared_ptr<HDF5NativeWriter> h5writer;
IO::IO(const Settings &s, MPI_Comm comm) IO::IO(const Settings &s, MPI_Comm comm)
{ {
std::string suffix = ".h5"; m_outputfilename = MakeFilename(s.outputfile, ".h5");
m_outputfilename = s.outputfile + suffix;
int ss = s.outputfile.size();
int pos = s.outputfile.find(suffix);
if ((ss > suffix.size()) && (pos == ss - suffix.size()))
{
// Your code here
m_outputfilename = s.outputfile;
}
// m_outputfilename = s.outputfile + ".h5";
if (s.outputfile[0] == '0') if (s.outputfile[0] == '0')
{ {
......
...@@ -21,16 +21,7 @@ adios2::Variable<unsigned int> *varGndx = nullptr; ...@@ -21,16 +21,7 @@ adios2::Variable<unsigned int> *varGndx = nullptr;
IO::IO(const Settings &s, MPI_Comm comm) IO::IO(const Settings &s, MPI_Comm comm)
{ {
std::string suffix = ".h5"; m_outputfilename = MakeFilename(s.outputfile, ".h5");
m_outputfilename = s.outputfile + suffix;
int ss = s.outputfile.size();
int pos = s.outputfile.find(suffix);
if ((ss > suffix.size()) && (pos == ss - suffix.size()))
{
// Your code here
m_outputfilename = s.outputfile;
}
ad = new adios2::ADIOS(comm, adios2::DebugOFF); ad = new adios2::ADIOS(comm, adios2::DebugOFF);
......
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