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
/*
* IO_hdf5_a.cpp
*
* Write output with sequential HDF5, one file per process, one separate set per timestep
*
* Created on: Feb 2017
* Author: Norbert Podhorszki
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include "IO.h"
#include "hdf5.h"
IO::IO( const Settings& s, MPI_Comm comm )
:m_outputfilename{s.outputfile}
{
}
IO::~IO()
{
}
void IO::write( int step, const HeatTransfer& ht, const Settings& s, MPI_Comm comm)
{
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;
}