X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/43f7ca1cac5ab1858e318fdd6239d0a0c3b3d893..ebf8e9cb9961c8310418ddcb7e6cee64f750cf8d:/src/smpi/colls/smpi_default_selector.cpp diff --git a/src/smpi/colls/smpi_default_selector.cpp b/src/smpi/colls/smpi_default_selector.cpp index d3736cc81b..d6126c7d69 100644 --- a/src/smpi/colls/smpi_default_selector.cpp +++ b/src/smpi/colls/smpi_default_selector.cpp @@ -1,13 +1,12 @@ /* selector with default/naive Simgrid algorithms. These should not be trusted for performance evaluations */ -/* Copyright (c) 2009-2010, 2013-2017. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2009-2019. 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 "smpi_process.hpp" +#include "colls_private.hpp" +#include "src/smpi/include/smpi_actor.hpp" namespace simgrid{ namespace smpi{ @@ -26,7 +25,7 @@ int Coll_barrier_default::barrier(MPI_Comm comm) int Coll_gather_default::gather(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { - int system_tag = COLL_TAG_GATHER; + const int system_tag = COLL_TAG_GATHER; MPI_Aint lb = 0; MPI_Aint recvext = 0; @@ -75,9 +74,8 @@ int Coll_reduce_scatter_default::reduce_scatter(void *sendbuf, void *recvbuf, in count += recvcounts[i]; } void *tmpbuf = static_cast(smpi_get_tmp_sendbuffer(count*datatype->get_extent())); - int ret = MPI_SUCCESS; - ret = Coll_reduce_default::reduce(sendbuf, tmpbuf, count, datatype, op, 0, comm); + int ret = Coll_reduce_default::reduce(sendbuf, tmpbuf, count, datatype, op, 0, comm); if(ret==MPI_SUCCESS) ret = Colls::scatterv(tmpbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm); xbt_free(displs); @@ -89,7 +87,7 @@ int Coll_reduce_scatter_default::reduce_scatter(void *sendbuf, void *recvbuf, in int Coll_allgather_default::allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,int recvcount, MPI_Datatype recvtype, MPI_Comm comm) { - int system_tag = COLL_TAG_ALLGATHER; + const int system_tag = COLL_TAG_ALLGATHER; MPI_Aint lb = 0; MPI_Aint recvext = 0; MPI_Request *requests; @@ -126,7 +124,7 @@ int Coll_allgather_default::allgather(void *sendbuf, int sendcount, MPI_Datatype int Coll_allgatherv_default::allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm) { - int system_tag = COLL_TAG_ALLGATHERV; + const int system_tag = COLL_TAG_ALLGATHERV; MPI_Aint lb = 0; MPI_Aint recvext = 0; @@ -162,7 +160,7 @@ int Coll_allgatherv_default::allgatherv(void *sendbuf, int sendcount, MPI_Dataty int Coll_scatter_default::scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { - int system_tag = COLL_TAG_SCATTER; + const int system_tag = COLL_TAG_SCATTER; MPI_Aint lb = 0; MPI_Aint sendext = 0; MPI_Request *requests; @@ -205,7 +203,7 @@ int Coll_scatter_default::scatter(void *sendbuf, int sendcount, MPI_Datatype sen int Coll_reduce_default::reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) { - int system_tag = COLL_TAG_REDUCE; + const int system_tag = COLL_TAG_REDUCE; MPI_Aint lb = 0; MPI_Aint dataext = 0; @@ -213,6 +211,8 @@ int Coll_reduce_default::reduce(void *sendbuf, void *recvbuf, int count, MPI_Dat int rank = comm->rank(); int size = comm->size(); + if (size <= 0) + return MPI_ERR_COMM; //non commutative case, use a working algo from openmpi if (op != MPI_OP_NULL && not op->is_commutative()) { return Coll_reduce_ompi_basic_linear::reduce(sendtmpbuf, recvbuf, count, datatype, op, root, comm); @@ -237,10 +237,7 @@ int Coll_reduce_default::reduce(void *sendbuf, void *recvbuf, int count, MPI_Dat int index = 0; for (int src = 0; src < size; src++) { if (src != root) { - if (not smpi_process()->replaying()) - tmpbufs[index] = xbt_malloc(count * dataext); - else - tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext); + tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext); requests[index] = Request::irecv_init(tmpbufs[index], count, datatype, src, system_tag, comm); index++; @@ -275,9 +272,9 @@ int Coll_reduce_default::reduce(void *sendbuf, void *recvbuf, int count, MPI_Dat int Coll_allreduce_default::allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { int ret; - ret = Colls::reduce(sendbuf, recvbuf, count, datatype, op, 0, comm); + ret = Coll_reduce_default::reduce(sendbuf, recvbuf, count, datatype, op, 0, comm); if(ret==MPI_SUCCESS) - ret = Colls::bcast(recvbuf, count, datatype, 0, comm); + ret = Coll_bcast_default::bcast(recvbuf, count, datatype, 0, comm); return ret; } @@ -291,9 +288,7 @@ int Coll_alltoall_default::alltoall( void *sbuf, int scount, MPI_Datatype sdtype int Coll_alltoallv_default::alltoallv(void *sendbuf, int *sendcounts, int *senddisps, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm) { - int system_tag = 889; - int i; - int count; + const int system_tag = 889; MPI_Aint lb = 0; MPI_Aint sendext = 0; MPI_Aint recvext = 0; @@ -311,9 +306,9 @@ int Coll_alltoallv_default::alltoallv(void *sendbuf, int *sendcounts, int *sendd if (err == MPI_SUCCESS && size > 1) { /* Initiate all send/recv to/from others. */ requests = xbt_new(MPI_Request, 2 * (size - 1)); - count = 0; + int count = 0; /* Create all receives that will be posted first */ - for (i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) { if (i != rank && recvcounts[i] != 0) { requests[count] = Request::irecv_init(static_cast(recvbuf) + recvdisps[i] * recvext, recvcounts[i], recvtype, i, system_tag, comm); @@ -323,7 +318,7 @@ int Coll_alltoallv_default::alltoallv(void *sendbuf, int *sendcounts, int *sendd } } /* Now create all sends */ - for (i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) { if (i != rank && sendcounts[i] != 0) { requests[count] = Request::isend_init(static_cast(sendbuf) + senddisps[i] * sendext, sendcounts[i], sendtype, i, system_tag, comm); @@ -336,7 +331,7 @@ int Coll_alltoallv_default::alltoallv(void *sendbuf, int *sendcounts, int *sendd Request::startall(count, requests); XBT_DEBUG("<%d> wait for %d requests", rank, count); Request::waitall(count, requests, MPI_STATUS_IGNORE); - for(i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if(requests[i]!=MPI_REQUEST_NULL) Request::unref(&requests[i]); }