Commit 5e808db6 authored by Alexandru Dura's avatar Alexandru Dura

Add region timers

parent febd5361
......@@ -2,6 +2,7 @@
#include "Field.h"
#include "Util.h"
#include "Problem.h"
#include "Timer.h"
#include <cmath>
#include <cstddef>
#include <cassert>
......@@ -155,9 +156,14 @@ int main(int argc, char **argv) {
double startTime = MPI_Wtime();
unsigned nOMPThreads;
double haloExchangeTime = 0;
double calcTime = 0;
double totalTime = 0;
#pragma omp parallel default(none) \
shared(p, restartFile, pauseFile, rank, config, nsize, nOMPThreads)
shared(p, restartFile, pauseFile, rank, config, nsize, nOMPThreads, haloExchangeTime, calcTime, totalTime)
{
ParallelRegionTimer totalTimer(totalTime);
#ifdef _OPENMP
nOMPThreads = omp_get_num_threads();
#else
......@@ -168,7 +174,7 @@ int main(int argc, char **argv) {
// close to the core that performs the computation.
p.initialize();
#pragma omp single
#pragma omp master
if (restartFile) {
// read in the data, if requested
readData(rank, p, restartFile);
......@@ -178,21 +184,27 @@ int main(int argc, char **argv) {
for (int i = 0; i < config.maxiter; ++i) {
// Let a single thread do the halo exchange. There is an implicit barrier
// at the end of the single section, so this means that all the threads
// wait until the halos are echanged before proceeding.
#pragma omp single
exchangeHalos(rank, nsize, p);
// step
p.step(config.cx, config.cy);
// wait until the halos are exchanged before proceeding.
#pragma omp master
{
RegionTimer haloExchangeTimer(haloExchangeTime);
exchangeHalos(rank, nsize, p);
}
{
ParallelRegionTimer calcTimer(calcTime);
// step
p.step(config.cx, config.cy);
}
}
#pragma omp single
#pragma omp master
if (pauseFile) {
// Write the problem out, for later restart
writeData(rank, p, pauseFile);
}
} // end of pramga omp parallel
double totalTime = MPI_Wtime() - startTime;
// Compute the global min and max
double localMin, localMax;
......@@ -249,7 +261,7 @@ int main(int argc, char **argv) {
if (rank == 0) {
double resNorm = std::sqrt(gatherResNorm2);
// printf("Norm of the residual: %f\n", std::sqrt(gatherResNorm2));
printf("%d,%d,%f,%f\n", nsize, nOMPThreads, totalTime, resNorm);
printf("%d,%d,%f,%f,%f,%f\n", nsize, nOMPThreads, totalTime, calcTime, haloExchangeTime, resNorm);
}
MPI_Finalize();
......
#pragma once
#include <mpi.h>
class RegionTimer {
double *time;
double startTime;
public:
RegionTimer(double &acc) {
time = &acc;
startTime = MPI_Wtime();
}
~RegionTimer() {
*time += MPI_Wtime() - startTime;
}
};
class ParallelRegionTimer {
double *time;
double startTime;
public:
ParallelRegionTimer(double &acc) {
#pragma omp master
{
time = &acc;
startTime = MPI_Wtime();
}
}
~ParallelRegionTimer() {
#pragma omp master
{
*time += MPI_Wtime() - startTime;
}
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment