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
* globalArrayXML.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("globalArrayXML.xml", comm, true);
Podhorszki, Norbert
committed
adios::ADIOS_OUTPUT &ckptfile =
adios.Open("globalArray.bp", comm, "a", "POSIX");
Podhorszki, Norbert
committed
adios::ADIOS_OUTPUT ckptfile("globalArray.bp", subcomm, "a", "POSIX");
// adios::ADIOS_OUTPUT *ckptfile = adios.Open( "globalArray.bp", "POSIX");
Podhorszki, Norbert
committed
// Get Monitor info
std::ofstream logStream("info_" + std::to_string(rank) + ".log");
adios.MonitorGroups(logStream);
Podhorszki, Norbert
committed
for (int it = 1; it <= 13; it++)
{
Podhorszki, Norbert
committed
for (int i = 0; i < NX; i++)
{
t[i] = it * 100.0 + rank * NX + i;
p[i] = it * 1000.0 + rank * NX + i;
}
Podhorszki, Norbert
committed
// if (it==1)
// adios.Open("arrays", "globalArray.bp", "w");
// else
// adios.Open("arrays", "globalArray.bp", "a");
Podhorszki, Norbert
committed
// uint64_t adios_groupsize, adios_totalsize;
// adios_groupsize = 4 + 4 + 4 + 2*NX*sizeof(double);
// adios_totalsize = adios.GroupSize("arrays", adios_groupsize);
Podhorszki, Norbert
committed
ckptfile.Write("NX", &NX);
ckptfile.Write("pressure", &p);
// 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);
Podhorszki, Norbert
committed
// adios.Close ("arrays");
ckptfile.PerformIO();
MPI_Barrier(comm);
if (rank == 0)
printf("Timestep %d written\n", it);
Podhorszki, Norbert
committed
}
MPI_Barrier(comm);
ckptfile.Close();
// 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;