Newer
Older
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Write output with sequential HDF5, one file per process, one separate set per
* timestep
*
* Created on: Feb 2017
* Author: Norbert Podhorszki
*/
#include <fstream>
#include <iomanip>
#include <iostream>
#include "adios2/IO.h"
#include "adios2/hdf5.h"
IO::IO(const Settings &s, MPI_Comm comm) : m_outputfilename{s.outputfile} {}
void IO::write(int step, const HeatTransfer &ht, const Settings &s,
MPI_Comm comm)
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
std::string rs = std::to_string(s.rank);
std::string ts = std::to_string(step);
std::string fname = s.outputfile + "." + rs + "." + ts + ".h5";
// for time measurements, let's synchronize the processes
MPI_Barrier(comm);
double time_start = MPI_Wtime();
hsize_t dims[2] = {static_cast<hsize_t>(s.ndx),
static_cast<hsize_t>(s.ndy)};
hid_t space = H5Screate_simple(2, dims, NULL);
hid_t file =
H5Fcreate(fname.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
hid_t dset = H5Dcreate(file, "T", H5T_NATIVE_DOUBLE, space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,
ht.data_noghost().data());
H5Dclose(dset);
H5Sclose(space);
H5Fclose(file);
MPI_Barrier(comm);
double total_time = MPI_Wtime() - time_start;
uint64_t adios_totalsize =
2 * sizeof(int) + 2 * s.ndx * s.ndy * sizeof(double);
uint64_t sizeMB =
adios_totalsize * s.nproc / 1024 / 1024 / 1024; // size in MB
uint64_t mbs = sizeMB / total_time;
if (s.rank == 0)
std::cout << "Step " << step << ": " << m_outputfilename << " "
<< sizeMB << " " << total_time << "" << mbs << std::endl;