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 if((nprocs&(nprocs-1)))
20 THROWF(arg_error,0, "allreduce rab1 algorithm can't be used with non power of two number of processes ! ");
22 extent = smpi_datatype_get_extent(dtype);
25 while (pof2 <= nprocs)
30 send_idx = recv_idx = 0;
33 if ((count % nprocs)) {
34 send_size = (count + nprocs) / nprocs;
35 newcnt = send_size * nprocs;
37 recv = (void *) xbt_malloc(extent * newcnt);
38 tmp_buf = (void *) xbt_malloc(extent * newcnt);
39 memcpy(recv, sbuff, extent * count);
43 share = newcnt / pof2;
46 send_cnt = recv_cnt = newcnt / (pof2 / mask);
49 send_idx = recv_idx + (mask * share);
51 recv_idx = send_idx + (mask * share);
53 smpi_mpi_sendrecv((char *) recv + send_idx * extent, send_cnt, dtype, dst, tag,
54 tmp_buf, recv_cnt, dtype, dst, tag, comm, &status);
56 smpi_op_apply(op, tmp_buf, (char *) recv + recv_idx * extent, &recv_cnt,
59 // update send_idx for next iteration
64 memcpy(tmp_buf, (char *) recv + recv_idx * extent, recv_cnt * extent);
65 mpi_coll_allgather_fun(tmp_buf, recv_cnt, dtype, recv, recv_cnt, dtype, comm);
67 memcpy(rbuff, recv, count * extent);
74 tmp_buf = (void *) xbt_malloc(extent * count);
75 memcpy(rbuff, sbuff, count * extent);
80 send_cnt = recv_cnt = count / (pof2 / mask);
83 send_idx = recv_idx + (mask * share);
85 recv_idx = send_idx + (mask * share);
87 smpi_mpi_sendrecv((char *) rbuff + send_idx * extent, send_cnt, dtype, dst,
88 tag, tmp_buf, recv_cnt, dtype, dst, tag, comm, &status);
90 smpi_op_apply(op, tmp_buf, (char *) rbuff + recv_idx * extent, &recv_cnt,
93 // update send_idx for next iteration
98 memcpy(tmp_buf, (char *) rbuff + recv_idx * extent, recv_cnt * extent);
99 mpi_coll_allgather_fun(tmp_buf, recv_cnt, dtype, rbuff, recv_cnt, dtype, comm);