"Framework/API/git@code.ornl.gov:mantidproject/mantid.git" did not exist on "4c87805dfa0c133aa5d751c09ec3f8ca831b4489"
Newer
Older
Podhorszki, Norbert
committed
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
Podhorszki, Norbert
committed
* globalArrayNoXML.cpp
*
* Created on: Oct 31, 2016
* Author: pnorbert
*/
#include <fstream>
#include <iostream>
#include <mpi.h>
#include <stdexcept>
Podhorszki, Norbert
committed
#include <string>
#include <vector>
#include "adios2/../../include/ADIOS.h"
Podhorszki, Norbert
committed
Podhorszki, Norbert
committed
{
int rank, size;
const int NX = 10;
double t[NX];
std::vector<double> p(NX);
MPI_Comm comm = MPI_COMM_WORLD;
Podhorszki, Norbert
committed
MPI_Init(&argc, &argv);
MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &size);
Podhorszki, Norbert
committed
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
// ADIOS manager object creation. MPI must be initialized
adios::ADIOS adios("globalArrayNoXML.xml", comm, true);
// set a maximum buffersize that ADIOS can use (for one group).
// multiple groups may use each such buffersize if they are overlapped
// or
// use time-aggregation or use zero-copy staging
// Define Group and its variables
// The group's transport can be defined at runtime in the input XML file
adios.CreateGroup("arrays");
// Set the maximum buffersize for this group. This must happen before
// defining a zero copy variable, which will cause the group's internal
// buffer
// allocated (during the variable definition call)
// adios.SetMaxBuffersize ("arrays", 10000000);
adios.CreateVariable("arrays", "NX", "int"); // scalar variable
adios.CreateVariable("arrays", "size", "int");
adios.CreateVariable("arrays", "size", "rank");
// define a 2D array with 1D decomposition
adios.CreateVariable("arrays", "temperature", "double", "1,NX", "NONE",
"size,NX", "rank,0");
// // set a variable-level transformation for this variable
// adios.SetVariableTransform ("arrays", "temperature", "none");
adios.CreateVariable("arrays", "pressure", "std::vector<double>",
"1,NX", "size,NX", "rank,0");
// set a group-level transport
adios.SetTransport("arrays",
"time-aggregate"); // no options passed here
// Get Monitor info
std::ofstream logStream("info_" + std::to_string(rank) + ".log");
adios.MonitorGroups(logStream);
adios.Open("arrays", "globalArray.bp", "w", 100000000);
for (int it = 1; it <= 13; it++)
{
for (int i = 0; i < NX; i++)
{
t[i] = it * 100.0 + rank * NX + i;
p[i] = it * 1000.0 + rank * NX + i;
}
// if (it==1)
//
// else
// adios.Open("arrays", "globalArray.bp", "a",
// 100000000 );
// uint64_t adios_groupsize, adios_totalsize;
// adios_groupsize = 4 + 4 + 4 + 2*NX*sizeof(double);
// adios_totalsize = adios.GroupSize("arrays", adios_groupsize);
adios.Write("arrays", "NX", &NX);
adios.Write("arrays", "size", &size);
adios.Write("arrays", "rank", &rank);
adios.Write("arrays", "temperature", t);
adios.Write("arrays", "pressure", &p);
MPI_Barrier(comm);
if (rank == 0)
printf("Timestep %d written\n", it);
}
adios.Close("arrays");
MPI_Barrier(comm);
// need barrier before we destroy the ADIOS object here automatically
if (rank == 0)
printf("Finalize adios\n");
Podhorszki, Norbert
committed
}
catch (std::exception &e) // need to think carefully how to handle C++
// exceptions with MPI to avoid deadlocking
Podhorszki, Norbert
committed
{
if (rank == 0)
{
std::cout << e.what() << "\n";
}
Podhorszki, Norbert
committed
}
if (rank == 0)
printf("Finalize MPI\n");
MPI_Finalize();
return 0;