1 #include "colls_private.h"
3 //#include <star-reduction.c>
5 int smpi_coll_tuned_reduce_binomial(void *sendbuf, void *recvbuf, int count,
6 MPI_Datatype datatype, MPI_Op op, int root,
11 int mask, relrank, source;
13 int tag = COLL_TAG_REDUCE;
16 MPI_Aint true_lb, true_extent;
19 rank = smpi_comm_rank(comm);
20 comm_size = smpi_comm_size(comm);
22 extent = smpi_datatype_get_extent(datatype);
24 tmp_buf = (void *) xbt_malloc(count * extent);
25 int is_commutative = smpi_op_is_commute(op);
33 relrank = (rank - lroot + comm_size) % comm_size;
35 smpi_datatype_extent(datatype, &true_lb, &true_extent);
37 /* adjust for potential negative lower bound in datatype */
38 tmp_buf = (void *)((char*)tmp_buf - true_lb);
40 /* If I'm not the root, then my recvbuf may not be valid, therefore
41 I have to allocate a temporary one */
43 recvbuf = (void *) malloc(count*(max(extent,true_extent)));
44 recvbuf = (void *)((char*)recvbuf - true_lb);
46 if ((rank != root) || (sendbuf != MPI_IN_PLACE)) {
47 smpi_datatype_copy(sendbuf, count, datatype, recvbuf,count, datatype);
50 while (mask < comm_size) {
52 if ((mask & relrank) == 0) {
53 source = (relrank | mask);
54 if (source < comm_size) {
55 source = (source + lroot) % comm_size;
56 smpi_mpi_recv(tmp_buf, count, datatype, source, tag, comm, &status);
59 smpi_op_apply(op, tmp_buf, recvbuf, &count, &datatype);
61 smpi_op_apply(op, recvbuf, tmp_buf, &count, &datatype);
62 smpi_datatype_copy(tmp_buf, count, datatype,recvbuf, count, datatype);
66 dst = ((relrank & (~mask)) + lroot) % comm_size;
67 smpi_mpi_send(recvbuf, count, datatype, dst, tag, comm);
73 if (!is_commutative && (root != 0)){
75 smpi_mpi_send(recvbuf, count, datatype, root,tag, comm);
76 }else if (rank == root){
77 smpi_mpi_recv(recvbuf, count, datatype, 0, tag, comm, &status);