Skip to content

Commit b6cecd0

Browse files
committed
coll: refactor barrier_intra_k_dissemination
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.
1 parent 5d72942 commit b6cecd0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/mpi/coll/barrier/barrier_intra_k_dissemination.c

+13-10
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int MPIR_Barrier_intra_k_dissemination(MPIR_Comm * comm, int coll_group, int k,
5151
int p_of_k; /* minimum power of k that is greater than or equal to number of ranks */
5252
int shift, to, from;
5353
int nphases = 0;
54-
MPIR_Request *sreqs[MAX_RADIX], *rreqs[MAX_RADIX * 2];
54+
MPIR_Request *static_sreqs[MAX_RADIX], *static_rreqs[MAX_RADIX * 2];
5555
MPIR_Request **send_reqs = NULL, **recv_reqs = NULL;
5656

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

8383
p_of_k = 1;
@@ -86,6 +86,8 @@ int MPIR_Barrier_intra_k_dissemination(MPIR_Comm * comm, int coll_group, int k,
8686
nphases++;
8787
}
8888

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

99101
/* recv from (k-1) nbrs */
100-
mpi_errno =
101-
MPIC_Irecv(NULL, 0, MPI_BYTE, from, MPIR_BARRIER_TAG, comm, coll_group,
102-
&recv_reqs[(j - 1) + ((k - 1) * (i & 1))]);
102+
mpi_errno = MPIC_Irecv(NULL, 0, MPI_BYTE, from, MPIR_BARRIER_TAG, comm, coll_group,
103+
&rreqs[j - 1]);
103104
MPIR_ERR_CHECK(mpi_errno);
104105
/* wait on recvs from prev phase */
105106
if (i > 0 && j == 1) {
106-
mpi_errno =
107-
MPIC_Waitall(k - 1, &recv_reqs[((k - 1) * ((i - 1) & 1))], MPI_STATUSES_IGNORE);
107+
mpi_errno = MPIC_Waitall(k - 1, prev_rreqs, MPI_STATUSES_IGNORE);
108108
MPIR_ERR_CHECK(mpi_errno);
109109
}
110110

@@ -115,10 +115,13 @@ int MPIR_Barrier_intra_k_dissemination(MPIR_Comm * comm, int coll_group, int k,
115115
mpi_errno = MPIC_Waitall(k - 1, send_reqs, MPI_STATUSES_IGNORE);
116116
MPIR_ERR_CHECK(mpi_errno);
117117
shift *= k;
118+
119+
MPIR_Request **tmp = rreqs;
120+
rreqs = prev_rreqs;
121+
prev_rreqs = tmp;
118122
}
119123

120-
mpi_errno =
121-
MPIC_Waitall(k - 1, recv_reqs + ((k - 1) * ((nphases - 1) & 1)), MPI_STATUSES_IGNORE);
124+
mpi_errno = MPIC_Waitall(k - 1, prev_rreqs, MPI_STATUSES_IGNORE);
122125
MPIR_ERR_CHECK(mpi_errno);
123126

124127
fn_exit:

0 commit comments

Comments
 (0)