X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a2f1b23687f04169144f4ffb4f20dc4fc5c28395..5b3677b425b9cc6949c1573d59ac772540cbf4b2:/src/smpi/colls/reduce-binomial.c diff --git a/src/smpi/colls/reduce-binomial.c b/src/smpi/colls/reduce-binomial.c index 580e3dbbb5..597c2e469f 100644 --- a/src/smpi/colls/reduce-binomial.c +++ b/src/smpi/colls/reduce-binomial.c @@ -1,4 +1,10 @@ -#include "colls.h" +/* Copyright (c) 2013-2014. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "colls_private.h" //#include @@ -10,41 +16,77 @@ int smpi_coll_tuned_reduce_binomial(void *sendbuf, void *recvbuf, int count, int comm_size, rank; int mask, relrank, source; int dst; - int tag = 4321; + int tag = COLL_TAG_REDUCE; MPI_Aint extent; void *tmp_buf; - + MPI_Aint true_lb, true_extent; if (count == 0) return 0; - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &comm_size); + rank = smpi_comm_rank(comm); + comm_size = smpi_comm_size(comm); - MPI_Type_extent(datatype, &extent); + extent = smpi_datatype_get_extent(datatype); - tmp_buf = (void *) malloc(count * extent); - - MPI_Sendrecv(sendbuf, count, datatype, rank, tag, - recvbuf, count, datatype, rank, tag, comm, &status); + tmp_buf = (void *) xbt_malloc(count * extent); + int is_commutative = smpi_op_is_commute(op); mask = 1; - relrank = (rank - root + comm_size) % comm_size; + + int lroot; + if (is_commutative) + lroot = root; + else + lroot = 0; + relrank = (rank - lroot + comm_size) % comm_size; + + smpi_datatype_extent(datatype, &true_lb, &true_extent); + + /* adjust for potential negative lower bound in datatype */ + tmp_buf = (void *)((char*)tmp_buf - true_lb); + + /* If I'm not the root, then my recvbuf may not be valid, therefore + I have to allocate a temporary one */ + if (rank != root) { + recvbuf = (void *) malloc(count*(max(extent,true_extent))); + recvbuf = (void *)((char*)recvbuf - true_lb); + } + if ((rank != root) || (sendbuf != MPI_IN_PLACE)) { + smpi_datatype_copy(sendbuf, count, datatype, recvbuf,count, datatype); + } while (mask < comm_size) { /* Receive */ if ((mask & relrank) == 0) { source = (relrank | mask); if (source < comm_size) { - source = (source + root) % comm_size; - MPI_Recv(tmp_buf, count, datatype, source, tag, comm, &status); - star_reduction(op, tmp_buf, recvbuf, &count, &datatype); + source = (source + lroot) % comm_size; + smpi_mpi_recv(tmp_buf, count, datatype, source, tag, comm, &status); + + if (is_commutative) { + smpi_op_apply(op, tmp_buf, recvbuf, &count, &datatype); + } else { + smpi_op_apply(op, recvbuf, tmp_buf, &count, &datatype); + smpi_datatype_copy(tmp_buf, count, datatype,recvbuf, count, datatype); + } } } else { - dst = ((relrank & (~mask)) + root) % comm_size; - MPI_Send(recvbuf, count, datatype, dst, tag, comm); + dst = ((relrank & (~mask)) + lroot) % comm_size; + smpi_mpi_send(recvbuf, count, datatype, dst, tag, comm); break; } mask <<= 1; } + if (!is_commutative && (root != 0)){ + if (rank == 0){ + smpi_mpi_send(recvbuf, count, datatype, root,tag, comm); + }else if (rank == root){ + smpi_mpi_recv(recvbuf, count, datatype, 0, tag, comm, &status); + } + } + + if (rank != root) { + xbt_free(recvbuf); + } free(tmp_buf); return 0;