Debian Codegraph @

examples/simulations/heatTransfer/readFileOnly/PrintData.h

raw
1 /*
2 * SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #ifndef PRINTDATA_H_
8 #define PRINTDATA_H_
9
10 #include <cstdint>
11 #include <fstream>
12 #include <iomanip>
13 #include <iostream>
14 #include <string>
15
16 template <class T>
17 void printData(double *xy, T *size, T *offset, int rank, size_t steps)
18 {
19 std::ofstream myfile;
20 std::string filename = "data." + std::to_string(rank);
21 myfile.open(filename);
22 double *data = xy;
23 uint64_t nelems = size[0] * size[1];
24 for (size_t step = 0; step < steps; step++)
25 {
26 myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1]
27 << " offsets=" << offset[0] << ":" << offset[1] << " step=" << step << std::endl;
28
29 myfile << " time row columns " << offset[1] << "..." << offset[1] + size[1] - 1
30 << std::endl;
31 myfile << " ";
32 for (int j = 0; j < static_cast<int>(size[1]); j++)
33 {
34 myfile << std::setw(9) << offset[1] + j;
35 }
36 myfile << std::endl;
37 myfile << "------------------------------------------------------------"
38 "--\n";
39 for (int i = 0; i < static_cast<int>(size[0]); i++)
40 {
41 myfile << std::setw(5) << step << std::setw(5) << offset[0] + i;
42 for (int j = 0; j < static_cast<int>(size[1]); j++)
43 {
44 myfile << std::setw(9) << std::setprecision(2) << data[i * size[1] + j];
45 }
46 myfile << std::endl;
47 }
48 data += nelems;
49 }
50 myfile.close();
51 }
52
53 #endif /* PRINTDATA_H_ */