From 69f1483006a1d736be071ba4d452d05e1f8ff208 Mon Sep 17 00:00:00 2001 From: Hannes Signer Date: Sat, 5 Aug 2023 16:20:23 +0200 Subject: [PATCH] add omp header and time measurement --- examples/reference-FTCS_2D_closed.cpp | 13 +++++-------- src/FTCS.cpp | 7 +++++++ src/Simulation.cpp | 5 ++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/examples/reference-FTCS_2D_closed.cpp b/examples/reference-FTCS_2D_closed.cpp index 2323531..d755e15 100644 --- a/examples/reference-FTCS_2D_closed.cpp +++ b/examples/reference-FTCS_2D_closed.cpp @@ -5,8 +5,8 @@ using namespace std; int main(int argc, char *argv[]) { - int row = 11; - int col = 11; + int row = 50; + int col = 50; int domain_row = 10; int domain_col = 10; @@ -45,14 +45,11 @@ int main(int argc, char *argv[]) { // Simulation Simulation sim = Simulation(grid, bc, FTCS_APPROACH); sim.setTimestep(0.001); - sim.setIterations(7000); - sim.setOutputCSV(CSV_OUTPUT_ON); - sim.setOutputConsole(CONSOLE_OUTPUT_ON); + sim.setIterations(100); + sim.setOutputCSV(CSV_OUTPUT_OFF); + sim.setOutputConsole(CONSOLE_OUTPUT_OFF); // RUN sim.run(); - - cout << grid.getConcentrations() << endl; - } \ No newline at end of file diff --git a/src/FTCS.cpp b/src/FTCS.cpp index afd7404..6de288e 100644 --- a/src/FTCS.cpp +++ b/src/FTCS.cpp @@ -9,6 +9,7 @@ #include #include #include +#include using namespace std; @@ -276,6 +277,8 @@ void FTCS_2D(Grid &grid, Boundary &bc, double ×tep) { // inner cells // these are independent of the boundary condition type + omp_set_num_threads(10); + #pragma omp parallel for for (int row = 1; row < rowMax-1; row++) { for (int col = 1; col < colMax-1; col++) { concentrations_t1(row, col) = grid.getConcentrations()(row, col) @@ -295,6 +298,7 @@ void FTCS_2D(Grid &grid, Boundary &bc, double ×tep) { // left without corners / looping over rows // hold column constant at index 0 int col = 0; + #pragma omp parallel for for (int row = 1; row < rowMax-1; row++) { concentrations_t1(row, col) = grid.getConcentrations()(row,col) + timestep / (deltaCol*deltaCol) @@ -311,6 +315,7 @@ void FTCS_2D(Grid &grid, Boundary &bc, double ×tep) { // right without corners / looping over rows // hold column constant at max index col = colMax-1; + #pragma omp parallel for for (int row = 1; row < rowMax-1; row++) { concentrations_t1(row,col) = grid.getConcentrations()(row,col) + timestep / (deltaCol*deltaCol) @@ -328,6 +333,7 @@ void FTCS_2D(Grid &grid, Boundary &bc, double ×tep) { // top without corners / looping over columns // hold row constant at index 0 int row = 0; + #pragma omp parallel for for (int col=1; col 0) { printConcentrationsConsole(); @@ -165,6 +165,9 @@ void Simulation::run() { FTCS(grid, bc, timestep); } + auto end = std::chrono::high_resolution_clock::now(); + auto milliseconds = std::chrono::duration_cast(end - begin); + std::cout << milliseconds.count() << endl; } else if (approach == BTCS_APPROACH) {