From 6cb5afaeb14a580a8150ae3f4c55674160452270 Mon Sep 17 00:00:00 2001 From: Hui Zhou Date: Sat, 24 Aug 2024 16:45:28 -0500 Subject: [PATCH] coll: refactor barrier_intra_k_dissemination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../barrier/barrier_intra_k_dissemination.c | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/mpi/coll/barrier/barrier_intra_k_dissemination.c b/src/mpi/coll/barrier/barrier_intra_k_dissemination.c index 2d006c162ba..1cd7dab7a01 100644 --- a/src/mpi/coll/barrier/barrier_intra_k_dissemination.c +++ b/src/mpi/coll/barrier/barrier_intra_k_dissemination.c @@ -49,7 +49,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); @@ -74,8 +74,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; @@ -84,6 +84,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++) { @@ -95,14 +97,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_COLL_CHECKANDCONT(mpi_errno, errflag, mpi_errno_ret); /* 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_COLL_CHECKANDCONT(mpi_errno, errflag, mpi_errno_ret); } @@ -114,10 +114,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_COLL_CHECKANDCONT(mpi_errno, errflag, mpi_errno_ret); 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_COLL_CHECKANDCONT(mpi_errno, errflag, mpi_errno_ret); fn_exit: