X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e631173bebbd716f33286a72e58d50cf1b79057a..7caa958a78f00f5474f026a068c59cad3d964a15:/src/smpi/smpi_pmpi.cpp?ds=sidebyside diff --git a/src/smpi/smpi_pmpi.cpp b/src/smpi/smpi_pmpi.cpp index 85fd0e5dfe..7e9d901fbf 100644 --- a/src/smpi/smpi_pmpi.cpp +++ b/src/smpi/smpi_pmpi.cpp @@ -3,9 +3,17 @@ /* 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 - -#include "private.h" +#include "simgrid/s4u/Engine.hpp" +#include "simgrid/s4u/Host.hpp" +#include "src/smpi/private.h" +#include "src/smpi/smpi_comm.hpp" +#include "src/smpi/smpi_coll.hpp" +#include "src/smpi/smpi_datatype_derived.hpp" +#include "src/smpi/smpi_op.hpp" +#include "src/smpi/smpi_process.hpp" +#include "src/smpi/smpi_request.hpp" +#include "src/smpi/smpi_status.hpp" +#include "src/smpi/smpi_win.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi, "Logging specific to SMPI (pmpi)"); @@ -24,7 +32,9 @@ extern "C" { // Obviously, the C MPI interface should use the C linkage int PMPI_Init(int *argc, char ***argv) { - // PMPI_Init is call only one time by only by SMPI process + xbt_assert(simgrid::s4u::Engine::isInitialized(), + "Your MPI program was not properly initialized. The easiest is to use smpirun to start it."); + // PMPI_Init is called only once per SMPI process int already_init; MPI_Initialized(&already_init); if(already_init == 0){ @@ -74,7 +84,7 @@ int PMPI_Get_version (int *version,int *subversion){ int PMPI_Get_library_version (char *version,int *len){ smpi_bench_end(); - snprintf(version,MPI_MAX_LIBRARY_VERSION_STRING,"SMPI Version %d.%d. Copyright The Simgrid Team 2007-2015", + snprintf(version, MPI_MAX_LIBRARY_VERSION_STRING, "SMPI Version %d.%d. Copyright The Simgrid Team 2007-2017", SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR); *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version); smpi_bench_begin(); @@ -616,8 +626,8 @@ int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag retval = MPI_ERR_ARG; } else if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid()) { - retval = MPI_ERR_TYPE; + } else if (not datatype->is_valid()) { + retval = MPI_ERR_TYPE; } else if (dst == MPI_PROC_NULL) { retval = MPI_SUCCESS; } else { @@ -639,8 +649,8 @@ int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag retval = MPI_ERR_ARG; } else if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid()) { - retval = MPI_ERR_TYPE; + } else if (not datatype->is_valid()) { + retval = MPI_ERR_TYPE; } else if (src == MPI_PROC_NULL) { retval = MPI_SUCCESS; } else { @@ -662,8 +672,8 @@ int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int ta retval = MPI_ERR_ARG; } else if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid()) { - retval = MPI_ERR_TYPE; + } else if (not datatype->is_valid()) { + retval = MPI_ERR_TYPE; } else if (dst == MPI_PROC_NULL) { retval = MPI_SUCCESS; } else { @@ -744,8 +754,8 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MP retval = MPI_ERR_RANK; } else if ((count < 0) || (buf==nullptr && count > 0)) { retval = MPI_ERR_COUNT; - } else if (!datatype->is_valid()) { - retval = MPI_ERR_TYPE; + } else if (not datatype->is_valid()) { + retval = MPI_ERR_TYPE; } else if(tag<0 && tag != MPI_ANY_TAG){ retval = MPI_ERR_TAG; } else { @@ -794,8 +804,8 @@ int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MP retval = MPI_ERR_RANK; } else if ((count < 0) || (buf==nullptr && count > 0)) { retval = MPI_ERR_COUNT; - } else if (!datatype->is_valid()) { - retval = MPI_ERR_TYPE; + } else if (not datatype->is_valid()) { + retval = MPI_ERR_TYPE; } else if(tag<0 && tag != MPI_ANY_TAG){ retval = MPI_ERR_TAG; } else { @@ -842,8 +852,8 @@ int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, M retval = MPI_ERR_RANK; } else if ((count < 0)|| (buf==nullptr && count > 0)) { retval = MPI_ERR_COUNT; - } else if (!datatype->is_valid()) { - retval = MPI_ERR_TYPE; + } else if (not datatype->is_valid()) { + retval = MPI_ERR_TYPE; } else if(tag<0 && tag != MPI_ANY_TAG){ retval = MPI_ERR_TAG; } else { @@ -889,8 +899,8 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI retval = MPI_ERR_RANK; } else if ((count < 0) || (buf==nullptr && count > 0)) { retval = MPI_ERR_COUNT; - } else if (!datatype->is_valid()) { - retval = MPI_ERR_TYPE; + } else if (not datatype->is_valid()) { + retval = MPI_ERR_TYPE; } else if(tag<0 && tag != MPI_ANY_TAG){ retval = MPI_ERR_TAG; } else { @@ -914,7 +924,7 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE) if (status != MPI_STATUS_IGNORE) { src_traced = comm->group()->index(status->MPI_SOURCE); - if (!TRACE_smpi_view_internals()) { + if (not TRACE_smpi_view_internals()) { TRACE_smpi_recv(rank, src_traced, rank, tag); } } @@ -939,7 +949,7 @@ int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI retval = MPI_ERR_RANK; } else if ((count < 0) || (buf == nullptr && count > 0)) { retval = MPI_ERR_COUNT; - } else if (!datatype->is_valid()) { + } else if (not datatype->is_valid()) { retval = MPI_ERR_TYPE; } else if(tag < 0 && tag != MPI_ANY_TAG){ retval = MPI_ERR_TAG; @@ -958,7 +968,7 @@ int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI } extra->send_size = count*dt_size_send; TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra); - if (!TRACE_smpi_view_internals()) { + if (not TRACE_smpi_view_internals()) { TRACE_smpi_send(rank, rank, dst_traced, tag,count*datatype->size()); } @@ -985,7 +995,7 @@ int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MP retval = MPI_ERR_RANK; } else if ((count < 0) || (buf==nullptr && count > 0)) { retval = MPI_ERR_COUNT; - } else if (!datatype->is_valid()){ + } else if (not datatype->is_valid()) { retval = MPI_ERR_TYPE; } else if(tag<0 && tag != MPI_ANY_TAG){ retval = MPI_ERR_TAG; @@ -1025,7 +1035,7 @@ int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!sendtype->is_valid() || !recvtype->is_valid()) { + } else if (not sendtype->is_valid() || not recvtype->is_valid()) { retval = MPI_ERR_TYPE; } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) { simgrid::smpi::Status::empty(status); @@ -1079,7 +1089,7 @@ int PMPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, MPI_Comm comm, MPI_Status* status) { int retval = 0; - if (!datatype->is_valid()) { + if (not datatype->is_valid()) { return MPI_ERR_TYPE; } else if (count < 0) { return MPI_ERR_COUNT; @@ -1378,7 +1388,7 @@ int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm c if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid()) { + } else if (not datatype->is_valid()) { retval = MPI_ERR_ARG; } else { int rank = comm != MPI_COMM_NULL ? smpi_process()->index() : -1; @@ -1511,7 +1521,6 @@ int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recv int rank = comm != MPI_COMM_NULL ? smpi_process()->index() : -1; int root_traced = comm->group()->index(root); - int i = 0; int size = comm->size(); instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1); extra->type = TRACING_GATHERV; @@ -1527,9 +1536,9 @@ int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recv int dt_size_recv = 1; if (known == 0) dt_size_recv = recvtype->size(); - if ((comm->rank() == root)) { + if (comm->rank() == root) { extra->recvcounts = xbt_new(int, size); - for (i = 0; i < size; i++) // copy data to avoid bad free + for (int i = 0; i < size; i++) // copy data to avoid bad free extra->recvcounts[i] = recvcounts[i] * dt_size_recv; } TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra); @@ -1650,8 +1659,8 @@ int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (((comm->rank() == root) && (!sendtype->is_valid())) || - ((recvbuf != MPI_IN_PLACE) && (!recvtype->is_valid()))) { + } else if (((comm->rank() == root) && (not sendtype->is_valid())) || + ((recvbuf != MPI_IN_PLACE) && (not recvtype->is_valid()))) { retval = MPI_ERR_TYPE; } else if ((sendbuf == recvbuf) || ((comm->rank()==root) && sendcount>0 && (sendbuf == nullptr))){ @@ -1710,7 +1719,6 @@ int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs, } int rank = comm != MPI_COMM_NULL ? smpi_process()->index() : -1; int root_traced = comm->group()->index(root); - int i = 0; int size = comm->size(); instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1); extra->type = TRACING_SCATTERV; @@ -1721,9 +1729,9 @@ int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs, int dt_size_send = 1; if (known == 0) dt_size_send = sendtype->size(); - if ((comm->rank() == root)) { + if (comm->rank() == root) { extra->sendcounts = xbt_new(int, size); - for (i = 0; i < size; i++) // copy data to avoid bad free + for (int i = 0; i < size; i++) // copy data to avoid bad free extra->sendcounts[i] = sendcounts[i] * dt_size_send; } extra->datatype2 = encode_datatype(recvtype, &known); @@ -1750,7 +1758,7 @@ int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid() || op == MPI_OP_NULL) { + } else if (not datatype->is_valid() || op == MPI_OP_NULL) { retval = MPI_ERR_ARG; } else { int rank = comm != MPI_COMM_NULL ? smpi_process()->index() : -1; @@ -1781,7 +1789,7 @@ int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datat int retval = 0; smpi_bench_end(); - if (!datatype->is_valid() || op == MPI_OP_NULL) { + if (not datatype->is_valid() || op == MPI_OP_NULL) { retval = MPI_ERR_ARG; } else { op->apply(inbuf, inoutbuf, &count, datatype); @@ -1799,7 +1807,7 @@ int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatyp if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid()) { + } else if (not datatype->is_valid()) { retval = MPI_ERR_TYPE; } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; @@ -1843,7 +1851,7 @@ int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MP if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid()) { + } else if (not datatype->is_valid()) { retval = MPI_ERR_TYPE; } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; @@ -1876,7 +1884,7 @@ int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid()) { + } else if (not datatype->is_valid()) { retval = MPI_ERR_TYPE; } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; @@ -1915,7 +1923,7 @@ int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datat if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid()) { + } else if (not datatype->is_valid()) { retval = MPI_ERR_TYPE; } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; @@ -1968,7 +1976,7 @@ int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount, if (comm == MPI_COMM_NULL) { retval = MPI_ERR_COMM; - } else if (!datatype->is_valid()) { + } else if (not datatype->is_valid()) { retval = MPI_ERR_TYPE; } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; @@ -2091,9 +2099,8 @@ int PMPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype extra->recvcounts = xbt_new(int, size); extra->sendcounts = xbt_new(int, size); int known = 0; - int dt_size_recv = 1; extra->datatype2 = encode_datatype(recvtype, &known); - dt_size_recv = recvtype->size(); + int dt_size_recv = recvtype->size(); void* sendtmpbuf = static_cast(sendbuf); int* sendtmpcounts = sendcounts; @@ -2157,7 +2164,7 @@ int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count) { if (status == nullptr || count == nullptr) { return MPI_ERR_ARG; - } else if (!datatype->is_valid()) { + } else if (not datatype->is_valid()) { return MPI_ERR_TYPE; } else { size_t size = datatype->size(); @@ -2619,7 +2626,7 @@ int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, } else if ((origin_count < 0 || target_count < 0) || (origin_addr==nullptr && origin_count > 0)){ retval = MPI_ERR_COUNT; - } else if ((!origin_datatype->is_valid()) || (!target_datatype->is_valid())) { + } else if ((not origin_datatype->is_valid()) || (not target_datatype->is_valid())) { retval = MPI_ERR_TYPE; } else { int rank = smpi_process()->index(); @@ -2654,7 +2661,7 @@ int PMPI_Rget( void *origin_addr, int origin_count, MPI_Datatype origin_datatype } else if ((origin_count < 0 || target_count < 0) || (origin_addr==nullptr && origin_count > 0)){ retval = MPI_ERR_COUNT; - } else if ((!origin_datatype->is_valid()) || (!target_datatype->is_valid())) { + } else if ((not origin_datatype->is_valid()) || (not target_datatype->is_valid())) { retval = MPI_ERR_TYPE; } else if(request == nullptr){ retval = MPI_ERR_REQUEST; @@ -2690,7 +2697,7 @@ int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, } else if ((origin_count < 0 || target_count < 0) || (origin_addr==nullptr && origin_count > 0)){ retval = MPI_ERR_COUNT; - } else if ((!origin_datatype->is_valid()) || (!target_datatype->is_valid())) { + } else if ((not origin_datatype->is_valid()) || (not target_datatype->is_valid())) { retval = MPI_ERR_TYPE; } else { int rank = smpi_process()->index(); @@ -2726,7 +2733,7 @@ int PMPI_Rput( void *origin_addr, int origin_count, MPI_Datatype origin_datatype } else if ((origin_count < 0 || target_count < 0) || (origin_addr==nullptr && origin_count > 0)){ retval = MPI_ERR_COUNT; - } else if ((!origin_datatype->is_valid()) || (!target_datatype->is_valid())) { + } else if ((not origin_datatype->is_valid()) || (not target_datatype->is_valid())) { retval = MPI_ERR_TYPE; } else if(request == nullptr){ retval = MPI_ERR_REQUEST; @@ -2763,8 +2770,7 @@ int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_da } else if ((origin_count < 0 || target_count < 0) || (origin_addr==nullptr && origin_count > 0)){ retval = MPI_ERR_COUNT; - } else if ((!origin_datatype->is_valid()) || - (!target_datatype->is_valid())) { + } else if ((not origin_datatype->is_valid()) || (not target_datatype->is_valid())) { retval = MPI_ERR_TYPE; } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; @@ -2801,8 +2807,7 @@ int PMPI_Raccumulate( void *origin_addr, int origin_count, MPI_Datatype origin_d } else if ((origin_count < 0 || target_count < 0) || (origin_addr==nullptr && origin_count > 0)){ retval = MPI_ERR_COUNT; - } else if ((!origin_datatype->is_valid()) || - (!target_datatype->is_valid())) { + } else if ((not origin_datatype->is_valid()) || (not target_datatype->is_valid())) { retval = MPI_ERR_TYPE; } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; @@ -2842,9 +2847,8 @@ MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){ (origin_addr==nullptr && origin_count > 0 && op != MPI_NO_OP) || (result_addr==nullptr && result_count > 0)){ retval = MPI_ERR_COUNT; - } else if ((origin_datatype!=MPI_DATATYPE_NULL && !origin_datatype->is_valid()) || - (!target_datatype->is_valid())|| - (!result_datatype->is_valid())) { + } else if ((origin_datatype != MPI_DATATYPE_NULL && not origin_datatype->is_valid()) || + (not target_datatype->is_valid()) || (not result_datatype->is_valid())) { retval = MPI_ERR_TYPE; } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; @@ -2885,9 +2889,8 @@ MPI_Datatype target_datatype, MPI_Op op, MPI_Win win, MPI_Request* request){ (origin_addr==nullptr && origin_count > 0 && op != MPI_NO_OP) || (result_addr==nullptr && result_count > 0)){ retval = MPI_ERR_COUNT; - } else if ((origin_datatype!=MPI_DATATYPE_NULL && !origin_datatype->is_valid()) || - (!target_datatype->is_valid())|| - (!result_datatype->is_valid())) { + } else if ((origin_datatype != MPI_DATATYPE_NULL && not origin_datatype->is_valid()) || + (not target_datatype->is_valid()) || (not result_datatype->is_valid())) { retval = MPI_ERR_TYPE; } else if (op == MPI_OP_NULL) { retval = MPI_ERR_OP; @@ -2930,7 +2933,7 @@ int PMPI_Compare_and_swap(void *origin_addr, void *compare_addr, retval = MPI_ERR_ARG; } else if (origin_addr==nullptr || result_addr==nullptr || compare_addr==nullptr){ retval = MPI_ERR_COUNT; - } else if (!datatype->is_valid()) { + } else if (not datatype->is_valid()) { retval = MPI_ERR_TYPE; } else { int rank = smpi_process()->index(); @@ -3495,7 +3498,7 @@ int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){ int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) { if(incount<0 || outcount < 0 || inbuf==nullptr || outbuf==nullptr) return MPI_ERR_ARG; - if(!type->is_valid()) + if (not type->is_valid()) return MPI_ERR_TYPE; if(comm==MPI_COMM_NULL) return MPI_ERR_COMM; @@ -3505,7 +3508,7 @@ int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outco int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) { if(incount<0 || outcount < 0|| inbuf==nullptr || outbuf==nullptr) return MPI_ERR_ARG; - if(!type->is_valid()) + if (not type->is_valid()) return MPI_ERR_TYPE; if(comm==MPI_COMM_NULL) return MPI_ERR_COMM; @@ -3515,7 +3518,7 @@ int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int out int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) { if(incount<0) return MPI_ERR_ARG; - if(!datatype->is_valid()) + if (not datatype->is_valid()) return MPI_ERR_TYPE; if(comm==MPI_COMM_NULL) return MPI_ERR_COMM;