| 1 | /* |
| 2 | * Copyright (C) by Argonne National Laboratory |
| 3 | * See COPYRIGHT in top-level directory |
| 4 | */ |
| 5 | |
| 6 | #include "mpiimpl.h"cxx . . $ `<file>/src/include/mpiimpl.h`/ |
| 7 | |
| 8 | /* Algorithm: Noncommutative recursive doubling |
| 9 | * |
| 10 | * Restrictions: This function currently only implements support for the |
| 11 | * power-of-2, block-regular case (all receive counts are equal). |
| 12 | * |
| 13 | * Implements the reduce-scatter butterfly algorithm described in J. L. Traff's |
| 14 | * "An Improved Algorithm for (Non-commutative) Reduce-Scatter with an |
| 15 | * Application" from EuroPVM/MPI 2005. |
| 16 | * |
| 17 | * It takes lgp steps. At step 1, processes exchange (n-n/p) amount of |
| 18 | * data; at step 2, (n-2n/p) amount of data; at step 3, (n-4n/p) |
| 19 | * amount of data, and so forth. |
| 20 | * |
| 21 | * Cost = lgp.alpha + n.(lgp-(p-1)/p).beta + n.(lgp-(p-1)/p).gamma |
| 22 | */ |
| 23 | int MPIR_Ireduce_scatter_intra_sched_noncommutativecxx . . $ MPIR_Ireduce_scatter_intra_sched_noncommutative(5d50b9ad876377b2).(const void *sendbuf, void *recvbuf, |
| 24 | const MPI_Aintcxx . . $ MPI_Aint# recvcounts[], |
| 25 | MPI_Datatypecxx . . $ MPI_Datatype# datatype, MPI_Opcxx . . $ MPI_Op# op, |
| 26 | MPIR_Commcxx . . $ MPIR_Comm# * comm_ptr, MPIR_Sched_tcxx . . $ MPIR_Sched_t# s) |
| 27 | { |
| 28 | int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!; |
| 29 | int comm_size; |
| 30 | int rank; |
| 31 | int log2_comm_size; |
| 32 | int i, k; |
| 33 | MPI_Aintcxx . . $ MPI_Aint# true_extent, true_lb; |
| 34 | int buf0_was_inout; |
| 35 | void *tmp_buf0; |
| 36 | void *tmp_buf1; |
| 37 | void *result_ptr; |
| 38 | |
| 39 | MPIR_COMM_RANK_SIZEcxx . . $ `src/include/mpir_comm.h:412:9`!(comm_ptr, rank, comm_size); |
| 40 | |
| 41 | MPIR_Type_get_true_extent_implcxx . . $ MPIR_Type_get_true_extent_impl(76a2ea8aac5bbe77).(datatype, &true_lb, &true_extent); |
| 42 | |
| 43 | #ifdef HAVE_ERROR_CHECKINGcxx . . $ `src/include/mpichconf.h:269:9`! |
| 44 | /* begin error checking */ |
| 45 | MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(MPL_is_pof2(comm_size)); /* FIXME this version only works for power of 2 procs */ |
| 46 | |
| 47 | for (i = 0; i < (comm_size - 1); ++i) { |
| 48 | MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(recvcounts[i] == recvcounts[i + 1]); |
| 49 | } |
| 50 | /* end error checking */ |
| 51 | #endif |
| 52 | |
| 53 | log2_comm_size = MPL_log2cxx . . $ MPL_log2(7864480464b09eea).(comm_size); |
| 54 | |
| 55 | /* size of a block (count of datatype per block, NOT bytes per block) */ |
| 56 | MPI_Aintcxx . . $ MPI_Aint# block_size, total_count; |
| 57 | block_size = recvcounts[0]; |
| 58 | total_count = block_size * comm_size; |
| 59 | |
| 60 | tmp_buf0 = MPIR_Sched_alloc_statecxx . . $ `src/mpid/ch4/include/mpid_sched.h:18:9`!(s, true_extent * total_count); |
| 61 | MPIR_ERR_CHKANDJUMPcxx . . $ `src/include/mpir_err.h:1034:9`!(!tmp_buf0, mpi_errno, MPI_ERR_OTHERcxx . . $ `src/include/mpi.h:679:9`!, "**nomem"); |
| 62 | tmp_buf1 = MPIR_Sched_alloc_statecxx . . $ `src/mpid/ch4/include/mpid_sched.h:18:9`!(s, true_extent * total_count); |
| 63 | MPIR_ERR_CHKANDJUMPcxx . . $ `src/include/mpir_err.h:1034:9`!(!tmp_buf1, mpi_errno, MPI_ERR_OTHERcxx . . $ `src/include/mpi.h:679:9`!, "**nomem"); |
| 64 | /* adjust for potential negative lower bound in datatype */ |
| 65 | tmp_buf0 = (void *) ((char *) tmp_buf0 - true_lb); |
| 66 | tmp_buf1 = (void *) ((char *) tmp_buf1 - true_lb); |
| 67 | |
| 68 | /* Copy our send data to tmp_buf0. We do this one block at a time and |
| 69 | * permute the blocks as we go according to the mirror permutation. */ |
| 70 | for (i = 0; i < comm_size; ++i) { |
| 71 | mpi_errno = |
| 72 | MPIR_Sched_copycxx . . $ `src/mpid/ch4/include/mpid_sched.h:27:9`!(((char *) (sendbuf == |
| 73 | MPI_IN_PLACEcxx . . $ `src/include/mpi.h:555:9`! ? (const void *) recvbuf : sendbuf) + |
| 74 | (i * true_extent * block_size)), block_size, datatype, |
| 75 | ((char *) tmp_buf0 + |
| 76 | (MPL_mirror_permutationcxx . . $ MPL_mirror_permutation(1cb9ad283036edc7).(i, log2_comm_size) * true_extent * |
| 77 | block_size)), block_size, datatype, s); |
| 78 | MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno); |
| 79 | MPIR_SCHED_BARRIERcxx . . $ `src/include/mpir_nbc.h:93:9`!(s); |
| 80 | } |
| 81 | buf0_was_inout = 1; |
| 82 | |
| 83 | MPI_Aintcxx . . $ MPI_Aint# send_offset, recv_offset, size; |
| 84 | send_offset = 0; |
| 85 | recv_offset = 0; |
| 86 | size = total_count; |
| 87 | for (k = 0; k < log2_comm_size; ++k) { |
| 88 | /* use a double-buffering scheme to avoid local copies */ |
| 89 | char *incoming_data = (buf0_was_inout ? tmp_buf1 : tmp_buf0); |
| 90 | char *outgoing_data = (buf0_was_inout ? tmp_buf0 : tmp_buf1); |
| 91 | int peer = rank ^ (0x1 << k); |
| 92 | size /= 2; |
| 93 | |
| 94 | if (rank > peer) { |
| 95 | /* we have the higher rank: send top half, recv bottom half */ |
| 96 | recv_offset += size; |
| 97 | } else { |
| 98 | /* we have the lower rank: recv top half, send bottom half */ |
| 99 | send_offset += size; |
| 100 | } |
| 101 | |
| 102 | mpi_errno = MPIR_Sched_sendcxx . . $ `src/mpid/ch4/include/mpid_sched.h:20:9`!((outgoing_data + send_offset * true_extent), |
| 103 | size, datatype, peer, comm_ptr, s); |
| 104 | MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno); |
| 105 | mpi_errno = MPIR_Sched_recvcxx . . $ `src/mpid/ch4/include/mpid_sched.h:23:9`!((incoming_data + recv_offset * true_extent), |
| 106 | size, datatype, peer, comm_ptr, s); |
| 107 | MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno); |
| 108 | MPIR_SCHED_BARRIERcxx . . $ `src/include/mpir_nbc.h:93:9`!(s); |
| 109 | |
| 110 | /* always perform the reduction at recv_offset, the data at send_offset |
| 111 | * is now our peer's responsibility */ |
| 112 | if (rank > peer) { |
| 113 | /* higher ranked value so need to call op(received_data, my_data) */ |
| 114 | mpi_errno = MPIR_Sched_reducecxx . . $ `src/mpid/ch4/include/mpid_sched.h:26:9`!((incoming_data + recv_offset * true_extent), |
| 115 | (outgoing_data + recv_offset * true_extent), |
| 116 | size, datatype, op, s); |
| 117 | MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno); |
| 118 | } else { |
| 119 | /* lower ranked value so need to call op(my_data, received_data) */ |
| 120 | mpi_errno = MPIR_Sched_reducecxx . . $ `src/mpid/ch4/include/mpid_sched.h:26:9`!((outgoing_data + recv_offset * true_extent), |
| 121 | (incoming_data + recv_offset * true_extent), |
| 122 | size, datatype, op, s); |
| 123 | MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno); |
| 124 | buf0_was_inout = !buf0_was_inout; |
| 125 | } |
| 126 | MPIR_SCHED_BARRIERcxx . . $ `src/include/mpir_nbc.h:93:9`!(s); |
| 127 | |
| 128 | /* the next round of send/recv needs to happen within the block (of size |
| 129 | * "size") that we just received and reduced */ |
| 130 | send_offset = recv_offset; |
| 131 | } |
| 132 | |
| 133 | MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(size == recvcounts[rank]); |
| 134 | |
| 135 | /* copy the reduced data to the recvbuf */ |
| 136 | result_ptr = (char *) (buf0_was_inout ? tmp_buf0 : tmp_buf1) + recv_offset * true_extent; |
| 137 | mpi_errno = MPIR_Sched_copycxx . . $ `src/mpid/ch4/include/mpid_sched.h:27:9`!(result_ptr, size, datatype, recvbuf, size, datatype, s); |
| 138 | MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno); |
| 139 | fn_exit: |
| 140 | return mpi_errno; |
| 141 | fn_fail: |
| 142 | goto fn_exit; |
| 143 | } |