Commit e29a8b84 authored by Alexandru Dura's avatar Alexandru Dura

Add all the required timers

parent 5e808db6
......@@ -101,6 +101,9 @@ static void writeData(int rank, Problem &p, const char *pauseFile) {
}
int main(int argc, char **argv) {
double globalTime = 0;
RegionTimer globalTimer(globalTime);
// Process arguments for checkpoint facility
const char *pauseFile = nullptr;
const char *restartFile = nullptr;
......@@ -154,16 +157,21 @@ int main(int argc, char **argv) {
Problem p(nsize, rank, localXdim, localYdim, nGates, nGates, gateVal);
double startTime = MPI_Wtime();
unsigned nOMPThreads;
// Total time spent exchanging halos, excluding OpenMP synchronization.
double haloExchangeTime = 0;
// Total time spent computing, accumulated over all iterations,
// measured on the master thread. This includes
// the synchronization at the end of each iteration of the for loops.
double calcTime = 0;
double totalTime = 0;
// Total time spent in the main loop, accumulated over all iterations,
// for the master thread.
double mainIterTime = 0;
#pragma omp parallel default(none) \
shared(p, restartFile, pauseFile, rank, config, nsize, nOMPThreads, haloExchangeTime, calcTime, totalTime)
shared(p, restartFile, pauseFile, rank, config, nsize, nOMPThreads, haloExchangeTime, calcTime, mainIterTime)
{
ParallelRegionTimer totalTimer(totalTime);
ParallelRegionTimer totalTimer(mainIterTime);
#ifdef _OPENMP
nOMPThreads = omp_get_num_threads();
#else
......@@ -174,9 +182,10 @@ int main(int argc, char **argv) {
// close to the core that performs the computation.
p.initialize();
#pragma omp master
if (restartFile) {
// read in the data, if requested
#pragma omp single
readData(rank, p, restartFile);
}
......@@ -185,7 +194,7 @@ int main(int argc, char **argv) {
// 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 exchanged before proceeding.
#pragma omp master
#pragma omp single
{
RegionTimer haloExchangeTimer(haloExchangeTime);
exchangeHalos(rank, nsize, p);
......@@ -198,9 +207,9 @@ int main(int argc, char **argv) {
}
}
#pragma omp master
if (pauseFile) {
// Write the problem out, for later restart
#pragma omp single
writeData(rank, p, pauseFile);
}
} // end of pramga omp parallel
......@@ -261,7 +270,8 @@ 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,%f,%f\n", nsize, nOMPThreads, totalTime, calcTime, haloExchangeTime, resNorm);
printf("%d,%d,%f,%f,%f,%f,%f\n", nsize, nOMPThreads, globalTimer.read(),
mainIterTime, calcTime, haloExchangeTime, resNorm);
}
MPI_Finalize();
......
......@@ -13,9 +13,12 @@ public:
}
~RegionTimer() {
*time += MPI_Wtime() - startTime;
*time += read();
}
double read() const {
return MPI_Wtime() - startTime;
}
};
class ParallelRegionTimer {
......@@ -23,6 +26,12 @@ class ParallelRegionTimer {
double startTime;
public:
// Measure time on the master thread. The 'omp master'
// directive does not have any implied barrier so we should
// not introduce synchronization overhead just from introducing
// a timer.
// On the other hand, we have to assume that all threads in
// the set take roughly the same ammount of time to do their job.
ParallelRegionTimer(double &acc) {
#pragma omp master
{
......
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