Newer
Older
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
137
138
139
140
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* TestBPWriteProfilingJSON.cpp
*
* Created on: Jul 18, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include <cstdint>
#include <cstring>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <adios2.h>
#include <gtest/gtest.h>
#include <json.hpp> //This fails to be included
#include "../SmallTestData.h"
using json = nlohmann::json;
class BPWriteProfilingJSONTest : public ::testing::Test
{
public:
BPWriteProfilingJSONTest() = default;
SmallTestData m_TestData;
};
//******************************************************************************
// 1D 1x8 test data
//******************************************************************************
// ADIOS2 write, native ADIOS1 read
TEST_F(BPWriteProfilingJSONTest, ADIOS2BPWriteProfilingJSON)
{
std::string fname = "ADIOS2BPWriteProfilingJSON.bp";
// Write test data and profiling.json using ADIOS2
{
adios2::ADIOS adios(true);
adios2::IO &io = adios.DeclareIO("TestIO");
// Declare 1D variables
{
auto &var_i8 =
io.DefineVariable<char>("i8", {}, {}, adios2::Dims{8});
auto &var_i16 =
io.DefineVariable<short>("i16", {}, {}, adios2::Dims{8});
auto &var_i32 =
io.DefineVariable<int>("i32", {}, {}, adios2::Dims{8});
auto &var_i64 =
io.DefineVariable<long>("i64", {}, {}, adios2::Dims{8});
auto &var_u8 =
io.DefineVariable<unsigned char>("u8", {}, {}, adios2::Dims{8});
auto &var_u16 = io.DefineVariable<unsigned short>("u16", {}, {},
adios2::Dims{8});
auto &var_u32 =
io.DefineVariable<unsigned int>("u32", {}, {}, adios2::Dims{8});
auto &var_u64 = io.DefineVariable<unsigned long>("u64", {}, {},
adios2::Dims{8});
auto &var_r32 =
io.DefineVariable<float>("r32", {}, {}, adios2::Dims{8});
auto &var_r64 =
io.DefineVariable<double>("r64", {}, {}, adios2::Dims{8});
}
// Create the BP Engine
io.SetEngine("BPFileWriter");
io.SetParameters({{"Threads", "2"}});
io.AddTransport("File", {{"Library", "POSIX"}});
auto engine = io.Open(fname, adios2::OpenMode::Write);
ASSERT_NE(engine.get(), nullptr);
for (size_t step = 0; step < 3; ++step)
{
// Retrieve the variables that previously went out of scope
auto &var_i8 = io.GetVariable<char>("i8");
auto &var_i16 = io.GetVariable<short>("i16");
auto &var_i32 = io.GetVariable<int>("i32");
auto &var_i64 = io.GetVariable<long>("i64");
auto &var_u8 = io.GetVariable<unsigned char>("u8");
auto &var_u16 = io.GetVariable<unsigned short>("u16");
auto &var_u32 = io.GetVariable<unsigned int>("u32");
auto &var_u64 = io.GetVariable<unsigned long>("u64");
auto &var_r32 = io.GetVariable<float>("r32");
auto &var_r64 = io.GetVariable<double>("r64");
// Write each one
engine->Write(var_i8, m_TestData.I8.data() + step);
engine->Write(var_i16, m_TestData.I16.data() + step);
engine->Write(var_i32, m_TestData.I32.data() + step);
engine->Write(var_i64, m_TestData.I64.data() + step);
engine->Write(var_u8, m_TestData.U8.data() + step);
engine->Write(var_u16, m_TestData.U16.data() + step);
engine->Write(var_u32, m_TestData.U32.data() + step);
engine->Write(var_u64, m_TestData.U64.data() + step);
engine->Write(var_r32, m_TestData.R32.data() + step);
engine->Write(var_r64, m_TestData.R64.data() + step);
// Advance to the next time step
engine->Advance();
}
// Close the file
engine->Close();
}
// open json file, parse it to a json structure, and verify a few things
{
std::ifstream profilingJSONFile(fname + ".dir/profiling.json");
std::stringstream buffer;
buffer << profilingJSONFile.rdbuf();
const json profilingJSON = json::parse(buffer);
// check rank is zero
const int rank = profilingJSON[0].value("rank", -1);
ASSERT_EQ(rank, 0);
// check threads
const int threads = profilingJSON[0].value("threads", 0);
ASSERT_EQ(threads, 2);
// check bytes
const unsigned long int bytes = profilingJSON[0].value("bytes", 0UL);
ASSERT_EQ(bytes, 6536);
const auto transportType =
profilingJSON[0]["transport_0"].value("type", "0");
ASSERT_EQ(transportType, "File_POSIX");
}
}