Skip to content
Snippets Groups Projects
Commit 14de1035 authored by Podhorszki, Norbert's avatar Podhorszki, Norbert
Browse files

templatize PrintData() so that it can work with all types

parent 6cefb9c9
No related branches found
No related tags found
1 merge request!227templatize PrintData() so that it can work with all types
......@@ -10,7 +10,7 @@ if(ADIOS2_HAVE_MPI)
find_package(MPI COMPONENTS C REQUIRED)
find_package(ADIOS1 REQUIRED)
add_executable(heatTransfer_read_adios2 heatRead_adios2.cpp PrintData.cpp)
add_executable(heatTransfer_read_adios2 heatRead_adios2.cpp PrintData.h)
target_include_directories(heatTransfer_read_adios2
PRIVATE ${MPI_C_INCLUDE_PATH}
)
......@@ -18,7 +18,7 @@ if(ADIOS2_HAVE_MPI)
adios2 ${MPI_C_LIBRARIES}
)
add_executable(heatTransfer_read_adios1 heatRead_adios1.cpp PrintData.cpp)
add_executable(heatTransfer_read_adios1 heatRead_adios1.cpp PrintData.h)
target_include_directories(heatTransfer_read_adios1
PRIVATE ${MPI_C_INCLUDE_PATH}
)
......
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* PrintData.cpp
*
* Created on: Apr 2017
* Author: Norbert Podhorszki
*/
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include "PrintData.h"
void printData(double *xy, size_t *size, size_t *offset, int rank, int steps)
{
std::ofstream myfile;
std::string filename = "data." + std::to_string(rank);
myfile.open(filename);
double *data = xy;
uint64_t nelems = size[0] * size[1];
for (int step = 0; step < steps; step++)
{
myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1]
<< " offsets=" << offset[0] << ":" << offset[1]
<< " step=" << step << std::endl;
myfile << " time row columns " << offset[1] << "..."
<< offset[1] + size[1] - 1 << std::endl;
myfile << " ";
for (int j = 0; j < size[1]; j++)
{
myfile << std::setw(9) << offset[1] + j;
}
myfile << std::endl;
myfile << "------------------------------------------------------------"
"--\n";
for (int i = 0; i < size[0]; i++)
{
myfile << std::setw(5) << step << std::setw(5) << offset[0] + i;
for (int j = 0; j < size[1]; j++)
{
myfile << std::setw(9) << std::setprecision(2)
<< data[i * size[1] + j];
}
myfile << std::endl;
}
data += nelems;
}
myfile.close();
}
void printData(double *xy, uint64_t *size, uint64_t *offset, int rank,
int steps)
{
std::ofstream myfile;
std::string filename = "data." + std::to_string(rank);
myfile.open(filename);
double *data = xy;
uint64_t nelems = size[0] * size[1];
for (int step = 0; step < steps; step++)
{
myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1]
<< " offsets=" << offset[0] << ":" << offset[1]
<< " step=" << step << std::endl;
myfile << " time row columns " << offset[1] << "..."
<< offset[1] + size[1] - 1 << std::endl;
myfile << " ";
for (int j = 0; j < size[1]; j++)
{
myfile << std::setw(9) << offset[1] + j;
}
myfile << std::endl;
myfile << "------------------------------------------------------------"
"--\n";
for (int i = 0; i < size[0]; i++)
{
myfile << std::setw(5) << step << std::setw(5) << offset[0] + i;
for (int j = 0; j < size[1]; j++)
{
myfile << std::setw(9) << std::setprecision(2)
<< data[i * size[1] + j];
}
myfile << std::endl;
}
data += nelems;
}
myfile.close();
}
......@@ -12,9 +12,48 @@
#define PRINTDATA_H_
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
void printData(double *xy, size_t *size, size_t *offset, int rank, int steps);
void printData(double *xy, uint64_t *size, uint64_t *offset, int rank,
int steps);
template <class T>
void printData(double *xy, T *size, T *offset, int rank, int steps)
{
std::ofstream myfile;
std::string filename = "data." + std::to_string(rank);
myfile.open(filename);
double *data = xy;
uint64_t nelems = size[0] * size[1];
for (int step = 0; step < steps; step++)
{
myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1]
<< " offsets=" << offset[0] << ":" << offset[1]
<< " step=" << step << std::endl;
myfile << " time row columns " << offset[1] << "..."
<< offset[1] + size[1] - 1 << std::endl;
myfile << " ";
for (int j = 0; j < size[1]; j++)
{
myfile << std::setw(9) << offset[1] + j;
}
myfile << std::endl;
myfile << "------------------------------------------------------------"
"--\n";
for (int i = 0; i < size[0]; i++)
{
myfile << std::setw(5) << step << std::setw(5) << offset[0] + i;
for (int j = 0; j < size[1]; j++)
{
myfile << std::setw(9) << std::setprecision(2)
<< data[i * size[1] + j];
}
myfile << std::endl;
}
data += nelems;
}
myfile.close();
}
#endif /* PRINTDATA_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment