-
Notifications
You must be signed in to change notification settings - Fork 16
/
hello-world.cpp
78 lines (67 loc) · 1.85 KB
/
hello-world.cpp
1
2
3
4
5
6
7
8
9
10
11
12
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
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* hello-world.cpp : adios2 low-level API example to write and read a
* std::string Variable with a greeting
*
* Created on: Nov 14, 2019
* Author: William F Godoy [email protected]
*/
#include <iostream>
#include <stdexcept>
#include <adios2.h>
#if ADIOS2_USE_MPI
#include <mpi.h>
#endif
void writer(adios2::ADIOS &adios, const std::string &greeting)
{
adios2::IO io = adios.DeclareIO("hello-world-writer");
adios2::Variable<std::string> varGreeting =
io.DefineVariable<std::string>("Greeting");
adios2::Engine writer = io.Open("hello-world-cpp.bp", adios2::Mode::Write);
writer.Put(varGreeting, greeting);
writer.Close();
}
std::string reader(adios2::ADIOS &adios)
{
adios2::IO io = adios.DeclareIO("hello-world-reader");
adios2::Engine reader = io.Open("hello-world-cpp.bp", adios2::Mode::Read);
reader.BeginStep();
adios2::Variable<std::string> varGreeting =
io.InquireVariable<std::string>("Greeting");
std::string greeting;
reader.Get(varGreeting, greeting);
reader.EndStep();
reader.Close();
return greeting;
}
int main(int argc, char *argv[])
{
#if ADIOS2_USE_MPI
MPI_Init(&argc, &argv);
#endif
try
{
#if ADIOS2_USE_MPI
adios2::ADIOS adios(MPI_COMM_WORLD);
#else
adios2::ADIOS adios;
#endif
const std::string greeting = "Hello World from ADIOS2";
writer(adios, greeting);
const std::string message = reader(adios);
std::cout << message << "\n";
}
catch (std::exception &e)
{
std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n";
#if ADIOS2_USE_MPI
MPI_Abort(MPI_COMM_WORLD, -1);
#endif
}
#if ADIOS2_USE_MPI
MPI_Finalize();
#endif
return 0;
}