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>
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
try
{
// ADIOS manager object creation. MPI must be initialized
adios::ADIOS adios("globalArrayNoXML.xml", comm, true);
Podhorszki, Norbert
committed
// 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
Podhorszki, Norbert
committed
// Define Group and its variables
// The group's transport can be defined at runtime in the input XML file
adios.CreateGroup("arrays");
Podhorszki, Norbert
committed
// 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);
Podhorszki, Norbert
committed
adios.CreateVariable("arrays", "NX", "int"); // scalar variable
adios.CreateVariable("arrays", "size", "int");
adios.CreateVariable("arrays", "size", "rank");
Podhorszki, Norbert
committed
// define a 2D array with 1D decomposition
adios.CreateVariable("arrays", "temperature", "double", "1,NX", "NONE",
"size,NX", "rank,0");
Podhorszki, Norbert
committed
// // set a variable-level transformation for this variable
// adios.SetVariableTransform ("arrays", "temperature", "none");
Podhorszki, Norbert
committed
adios.CreateVariable("arrays", "pressure", "std::vector<double>", "1,NX",
"size,NX", "rank,0");
Podhorszki, Norbert
committed
// set a group-level transport
adios.SetTransport("arrays", "time-aggregate"); // no options passed here
Podhorszki, Norbert
committed
// Get Monitor info
std::ofstream logStream("info_" + std::to_string(rank) + ".log");
adios.MonitorGroups(logStream);
adios.Open("arrays", "globalArray.bp", "w", 100000000);
Podhorszki, Norbert
committed
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);
Podhorszki, Norbert
committed
}
adios.Close("arrays");
MPI_Barrier(comm);
// need barrier before we destroy the ADIOS object here automatically
if (rank == 0)
printf("Finalize adios\n");
}
catch (std::exception &e) // need to think carefully how to handle C++
// exceptions with MPI to avoid deadlocking
{
if (rank == 0)
Podhorszki, Norbert
committed
{
Podhorszki, Norbert
committed
}
Podhorszki, Norbert
committed
if (rank == 0)
printf("Finalize MPI\n");
MPI_Finalize();
return 0;