Skip to content
Snippets Groups Projects
Unverified Commit 42a905fe authored by williamfgc's avatar williamfgc Committed by GitHub
Browse files

Merge pull request #328 from pnorbert/heat

Heat
parents 1c9dce85 5471c6a2
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0"?>
<!-- Config XML file fo the
- heatTransfer_write_adios2
- heatTransfer_read
executables in build/bin -->
<adios-config>
<!--====================================
Configuration for the Writer
====================================-->
<io name="writer">
<engine type="ADIOS1Writer">
<!-- for vectorized memory operations, make sure your system
enables threads-->
<parameter key="Threads" value="2"/>
<!-- Microseconds (default), Milliseconds, Seconds,
Minutes, Hours -->
<parameter key="ProfileUnits" value="Microseconds"/>
</engine>
<transport type="File">
<!-- POSIX, stdio (C FILE*), fstream (C++) -->
<parameter key="Library" value="MPI"/>
<!-- For read/write, Microseconds (default), Milliseconds, Seconds,
Minutes, Hours. open/close always in Microseconds -->
<parameter key="ProfileUnits" value="Microseconds"/>
</transport>
</io>
<!--====================================
Configuration for the Reader
====================================-->
<io name="reader">
<engine type="ADIOS1Reader">
<!-- for vectorized memory operations, make sure your system
enables threads-->
<parameter key="Threads" value="2"/>
<!-- Microseconds (default), Milliseconds, Seconds,
Minutes, Hours -->
<parameter key="ProfileUnits" value="Microseconds"/>
</engine>
<transport type="File">
<!-- POSIX, stdio (C FILE*), fstream (C++) -->
<parameter key="Library" value="POSIX"/>
<!-- For read/write, Microseconds (default), Milliseconds, Seconds,
Minutes, Hours. open/close always in Microseconds -->
<parameter key="ProfileUnits" value="Microseconds"/>
</transport>
</io>
</adios-config>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
====================================--> ====================================-->
<io name="writer"> <io name="writer">
<engine type="ADIOS1Writer"> <engine type="BPFileWriter">
<!-- for vectorized memory operations, make sure your system <!-- for vectorized memory operations, make sure your system
enables threads--> enables threads-->
......
...@@ -10,6 +10,4 @@ if(ADIOS2_HAVE_MPI) ...@@ -10,6 +10,4 @@ if(ADIOS2_HAVE_MPI)
ReadSettings.cpp ReadSettings.cpp
) )
target_link_libraries(heatTransfer_read adios2 MPI::MPI_C) target_link_libraries(heatTransfer_read adios2 MPI::MPI_C)
target_compile_definitions(heatTransfer_read PRIVATE
-DDEFAULT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/../heat.xml)
endif() endif()
...@@ -89,13 +89,18 @@ int main(int argc, char *argv[]) ...@@ -89,13 +89,18 @@ int main(int argc, char *argv[])
while (true) while (true)
{ {
adios2::StepStatus status = adios2::StepStatus status =
bpReader.BeginStep(adios2::StepMode::NextAvailable); bpReader.BeginStep(adios2::StepMode::NextAvailable, 10.0f);
if (status != adios2::StepStatus::OK) if (status != adios2::StepStatus::OK)
{
break; break;
}
// Variable objects disappear between steps so we need this every
// step
vT = bpReaderIO.InquireVariable<double>("T");
if (firstStep) if (firstStep)
{ {
vT = bpReaderIO.InquireVariable<double>("T");
unsigned int gndx = vT->m_Shape[0]; unsigned int gndx = vT->m_Shape[0];
unsigned int gndy = vT->m_Shape[1]; unsigned int gndy = vT->m_Shape[1];
...@@ -108,9 +113,6 @@ int main(int argc, char *argv[]) ...@@ -108,9 +113,6 @@ int main(int argc, char *argv[])
settings.DecomposeArray(gndx, gndy); settings.DecomposeArray(gndx, gndy);
T = new double[settings.readsize[0] * settings.readsize[1]]; T = new double[settings.readsize[0] * settings.readsize[1]];
// Create a 2D selection for the subset
vT->SetSelection(adios2::Box<adios2::Dims>(settings.offset,
settings.readsize));
firstStep = false; firstStep = false;
MPI_Barrier(mpiReaderComm); // sync processes just for stdout MPI_Barrier(mpiReaderComm); // sync processes just for stdout
} }
...@@ -119,8 +121,14 @@ int main(int argc, char *argv[]) ...@@ -119,8 +121,14 @@ int main(int argc, char *argv[])
{ {
std::cout << "Processing step " << step << std::endl; std::cout << "Processing step " << step << std::endl;
} }
// Create a 2D selection for the subset
vT->SetSelection(
adios2::Box<adios2::Dims>(settings.offset, settings.readsize));
// Arrays are read by scheduling one or more of them // Arrays are read by scheduling one or more of them
// and performing the reads at once // and performing the reads at once
bpReader.GetDeferred<double>(*vT, T); bpReader.GetDeferred<double>(*vT, T);
bpReader.PerformGets(); bpReader.PerformGets();
......
...@@ -13,9 +13,7 @@ if(ADIOS2_HAVE_MPI) ...@@ -13,9 +13,7 @@ if(ADIOS2_HAVE_MPI)
target_link_libraries(heatTransfer_write_adios2 target_link_libraries(heatTransfer_write_adios2
adios2 MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} adios2 MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}
) )
target_compile_definitions(heatTransfer_write_adios2 PRIVATE
-DDEFAULT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/config.xml
)
if(ADIOS2_HAVE_ADIOS1) if(ADIOS2_HAVE_ADIOS1)
add_executable(heatTransfer_write_adios1 add_executable(heatTransfer_write_adios1
......
...@@ -26,8 +26,7 @@ ADIOS1Reader::ADIOS1Reader(IO &io, const std::string &name, const Mode mode, ...@@ -26,8 +26,7 @@ ADIOS1Reader::ADIOS1Reader(IO &io, const std::string &name, const Mode mode,
m_EndMessage = " in call to IO Open ADIOS1Reader " + m_Name + "\n"; m_EndMessage = " in call to IO Open ADIOS1Reader " + m_Name + "\n";
Init(); Init();
m_ADIOS1.Open(); // adios_read_init_method(m_ReadMethod, mpiComm, ""); m_ADIOS1.Open(io);
m_ADIOS1.GenerateVariables(io);
} }
ADIOS1Reader::~ADIOS1Reader() ADIOS1Reader::~ADIOS1Reader()
...@@ -38,7 +37,7 @@ ADIOS1Reader::~ADIOS1Reader() ...@@ -38,7 +37,7 @@ ADIOS1Reader::~ADIOS1Reader()
StepStatus ADIOS1Reader::BeginStep(const StepMode mode, StepStatus ADIOS1Reader::BeginStep(const StepMode mode,
const float timeoutSeconds) const float timeoutSeconds)
{ {
return m_ADIOS1.AdvanceStep(mode, timeoutSeconds); return m_ADIOS1.AdvanceStep(m_IO, mode, timeoutSeconds);
} }
// PRIVATE // PRIVATE
......
...@@ -28,7 +28,6 @@ ADIOS1CommonRead::ADIOS1CommonRead(const std::string &fileName, ...@@ -28,7 +28,6 @@ ADIOS1CommonRead::ADIOS1CommonRead(const std::string &fileName,
: ADIOS1Common(fileName, mpiComm, debugMode) : ADIOS1Common(fileName, mpiComm, debugMode)
{ {
Init(); Init();
adios_read_init_method(m_ReadMethod, m_MPIComm, "");
} }
ADIOS1CommonRead::~ADIOS1CommonRead() ADIOS1CommonRead::~ADIOS1CommonRead()
...@@ -37,12 +36,13 @@ ADIOS1CommonRead::~ADIOS1CommonRead() ...@@ -37,12 +36,13 @@ ADIOS1CommonRead::~ADIOS1CommonRead()
adios_read_finalize_method(m_ReadMethod); adios_read_finalize_method(m_ReadMethod);
} }
bool ADIOS1CommonRead::Open() bool ADIOS1CommonRead::Open(IO &io)
{ {
if (m_OpenAsFile) if (m_OpenAsFile)
{ {
m_fh = m_fh =
adios_read_open_file(m_FileName.c_str(), m_ReadMethod, m_MPIComm); adios_read_open_file(m_FileName.c_str(), m_ReadMethod, m_MPIComm);
GenerateVariables(io);
} }
else else
{ {
...@@ -120,6 +120,8 @@ void ADIOS1CommonRead::DefineADIOS2Variable(IO &io, const char *name, ...@@ -120,6 +120,8 @@ void ADIOS1CommonRead::DefineADIOS2Variable(IO &io, const char *name,
void ADIOS1CommonRead::GenerateVariables(IO &io) void ADIOS1CommonRead::GenerateVariables(IO &io)
{ {
if (!m_fh)
return;
/* Create a Variable for each variable in the file */ /* Create a Variable for each variable in the file */
for (int varid = 0; varid < m_fh->nvars; varid++) for (int varid = 0; varid < m_fh->nvars; varid++)
{ {
...@@ -217,6 +219,7 @@ void ADIOS1CommonRead::ScheduleReadCommon(const std::string &name, ...@@ -217,6 +219,7 @@ void ADIOS1CommonRead::ScheduleReadCommon(const std::string &name,
const bool readAsJoinedArray, const bool readAsJoinedArray,
void *data) void *data)
{ {
const int adios1FromStep = fromStep - 1;
if (readAsLocalValue) if (readAsLocalValue)
{ {
/* Get all the requested values from metadata now */ /* Get all the requested values from metadata now */
...@@ -226,12 +229,12 @@ void ADIOS1CommonRead::ScheduleReadCommon(const std::string &name, ...@@ -226,12 +229,12 @@ void ADIOS1CommonRead::ScheduleReadCommon(const std::string &name,
adios_inq_var_stat(m_fh, vi, 0, 1); adios_inq_var_stat(m_fh, vi, 0, 1);
int elemsize = adios_type_size(vi->type, nullptr); int elemsize = adios_type_size(vi->type, nullptr);
long long blockidx = 0; long long blockidx = 0;
for (int i = 0; i < fromStep; i++) for (int i = 0; i < adios1FromStep; i++)
{ {
blockidx += vi->nblocks[i]; blockidx += vi->nblocks[i];
} }
char *dest = (char *)data; char *dest = (char *)data;
for (int i = fromStep; i < fromStep + nSteps; i++) for (int i = adios1FromStep; i < adios1FromStep + nSteps; i++)
{ {
for (int j = 0; j < vi->nblocks[i]; j++) for (int j = 0; j < vi->nblocks[i]; j++)
{ {
...@@ -257,8 +260,8 @@ void ADIOS1CommonRead::ScheduleReadCommon(const std::string &name, ...@@ -257,8 +260,8 @@ void ADIOS1CommonRead::ScheduleReadCommon(const std::string &name,
{ {
sel = adios_selection_boundingbox(ldims.size(), start, count); sel = adios_selection_boundingbox(ldims.size(), start, count);
} }
adios_schedule_read(m_fh, sel, name.c_str(), (int)fromStep, (int)nSteps, adios_schedule_read(m_fh, sel, name.c_str(), (int)adios1FromStep,
data); (int)nSteps, data);
adios_selection_delete(sel); adios_selection_delete(sel);
} }
} }
...@@ -268,7 +271,7 @@ void ADIOS1CommonRead::PerformReads() ...@@ -268,7 +271,7 @@ void ADIOS1CommonRead::PerformReads()
adios_perform_reads(m_fh, static_cast<int>(ReadMode::Blocking)); adios_perform_reads(m_fh, static_cast<int>(ReadMode::Blocking));
} }
StepStatus ADIOS1CommonRead::AdvanceStep(const StepMode mode, StepStatus ADIOS1CommonRead::AdvanceStep(IO &io, const StepMode mode,
const float timeout_sec) const float timeout_sec)
{ {
if (m_OpenAsFile) if (m_OpenAsFile)
...@@ -277,21 +280,41 @@ StepStatus ADIOS1CommonRead::AdvanceStep(const StepMode mode, ...@@ -277,21 +280,41 @@ StepStatus ADIOS1CommonRead::AdvanceStep(const StepMode mode,
"Advance() on a file which was opened for " "Advance() on a file which was opened for "
"read as File\n"); "read as File\n");
} }
if (mode != StepMode::NextAvailable && mode != StepMode::LatestAvailable) if (mode != StepMode::NextAvailable && mode != StepMode::LatestAvailable)
{ {
throw std::invalid_argument( throw std::invalid_argument(
"ERROR: ADIOS1Reader.Advance() only allows " "ERROR: ADIOS1Reader.Advance() only allows "
"for NextAvailable or LatestAvailable modes.\n"); "for NextAvailable or LatestAvailable modes.\n");
} }
int last = (mode == StepMode::NextAvailable ? 0 : 1);
float *to = const_cast<float *>(&timeout_sec); if (m_IsBeforeFirstStep)
adios_advance_step(m_fh, last, *to); {
/* ADIOS1 already has the first step open after Open(), in ADIOS2 we
* wait for
* the first call to BeginStep(), which calls this function.
*/
m_IsBeforeFirstStep = false;
adios_errno = err_no_error;
}
else
{
int last = (mode == StepMode::NextAvailable ? 0 : 1);
float *timeout = const_cast<float *>(&timeout_sec);
adios_advance_step(m_fh, last, *timeout);
if (adios_errno != err_step_notready)
{
io.RemoveAllVariables();
}
}
StepStatus status; StepStatus status;
switch (adios_errno) switch (adios_errno)
{ {
case err_no_error: case err_no_error:
status = StepStatus::OK; status = StepStatus::OK;
GenerateVariables(io);
break; break;
case err_end_of_stream: case err_end_of_stream:
status = StepStatus::EndOfStream; status = StepStatus::EndOfStream;
...@@ -403,6 +426,7 @@ void ADIOS1CommonRead::InitTransports( ...@@ -403,6 +426,7 @@ void ADIOS1CommonRead::InitTransports(
} }
} }
} }
adios_read_init_method(m_ReadMethod, m_MPIComm, "");
} }
/* /*
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
void InitParameters(const Params &parameters); void InitParameters(const Params &parameters);
void InitTransports(const std::vector<Params> &transportsParameters); void InitTransports(const std::vector<Params> &transportsParameters);
bool Open(); // return true if file is opened successfully bool Open(IO &io); // return true if file is opened successfully
void GenerateVariables(IO &io); void GenerateVariables(IO &io);
void ScheduleReadCommon(const std::string &name, const Dims &offs, void ScheduleReadCommon(const std::string &name, const Dims &offs,
...@@ -57,7 +57,8 @@ public: ...@@ -57,7 +57,8 @@ public:
const bool readAsJoinedArray, void *data); const bool readAsJoinedArray, void *data);
void PerformReads(); void PerformReads();
StepStatus AdvanceStep(const StepMode mode, const float timeout_sec = 0.0); StepStatus AdvanceStep(IO &io, const StepMode mode,
const float timeout_sec = 0.0);
void ReleaseStep(); void ReleaseStep();
ADIOS_VARINFO *InqVar(const std::string &varName); ADIOS_VARINFO *InqVar(const std::string &varName);
...@@ -73,6 +74,11 @@ private: ...@@ -73,6 +74,11 @@ private:
bool m_OpenAsFile = false; bool m_OpenAsFile = false;
ADIOS_FILE *m_fh = nullptr; ///< ADIOS1 file handler ADIOS_FILE *m_fh = nullptr; ///< ADIOS1 file handler
// In streaming mode, Open() does not generate the variable map.
// The first BeginStep() call does that to publish the variables of the
// first step
bool m_IsBeforeFirstStep = true;
void Init(); void Init();
void DefineADIOS2Variable(IO &io, const char *name, const ADIOS_VARINFO *vi, void DefineADIOS2Variable(IO &io, const char *name, const ADIOS_VARINFO *vi,
......
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