X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e709643ef0c5b61c6c878016c418bffa2b1b20cd..9cfb1e3cb58d1b202719b8380fbca27f7dcef9c4:/src/smpi/mpi/smpi_request.cpp diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index 2bc696f74f..390fed1ce7 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -18,6 +18,7 @@ #include "src/smpi/include/smpi_actor.hpp" #include +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_request, smpi, "Logging specific to SMPI (request)"); @@ -61,7 +62,6 @@ Request::Request(const void* buf, int count, MPI_Datatype datatype, int src, int else refcount_ = 0; cancelled_ = 0; - generalized_funcs=nullptr; nbc_requests_=nullptr; nbc_requests_size_=0; init_buffer(count); @@ -82,7 +82,6 @@ void Request::unref(MPI_Request* request) if((*request)->refcount_==0){ if ((*request)->flags_ & MPI_REQ_GENERALIZED){ ((*request)->generalized_funcs)->free_fn(((*request)->generalized_funcs)->extra_state); - delete (*request)->generalized_funcs; }else{ Comm::unref((*request)->comm_); Datatype::unref((*request)->old_type_); @@ -153,15 +152,15 @@ void Request::init_buffer(int count){ bool Request::match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl*) { - MPI_Request ref = static_cast(a); - MPI_Request req = static_cast(b); + auto ref = static_cast(a); + auto req = static_cast(b); return match_common(req, req, ref); } bool Request::match_send(void* a, void* b, simgrid::kernel::activity::CommImpl*) { - MPI_Request ref = static_cast(a); - MPI_Request req = static_cast(b); + auto ref = static_cast(a); + auto req = static_cast(b); return match_common(req, ref, req); } @@ -337,8 +336,8 @@ void Request::sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype void *recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status) { - MPI_Request requests[2]; - MPI_Status stats[2]; + std::array requests; + std::array stats; int myid = simgrid::s4u::this_actor::get_pid(); if ((comm->group()->actor(dst)->get_pid() == myid) && (comm->group()->actor(src)->get_pid() == myid)) { Datatype::copy(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype); @@ -352,8 +351,8 @@ void Request::sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype } requests[0] = isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm); requests[1] = irecv_init(recvbuf, recvcount, recvtype, src, recvtag, comm); - startall(2, requests); - waitall(2, requests, stats); + startall(2, requests.data()); + waitall(2, requests.data(), stats.data()); unref(&requests[0]); unref(&requests[1]); if(status != MPI_STATUS_IGNORE) { @@ -552,11 +551,13 @@ void Request::cancel() } int Request::test(MPI_Request * request, MPI_Status * status, int* flag) { - //assume that request is not MPI_REQUEST_NULL (filtered in PMPI_Test or testall before) + // assume that *request is not MPI_REQUEST_NULL (filtered in PMPI_Test or testall before) // to avoid deadlocks if used as a break condition, such as // while (MPI_Test(request, flag, status) && flag) dostuff... // because the time will not normally advance when only calls to MPI_Test are made -> deadlock // multiplier to the sleeptime, to increase speed of execution, each failed test will increase it + xbt_assert(*request != MPI_REQUEST_NULL); + static int nsleeps = 1; int ret = MPI_SUCCESS; @@ -586,23 +587,20 @@ int Request::test(MPI_Request * request, MPI_Status * status, int* flag) { return ret; } } - if (*request != MPI_REQUEST_NULL && - ((*request)->flags_ & MPI_REQ_GENERALIZED) - && !((*request)->flags_ & MPI_REQ_COMPLETE)) + if (((*request)->flags_ & MPI_REQ_GENERALIZED) && !((*request)->flags_ & MPI_REQ_COMPLETE)) *flag=0; if (*flag) { - finish_wait(request,status); + finish_wait(request, status); // may invalidate *request if (*request != MPI_REQUEST_NULL && ((*request)->flags_ & MPI_REQ_GENERALIZED)){ + MPI_Status tmp_status; MPI_Status* mystatus; - if(status==MPI_STATUS_IGNORE){ - mystatus=new MPI_Status(); + if (status == MPI_STATUS_IGNORE) { + mystatus = &tmp_status; Status::empty(mystatus); - }else{ - mystatus=status; + } else { + mystatus = status; } ret = ((*request)->generalized_funcs)->query_fn(((*request)->generalized_funcs)->extra_state, mystatus); - if(status==MPI_STATUS_IGNORE) - delete mystatus; } nsleeps=1;//reset the number of sleeps we will do next time if (*request != MPI_REQUEST_NULL && ((*request)->flags_ & MPI_REQ_PERSISTENT) == 0) @@ -685,16 +683,15 @@ int Request::testany(int count, MPI_Request requests[], int *index, int* flag, M } else { finish_wait(&requests[*index],status); if (requests[*index] != MPI_REQUEST_NULL && (requests[*index]->flags_ & MPI_REQ_GENERALIZED)){ + MPI_Status tmp_status; MPI_Status* mystatus; - if(status==MPI_STATUS_IGNORE){ - mystatus=new MPI_Status(); + if (status == MPI_STATUS_IGNORE) { + mystatus = &tmp_status; Status::empty(mystatus); - }else{ - mystatus=status; + } else { + mystatus = status; } ret=(requests[*index]->generalized_funcs)->query_fn((requests[*index]->generalized_funcs)->extra_state, mystatus); - if(status==MPI_STATUS_IGNORE) - delete mystatus; } if (requests[*index] != MPI_REQUEST_NULL && (requests[*index]->flags_ & MPI_REQ_NON_PERSISTENT)) @@ -766,9 +763,9 @@ void Request::iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* static int nsleeps = 1; double speed = s4u::this_actor::get_host()->get_speed(); double maxrate = smpi_cfg_iprobe_cpu_usage(); - MPI_Request request = new Request(nullptr, 0, MPI_CHAR, - source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(source)->get_pid(), - simgrid::s4u::this_actor::get_pid(), tag, comm, MPI_REQ_PERSISTENT | MPI_REQ_RECV); + auto request = new Request(nullptr, 0, MPI_CHAR, + source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(source)->get_pid(), + simgrid::s4u::this_actor::get_pid(), tag, comm, MPI_REQ_PERSISTENT | MPI_REQ_RECV); if (smpi_iprobe_sleep > 0) { /** Compute the number of flops we will sleep **/ s4u::this_actor::exec_init(/*nsleeps: See comment above */ nsleeps * @@ -900,6 +897,9 @@ void Request::finish_wait(MPI_Request* request, MPI_Status * status) int Request::wait(MPI_Request * request, MPI_Status * status) { + // assume that *request is not MPI_REQUEST_NULL (filtered in PMPI_Wait before) + xbt_assert(*request != MPI_REQUEST_NULL); + int ret=MPI_SUCCESS; // Are we waiting on a request meant for non blocking collectives ? // If so, wait for all the subrequests. @@ -943,25 +943,24 @@ int Request::wait(MPI_Request * request, MPI_Status * status) } } - if (*request != MPI_REQUEST_NULL && ((*request)->flags_ & MPI_REQ_GENERALIZED)){ - MPI_Status* mystatus; + if ((*request)->flags_ & MPI_REQ_GENERALIZED) { if(!((*request)->flags_ & MPI_REQ_COMPLETE)){ ((*request)->generalized_funcs)->mutex->lock(); ((*request)->generalized_funcs)->cond->wait(((*request)->generalized_funcs)->mutex); ((*request)->generalized_funcs)->mutex->unlock(); - } - if(status==MPI_STATUS_IGNORE){ - mystatus=new MPI_Status(); + } + MPI_Status tmp_status; + MPI_Status* mystatus; + if (status == MPI_STATUS_IGNORE) { + mystatus = &tmp_status; Status::empty(mystatus); - }else{ - mystatus=status; + } else { + mystatus = status; } ret = ((*request)->generalized_funcs)->query_fn(((*request)->generalized_funcs)->extra_state, mystatus); - if(status==MPI_STATUS_IGNORE) - delete mystatus; } - finish_wait(request,status); + finish_wait(request, status); // may invalidate *request if (*request != MPI_REQUEST_NULL && (((*request)->flags_ & MPI_REQ_NON_PERSISTENT) != 0)) *request = MPI_REQUEST_NULL; return ret; @@ -1117,17 +1116,15 @@ int Request::waitsome(int incount, MPI_Request requests[], int *indices, MPI_Sta MPI_Request Request::f2c(int id) { - char key[KEY_SIZE]; if(id==MPI_FORTRAN_REQUEST_NULL) return MPI_REQUEST_NULL; - return static_cast(F2C::f2c_lookup()->at(get_key(key,id))); + return static_cast(F2C::lookup()->at(id)); } void Request::free_f(int id) { if (id != MPI_FORTRAN_REQUEST_NULL) { - char key[KEY_SIZE]; - F2C::f2c_lookup()->erase(get_key(key, id)); + F2C::lookup()->erase(id); } } @@ -1166,7 +1163,7 @@ int Request::grequest_start(MPI_Grequest_query_function* query_fn, MPI_Grequest_ (*request)->flags_ |= MPI_REQ_GENERALIZED; (*request)->flags_ |= MPI_REQ_PERSISTENT; (*request)->refcount_ = 1; - ((*request)->generalized_funcs) = new s_smpi_mpi_generalized_request_funcs_t; + ((*request)->generalized_funcs) = std::make_unique(); ((*request)->generalized_funcs)->query_fn=query_fn; ((*request)->generalized_funcs)->free_fn=free_fn; ((*request)->generalized_funcs)->cancel_fn=cancel_fn; @@ -1178,7 +1175,7 @@ int Request::grequest_start(MPI_Grequest_query_function* query_fn, MPI_Grequest_ int Request::grequest_complete(MPI_Request request) { - if ((!(request->flags_ & MPI_REQ_GENERALIZED)) || request->generalized_funcs->mutex==NULL) + if ((!(request->flags_ & MPI_REQ_GENERALIZED)) || request->generalized_funcs->mutex == nullptr) return MPI_ERR_REQUEST; request->generalized_funcs->mutex->lock(); request->flags_ |= MPI_REQ_COMPLETE; // in case wait would be called after complete