Newer
Older
/*
* helloADIOSNoXML_OOP.cpp
*
* Created on: Jan 9, 2017
* Author: wfg
*/
#include <iostream>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
int main(int argc, char *argv[])
{
const bool adiosDebug = true;
adios::ADIOS adios(adiosDebug);
// Application variable
std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const std::size_t Nx = myDoubles.size();
const std::size_t rows = 3;
const std::size_t columns = 3;
std::vector<float> myMatrix = {1, 2, 3, 4, 5, 6, 7, 8, 9};
std::vector<float> myMatrix2 = {-1, -2, -3, -4, -5, -6, -7, -8, -9};
try
{
// Define variable and local size
adios::Variable<double> &ioMyDoubles =
adios.DefineVariable<double>("myDoubles", adios::Dims{Nx});
adios::Variable<float> &ioMyMatrix =
adios.DefineVariable<float>("myMatrix", adios::Dims{rows, columns});
adios::Variable<float> &ioMyMatrix2 =
adios.DefineVariable<float>("myMatrix2", adios::Dims{rows, columns});
adios::Variable<float> &ioMyMatrix3 =
adios.DefineVariable<float>("myMatrix3", adios::Dims{rows, columns});
// Define method for engine creation, it is basically straight-forward
// parameters
adios::Method &bpWriterSettings =
adios.DeclareMethod("SinglePOSIXFile"); // default method type is Writer
bpWriterSettings.SetParameters("profile_units=mus");
bpWriterSettings.AddTransport("File", "have_metadata_file=yes",
"profile_units=mus");
// Create engine smart pointer due to polymorphism,
// Open returns a smart pointer to Engine containing the Derived class
// Writer
auto bpFileWriter = adios.Open("myDoubles_nompi.bp", "w", bpWriterSettings,
adios::IOMode::COLLECTIVE);
if (bpFileWriter == nullptr)
throw std::ios_base::failure("ERROR: couldn't create bpWriter at Open\n");
bpFileWriter->Write<double>(
ioMyDoubles, myDoubles.data()); // Base class Engine own the Write<T>
// that will call overloaded Write from
// Derived
bpFileWriter->Write<float>(ioMyMatrix, myMatrix.data()); // 2d Example
bpFileWriter->Write<float>(ioMyMatrix2, myMatrix2.data()); // 2d Example
bpFileWriter->Write<float>(ioMyMatrix3, myMatrix2.data()); // 2d Example
bpFileWriter->Close();
//
}
catch (std::invalid_argument &e)
{
std::cout << "Invalid argument exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
catch (std::ios_base::failure &e)
{
std::cout << "System exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
catch (std::exception &e)
{
std::cout << "Exception, STOPPING PROGRAM\n";
std::cout << e.what() << "\n";
}
return 0;