Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / smpi / mpi / smpi_request.cpp
index 2ab04d5..2b54eac 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved.          */
 
 /* 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. */
@@ -57,6 +57,10 @@ Request::Request(const void* buf, int count, MPI_Datatype datatype, aid_t src, a
   detached_        = false;
   detached_sender_ = nullptr;
   real_src_        = 0;
+  // get src_host if it's available (src is valid)
+  auto src_process = simgrid::s4u::Actor::by_pid(src);
+  if (src_process)
+    src_host_ = src_process->get_host();
   truncated_       = false;
   unmatched_types_ = false;
   real_size_       = 0;
@@ -132,8 +136,10 @@ bool Request::match_common(MPI_Request req, MPI_Request sender, MPI_Request rece
        receiver->src_ == sender->src_) &&
       ((receiver->tag_ == MPI_ANY_TAG && sender->tag_ >= 0) || receiver->tag_ == sender->tag_)) {
     // we match, we can transfer some values
-    if (receiver->src_ == MPI_ANY_SOURCE)
+    if (receiver->src_ == MPI_ANY_SOURCE) {
       receiver->real_src_ = sender->src_;
+      receiver->src_host_ = sender->src_host_;
+    }
     if (receiver->tag_ == MPI_ANY_TAG)
       receiver->real_tag_ = sender->tag_;
     if ((receiver->flags_ & MPI_REQ_PROBE) == 0 ){
@@ -513,9 +519,13 @@ void Request::start()
     double sleeptime = 0.0;
     if (detached_ || ((flags_ & (MPI_REQ_ISEND | MPI_REQ_SSEND)) != 0)) { // issend should be treated as isend
       // isend and send timings may be different
-      sleeptime = ((flags_ & MPI_REQ_ISEND) != 0)
-                      ? simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->oisend(size_)
-                      : simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->osend(size_);
+      sleeptime =
+          ((flags_ & MPI_REQ_ISEND) != 0)
+              ? simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->oisend(
+                    size_, simgrid::s4u::Actor::by_pid(src_)->get_host(), simgrid::s4u::Actor::by_pid(dst_)->get_host())
+              : simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->osend(
+                    size_, simgrid::s4u::Actor::by_pid(src_)->get_host(),
+                    simgrid::s4u::Actor::by_pid(dst_)->get_host());
     }
 
     if(sleeptime > 0.0){
@@ -712,7 +722,7 @@ int Request::testany(int count, MPI_Request requests[], int *index, int* flag, M
       XBT_DEBUG("Exception in testany");
       return 0;
     }
-    
+
     if (i != -1) { // -1 is not MPI_UNDEFINED but a SIMIX return code. (nothing matches)
       *index = map[i];
       if (requests[*index] != MPI_REQUEST_NULL && (requests[*index]->flags_ & MPI_REQ_GENERALIZED) &&
@@ -771,7 +781,7 @@ int Request::testall(int count, MPI_Request requests[], int* outflag, MPI_Status
       }else{
         *outflag=0;
       }
-      if (ret != MPI_SUCCESS) 
+      if (ret != MPI_SUCCESS)
         error = 1;
     }else{
       Status::empty(pstat);
@@ -780,9 +790,9 @@ int Request::testall(int count, MPI_Request requests[], int* outflag, MPI_Status
       status[i] = *pstat;
     }
   }
-  if(error==1) 
+  if (error == 1)
     return MPI_ERR_IN_STATUS;
-  else 
+  else
     return MPI_SUCCESS;
 }
 
@@ -813,11 +823,11 @@ void Request::iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status*
                                /*(seconds * flop/s -> total flops)*/ smpi_iprobe_sleep * speed * maxrate)
         ->set_name("iprobe")
         /* Not the entire CPU can be used when iprobing: This is important for
-         * the energy consumption caused by polling with iprobes. 
+         * the energy consumption caused by polling with iprobes.
          * Note also that the number of flops that was
          * computed above contains a maxrate factor and is hence reduced (maxrate < 1)
          */
-        ->set_bound(maxrate*speed)
+        ->set_bound(maxrate * speed)
         ->start()
         ->wait();
   }
@@ -955,8 +965,9 @@ void Request::finish_wait(MPI_Request* request, MPI_Status * status)
   }
   if(req->detached_sender_ != nullptr){
     //integrate pseudo-timing for buffering of small messages, do not bother to execute the simcall if 0
-    double sleeptime =
-        simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->orecv(req->real_size());
+    simgrid::s4u::Host* dst_host = simgrid::s4u::Actor::by_pid(req->dst_)->get_host();
+    double sleeptime             = simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->orecv(
+        req->real_size(), req->src_host_, dst_host);
     if (sleeptime > 0.0) {
       simgrid::s4u::this_actor::sleep_for(sleeptime);
       XBT_DEBUG("receiving size of %zu : sleep %f ", req->real_size_, sleeptime);
@@ -1180,8 +1191,7 @@ int Request::waitsome(int incount, MPI_Request requests[], int *indices, MPI_Sta
   indices[count] = index;
   count++;
   for (int i = 0; i < incount; i++) {
-    if (i!=index && requests[i] != MPI_REQUEST_NULL 
-        && not(requests[i]->flags_ & MPI_REQ_FINISHED)) {
+    if (i != index && requests[i] != MPI_REQUEST_NULL && not(requests[i]->flags_ & MPI_REQ_FINISHED)) {
       test(&requests[i], pstat,&flag);
       if (flag==1){
         indices[count] = i;