Skip to content

Commit

Permalink
Tweaked a few things so that environment can exit cleanly from applic…
Browse files Browse the repository at this point in the history
…ations that

are initialized by a communicator and to prevent problems with tests using the
GA progress ranks runtime.
  • Loading branch information
Bruce J Palmer authored and wperkins committed Nov 29, 2023
1 parent 6b11e84 commit 48c70be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
7 changes: 7 additions & 0 deletions src/applications/dynamic_simulation_full_y/dsf_comm_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ void dsf(MPI_Comm comm, int argc, char **argv)
gridpack::NoPrint *noprint_ins = gridpack::NoPrint::instance();
noprint_ins->setStatus(true);


int rank,size;
MPI_Comm_rank(comm,&rank);
MPI_Comm_size(comm,&size);
std::cout << "Rank: "<<rank<<" Size: "<<size <<std::endl;
gridpack::Environment env(argc,argv,comm);

if (env.active()) {
gridpack::parallel::Communicator gp_world;
std::cout << "p["<<rank<<"] Size of world communicator: "<<gp_world.size() <<std::endl;

gridpack::utility::CoarseTimer *timer =
gridpack::utility::CoarseTimer::instance();
Expand Down
11 changes: 5 additions & 6 deletions src/environment/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,20 @@ Environment::Environment(int argc, char **argv, MPI_Comm &comm): p_boostEnv(argc
PrintStatus();
pma_stack = 200000;
pma_heap = 200000;
// GA_Initialize_comm returns false if the processor is not in the active
// set. This is needed so that applications can exit cleanly instead of
// hanging.
if (GA_Initialize_comm(comm)) {
p_from_comm = true;
MA_init(C_DBL,pma_stack,pma_heap);
gridpack::math::Initialize(&argc,&argv);
} else {
int rank;
MPI_Comm_rank(comm,&rank);
if (rank == 0) {
std::cout<<"Initialize GA from communicator failed" << std::endl;
}
MPI_Abort(comm, 1);
p_from_comm = false;
}
#else
int rank;
MPI_Comm_rank(comm,&rank);
p_from_comm = true;
if (rank == 0) {
std::cout<<"Initialize GridPACK Environment from communicator not implemented"
<< std::endl;
Expand Down
12 changes: 7 additions & 5 deletions src/environment/test/env_comm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ main(int argc, char **argv)
printf("MPI %d: Process %d of %d (global: %d of %d)\n",
color, color_rank, color_size, global_rank, global_size);

{
if (color_size > 2) {
using namespace gridpack;
using namespace gridpack::parallel;

Environment env(argc,argv,csplit);
Communicator gp_world;
if (env.active()) {
Communicator gp_world;

printf("GP %d: Process %d of %d (global: %d of %d)\n",
color, gp_world.rank(), gp_world.size(),
global_rank, global_size);
printf("GP %d: Process %d of %d (global: %d of %d)\n",
color, gp_world.rank(), gp_world.size(),
global_rank, global_size);
}

}

Expand Down

0 comments on commit 48c70be

Please sign in to comment.