Skip to content

Commit

Permalink
Making MPI communicator variables private in parallelComm, and adding…
Browse files Browse the repository at this point in the history
… access functions
  • Loading branch information
itopcuoglu committed Dec 30, 2024
1 parent b4f7aa9 commit d21e26f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
20 changes: 12 additions & 8 deletions src/exchangeAMRDonors.C
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ void tioga::exchangeAMRDonors()
// since the receiver side is unknown
//
pc_cart->getMap(&nsend_sav, &nrecv_sav, &sndMap, &rcvMap);
sndMapAll = (int*)malloc(sizeof(int) * pc_cart->numprocs);
rcvMapAll = (int*)malloc(sizeof(int) * pc_cart->numprocs);
nsend = nrecv = pc_cart->numprocs;
imap = (int*)malloc(sizeof(int) * pc_cart->numprocs);
icount = (int*)malloc(sizeof(int) * pc_cart->numprocs);
for (i = 0; i < pc_cart->numprocs; i++) {
int cart_comm_size = pc_cart->get_comm_size();
sndMapAll = (int*)malloc(sizeof(int) * cart_comm_size);
rcvMapAll = (int*)malloc(sizeof(int) * cart_comm_size);
nsend = nrecv = cart_comm_size;
imap = (int*)malloc(sizeof(int) * cart_comm_size);
icount = (int*)malloc(sizeof(int) * cart_comm_size);
for (i = 0; i < cart_comm_size; i++) {
sndMapAll[i] = rcvMapAll[i] = imap[i] = i;
icount[i] = 0;
}
Expand Down Expand Up @@ -319,10 +320,13 @@ void tioga::checkComm()
int *sndMap, *rcvMap;
PACKET *sndPack, *rcvPack;

nsend = nrecv = pc_cart->numprocs;
int cart_comm_size = pc_cart->get_comm_size();
nsend = cart_comm_size;
nrecv = cart_comm_size;
// nsend = nrecv = pc_cart->numprocs;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
sndMap = (int*)malloc(sizeof(int) * nsend);
rcvMap = (int*)malloc(sizeof(int) * nrecv);
for (i = 0; i < pc_cart->numprocs; i++) {
for (i = 0; i < cart_comm_size; i++) {
sndMap[i] = rcvMap[i] = i;
}
pc_cart->setMap(nsend, nrecv, sndMap, rcvMap);
Expand Down
9 changes: 5 additions & 4 deletions src/getCartReceptors.C
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc)
//
// limit case we communicate to everybody
//
int* pmap = (int*)malloc(sizeof(int) * pc->numprocs);
for (int i = 0; i < pc->numprocs; i++) {
int comm_size = pc->get_comm_size();
int* pmap = (int*)malloc(sizeof(int) * comm_size);
for (int i = 0; i < comm_size; i++) {
pmap[i] = 0;
}
//
Expand Down Expand Up @@ -111,7 +112,7 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc)
// create the communication map
//
int nsend = 0;
for (int i = 0; i < pc->numprocs; i++) {
for (int i = 0; i < comm_size; i++) {
if (pmap[i] == 1) {
nsend++;
}
Expand All @@ -120,7 +121,7 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc)
int* sndMap = (int*)malloc(sizeof(int) * nsend);
int* rcvMap = (int*)malloc(sizeof(int) * nrecv);
int m = 0;
for (int i = 0; i < pc->numprocs; i++) {
for (int i = 0; i < comm_size; i++) {
if (pmap[i] == 1) {
sndMap[m] = rcvMap[m] = i;
m++;
Expand Down
12 changes: 12 additions & 0 deletions src/parallelComm.C
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,15 @@ void parallelComm::initPackets(PACKET* sndPack, PACKET* rcvPack) const
}
//
}

void parallelComm::set_comm_size(int nprocs) { numprocs = nprocs; }

int parallelComm::get_comm_size() { return numprocs; }

void parallelComm::set_rank(int procid) { myid = procid; }

int parallelComm::get_rank() { return myid; }

void parallelComm::set_comm(MPI_Comm comm) { scomm = comm; }

MPI_Comm parallelComm::get_comm() { return scomm; }
15 changes: 13 additions & 2 deletions src/parallelComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ class parallelComm
int nrecv;
int* sndMap;
int* rcvMap;

public:
int myid;
int numprocs;
MPI_Comm scomm;

public:
parallelComm()
{
sndMap = nullptr;
Expand Down Expand Up @@ -74,6 +73,18 @@ class parallelComm
void initPackets(PACKET* sndPack, PACKET* rcvPack) const;

void clearPackets(PACKET* sndPack, PACKET* rcvPack) const;

void set_comm_size(int nprocs);

int get_comm_size();

void set_rank(int procid);

int get_rank();

void set_comm(MPI_Comm comm);

MPI_Comm get_comm();
};

#endif /* PARALLELCOMM_H */
18 changes: 12 additions & 6 deletions src/tioga.C
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,22 @@ void tioga::setCommunicator(MPI_Comm communicator, int id_proc, int nprocs)
// instantiate the parallel communication class
//
pc = new parallelComm[1];
pc->myid = myid;
pc->scomm = scomm;
pc->numprocs = numprocs;
pc->set_rank(myid);
pc->set_comm(scomm);
pc->set_comm_size(numprocs);
// pc->myid = myid;
// pc->scomm = scomm;
// pc->numprocs = numprocs;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

// instantiate the parallel communication class
//
pc_cart = new parallelComm[1];
pc_cart->myid = myid;
pc_cart->scomm = scomm;
pc_cart->numprocs = numprocs;
pc_cart->set_rank(myid);
pc_cart->set_comm(scomm);
pc_cart->set_comm_size(numprocs);
// pc_cart->myid = myid;
// pc_cart->scomm = scomm;
// pc_cart->numprocs = numprocs;
//

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
}

Expand Down

0 comments on commit d21e26f

Please sign in to comment.