Skip to content

Commit

Permalink
coll: refactor barrier_intra_k_dissemination
Browse files Browse the repository at this point in the history
Because the compiler can't figure out the arithmetic, it is warning:
    ‘MPIC_Waitall’ accessing 8 bytes in a region of size 0
[-Wstringop-overflow=]

Refactor to suppress warning and for better readability.
  • Loading branch information
hzhou committed Sep 12, 2024
1 parent 5d72942 commit b6cecd0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/mpi/coll/barrier/barrier_intra_k_dissemination.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int MPIR_Barrier_intra_k_dissemination(MPIR_Comm * comm, int coll_group, int k,
int p_of_k; /* minimum power of k that is greater than or equal to number of ranks */
int shift, to, from;
int nphases = 0;
MPIR_Request *sreqs[MAX_RADIX], *rreqs[MAX_RADIX * 2];
MPIR_Request *static_sreqs[MAX_RADIX], *static_rreqs[MAX_RADIX * 2];
MPIR_Request **send_reqs = NULL, **recv_reqs = NULL;

MPIR_COLL_RANK_SIZE(comm, coll_group, rank, nranks);
Expand All @@ -76,8 +76,8 @@ int MPIR_Barrier_intra_k_dissemination(MPIR_Comm * comm, int coll_group, int k,
send_reqs = (MPIR_Request **) MPL_malloc((k - 1) * sizeof(MPIR_Request *), MPL_MEM_BUFFER);
MPIR_ERR_CHKANDJUMP(!send_reqs, mpi_errno, MPI_ERR_OTHER, "**nomem");
} else {
send_reqs = sreqs;
recv_reqs = rreqs;
send_reqs = static_sreqs;
recv_reqs = static_rreqs;
}

p_of_k = 1;
Expand All @@ -86,6 +86,8 @@ int MPIR_Barrier_intra_k_dissemination(MPIR_Comm * comm, int coll_group, int k,
nphases++;
}

MPIR_Request **rreqs = recv_reqs;
MPIR_Request **prev_rreqs = recv_reqs + (k - 1);
shift = 1;
for (i = 0; i < nphases; i++) {
for (j = 1; j < k; j++) {
Expand All @@ -97,14 +99,12 @@ int MPIR_Barrier_intra_k_dissemination(MPIR_Comm * comm, int coll_group, int k,
MPIR_Assert(to >= 0 && to < nranks);

/* recv from (k-1) nbrs */
mpi_errno =
MPIC_Irecv(NULL, 0, MPI_BYTE, from, MPIR_BARRIER_TAG, comm, coll_group,
&recv_reqs[(j - 1) + ((k - 1) * (i & 1))]);
mpi_errno = MPIC_Irecv(NULL, 0, MPI_BYTE, from, MPIR_BARRIER_TAG, comm, coll_group,
&rreqs[j - 1]);
MPIR_ERR_CHECK(mpi_errno);
/* wait on recvs from prev phase */
if (i > 0 && j == 1) {
mpi_errno =
MPIC_Waitall(k - 1, &recv_reqs[((k - 1) * ((i - 1) & 1))], MPI_STATUSES_IGNORE);
mpi_errno = MPIC_Waitall(k - 1, prev_rreqs, MPI_STATUSES_IGNORE);
MPIR_ERR_CHECK(mpi_errno);
}

Expand All @@ -115,10 +115,13 @@ int MPIR_Barrier_intra_k_dissemination(MPIR_Comm * comm, int coll_group, int k,
mpi_errno = MPIC_Waitall(k - 1, send_reqs, MPI_STATUSES_IGNORE);
MPIR_ERR_CHECK(mpi_errno);
shift *= k;

MPIR_Request **tmp = rreqs;
rreqs = prev_rreqs;
prev_rreqs = tmp;
}

mpi_errno =
MPIC_Waitall(k - 1, recv_reqs + ((k - 1) * ((nphases - 1) & 1)), MPI_STATUSES_IGNORE);
mpi_errno = MPIC_Waitall(k - 1, prev_rreqs, MPI_STATUSES_IGNORE);
MPIR_ERR_CHECK(mpi_errno);

fn_exit:
Expand Down

0 comments on commit b6cecd0

Please sign in to comment.