1 #include "colls_private.h"
2 //#include <star-reduction.c>
5 int smpi_coll_tuned_allreduce_rab1(void *sbuff, void *rbuff,
6 int count, MPI_Datatype dtype,
7 MPI_Op op, MPI_Comm comm)
11 int tag = COLL_TAG_ALLREDUCE, rank, nprocs, send_size, newcnt, share;
12 int pof2 = 1, mask, send_idx, recv_idx, dst, send_cnt, recv_cnt;
16 rank = smpi_comm_rank(comm);
17 nprocs = smpi_comm_size(comm);
19 extent = smpi_datatype_get_extent(dtype);
22 while (pof2 <= nprocs)
27 send_idx = recv_idx = 0;
30 if ((count % nprocs)) {
31 send_size = (count + nprocs) / nprocs;
32 newcnt = send_size * nprocs;
34 recv = (void *) xbt_malloc(extent * newcnt);
35 tmp_buf = (void *) xbt_malloc(extent * newcnt);
36 memcpy(recv, sbuff, extent * count);
40 share = newcnt / pof2;
43 send_cnt = recv_cnt = newcnt / (pof2 / mask);
46 send_idx = recv_idx + (mask * share);
48 recv_idx = send_idx + (mask * share);
50 smpi_mpi_sendrecv((char *) recv + send_idx * extent, send_cnt, dtype, dst, tag,
51 tmp_buf, recv_cnt, dtype, dst, tag, comm, &status);
53 smpi_op_apply(op, tmp_buf, (char *) recv + recv_idx * extent, &recv_cnt,
56 // update send_idx for next iteration
61 memcpy(tmp_buf, (char *) recv + recv_idx * extent, recv_cnt * extent);
62 mpi_coll_allgather_fun(tmp_buf, recv_cnt, dtype, recv, recv_cnt, dtype, comm);
64 memcpy(rbuff, recv, count * extent);
71 tmp_buf = (void *) xbt_malloc(extent * count);
72 memcpy(rbuff, sbuff, count * extent);
77 send_cnt = recv_cnt = count / (pof2 / mask);
80 send_idx = recv_idx + (mask * share);
82 recv_idx = send_idx + (mask * share);
84 smpi_mpi_sendrecv((char *) rbuff + send_idx * extent, send_cnt, dtype, dst,
85 tag, tmp_buf, recv_cnt, dtype, dst, tag, comm, &status);
87 smpi_op_apply(op, tmp_buf, (char *) rbuff + recv_idx * extent, &recv_cnt,
90 // update send_idx for next iteration
95 memcpy(tmp_buf, (char *) rbuff + recv_idx * extent, recv_cnt * extent);
96 mpi_coll_allgather_fun(tmp_buf, recv_cnt, dtype, rbuff, recv_cnt, dtype, comm);