diff --git a/examples/heatTransfer/read/CMakeLists.txt b/examples/heatTransfer/read/CMakeLists.txt index 5691e81b41f61d55ba77f41243a350d6bc7c4f47..d1b7e2853fe0dee152b0773f4ede495d359538e4 100644 --- a/examples/heatTransfer/read/CMakeLists.txt +++ b/examples/heatTransfer/read/CMakeLists.txt @@ -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} ) diff --git a/examples/heatTransfer/read/PrintData.cpp b/examples/heatTransfer/read/PrintData.cpp deleted file mode 100644 index edbc6688fba93569b4d3eb9b74190735d9b21be7..0000000000000000000000000000000000000000 --- a/examples/heatTransfer/read/PrintData.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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(); -} diff --git a/examples/heatTransfer/read/PrintData.h b/examples/heatTransfer/read/PrintData.h index 13e1e527ce1a27036d0f65c540be48a459b3b3eb..f18948af619cae90f15eabdc0073d46612e37577 100644 --- a/examples/heatTransfer/read/PrintData.h +++ b/examples/heatTransfer/read/PrintData.h @@ -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_ */