| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: Apache-2.0 |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "IO.h" |
| 8 |
|
| 9 |
#include <string> |
| 10 |
|
| 11 |
#include <adios2.h> |
| 12 |
|
| 13 |
#define str_helper(X) #X |
| 14 |
#define str(X) str_helper(X) |
| 15 |
// #ifndef DEFAULT_CONFIG |
| 16 |
// #define DEFAULT_CONFIG config.xml |
| 17 |
// #endif |
| 18 |
#define DEFAULT_CONFIG mix.xml |
| 19 |
#define DEFAULT_CONFIG_STR str(DEFAULT_CONFIG) |
| 20 |
|
| 21 |
adios2::ADIOS *ad = nullptr; |
| 22 |
// std::shared_ptr<adios2::Engine> h5mixerWriter; |
| 23 |
adios2::Engine h5mixerWriter; |
| 24 |
adios2::Variable<double> varT; |
| 25 |
adios2::Variable<unsigned int> varGndx; |
| 26 |
|
| 27 |
IO::IO(const Settings &s, MPI_Comm comm) |
| 28 |
{ |
| 29 |
m_outputfilename = MakeFilename(s.outputfile, ".h5"); |
| 30 |
|
| 31 |
/*ad = new adios2::ADIOS(std::string(DEFAULT_CONFIG_STR), comm); |
| 32 |
*/ |
| 33 |
ad = new adios2::ADIOS(comm); |
| 34 |
|
| 35 |
// Define method for engine creation |
| 36 |
|
| 37 |
adios2::IO h5io = ad->DeclareIO("writer"); |
| 38 |
if (!h5io.InConfigFile()) |
| 39 |
{ |
| 40 |
// if not defined by user, we can change the default settings |
| 41 |
// BPFile is the default engine |
| 42 |
|
| 43 |
// Allow an extra thread for data processing |
| 44 |
// ISO-POSIX file is the default transport |
| 45 |
// Passing parameters to the transport |
| 46 |
h5io.SetEngine("HDFMixer"); |
| 47 |
} |
| 48 |
|
| 49 |
varGndx = h5io.DefineVariable<unsigned int>("gndx"); |
| 50 |
h5io.DefineVariable<unsigned int>("gndy"); |
| 51 |
|
| 52 |
// define T as 2D global array |
| 53 |
varT = h5io.DefineVariable<double>("T", |
| 54 |
// Global dimensions |
| 55 |
{s.gndx, s.gndy}, |
| 56 |
// starting offset of the local array in the global space |
| 57 |
{s.offsx, s.offsy}, |
| 58 |
// local size, could be defined later using SetSelection() |
| 59 |
{s.ndx, s.ndy}); |
| 60 |
|
| 61 |
// add transform to variable |
| 62 |
// adios2::Transform tr = adios2::transform::BZIP2( ); |
| 63 |
// varT.AddTransform( tr, "" ); |
| 64 |
// varT.AddTransform( tr,"accuracy=0.001" ); // for ZFP |
| 65 |
|
| 66 |
h5mixerWriter = h5io.Open(m_outputfilename, adios2::Mode::Write, comm); |
| 67 |
|
| 68 |
if (!h5mixerWriter) |
| 69 |
{ |
| 70 |
throw std::ios_base::failure("ERROR: failed to open ADIOS h5mixerWriter\n"); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
IO::~IO() |
| 75 |
{ |
| 76 |
h5mixerWriter.Close(); |
| 77 |
delete ad; |
| 78 |
} |
| 79 |
|
| 80 |
void IO::write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm comm) |
| 81 |
{ |
| 82 |
|
| 83 |
h5mixerWriter.BeginStep(); |
| 84 |
/* This selection is redundant and not required, since we defined |
| 85 |
* the selection already in DefineVariable(). It is here just as an example. |
| 86 |
*/ |
| 87 |
// Make a selection to describe the local dimensions of the variable we |
| 88 |
// write and its offsets in the global spaces. This could have been done in |
| 89 |
// adios.DefineVariable() |
| 90 |
varT.SetSelection(adios2::Box<adios2::Dims>({s.offsx, s.offsy}, {s.ndx, s.ndy})); |
| 91 |
|
| 92 |
/* Select the area that we want to write from the data pointer we pass to |
| 93 |
the |
| 94 |
writer. |
| 95 |
Think HDF5 memspace, just not hyperslabs, only a bounding box |
| 96 |
selection. Engine will copy this bounding box from the data pointer into |
| 97 |
the output buffer. Size of the bounding box should match the "space" |
| 98 |
selection which was given above. Default memspace is always the full |
| 99 |
selection. |
| 100 |
*/ |
| 101 |
// varT.SetMemorySelection(adios2::Box<adios2::Dims>({1, 1}, {s.ndx, |
| 102 |
// s.ndy})); |
| 103 |
|
| 104 |
h5mixerWriter.Put<unsigned int>(varGndx, s.gndx); |
| 105 |
h5mixerWriter.Put<unsigned int>("gndy", s.gndy); |
| 106 |
h5mixerWriter.Put<double>(varT, ht.data_noghost().data()); |
| 107 |
|
| 108 |
h5mixerWriter.EndStep(); |
| 109 |
|
| 110 |
#ifdef NEVER |
| 111 |
#if 1 |
| 112 |
|
| 113 |
/* This selection is redundant and not required, since we defined |
| 114 |
* the selection already in DefineVariable(). It is here just as an example. |
| 115 |
*/ |
| 116 |
// Make a selection to describe the local dimensions of the variable we |
| 117 |
// write and its offsets in the global spaces. This could have been done in |
| 118 |
// adios.DefineVariable() |
| 119 |
adios2::SelectionBoundingBox sel({s.offsx, s.offsy}, {s.ndx, s.ndy}); |
| 120 |
varT->SetSelection(sel); |
| 121 |
|
| 122 |
/* Select the area that we want to write from the data pointer we pass to |
| 123 |
the |
| 124 |
writer. |
| 125 |
Think HDF5 memspace, just not hyperslabs, only a bounding box selection. |
| 126 |
Engine will copy this bounding box from the data pointer into the output |
| 127 |
buffer. |
| 128 |
Size of the bounding box should match the "space" selection which was |
| 129 |
given |
| 130 |
above. |
| 131 |
Default memspace is always the full selection. |
| 132 |
*/ |
| 133 |
adios2::SelectionBoundingBox memspace = adios2::SelectionBoundingBox({1, 1}, {s.ndx, s.ndy}); |
| 134 |
varT->SetMemorySelection(memspace); |
| 135 |
|
| 136 |
h5mixerWriter->Write<unsigned int>(*varGndx, s.gndx); |
| 137 |
h5mixerWriter->Write<unsigned int>("gndy", s.gndy); |
| 138 |
h5mixerWriter->Write<double>(*varT, ht.data_noghost().data()); |
| 139 |
h5mixerWriter->Advance(); |
| 140 |
|
| 141 |
#else |
| 142 |
h5mixerWriter->Write<double>(*varT, ht.data_noghost().data()); |
| 143 |
h5mixerWriter->Advance(); |
| 144 |
#endif |
| 145 |
#endif |
| 146 |
} |