From: Augustin Degomme Date: Mon, 8 Jul 2013 13:01:53 +0000 (+0200) Subject: quick and naive implementation of the MPI_Exscan collective X-Git-Tag: v3_9_90~187 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cd701c7e68bbf6598c9350e19389c0b6952bdeef quick and naive implementation of the MPI_Exscan collective --- diff --git a/src/smpi/instr_smpi.c b/src/smpi/instr_smpi.c index 2aa3d53f0c..dca11e4f44 100644 --- a/src/smpi/instr_smpi.c +++ b/src/smpi/instr_smpi.c @@ -38,6 +38,7 @@ static const char *smpi_colors[] ={ "reduce", "0 1 0", "reducescatter", "0.52 1 0.52", "scan", "1 0.58 0.23", + "exscan", "1 0.54 0.25", "scatterv", "0.52 0 0.52", "scatter", "1 0.74 0.54", "computing", "0 1 1", diff --git a/src/smpi/private.h b/src/smpi/private.h index 1e2a3c2142..52b9ed8cc2 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -255,6 +255,8 @@ void smpi_mpi_allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); +void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); void nary_tree_bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, int arity); diff --git a/src/smpi/smpi_base.c b/src/smpi/smpi_base.c index 73fe79ad64..8afbcae3cb 100644 --- a/src/smpi/smpi_base.c +++ b/src/smpi/smpi_base.c @@ -1298,3 +1298,56 @@ void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count, xbt_free(tmpbufs); xbt_free(requests); } + +void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, + MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) +{ + int system_tag = 888; + int rank, size, other, index; + MPI_Aint lb = 0, dataext = 0; + MPI_Request *requests; + void **tmpbufs; + int recvbuf_is_empty=1; + rank = smpi_comm_rank(comm); + size = smpi_comm_size(comm); + + // FIXME: check for errors + smpi_datatype_extent(datatype, &lb, &dataext); + + // Send/Recv buffers to/from others; + requests = xbt_new(MPI_Request, size - 1); + tmpbufs = xbt_new(void *, rank); + index = 0; + for(other = 0; other < rank; other++) { + // FIXME: possibly overkill we we have contiguous/noncontiguous data + // mapping... + tmpbufs[index] = xbt_malloc(count * dataext); + requests[index] = + smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag, + comm); + index++; + } + for(other = rank + 1; other < size; other++) { + requests[index] = + smpi_isend_init(sendbuf, count, datatype, other, system_tag, comm); + index++; + } + // Wait for completion of all comms. + smpi_mpi_startall(size - 1, requests); + for(other = 0; other < size - 1; other++) { + index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE); + if(index == MPI_UNDEFINED) { + break; + } + if(index < rank) { + if(recvbuf_is_empty) smpi_datatype_copy(tmpbufs[index], count, datatype, recvbuf, count, datatype); + // #Request is below rank: it's a irecv + else smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype); + } + } + for(index = 0; index < rank; index++) { + xbt_free(tmpbufs[index]); + } + xbt_free(tmpbufs); + xbt_free(requests); +} diff --git a/src/smpi/smpi_pmpi.c b/src/smpi/smpi_pmpi.c index 25acf31d7e..df6074bdbd 100644 --- a/src/smpi/smpi_pmpi.c +++ b/src/smpi/smpi_pmpi.c @@ -2013,6 +2013,34 @@ int PMPI_Scan(void *sendbuf, void *recvbuf, int count, return retval; } +int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, + MPI_Op op, MPI_Comm comm){ + int retval; + + smpi_bench_end(); +#ifdef HAVE_TRACING + int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1; + TRACE_smpi_computing_out(rank); + TRACE_smpi_collective_in(rank, -1, __FUNCTION__); +#endif + if (comm == MPI_COMM_NULL) { + retval = MPI_ERR_COMM; + } else if (datatype == MPI_DATATYPE_NULL) { + retval = MPI_ERR_TYPE; + } else if (op == MPI_OP_NULL) { + retval = MPI_ERR_OP; + } else { + smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm); + retval = MPI_SUCCESS; + } +#ifdef HAVE_TRACING + TRACE_smpi_collective_out(rank, -1, __FUNCTION__); + TRACE_smpi_computing_in(rank); +#endif + smpi_bench_begin(); + return retval; +} + int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { @@ -2686,11 +2714,6 @@ int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *se NOT_YET_IMPLEMENTED } -int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, - MPI_Op op, MPI_Comm comm){ - NOT_YET_IMPLEMENTED -} - int PMPI_Comm_set_name(MPI_Comm comm, char* name){ NOT_YET_IMPLEMENTED }