1 /* Copyright (c) 2013-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "colls_private.h"
8 //#include <star-reduction.c>
10 // this requires that count >= NP
11 int smpi_coll_tuned_allreduce_rab2(void *sbuff, void *rbuff,
12 int count, MPI_Datatype dtype,
13 MPI_Op op, MPI_Comm comm)
17 int nbytes, send_size, s_offset, r_offset;
18 void *recv, *send, *tmp;
20 #ifdef MPICH2_REDUCTION
21 MPI_User_function * uop = MPIR_Op_table[op % 16 - 1];
23 MPI_User_function *uop;
24 struct MPIR_OP *op_ptr;
25 op_ptr = MPIR_ToPointer(op);
29 rank = smpi_comm_rank(comm);
30 nprocs = smpi_comm_size(comm);
33 s_extent = smpi_datatype_get_extent(dtype);
40 send_size = (count + nprocs) / nprocs;
41 nbytes = send_size * s_extent;
43 send = (void *) xbt_malloc(s_extent * send_size * nprocs);
44 recv = (void *) xbt_malloc(s_extent * send_size * nprocs);
45 tmp = (void *) xbt_malloc(nbytes);
47 memcpy(send, sbuff, s_extent * count);
49 mpi_coll_alltoall_fun(send, send_size, dtype, recv, send_size, dtype, comm);
51 memcpy(tmp, recv, nbytes);
53 for (i = 1, s_offset = nbytes; i < nprocs; i++, s_offset = i * nbytes)
54 smpi_op_apply(op, (char *) recv + s_offset, tmp, &send_size, &dtype);
56 mpi_coll_allgather_fun(tmp, send_size, dtype, recv, send_size, dtype, comm);
57 memcpy(rbuff, recv, count * s_extent);
64 send_size = count / nprocs;
65 nbytes = send_size * s_extent;
66 r_offset = rank * nbytes;
68 recv = (void *) xbt_malloc(s_extent * send_size * nprocs);
70 mpi_coll_alltoall_fun(send, send_size, dtype, recv, send_size, dtype, comm);
72 memcpy((char *) rbuff + r_offset, recv, nbytes);
74 for (i = 1, s_offset = nbytes; i < nprocs; i++, s_offset = i * nbytes)
75 smpi_op_apply(op, (char *) recv + s_offset, (char *) rbuff + r_offset,
78 mpi_coll_allgather_fun((char *) rbuff + r_offset, send_size, dtype, rbuff, send_size,