Debian Codegraph @

examples/simulations/heatTransfer/write/IO_hdf5_a.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "IO.h"
8
9 #include <fstream>
10 #include <iomanip>
11 #include <iostream>
12 #include <string>
13
14 #include <hdf5.h>
15
16 IO::IO(const Settings &s, MPI_Comm comm) : m_outputfilename{s.outputfile} {}
17
18 IO::~IO() {}
19
20 void IO::write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm comm)
21 {
22 m_outputfilename = MakeFilename(s.outputfile, ".h5", s.rank, step);
23
24 // for time measurements, let's synchronize the processes
25 MPI_Barrier(comm);
26 double time_start = MPI_Wtime();
27
28 hsize_t dims[2] = {static_cast<hsize_t>(s.ndx), static_cast<hsize_t>(s.ndy)};
29
30 hid_t space = H5Screate_simple(2, dims, NULL);
31 hid_t file = H5Fcreate(m_outputfilename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
32 hid_t dset =
33 H5Dcreate(file, "T", H5T_NATIVE_DOUBLE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
34
35 H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, ht.data_noghost().data());
36
37 H5Dclose(dset);
38 H5Sclose(space);
39 H5Fclose(file);
40
41 MPI_Barrier(comm);
42 double total_time = MPI_Wtime() - time_start;
43 uint64_t adios_totalsize = 2 * sizeof(int) + 2 * s.ndx * s.ndy * sizeof(double);
44 uint64_t sizeMB = adios_totalsize * s.nproc / 1024 / 1024 / 1024; // size in MB
45 double mbs = static_cast<double>(sizeMB) / total_time;
46 if (s.rank == 0)
47 std::cout << "Step " << step << ": " << m_outputfilename << " " << sizeMB << " "
48 << total_time << "" << mbs << std::endl;
49 }