X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e05a1337ff6756490bf19378bcaf875b002b9b82..9322977e4345ed358e0d3b2e2705926038b84042:/src/smpi/mpi/smpi_request.cpp diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index 0d846a1826..8e9f37fd6c 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -5,16 +5,16 @@ #include "smpi_request.hpp" -#include "mc/mc.h" -#include "src/kernel/activity/CommImpl.hpp" -#include "src/mc/mc_replay.h" #include "SmpiHost.hpp" -#include "private.h" +#include "mc/mc.h" #include "private.hpp" #include "smpi_comm.hpp" #include "smpi_datatype.hpp" #include "smpi_op.hpp" #include "smpi_process.hpp" +#include "src/kernel/activity/CommImpl.hpp" +#include "src/mc/mc_replay.hpp" +#include "src/simix/ActorImpl.hpp" #include @@ -32,7 +32,8 @@ extern void (*smpi_comm_copy_data_callback) (smx_activity_t, void*, size_t); namespace simgrid{ namespace smpi{ -Request::Request(void *buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags) : buf_(buf), old_type_(datatype), src_(src), dst_(dst), tag_(tag), comm_(comm), flags_(flags) +Request::Request(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags) + : buf_(buf), old_type_(datatype), src_(src), dst_(dst), tag_(tag), comm_(comm), flags_(flags) { void *old_buf = nullptr; // FIXME Handle the case of a partial shared malloc. @@ -177,20 +178,20 @@ void Request::print_request(const char *message) MPI_Request Request::send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { - return new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process()->index(), - comm->group()->index(dst), tag, comm, PERSISTENT | SEND | PREPARED); + return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::Actor::self()->getPid() - 1, + comm->group()->actor(dst)->getPid() - 1, tag, comm, PERSISTENT | SEND | PREPARED); } MPI_Request Request::ssend_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { - return new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process()->index(), - comm->group()->index(dst), tag, comm, PERSISTENT | SSEND | SEND | PREPARED); + return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::Actor::self()->getPid() - 1, + comm->group()->actor(dst)->getPid() - 1, tag, comm, PERSISTENT | SSEND | SEND | PREPARED); } MPI_Request Request::isend_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { - return new Request(buf==MPI_BOTTOM ? nullptr : buf , count, datatype, smpi_process()->index(), - comm->group()->index(dst), tag,comm, PERSISTENT | ISEND | SEND | PREPARED); + return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::Actor::self()->getPid() - 1, + comm->group()->actor(dst)->getPid() - 1, tag, comm, PERSISTENT | ISEND | SEND | PREPARED); } @@ -211,9 +212,9 @@ MPI_Request Request::rma_send_init(void *buf, int count, MPI_Datatype datatype, MPI_Request Request::recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm) { - return new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, - src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->index(src), - smpi_process()->index(), tag, comm, PERSISTENT | RECV | PREPARED); + return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, + src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(src)->getPid() - 1, + simgrid::s4u::Actor::self()->getPid() - 1, tag, comm, PERSISTENT | RECV | PREPARED); } MPI_Request Request::rma_recv_init(void *buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, @@ -221,11 +222,11 @@ MPI_Request Request::rma_recv_init(void *buf, int count, MPI_Datatype datatype, { MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */ if(op==MPI_OP_NULL){ - request = new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, src, dst, tag, - comm, RMA | NON_PERSISTENT | RECV | PREPARED); + request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, src, dst, tag, comm, + RMA | NON_PERSISTENT | RECV | PREPARED); }else{ - request = new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, src, dst, tag, - comm, RMA | NON_PERSISTENT | RECV | PREPARED | ACCUMULATE); + request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, src, dst, tag, comm, + RMA | NON_PERSISTENT | RECV | PREPARED | ACCUMULATE); request->op_ = op; } return request; @@ -233,16 +234,16 @@ MPI_Request Request::rma_recv_init(void *buf, int count, MPI_Datatype datatype, MPI_Request Request::irecv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm) { - return new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : - comm->group()->index(src), smpi_process()->index(), tag, - comm, PERSISTENT | RECV | PREPARED); + return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, + src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(src)->getPid() - 1, + simgrid::s4u::Actor::self()->getPid() - 1, tag, comm, PERSISTENT | RECV | PREPARED); } MPI_Request Request::isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */ - request = new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process()->index(), - comm->group()->index(dst), tag, comm, NON_PERSISTENT | ISEND | SEND); + request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::Actor::self()->getPid() - 1, + comm->group()->actor(dst)->getPid() - 1, tag, comm, NON_PERSISTENT | ISEND | SEND); request->start(); return request; } @@ -250,8 +251,8 @@ MPI_Request Request::isend(void *buf, int count, MPI_Datatype datatype, int dst, MPI_Request Request::issend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */ - request = new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process()->index(), - comm->group()->index(dst), tag,comm, NON_PERSISTENT | ISEND | SSEND | SEND); + request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::Actor::self()->getPid() - 1, + comm->group()->actor(dst)->getPid() - 1, tag, comm, NON_PERSISTENT | ISEND | SSEND | SEND); request->start(); return request; } @@ -260,9 +261,9 @@ MPI_Request Request::issend(void *buf, int count, MPI_Datatype datatype, int dst MPI_Request Request::irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm) { MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */ - request = new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : - comm->group()->index(src), smpi_process()->index(), tag, comm, - NON_PERSISTENT | RECV); + request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, + src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(src)->getPid() - 1, + simgrid::s4u::Actor::self()->getPid() - 1, tag, comm, NON_PERSISTENT | RECV); request->start(); return request; } @@ -278,8 +279,8 @@ void Request::recv(void *buf, int count, MPI_Datatype datatype, int src, int tag void Request::send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */ - request = new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process()->index(), - comm->group()->index(dst), tag, comm, NON_PERSISTENT | SEND); + request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::Actor::self()->getPid() - 1, + comm->group()->actor(dst)->getPid() - 1, tag, comm, NON_PERSISTENT | SEND); request->start(); wait(&request, MPI_STATUS_IGNORE); @@ -289,8 +290,8 @@ void Request::send(void *buf, int count, MPI_Datatype datatype, int dst, int tag void Request::ssend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) { MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */ - request = new Request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process()->index(), - comm->group()->index(dst), tag, comm, NON_PERSISTENT | SSEND | SEND); + request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::Actor::self()->getPid() - 1, + comm->group()->actor(dst)->getPid() - 1, tag, comm, NON_PERSISTENT | SSEND | SEND); request->start(); wait(&request,MPI_STATUS_IGNORE); @@ -303,8 +304,8 @@ void Request::sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,int d { MPI_Request requests[2]; MPI_Status stats[2]; - int myid=smpi_process()->index(); - if ((comm->group()->index(dst) == myid) && (comm->group()->index(src) == myid)){ + unsigned int myid = simgrid::s4u::Actor::self()->getPid() - 1; + if ((comm->group()->actor(dst)->getPid()-1 == myid) && (comm->group()->actor(src)->getPid()-1 == myid)){ Datatype::copy(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype); return; } @@ -332,7 +333,7 @@ void Request::start() if ((flags_ & RECV) != 0) { this->print_request("New recv"); - simgrid::smpi::Process* process = smpi_process_remote(dst_); + simgrid::smpi::Process* process = smpi_process_remote(simgrid::s4u::Actor::byPid(dst_+1)); int async_small_thresh = xbt_cfg_get_int("smpi/async-small-thresh"); @@ -377,14 +378,14 @@ void Request::start() // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later real_size_=size_; action_ = simcall_comm_irecv( - process->process(), mailbox, buf_, &real_size_, &match_recv, + process->process()->getImpl(), mailbox, buf_, &real_size_, &match_recv, process->replaying() ? &smpi_comm_null_copy_buffer_callback : smpi_comm_copy_data_callback, this, -1.0); XBT_DEBUG("recv simcall posted"); if (async_small_thresh != 0 || (flags_ & RMA) != 0 ) xbt_mutex_release(mut); } else { /* the RECV flag was not set, so this is a send */ - simgrid::smpi::Process* process = smpi_process_remote(dst_); + simgrid::smpi::Process* process = smpi_process_remote(simgrid::s4u::Actor::byPid(dst_+1)); int rank = src_; if (TRACE_smpi_view_internals()) { TRACE_smpi_send(rank, rank, dst_, tag_, size_); @@ -401,9 +402,8 @@ void Request::start() if (not(old_type_->flags() & DT_FLAG_DERIVED)) { oldbuf = buf_; if (not process->replaying() && oldbuf != nullptr && size_ != 0) { - if((smpi_privatize_global_variables != 0) - && (static_cast(buf_) >= smpi_start_data_exe) - && (static_cast(buf_) < smpi_start_data_exe + smpi_size_data_exe )){ + if ((smpi_privatize_global_variables != 0) && (static_cast(buf_) >= smpi_data_exe_start) && + (static_cast(buf_) < smpi_data_exe_start + smpi_data_exe_size)) { XBT_DEBUG("Privatization : We are sending from a zone inside global memory. Switch data segment "); smpi_switch_data_segment(src_); } @@ -465,7 +465,7 @@ void Request::start() // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later real_size_=size_; action_ = simcall_comm_isend( - SIMIX_process_from_PID(src_ + 1), mailbox, size_, -1.0, buf, real_size_, &match_send, + simgrid::s4u::Actor::byPid(src_ + 1)->getImpl(), mailbox, size_, -1.0, buf, real_size_, &match_send, &xbt_free_f, // how to free the userdata if a detached send fails not process->replaying() ? smpi_comm_copy_data_callback : &smpi_comm_null_copy_buffer_callback, this, // detach if msg size < eager/rdv switch limit @@ -508,8 +508,8 @@ int Request::test(MPI_Request * request, MPI_Status * status) { if (flag) { finish_wait(request,status); nsleeps=1;//reset the number of sleeps we will do next time - if (*request != MPI_REQUEST_NULL && ((*request)->flags_ & PERSISTENT)==0) - *request = MPI_REQUEST_NULL; + if (*request != MPI_REQUEST_NULL && ((*request)->flags_ & PERSISTENT) == 0) + *request = MPI_REQUEST_NULL; } else if (xbt_cfg_get_boolean("smpi/grow-injected-times")){ nsleeps++; } @@ -627,10 +627,13 @@ void Request::iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* static int nsleeps = 1; double speed = simgrid::s4u::Actor::self()->getHost()->getSpeed(); double maxrate = xbt_cfg_get_double("smpi/iprobe-cpu-usage"); - MPI_Request request = new Request(nullptr, 0, MPI_CHAR, source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : - comm->group()->index(source), comm->rank(), tag, comm, PERSISTENT | RECV); + MPI_Request request = new Request( + nullptr, 0, MPI_CHAR, source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(source)->getPid() - 1, + simgrid::s4u::Actor::self()->getPid() - 1, tag, comm, PERSISTENT | RECV); if (smpi_iprobe_sleep > 0) { - smx_activity_t iprobe_sleep = simcall_execution_start("iprobe", /* flops to executek*/nsleeps*smpi_iprobe_sleep*speed*maxrate, /* priority */1.0, /* performance bound */maxrate*speed); + smx_activity_t iprobe_sleep = simcall_execution_start( + "iprobe", /* flops to executek*/ nsleeps * smpi_iprobe_sleep * speed * maxrate, /* priority */ 1.0, + /* performance bound */ maxrate * speed, smpi_process()->process()->getImpl()->host); simcall_execution_wait(iprobe_sleep); } // behave like a receive, but don't do it @@ -693,12 +696,11 @@ void Request::finish_wait(MPI_Request* request, MPI_Status * status) if (((req->flags_ & ACCUMULATE) != 0) || (datatype->flags() & DT_FLAG_DERIVED)) { // && (not smpi_is_shared(req->old_buf_))){ - if (not smpi_process()->replaying()) { - if( smpi_privatize_global_variables != 0 && (static_cast(req->old_buf_) >= smpi_start_data_exe) - && ((char*)req->old_buf_ < smpi_start_data_exe + smpi_size_data_exe )){ - XBT_VERB("Privatization : We are unserializing to a zone in global memory Switch data segment "); - smpi_switch_data_segment(smpi_process()->index()); - } + if (not smpi_process()->replaying() && smpi_privatize_global_variables != 0 && + static_cast(req->old_buf_) >= smpi_data_exe_start && + static_cast(req->old_buf_) < smpi_data_exe_start + smpi_data_exe_size) { + XBT_VERB("Privatization : We are unserializing to a zone in global memory Switch data segment "); + smpi_switch_data_segment(simgrid::s4u::Actor::self()->getPid() - 1); } if(datatype->flags() & DT_FLAG_DERIVED){ @@ -717,7 +719,7 @@ void Request::finish_wait(MPI_Request* request, MPI_Status * status) } if (TRACE_smpi_view_internals() && ((req->flags_ & RECV) != 0)){ - int rank = smpi_process()->index(); + int rank = simgrid::s4u::Actor::self()->getPid() - 1; int src_traced = (req->src_ == MPI_ANY_SOURCE ? req->real_src_ : req->src_); TRACE_smpi_recv(src_traced, rank,req->tag_); } @@ -862,7 +864,7 @@ int Request::waitall(int count, MPI_Request requests[], MPI_Status status[]) if (not accumulates.empty()) { std::sort(accumulates.begin(), accumulates.end(), sort_accumulates); - for (auto req : accumulates) { + for (auto& req : accumulates) { finish_wait(&req, status); } } @@ -885,7 +887,7 @@ int Request::waitsome(int incount, MPI_Request requests[], int *indices, MPI_Sta status[index] = *pstat; } if (requests[index] != MPI_REQUEST_NULL && (requests[index]->flags_ & NON_PERSISTENT)) - requests[index]=MPI_REQUEST_NULL; + requests[index] = MPI_REQUEST_NULL; }else{ return MPI_UNDEFINED; } @@ -897,28 +899,27 @@ MPI_Request Request::f2c(int id) { char key[KEY_SIZE]; if(id==MPI_FORTRAN_REQUEST_NULL) return static_cast(MPI_REQUEST_NULL); - return static_cast(xbt_dict_get(F2C::f2c_lookup(), get_key_id(key, id))); + return static_cast(F2C::f2c_lookup()->at(get_key_id(key, id))); } -int Request::add_f() { - if(F2C::f2c_lookup()==nullptr){ - F2C::set_f2c_lookup(xbt_dict_new_homogeneous(nullptr)); +int Request::add_f() +{ + if (F2C::f2c_lookup() == nullptr) { + F2C::set_f2c_lookup(new std::unordered_map); } char key[KEY_SIZE]; - xbt_dict_set(F2C::f2c_lookup(), get_key_id(key, F2C::f2c_id()), this, nullptr); + (*(F2C::f2c_lookup()))[get_key_id(key, F2C::f2c_id())] = this; F2C::f2c_id_increment(); return F2C::f2c_id()-1; } -void Request::free_f(int id) { +void Request::free_f(int id) +{ if (id != MPI_FORTRAN_REQUEST_NULL) { char key[KEY_SIZE]; - xbt_dict_remove(F2C::f2c_lookup(), get_key_id(key, id)); + F2C::f2c_lookup()->erase(get_key_id(key, id)); } } } } - - -