#include "src/smpi/include/smpi_actor.hpp"
#include <algorithm>
+#include <array>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_request, smpi, "Logging specific to SMPI (request)");
else
refcount_ = 0;
cancelled_ = 0;
- generalized_funcs=nullptr;
nbc_requests_=nullptr;
nbc_requests_size_=0;
init_buffer(count);
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_);
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<MPI_Request, 2> requests;
+ std::array<MPI_Status, 2> 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);
}
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) {
}
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;
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)
} 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))
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.
}
}
- 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;
{
if(id==MPI_FORTRAN_REQUEST_NULL)
return MPI_REQUEST_NULL;
- return static_cast<MPI_Request>(F2C::f2c_lookup()->at(get_key(id)));
+ return static_cast<MPI_Request>(F2C::lookup()->at(id));
}
void Request::free_f(int id)
{
if (id != MPI_FORTRAN_REQUEST_NULL) {
- F2C::f2c_lookup()->erase(get_key(id));
+ F2C::lookup()->erase(id);
}
}
(*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<smpi_mpi_generalized_request_funcs_t>();
((*request)->generalized_funcs)->query_fn=query_fn;
((*request)->generalized_funcs)->free_fn=free_fn;
((*request)->generalized_funcs)->cancel_fn=cancel_fn;