Add optional BSSN kernel profiling switches
(cherry picked from commit 9c31384b2f)
This commit is contained in:
@@ -63,6 +63,14 @@ using namespace std;
|
||||
#define BSSN_FINE_TIMING_TOPN 8
|
||||
#endif
|
||||
|
||||
#ifndef BSSN_KERNEL_FINE_TIMING
|
||||
#define BSSN_KERNEL_FINE_TIMING 0
|
||||
#endif
|
||||
|
||||
#ifndef BSSN_ENABLE_STDIN_ABORT_POLL
|
||||
#define BSSN_ENABLE_STDIN_ABORT_POLL 0
|
||||
#endif
|
||||
|
||||
#if BSSN_FINE_TIMING
|
||||
namespace step_timing
|
||||
{
|
||||
@@ -157,6 +165,74 @@ namespace step_timing
|
||||
#define STEP_TIMER_ADD(bucket_name, var_name)
|
||||
#endif
|
||||
|
||||
#if BSSN_KERNEL_FINE_TIMING
|
||||
namespace rhs_kernel_timing_report
|
||||
{
|
||||
void report(int myrank, int nprocs, int step_index, double step_wall_seconds)
|
||||
{
|
||||
const int bucket_count = f_bssn_rhs_kernel_timing_bucket_count();
|
||||
const double *local_bucket_seconds = f_bssn_rhs_kernel_timing_local_seconds();
|
||||
|
||||
if (bucket_count <= 0 || !local_bucket_seconds)
|
||||
return;
|
||||
|
||||
double *max_bucket_seconds = new double[bucket_count];
|
||||
double *avg_bucket_seconds = new double[bucket_count];
|
||||
int *order = new int[bucket_count];
|
||||
|
||||
MPI_Reduce((void *)local_bucket_seconds, max_bucket_seconds, bucket_count, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
|
||||
MPI_Reduce((void *)local_bucket_seconds, avg_bucket_seconds, bucket_count, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
|
||||
|
||||
if (myrank == 0)
|
||||
{
|
||||
double kernel_total = 0.0;
|
||||
for (int i = 0; i < bucket_count; ++i)
|
||||
{
|
||||
avg_bucket_seconds[i] /= Mymax(1, nprocs);
|
||||
order[i] = i;
|
||||
kernel_total += max_bucket_seconds[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < bucket_count - 1; ++i)
|
||||
for (int j = i + 1; j < bucket_count; ++j)
|
||||
if (max_bucket_seconds[order[j]] > max_bucket_seconds[order[i]])
|
||||
{
|
||||
int tmp = order[i];
|
||||
order[i] = order[j];
|
||||
order[j] = tmp;
|
||||
}
|
||||
|
||||
ios::fmtflags old_flags = cout.flags();
|
||||
streamsize old_precision = cout.precision();
|
||||
|
||||
const double kernel_frac = (step_wall_seconds > 0.0) ? (100.0 * kernel_total / step_wall_seconds) : 0.0;
|
||||
cout << " RHS kernel split (max-rank accumulated over step " << step_index << "): total "
|
||||
<< setprecision(6) << kernel_total << " s (" << setprecision(4)
|
||||
<< kernel_frac << "% of coarse step)" << endl;
|
||||
|
||||
const int topn = Mymin(BSSN_FINE_TIMING_TOPN, bucket_count);
|
||||
for (int i = 0; i < topn; ++i)
|
||||
{
|
||||
const int ib = order[i];
|
||||
const double frac = (kernel_total > 0.0) ? (100.0 * max_bucket_seconds[ib] / kernel_total) : 0.0;
|
||||
cout << " "
|
||||
<< setw(20) << left << f_bssn_rhs_kernel_timing_label(ib)
|
||||
<< " = " << setw(10) << right << setprecision(6) << max_bucket_seconds[ib]
|
||||
<< " s (" << setw(6) << setprecision(4) << frac << "% of kernel)" << endl;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
cout.flags(old_flags);
|
||||
cout.precision(old_precision);
|
||||
}
|
||||
|
||||
delete[] max_bucket_seconds;
|
||||
delete[] avg_bucket_seconds;
|
||||
delete[] order;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if USE_CUDA_BSSN
|
||||
namespace {
|
||||
|
||||
@@ -2593,7 +2669,12 @@ void bssn_class::Evolve(int Steps)
|
||||
cuda_level0_constraint_cache_valid = false;
|
||||
#if BSSN_FINE_TIMING
|
||||
step_timing::reset();
|
||||
STEP_TIMER_DECL(step_wall_start);
|
||||
#endif
|
||||
#if BSSN_KERNEL_FINE_TIMING
|
||||
f_bssn_rhs_kernel_timing_reset();
|
||||
#endif
|
||||
#if (BSSN_FINE_TIMING || BSSN_KERNEL_FINE_TIMING)
|
||||
const double step_wall_start = MPI_Wtime();
|
||||
#endif
|
||||
|
||||
// special for large mass ratio consideration
|
||||
@@ -2720,16 +2801,18 @@ void bssn_class::Evolve(int Steps)
|
||||
<< endl;
|
||||
}
|
||||
cout << endl;
|
||||
#if BSSN_ENABLE_STDIN_ABORT_POLL
|
||||
cout << " If you think the physical evolution time is enough for this simulation, please input 'stop' in the terminal to stop the MPI processes in the next evolution step ! " << endl;
|
||||
#endif
|
||||
// cout << endl;
|
||||
}
|
||||
|
||||
|
||||
#if BSSN_ENABLE_STDIN_ABORT_POLL
|
||||
////////////////////////////////////////////////////////////
|
||||
// If an "abort" command is detected on stdin, terminate MPI processes
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
bool shouldAbort = false;
|
||||
|
||||
|
||||
// Only rank 0 checks stdin
|
||||
if (myrank == 0) {
|
||||
@@ -2749,8 +2832,9 @@ void bssn_class::Evolve(int Steps)
|
||||
MPI_Abort(MPI_COMM_WORLD, 1); // terminate MPI processes
|
||||
// MPI_Finalize();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
#endif
|
||||
|
||||
// When LastCheck >= CheckTime, perform runtime checks and output status data
|
||||
if (LastCheck >= CheckTime)
|
||||
@@ -2770,6 +2854,10 @@ void bssn_class::Evolve(int Steps)
|
||||
#if BSSN_FINE_TIMING
|
||||
if (ncount % BSSN_FINE_TIMING_EVERY == 0)
|
||||
step_timing::report(myrank, nprocs, TimingMonitor, ncount, PhysTime, MPI_Wtime() - step_wall_start);
|
||||
#endif
|
||||
#if BSSN_KERNEL_FINE_TIMING
|
||||
if (ncount % BSSN_FINE_TIMING_EVERY == 0)
|
||||
rhs_kernel_timing_report::report(myrank, nprocs, ncount, MPI_Wtime() - step_wall_start);
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user