Skip to content
Snippets Groups Projects
Commit 729df873 authored by guj's avatar guj
Browse files

added IO_ph5_adios2 for heatTransfer

parent 61fcab23
No related branches found
No related tags found
1 merge request!112added heatTransfer with adios/hdf5
...@@ -52,4 +52,25 @@ if(ADIOS_USE_MPI) ...@@ -52,4 +52,25 @@ if(ADIOS_USE_MPI)
${MPI_C_LIBRARIES} ${HDF5_C_LIBRARIES} ${MPI_C_LIBRARIES} ${HDF5_C_LIBRARIES}
) )
endif() endif()
if(ADIOS_USE_HDF5)
find_package(MPI COMPONENTS C REQUIRED)
add_executable(heatTransfer_write_a2h5
main.cpp
HeatTransfer.cpp
Settings.cpp
IO_ph5_adios2.cpp
)
target_include_directories(heatTransfer_write_a2h5
PRIVATE ${MPI_C_INCLUDE_PATH}
)
#target_link_libraries(heatTransfer_write_a2h5
# ${MPI_C_LIBRARIES}
#)
target_link_libraries(heatTransfer_write_a2h5 PUBLIC adios2)
endif()
endif() endif()
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* IO_ADIOS2.cpp
*
* Created on: Feb 2017
* Author: Norbert Podhorszki
*/
#include "IO.h"
#include <string>
#include <adios2.h>
static int rank_saved;
adios::ADIOS *ad = nullptr;
std::shared_ptr<adios::Engine> h5writer;
adios::Variable<double> *varT = nullptr;
adios::Variable<unsigned int> *varGndx = nullptr;
IO::IO(const Settings &s, MPI_Comm comm)
{
rank_saved = s.rank;
m_outputfilename = s.outputfile + ".h5";
//adios::ADIOS adios(comm, adios::Verbose::INFO, false);
ad = new adios::ADIOS(comm, adios::Verbose::INFO, false);
// Define method for engine creation
// 1. Get method def from config file or define new one
adios::Method &h5writerSettings = ad->DeclareMethod("output");
if (!h5writerSettings.IsUserDefined())
{
// if not defined by user, we can change the default settings
// BPFileWriter is the default engine
h5writerSettings.SetEngine("HDF5Writer");
// Allow an extra thread for data processing
const std::string aggregatorsParam("Aggregators=" +
std::to_string((s.nproc + 1) / 2));
h5writerSettings.SetParameters("have_metadata_file=yes",
aggregatorsParam);
}
// ad->DefineScalar<unsigned int>("gndx", true);
varGndx = &(ad->DefineVariable<unsigned int>("gndx"));
ad->DefineVariable<unsigned int>("gndy");
// define T as 2D global array
varT = &(ad->DefineArray<double>(
"T",
// Global dimensions
{s.gndx, s.gndy},
// starting offset of the local array in the global space
{s.offsx, s.offsy},
// local size, could be defined later using SetSelection()
{s.ndx, s.ndy}));
// add transform to variable
// adios::Transform tr = adios::transform::BZIP2( );
// varT.AddTransform( tr, "" );
// varT.AddTransform( tr,"accuracy=0.001" ); // for ZFP
h5writer = ad->Open(m_outputfilename, "w", comm, h5writerSettings);
if (h5writer == nullptr)
throw std::ios_base::failure("ERROR: failed to open ADIOS h5writer\n");
}
IO::~IO()
{
h5writer->Close();
//delete ad;
}
void IO::write(int step, const HeatTransfer &ht, const Settings &s,
MPI_Comm comm)
{
#if 1
/* This selection is redundant and not required, since we defined
* the selection already in DefineVariable(). It is here just as an example.
*/
// Make a selection to describe the local dimensions of the variable we
// write and its offsets in the global spaces. This could have been done in
// adios.DefineVariable()
//adios::SelectionBoundingBox sel({s.offsx, s.offsy}, {s.ndx, s.ndy});
//varT->SetSelection(sel);
/* Select the area that we want to write from the data pointer we pass to
the
writer.
Think HDF5 memspace, just not hyperslabs, only a bounding box selection.
Engine will copy this bounding box from the data pointer into the output
buffer.
Size of the bounding box should match the "space" selection which was
given
above.
Default memspace is always the full selection.
*/
//adios::SelectionBoundingBox memspace =
// adios::SelectionBoundingBox({1, 1}, {s.ndx, s.ndy});
//varT->SetMemorySelection(memspace);
h5writer->Write<double>(*varT, ht.data_noghost().data());
//h5writer->Write(*varT, ht.data_noghost().data());
h5writer->Write<unsigned int>(*varGndx, s.gndx);
h5writer->Write<unsigned int>("gndy", s.gndy);
h5writer->Advance();
#else
h5writer->Write<double>(*varT, ht.data_noghost().data());
h5writer->Advance();
#endif
}
...@@ -73,17 +73,16 @@ int main(int argc, char *argv[]) ...@@ -73,17 +73,16 @@ int main(int argc, char *argv[])
try try
{ {
// Define variable and local size // Define variable and local size
auto &ioMyInts = auto &ioMyInts = adios.DefineArray<int>("myInts", {4, 3},
adios.DefineArray<int>("myInts", {intCountDim1, intDim2}, {4, 3}, {intOffsetDim1, intOffsetDim2}, {intCountDim1, intDim2});
{intOffsetDim1, intOffsetDim2});
auto &ioMyDoubles = adios.DefineArray<double>( auto &ioMyDoubles = adios.DefineArray<double>(
"myDoubles", {doubleVCount}, {Nx}, {doubleVOffset}); "myDoubles", {Nx}, {doubleVOffset}, {doubleVCount});
auto &ioMyCFloats = adios.DefineArray<std::complex<float>>( auto &ioMyCFloats = adios.DefineArray<std::complex<float>>(
"myCFloats", {complexCount}, {3}, {complexOffset}); "myCFloats", {3}, {complexOffset}, {complexCount});
auto &ioMyCDoubles = adios.DefineArray<std::complex<double>>( auto &ioMyCDoubles = adios.DefineArray<std::complex<double>>(
"myCDoubles", {complexCount}, {3}, {complexOffset}); "myCDoubles", {3}, {complexOffset}, {complexCount});
auto &ioMyCLongDoubles = adios.DefineArray<std::complex<long double>>( auto &ioMyCLongDoubles = adios.DefineArray<std::complex<long double>>(
"myCLongDoubles", {complexCount}, {3}, {complexOffset}); "myCLongDoubles", {3}, {complexOffset}, {complexCount});
// Define method for engine creation, it is basically straight-forward // Define method for engine creation, it is basically straight-forward
// parameters // parameters
......
...@@ -162,6 +162,10 @@ void HDF5Common::Close() ...@@ -162,6 +162,10 @@ void HDF5Common::Close()
H5Fclose(m_FileId); H5Fclose(m_FileId);
m_FileId = -1; m_FileId = -1;
m_GroupId = -1; m_GroupId = -1;
H5Tclose(m_DefH5TypeComplexFloat);
H5Tclose(m_DefH5TypeComplexDouble);
H5Tclose(m_DefH5TypeComplexLongDouble);
} }
void HDF5Common::Advance() void HDF5Common::Advance()
......
...@@ -22,8 +22,8 @@ HDF5Writer::HDF5Writer(ADIOS &adios, const std::string name, ...@@ -22,8 +22,8 @@ HDF5Writer::HDF5Writer(ADIOS &adios, const std::string name,
const Method &method) const Method &method)
: Engine(adios, "HDF5Writer", name, accessMode, mpiComm, : Engine(adios, "HDF5Writer", name, accessMode, mpiComm,
method, /*debugMode, cores,*/ method, /*debugMode, cores,*/
" HDF5Writer constructor (or call to ADIOS Open).\n"), " HDF5Writer constructor (or call to ADIOS Open).\n")
m_Buffer(m_DebugMode) //m_Buffer(m_DebugMode)
{ {
Init(); Init();
} }
...@@ -256,6 +256,19 @@ void HDF5Writer::UseHDFWrite(Variable<T> &variable, const T *values, ...@@ -256,6 +256,19 @@ void HDF5Writer::UseHDFWrite(Variable<T> &variable, const T *values,
int dimSize = std::max(variable.m_Shape.size(), variable.m_Count.size()); int dimSize = std::max(variable.m_Shape.size(), variable.m_Count.size());
if (dimSize == 0) {
// scalar
hid_t filespaceID = H5Screate(H5S_SCALAR);
hid_t dsetID = H5Dcreate(m_H5File.m_GroupId, variable.m_Name.c_str(), h5Type, filespaceID,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
herr_t status = H5Dwrite(dsetID, h5Type, H5S_ALL, H5S_ALL, H5P_DEFAULT, values);
H5Sclose (filespaceID);
H5Dclose (dsetID);
return;
}
std::vector<hsize_t> dimsf, count, offset; std::vector<hsize_t> dimsf, count, offset;
for (int i = 0; i < dimSize; i++) for (int i = 0; i < dimSize; i++)
......
...@@ -91,7 +91,7 @@ public: ...@@ -91,7 +91,7 @@ public:
private: private:
///< heap capsule, contains data and metadata buffers ///< heap capsule, contains data and metadata buffers
capsule::STLVector m_Buffer; //capsule::STLVector m_Buffer;
void Init(); void Init();
......
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