Cache GSL in SyncPlan and apply async Sync to Z4c_class
Major optimization: Pre-build grid segment lists (GSLs) once per Step() call via SyncPreparePlan(), then reuse them across all 4 RK4 substep SyncBegin calls via SyncBeginWithPlan(). This eliminates the O(cpusize * blocks^2) GSL rebuild cost that was incurred on every ghost zone exchange. Applied async SyncBegin/SyncEnd overlap pattern to Z4c_class.C (ABEtype==2, the default configuration), which was still using blocking Parallel::Sync. Both the regular and CPBC variants of Z4c Step() are now optimized. Co-authored-by: copilot-swe-agent[bot] <198982749+copilot@users.noreply.github.com>
This commit is contained in:
@@ -186,6 +186,12 @@ void Z4c_class::Step(int lev, int YN)
|
||||
int ERROR = 0;
|
||||
|
||||
MyList<ss_patch> *sPp;
|
||||
|
||||
// Pre-build grid segment lists once for this level's patches.
|
||||
// These are reused across predictor + 3 corrector SyncBegin calls,
|
||||
// avoiding O(cpusize * blocks^2) rebuild each time.
|
||||
Parallel::SyncPlan *sync_plan = Parallel::SyncPreparePlan(GH->PatL[lev], Symmetry);
|
||||
|
||||
// Predictor
|
||||
MyList<Patch> *Pp = GH->PatL[lev];
|
||||
while (Pp)
|
||||
@@ -321,13 +327,17 @@ void Z4c_class::Step(int lev, int YN)
|
||||
}
|
||||
Pp = Pp->next;
|
||||
}
|
||||
// check error information
|
||||
// Start async ghost zone exchange - overlaps with error check and Shell computation
|
||||
Parallel::SyncHandle *sync_pre = Parallel::SyncBeginWithPlan(sync_plan, SynchList_pre);
|
||||
|
||||
// check error information (overlaps with MPI transfer)
|
||||
{
|
||||
int erh = ERROR;
|
||||
MPI_Allreduce(&erh, &ERROR, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
||||
}
|
||||
if (ERROR)
|
||||
{
|
||||
Parallel::SyncEnd(sync_pre); sync_pre = 0;
|
||||
Parallel::Dump_Data(GH->PatL[lev], StateList, 0, PhysTime, dT_lev);
|
||||
if (myrank == 0)
|
||||
{
|
||||
@@ -475,6 +485,7 @@ void Z4c_class::Step(int lev, int YN)
|
||||
}
|
||||
if (ERROR)
|
||||
{
|
||||
Parallel::SyncEnd(sync_pre); sync_pre = 0;
|
||||
SH->Dump_Data(StateList, 0, PhysTime, dT_lev);
|
||||
if (myrank == 0)
|
||||
{
|
||||
@@ -485,7 +496,8 @@ void Z4c_class::Step(int lev, int YN)
|
||||
}
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev], SynchList_pre, Symmetry);
|
||||
// Complete async ghost zone exchange
|
||||
if (sync_pre) Parallel::SyncEnd(sync_pre);
|
||||
|
||||
#ifdef WithShell
|
||||
if (lev == 0)
|
||||
@@ -693,13 +705,17 @@ void Z4c_class::Step(int lev, int YN)
|
||||
Pp = Pp->next;
|
||||
}
|
||||
|
||||
// check error information
|
||||
// Start async ghost zone exchange - overlaps with error check and Shell computation
|
||||
Parallel::SyncHandle *sync_cor = Parallel::SyncBeginWithPlan(sync_plan, SynchList_cor);
|
||||
|
||||
// check error information (overlaps with MPI transfer)
|
||||
{
|
||||
int erh = ERROR;
|
||||
MPI_Allreduce(&erh, &ERROR, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
||||
}
|
||||
if (ERROR)
|
||||
{
|
||||
Parallel::SyncEnd(sync_cor); sync_cor = 0;
|
||||
Parallel::Dump_Data(GH->PatL[lev], SynchList_pre, 0, PhysTime, dT_lev);
|
||||
if (myrank == 0)
|
||||
{
|
||||
@@ -857,6 +873,7 @@ void Z4c_class::Step(int lev, int YN)
|
||||
}
|
||||
if (ERROR)
|
||||
{
|
||||
Parallel::SyncEnd(sync_cor); sync_cor = 0;
|
||||
SH->Dump_Data(SynchList_pre, 0, PhysTime, dT_lev);
|
||||
if (myrank == 0)
|
||||
{
|
||||
@@ -868,7 +885,8 @@ void Z4c_class::Step(int lev, int YN)
|
||||
}
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev], SynchList_cor, Symmetry);
|
||||
// Complete async ghost zone exchange
|
||||
if (sync_cor) Parallel::SyncEnd(sync_cor);
|
||||
|
||||
#ifdef WithShell
|
||||
if (lev == 0)
|
||||
@@ -1042,6 +1060,8 @@ void Z4c_class::Step(int lev, int YN)
|
||||
Porg0[ithBH][2] = Porg1[ithBH][2];
|
||||
}
|
||||
}
|
||||
|
||||
Parallel::SyncFreePlan(sync_plan);
|
||||
}
|
||||
#else
|
||||
// for constraint preserving boundary (CPBC)
|
||||
@@ -1075,6 +1095,10 @@ void Z4c_class::Step(int lev, int YN)
|
||||
int ERROR = 0;
|
||||
|
||||
MyList<ss_patch> *sPp;
|
||||
|
||||
// Pre-build grid segment lists once for this level's patches.
|
||||
Parallel::SyncPlan *sync_plan = Parallel::SyncPreparePlan(GH->PatL[lev], Symmetry);
|
||||
|
||||
// Predictor
|
||||
MyList<Patch> *Pp = GH->PatL[lev];
|
||||
while (Pp)
|
||||
@@ -1542,13 +1566,17 @@ void Z4c_class::Step(int lev, int YN)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// check error information
|
||||
// Start async ghost zone exchange - overlaps with error check
|
||||
Parallel::SyncHandle *sync_pre = Parallel::SyncBeginWithPlan(sync_plan, SynchList_pre);
|
||||
|
||||
// check error information (overlaps with MPI transfer)
|
||||
{
|
||||
int erh = ERROR;
|
||||
MPI_Allreduce(&erh, &ERROR, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
||||
}
|
||||
if (ERROR)
|
||||
{
|
||||
Parallel::SyncEnd(sync_pre); sync_pre = 0;
|
||||
SH->Dump_Data(StateList, 0, PhysTime, dT_lev);
|
||||
if (myrank == 0)
|
||||
{
|
||||
@@ -1558,7 +1586,8 @@ void Z4c_class::Step(int lev, int YN)
|
||||
}
|
||||
}
|
||||
|
||||
Parallel::Sync(GH->PatL[lev], SynchList_pre, Symmetry);
|
||||
// Complete async ghost zone exchange
|
||||
if (sync_pre) Parallel::SyncEnd(sync_pre);
|
||||
|
||||
if (lev == 0)
|
||||
{
|
||||
@@ -2103,13 +2132,17 @@ void Z4c_class::Step(int lev, int YN)
|
||||
sPp = sPp->next;
|
||||
}
|
||||
}
|
||||
// check error information
|
||||
// Start async ghost zone exchange - overlaps with error check
|
||||
Parallel::SyncHandle *sync_cor = Parallel::SyncBeginWithPlan(sync_plan, SynchList_cor);
|
||||
|
||||
// check error information (overlaps with MPI transfer)
|
||||
{
|
||||
int erh = ERROR;
|
||||
MPI_Allreduce(&erh, &ERROR, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
||||
}
|
||||
if (ERROR)
|
||||
{
|
||||
Parallel::SyncEnd(sync_cor); sync_cor = 0;
|
||||
SH->Dump_Data(SynchList_pre, 0, PhysTime, dT_lev);
|
||||
if (myrank == 0)
|
||||
{
|
||||
@@ -2120,7 +2153,8 @@ void Z4c_class::Step(int lev, int YN)
|
||||
}
|
||||
}
|
||||
|
||||
Parallel::Sync(GH->PatL[lev], SynchList_cor, Symmetry);
|
||||
// Complete async ghost zone exchange
|
||||
if (sync_cor) Parallel::SyncEnd(sync_cor);
|
||||
|
||||
if (lev == 0)
|
||||
{
|
||||
@@ -2346,6 +2380,8 @@ void Z4c_class::Step(int lev, int YN)
|
||||
DG_List->clearList();
|
||||
}
|
||||
#endif
|
||||
|
||||
Parallel::SyncFreePlan(sync_plan);
|
||||
}
|
||||
#endif
|
||||
#undef MRBD
|
||||
|
||||
Reference in New Issue
Block a user