Newer
Older
/*
* HDF5Writer.cpp
*
* Created on: March 20, 2017
* Author: Junmin
*/
#include <iostream>
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
const bool adiosDebug = true;
adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::INFO, adiosDebug);
const std::size_t intDim1 = 4;
const std::size_t intDim2 = 3;
std::vector<int> myInts = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
const std::size_t Nx = myDoubles.size();
std::vector<std::complex<float>> myCFloats;
const std::size_t ComplexDataSize = 3;
myCFloats.reserve(ComplexDataSize);
myCFloats.emplace_back(1, 3);
myCFloats.emplace_back(2, 2);
myCFloats.emplace_back(3, 1);
myCDoubles.reserve(ComplexDataSize);
myCDoubles.emplace_back(1.1, -3.3);
myCDoubles.emplace_back(2.1, -2.2);
myCDoubles.emplace_back(3.1, -1.1);
myCLongDoubles.reserve(ComplexDataSize);
myCLongDoubles.emplace_back(1.11, -3.33);
myCLongDoubles.emplace_back(2.11, -2.22);
myCLongDoubles.emplace_back(3.11, -1.11);
std::size_t doubleVCount = Nx / size;
std::size_t complexCount = ComplexDataSize / size;
std::size_t intCountDim1 = intDim1 / size;
std::size_t intOffsetDim1 = rank * intCountDim1;
std::size_t intOffsetDim2 = 0;
doubleVCount = Nx - rank * (Nx / size);
complexCount = ComplexDataSize - rank * (ComplexDataSize / size);
intCountDim1 = intDim1 - rank * (intDim1 / size);
}
std::cout << " rank=" << rank << " of " << size
<< ", dim1 count: " << intCountDim1
<< ", offset: " << intOffsetDim1 << std::endl;
std::cout << " intOffsetDim2=" << intOffsetDim2 << " " << intDim2
<< std::endl;
// Define variable and local size
auto &ioMyInts =
adios.DefineVariable<int>("myInts", {intCountDim1, intDim2}, {4, 3},
{intOffsetDim1, intOffsetDim2});
auto &ioMyDoubles = adios.DefineVariable<double>(
"myDoubles", {doubleVCount}, {Nx}, {doubleVOffset});
auto &ioMyCFloats = adios.DefineVariable<std::complex<float>>(
"myCFloats", {complexCount}, {3}, {complexOffset});
auto &ioMyCDoubles = adios.DefineVariable<std::complex<double>>(
"myCDoubles", {complexCount}, {3}, {complexOffset});
auto &ioMyCLongDoubles =
adios.DefineVariable<std::complex<long double>>(
"myCLongDoubles", {complexCount}, {3}, {complexOffset});
// Define method for engine creation, it is basically straight-forward
// parameters
adios::Method &HDF5Settings = adios.DeclareMethod("hdf5");
HDF5Settings.SetEngine("HDF5Writer");
HDF5Settings.SetParameters("chunck=yes", "collectiveIO=yes");
// HDF5Settings.AddTransport( "Mdtm", "localIP=128.0.0.0.1",
// "remoteIP=128.0.0.0.2", "tolerances=1,2,3" );
// Create engine smart pointer to HDF5 Engine due to polymorphism,
// Open returns a smart pointer to Engine containing the Derived class
// HDF5
auto HDF5Writer = adios.Open("test.h5", "w", HDF5Settings);
if (HDF5Writer == nullptr)
throw std::ios_base::failure(
"ERROR: failed to create HDF5 I/O engine at Open\n");
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
int ts = 0;
int totalts = 2;
while (true)
{
if (rank == 0)
{
std::cout << " total timesteps: " << totalts << " curr: " << ts
<< " th" << std::endl;
}
HDF5Writer->Write(ioMyDoubles,
myDoubles.data() +
doubleVOffset); // Base class Engine
// own the Write<T>
// that will call
// overloaded Write
// from Derived
HDF5Writer->Write(ioMyInts,
myInts.data() + (intOffsetDim1 * intDim2));
HDF5Writer->Write(ioMyCFloats, myCFloats.data() + complexOffset);
HDF5Writer->Write(ioMyCDoubles, myCDoubles.data() + complexOffset);
HDF5Writer->Write(ioMyCLongDoubles,
myCLongDoubles.data() + complexOffset);
ts++;
if (ts >= totalts)
{
break;
}
HDF5Writer->Advance();
}
HDF5Writer->Close();
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// now read out:
/*
HDF5Settings.SetEngine("HDF5Reader");
std::cout<<"... Testing a copy of test.h5, [test1.h5] , b/c engine does
not decrease name count !! "<<std::endl;
auto HDF5Reader = adios.Open("test1.h5", "r", HDF5Settings);
//int findts = HDF5Reader->getNumTimeSteps();
//HDF5Reader->InquireVariableDouble("wrongMyDoubles", true);
HDF5Reader->InquireVariableDouble(ioMyDoubles.m_Name, true);
*/
/*
adios::HDF5Reader myReader(adios, "test.h5", "r",
MPI_COMM_WORLD, HDF5Settings);
double values[15];
#ifndef NEVER
ts = 0;
while (ts < totalts) {
myReader.ReadMe(ioMyDoubles, values, H5T_NATIVE_DOUBLE);
myReader.Advance();
ts++;
}
#else
myReader.ReadMe(ioMyDoubles, values, H5T_NATIVE_DOUBLE);
#endif
*/
{
std::cout << "Invalid argument exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
}
{
std::cout << "System exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
}
{
std::cout << "Exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
}