From: pini Date: Thu, 25 Mar 2010 14:41:50 +0000 (+0000) Subject: More MPI calls support in SMPI X-Git-Tag: SVN~362 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a3cfaa2faa67ffc56086239c68bc548fc48f3e62 More MPI calls support in SMPI git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7378 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index a4a815a0f8..4fe9a6d836 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -23,6 +23,7 @@ SG_BEGIN_DECL() #define SMPI_RAND_SEED 5 #define MPI_ANY_SOURCE -1 +#define MPI_PROC_NULL -2 #define MPI_ANY_TAG -1 #define MPI_UNDEFINED -1 @@ -45,6 +46,8 @@ SG_BEGIN_DECL() #define MPI_UNEQUAL 2 #define MPI_CONGRUENT 3 +#define MPI_WTIME_IS_GLOBAL 1 + typedef ptrdiff_t MPI_Aint; typedef long long MPI_Offset; @@ -149,8 +152,12 @@ XBT_PUBLIC(int) MPI_Is_thread_main(int* flag); XBT_PUBLIC(int) MPI_Abort(MPI_Comm comm, int errorcode); XBT_PUBLIC(double) MPI_Wtime(void); +XBT_PUBLIC(int) MPI_Address(void *location, MPI_Aint *address); + +XBT_PUBLIC(int) MPI_Type_free(MPI_Datatype* datatype); XBT_PUBLIC(int) MPI_Type_size(MPI_Datatype datatype, size_t* size); XBT_PUBLIC(int) MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint* extent); +XBT_PUBLIC(int) MPI_Type_extent(MPI_Datatype datatype, MPI_Aint* extent); XBT_PUBLIC(int) MPI_Type_lb(MPI_Datatype datatype, MPI_Aint* disp); XBT_PUBLIC(int) MPI_Type_ub(MPI_Datatype datatype, MPI_Aint* disp); @@ -206,6 +213,7 @@ XBT_PUBLIC(int) MPI_Scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, XBT_PUBLIC(int) MPI_Scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); XBT_PUBLIC(int) MPI_Reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm); XBT_PUBLIC(int) MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); +XBT_PUBLIC(int) MPI_Scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); XBT_PUBLIC(int) MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); XBT_PUBLIC(int) MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm); XBT_PUBLIC(int) MPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm); diff --git a/src/smpi/private.h b/src/smpi/private.h index bc1580e55c..be53ddaaea 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -83,6 +83,7 @@ void smpi_mpi_scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* void smpi_mpi_scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); void smpi_mpi_reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm); 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 nary_tree_bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, int arity); void nary_tree_barrier(MPI_Comm comm, int arity); diff --git a/src/smpi/smpi_base.c b/src/smpi/smpi_base.c index a48592d841..a85dcd5be4 100644 --- a/src/smpi/smpi_base.c +++ b/src/smpi/smpi_base.c @@ -545,3 +545,47 @@ FIXME: buggy implementation xbt_free(requests); */ } + +void smpi_mpi_scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { + int system_tag = 666; + int rank, size, other, index, datasize; + int total; + MPI_Request* requests; + void** tmpbufs; + + rank = smpi_comm_rank(comm); + size = smpi_comm_size(comm); + datasize = smpi_datatype_size(datatype); + // Local copy from self + memcpy(recvbuf, sendbuf, count * datasize * sizeof(char)); + // Send/Recv buffers to/from others; + total = rank + (size - (rank + 1)); + requests = xbt_new(MPI_Request, total); + tmpbufs = xbt_new(void*, rank); + index = 0; + for(other = 0; other < rank; other++) { + tmpbufs[index] = xbt_malloc(count * datasize); + requests[index] = smpi_mpi_irecv(tmpbufs[index], count, datatype, other, system_tag, comm); + index++; + } + for(other = rank + 1; other < size; other++) { + requests[index] = smpi_mpi_isend(sendbuf, count, datatype, other, system_tag, comm); + index++; + } + // Wait for completion of all comms. + for(other = 0; other < total; other++) { + index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE); + if(index == MPI_UNDEFINED) { + break; + } + if(index < rank) { + // #Request is below rank: it's a irecv + smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype); + } + } + for(index = 0; index < size - 1; index++) { + xbt_free(tmpbufs[index]); + } + xbt_free(tmpbufs); + xbt_free(requests); +} diff --git a/src/smpi/smpi_mpi.c b/src/smpi/smpi_mpi.c index 3dda18f396..aab96e300c 100644 --- a/src/smpi/smpi_mpi.c +++ b/src/smpi/smpi_mpi.c @@ -73,6 +73,33 @@ double MPI_Wtime(void) { return time; } +int MPI_Address(void *location, MPI_Aint *address) { + int retval; + + smpi_bench_end(-1, NULL); + if(!address) { + retval = MPI_ERR_ARG; + } else { + *address = (MPI_Aint)location; + } + smpi_bench_begin(-1, NULL); + return retval; +} + +int MPI_Type_free(MPI_Datatype* datatype) { + int retval; + + smpi_bench_end(-1, NULL); + if(!datatype) { + retval = MPI_ERR_ARG; + } else { + // FIXME: always fail for now + retval = MPI_ERR_TYPE; + } + smpi_bench_begin(-1, NULL); + return retval; +} + int MPI_Type_size(MPI_Datatype datatype, size_t* size) { int retval; @@ -104,6 +131,22 @@ int MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint* extent) { return retval; } +int MPI_Type_extent(MPI_Datatype datatype, MPI_Aint* extent) { + int retval; + MPI_Aint dummy; + + smpi_bench_end(-1, NULL); + if(datatype == MPI_DATATYPE_NULL) { + retval = MPI_ERR_TYPE; + } else if(extent == NULL) { + retval = MPI_ERR_ARG; + } else { + retval = smpi_datatype_extent(datatype, &dummy, extent); + } + smpi_bench_begin(-1, NULL); + return retval; +} + int MPI_Type_lb(MPI_Datatype datatype, MPI_Aint* disp) { int retval; @@ -1017,6 +1060,25 @@ int MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype return retval; } +int MPI_Scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { + int retval; + int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1; + + smpi_bench_end(rank, "Scan"); + 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_scan(sendbuf, recvbuf, count, datatype, op, comm); + retval = MPI_SUCCESS; + } + smpi_bench_begin(rank, "Scan"); + return retval; +} + int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { int retval, i, size, count; int* displs;