2 //#include <star-reduction.c>
4 // this requires that count >= NP
5 int smpi_coll_tuned_allreduce_rab2(void *sbuff, void *rbuff,
6 int count, MPI_Datatype dtype,
7 MPI_Op op, MPI_Comm comm)
11 int nbytes, send_size, s_offset, r_offset;
12 void *recv, *send, *tmp;
14 #ifdef MPICH2_REDUCTION
15 MPI_User_function * uop = MPIR_Op_table[op % 16 - 1];
17 MPI_User_function *uop;
18 struct MPIR_OP *op_ptr;
19 op_ptr = MPIR_ToPointer(op);
23 MPI_Comm_rank(comm, &rank);
24 MPI_Comm_size(comm, &nprocs);
27 MPI_Type_extent(dtype, &s_extent);
34 send_size = (count + nprocs) / nprocs;
35 nbytes = send_size * s_extent;
37 send = (void *) malloc(s_extent * send_size * nprocs);
38 recv = (void *) malloc(s_extent * send_size * nprocs);
39 tmp = (void *) malloc(nbytes);
41 memcpy(send, sbuff, s_extent * count);
43 MPI_Alltoall(send, send_size, dtype, recv, send_size, dtype, comm);
45 memcpy(tmp, recv, nbytes);
47 for (i = 1, s_offset = nbytes; i < nprocs; i++, s_offset = i * nbytes)
48 star_reduction(op, (char *) recv + s_offset, tmp, &send_size, &dtype);
50 MPI_Allgather(tmp, send_size, dtype, recv, send_size, dtype, comm);
51 memcpy(rbuff, recv, count * s_extent);
58 send_size = count / nprocs;
59 nbytes = send_size * s_extent;
60 r_offset = rank * nbytes;
62 recv = (void *) malloc(s_extent * send_size * nprocs);
64 MPI_Alltoall(send, send_size, dtype, recv, send_size, dtype, comm);
66 memcpy((char *) rbuff + r_offset, recv, nbytes);
68 for (i = 1, s_offset = nbytes; i < nprocs; i++, s_offset = i * nbytes)
69 star_reduction(op, (char *) recv + s_offset, (char *) rbuff + r_offset,
72 MPI_Allgather((char *) rbuff + r_offset, send_size, dtype, rbuff, send_size,