Fix timing: replace clock() with MPI_Wtime() for wall-clock measurement

clock() measures total CPU time across all threads, not wall-clock
time. With the new OpenMP parallel regions in bssn_rhs_c.C, clock()
sums CPU time from all OpenMP threads, producing inflated timing that
scales with thread count rather than reflecting actual elapsed time.

MPI_Wtime() returns wall-clock seconds, giving accurate timing
regardless of the number of OpenMP threads running inside the
measured interval.

Co-authored-by: ianchb <i@4t.pw>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-25 12:42:47 +00:00
committed by ianchb
parent 8a9c775705
commit 09b937c022
2 changed files with 80 additions and 80 deletions

View File

@@ -319,7 +319,7 @@ void scalar_class::Setup_Initial_Data()
}
void scalar_class::Evolve(int Steps)
{
clock_t prev_clock, curr_clock;
double prev_clock, curr_clock;
double LastDump = 0.0, LastCheck = 0.0;
LastAnas = 0;
@@ -328,7 +328,7 @@ void scalar_class::Evolve(int Steps)
for (int ncount = 1; ncount < Steps + 1; ncount++)
{
if (myrank == 0)
curr_clock = clock();
curr_clock = MPI_Wtime();
RecursiveStep(0);
LastDump += dT_mon;
@@ -346,9 +346,9 @@ void scalar_class::Evolve(int Steps)
if (myrank == 0)
{
prev_clock = curr_clock;
curr_clock = clock();
curr_clock = MPI_Wtime();
cout << " Timestep # " << ncount << ": integrating to time: " << PhysTime
<< " Computer used " << (double)(curr_clock - prev_clock) / ((double)CLOCKS_PER_SEC) << " seconds! " << endl;
<< " Computer used " << (curr_clock - prev_clock) << " seconds! " << endl;
}
if (PhysTime >= TotalTime)
break;
@@ -549,15 +549,15 @@ void scalar_class::Step(int lev, int YN)
#ifdef WithShell
if (lev == 0)
{
clock_t prev_clock, curr_clock;
double prev_clock, curr_clock;
if (myrank == 0)
curr_clock = clock();
curr_clock = MPI_Wtime();
SH->Synch(SynchList_pre, Symmetry);
if (myrank == 0)
{
prev_clock = curr_clock;
curr_clock = clock();
cout << " Shell stuff synchronization used " << (double)(curr_clock - prev_clock) / ((double)CLOCKS_PER_SEC) << " seconds! " << endl;
curr_clock = MPI_Wtime();
cout << " Shell stuff synchronization used " << (curr_clock - prev_clock) << " seconds! " << endl;
}
}
#endif
@@ -731,15 +731,15 @@ void scalar_class::Step(int lev, int YN)
#ifdef WithShell
if (lev == 0)
{
clock_t prev_clock, curr_clock;
double prev_clock, curr_clock;
if (myrank == 0)
curr_clock = clock();
curr_clock = MPI_Wtime();
SH->Synch(SynchList_cor, Symmetry);
if (myrank == 0)
{
prev_clock = curr_clock;
curr_clock = clock();
cout << " Shell stuff synchronization used " << (double)(curr_clock - prev_clock) / ((double)CLOCKS_PER_SEC) << " seconds! " << endl;
curr_clock = MPI_Wtime();
cout << " Shell stuff synchronization used " << (curr_clock - prev_clock) << " seconds! " << endl;
}
}
#endif
@@ -786,15 +786,15 @@ void scalar_class::Step(int lev, int YN)
#ifdef WithShell
if (lev == 0)
{
clock_t prev_clock, curr_clock;
double prev_clock, curr_clock;
if (myrank == 0)
curr_clock = clock();
curr_clock = MPI_Wtime();
SH->CS_Inter(SynchList_cor, Symmetry);
if (myrank == 0)
{
prev_clock = curr_clock;
curr_clock = clock();
cout << " CS_Inter used " << (double)(curr_clock - prev_clock) / ((double)CLOCKS_PER_SEC) << " seconds! " << endl;
curr_clock = MPI_Wtime();
cout << " CS_Inter used " << (curr_clock - prev_clock) << " seconds! " << endl;
}
}
#endif
@@ -1010,15 +1010,15 @@ void scalar_class::Step(int lev, int YN)
#ifdef WithShell
if (lev == 0)
{
clock_t prev_clock, curr_clock;
double prev_clock, curr_clock;
if (myrank == 0)
curr_clock = clock();
curr_clock = MPI_Wtime();
SH->Synch(SynchList_cor, Symmetry);
if (myrank == 0)
{
prev_clock = curr_clock;
curr_clock = clock();
cout << " Shell stuff synchronization used " << (double)(curr_clock - prev_clock) / ((double)CLOCKS_PER_SEC) << " seconds! " << endl;
curr_clock = MPI_Wtime();
cout << " Shell stuff synchronization used " << (curr_clock - prev_clock) << " seconds! " << endl;
}
}
#endif
@@ -1027,15 +1027,15 @@ void scalar_class::Step(int lev, int YN)
#ifdef WithShell
if (lev == 0)
{
clock_t prev_clock, curr_clock;
double prev_clock, curr_clock;
if (myrank == 0)
curr_clock = clock();
curr_clock = MPI_Wtime();
SH->CS_Inter(SynchList_cor, Symmetry);
if (myrank == 0)
{
prev_clock = curr_clock;
curr_clock = clock();
cout << " CS_Inter used " << (double)(curr_clock - prev_clock) / ((double)CLOCKS_PER_SEC) << " seconds! " << endl;
curr_clock = MPI_Wtime();
cout << " CS_Inter used " << (curr_clock - prev_clock) << " seconds! " << endl;
}
}
#endif