Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 1 Sep 2016 16:50:09 +0000 (18:50 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 1 Sep 2016 16:50:09 +0000 (18:50 +0200)
src/smpi/smpi_replay.cpp
src/smpi/smpi_rma.cpp

index 08e9998..3941fb6 100644 (file)
@@ -8,6 +8,8 @@
 #include <stdio.h>
 #include <xbt.h>
 #include <xbt/replay.h>
+#include <unordered_map>
+#include <vector>
 
 #define KEY_SIZE (sizeof(int) * 2 + 1)
 
@@ -15,7 +17,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_replay,smpi,"Trace Replay with SMPI");
 
 int communicator_size = 0;
 static int active_processes = 0;
-xbt_dict_t reqq = nullptr;
+std::unordered_map<int,std::vector<MPI_Request>*> reqq;
 
 MPI_Datatype MPI_DEFAULT_TYPE;
 MPI_Datatype MPI_CURRENT_TYPE;
@@ -33,20 +35,14 @@ static void log_timed_action (const char *const *action, double clock){
   }
 }
 
-static xbt_dynar_t get_reqq_self()
+static std::vector<MPI_Request>* get_reqq_self()
 {
-   char * key = bprintf("%d", smpi_process_index());
-   xbt_dynar_t dynar_mpi_request = static_cast<xbt_dynar_t>(xbt_dict_get(reqq, key));
-   xbt_free(key);
-   return dynar_mpi_request;
+  return reqq.at(smpi_process_index());
 }
 
-static void set_reqq_self(xbt_dynar_t mpi_request)
+static void set_reqq_self(std::vector<MPI_Request> *mpi_request)
 {
-   char * key = bprintf("%d", smpi_process_index());
-   xbt_dict_set(reqq, key, mpi_request, free);
-   xbt_free(key);
+   reqq.insert({smpi_process_index(), mpi_request});
 }
 
 //allocate a single buffer for all sends, growing it if needed
@@ -173,11 +169,7 @@ static void action_init(const char *const *action)
   /*initialize the number of active processes */
   active_processes = smpi_process_count();
 
-  if (reqq==nullptr) {
-    reqq = xbt_dict_new();
-  }
-
-  set_reqq_self(xbt_dynar_new(sizeof(MPI_Request),&xbt_free_ref));
+  set_reqq_self(new std::vector<MPI_Request>);
 }
 
 static void action_finalize(const char *const *action)
@@ -288,7 +280,7 @@ static void action_Isend(const char *const *action)
   TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
   request->send = 1;
 
-  xbt_dynar_push(get_reqq_self(),&request);
+  get_reqq_self()->push_back(request);
 
   log_timed_action (action, clock);
 }
@@ -365,7 +357,7 @@ static void action_Irecv(const char *const *action)
 
   TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
   request->recv = 1;
-  xbt_dynar_push(get_reqq_self(),&request);
+  get_reqq_self()->push_back(request);
 
   log_timed_action (action, clock);
 }
@@ -373,11 +365,11 @@ static void action_Irecv(const char *const *action)
 static void action_test(const char *const *action){
   CHECK_ACTION_PARAMS(action, 0, 0)
   double clock = smpi_process_simulated_elapsed();
-  MPI_Request request;
   MPI_Status status;
   int flag = true;
 
-  request = xbt_dynar_pop_as(get_reqq_self(),MPI_Request);
+  MPI_Request request = get_reqq_self()->back();
+  get_reqq_self()->pop_back();
   //if request is null here, this may mean that a previous test has succeeded 
   //Different times in traced application and replayed version may lead to this 
   //In this case, ignore the extra calls.
@@ -390,8 +382,8 @@ static void action_test(const char *const *action){
     flag = smpi_mpi_test(&request, &status);
 
     XBT_DEBUG("MPI_Test result: %d", flag);
-    /* push back request in dynar to be caught by a subsequent wait. if the test did succeed, the request is now nullptr.*/
-    xbt_dynar_push_as(get_reqq_self(),MPI_Request, request);
+    /* push back request in vector to be caught by a subsequent wait. if the test did succeed, the request is now nullptr.*/
+    get_reqq_self()->push_back(request);
 
     TRACE_smpi_testing_out(rank);
   }
@@ -401,13 +393,12 @@ static void action_test(const char *const *action){
 static void action_wait(const char *const *action){
   CHECK_ACTION_PARAMS(action, 0, 0)
   double clock = smpi_process_simulated_elapsed();
-  MPI_Request request;
   MPI_Status status;
 
-  xbt_assert(xbt_dynar_length(get_reqq_self()),
-      "action wait not preceded by any irecv or isend: %s",
+  xbt_assert(get_reqq_self()->size(), "action wait not preceded by any irecv or isend: %s",
       xbt_str_join_array(action," "));
-  request = xbt_dynar_pop_as(get_reqq_self(),MPI_Request);
+  MPI_Request request = get_reqq_self()->back();
+  get_reqq_self()->pop_back();
 
   if (request==nullptr){
     /* Assume that the trace is well formed, meaning the comm might have been caught by a MPI_test. Then just return.*/
@@ -435,68 +426,25 @@ static void action_wait(const char *const *action){
 static void action_waitall(const char *const *action){
   CHECK_ACTION_PARAMS(action, 0, 0)
   double clock = smpi_process_simulated_elapsed();
-  int count_requests=0;
-  unsigned int i=0;
-
-  count_requests=xbt_dynar_length(get_reqq_self());
+  unsigned int count_requests=get_reqq_self()->size();
 
   if (count_requests>0) {
-    MPI_Request requests[count_requests];
     MPI_Status status[count_requests];
 
-    /*  The reqq is an array of dynars. Its index corresponds to the rank.
-     Thus each rank saves its own requests to the array request. */
-    xbt_dynar_foreach(get_reqq_self(),i,requests[i]); 
-
-   //save information from requests
-   xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), nullptr);
-   xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), nullptr);
-   xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), nullptr);
-   for (i = 0; static_cast<int>(i) < count_requests; i++) {
-    if(requests[i]){
-      int *asrc = xbt_new(int, 1);
-      int *adst = xbt_new(int, 1);
-      int *arecv = xbt_new(int, 1);
-      *asrc = requests[i]->src;
-      *adst = requests[i]->dst;
-      *arecv = requests[i]->recv;
-      xbt_dynar_insert_at(srcs, i, asrc);
-      xbt_dynar_insert_at(dsts, i, adst);
-      xbt_dynar_insert_at(recvs, i, arecv);
-      xbt_free(asrc);
-      xbt_free(adst);
-      xbt_free(arecv);
-    }else {
-      int *t = xbt_new(int, 1);
-      xbt_dynar_insert_at(srcs, i, t);
-      xbt_dynar_insert_at(dsts, i, t);
-      xbt_dynar_insert_at(recvs, i, t);
-      xbt_free(t);
-    }
-   }
    int rank_traced = smpi_process_index();
    instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
    extra->type = TRACING_WAITALL;
    extra->send_size=count_requests;
    TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
 
-   smpi_mpi_waitall(count_requests, requests, status);
+   smpi_mpi_waitall(count_requests, &(*get_reqq_self())[0], status);
 
-   for (i = 0; static_cast<int>(i) < count_requests; i++) {
-    int src_traced, dst_traced, is_wait_for_receive;
-    xbt_dynar_get_cpy(srcs, i, &src_traced);
-    xbt_dynar_get_cpy(dsts, i, &dst_traced);
-    xbt_dynar_get_cpy(recvs, i, &is_wait_for_receive);
-    if (is_wait_for_receive) {
-      TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
-    }
+   for (auto req : *(get_reqq_self())){
+     if (req && req->recv)
+       TRACE_smpi_recv(rank_traced, req->src, req->dst);
    }
    TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
-   //clean-up of dynars
-   xbt_dynar_free(&srcs);
-   xbt_dynar_free(&dsts);
-   xbt_dynar_free(&recvs);
-   set_reqq_self(xbt_dynar_new(sizeof(MPI_Request),&xbt_free_ref));
+   set_reqq_self(new std::vector<MPI_Request>);
   }
   log_timed_action (action, clock);
 }
@@ -1047,14 +995,17 @@ void smpi_replay_run(int *argc, char***argv){
   /* and now, finalize everything */
   double sim_time= 1.;
   /* One active process will stop. Decrease the counter*/
-  XBT_DEBUG("There are %lu elements in reqq[*]", xbt_dynar_length(get_reqq_self()));
-  if (xbt_dynar_is_empty(get_reqq_self())==0){
-    int count_requests=xbt_dynar_length(get_reqq_self());
+  XBT_DEBUG("There are %zu elements in reqq[*]", get_reqq_self()->size());
+  if (!get_reqq_self()->empty()){
+    unsigned int count_requests=get_reqq_self()->size();
     MPI_Request requests[count_requests];
     MPI_Status status[count_requests];
-    unsigned int i;
+    unsigned int i=0;
 
-    xbt_dynar_foreach(get_reqq_self(),i,requests[i]);
+    for (auto req: *get_reqq_self()){
+      requests[i] = req;
+      i++;
+    }
     smpi_mpi_waitall(count_requests, requests, status);
     active_processes--;
   } else {
@@ -1069,8 +1020,6 @@ void smpi_replay_run(int *argc, char***argv){
     _xbt_replay_action_exit();
     xbt_free(sendbuffer);
     xbt_free(recvbuffer);
-    xbt_dict_free(&reqq); //not need, data have been freed ???
-    reqq = nullptr;
   }
 
   instr_extra_data extra_fin = xbt_new0(s_instr_extra_data_t,1);
index 039676f..c15a1aa 100644 (file)
@@ -6,6 +6,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "private.h"
+#include <vector>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA operations)");
 
@@ -20,7 +21,7 @@ typedef struct s_smpi_mpi_win{
   MPI_Comm comm;
   MPI_Info info;
   int assert;
-  xbt_dynar_t requests;
+  std::vector<MPI_Request> *requests;
   xbt_bar_t bar;
   MPI_Win* connected_wins;
   char* name;
@@ -48,7 +49,7 @@ MPI_Win smpi_mpi_win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info
   win->name = nullptr;
   win->opened = 0;
   win->group = MPI_GROUP_NULL;
-  win->requests = xbt_dynar_new(sizeof(MPI_Request), nullptr);
+  win->requests = new std::vector<MPI_Request>();
   win->connected_wins = xbt_new0(MPI_Win, comm_size);
   win->connected_wins[rank] = win;
 
@@ -68,7 +69,7 @@ MPI_Win smpi_mpi_win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info
 int smpi_mpi_win_free( MPI_Win* win){
   //As per the standard, perform a barrier to ensure every async comm is finished
   xbt_barrier_wait((*win)->bar);
-  xbt_dynar_free(&(*win)->requests);
+  delete (*win)->requests;
   xbt_free((*win)->connected_wins);
   if ((*win)->name != nullptr){
     xbt_free((*win)->name);
@@ -113,21 +114,16 @@ int smpi_mpi_win_fence( int assert,  MPI_Win win){
   if(assert != MPI_MODE_NOPRECEDE){
     xbt_barrier_wait(win->bar);
 
-    xbt_dynar_t reqs = win->requests;
-    int size = xbt_dynar_length(reqs);
-    unsigned int cpt=0;
-    MPI_Request req;
+    std::vector<MPI_Request> *reqs = win->requests;
+    int size = static_cast<int>(reqs->size());
     // start all requests that have been prepared by another process
-    xbt_dynar_foreach(reqs, cpt, req){
+    for(auto req: *reqs){
       if (req->flags & PREPARED) 
         smpi_mpi_start(req);
     }
 
-    MPI_Request* treqs = static_cast<MPI_Request*>(xbt_dynar_to_array(reqs));
-    win->requests=xbt_dynar_new(sizeof(MPI_Request), nullptr);
+    MPI_Request* treqs = &(*reqs)[0];
     smpi_mpi_waitall(size,treqs,MPI_STATUSES_IGNORE);
-    xbt_free(treqs);
-
   }
   win->assert = assert;
 
@@ -158,13 +154,13 @@ int smpi_mpi_put( void *origin_addr, int origin_count, MPI_Datatype origin_datat
         smpi_group_index(smpi_comm_group(win->comm),target_rank), RMA_TAG+1, recv_win->comm, MPI_OP_NULL);
 
     //push request to receiver's win
-    xbt_dynar_push_as(recv_win->requests, MPI_Request, rreq);
+    recv_win->requests->push_back(rreq);
 
     //start send
     smpi_mpi_start(sreq);
 
     //push request to sender's win
-    xbt_dynar_push_as(win->requests, MPI_Request, sreq);
+    win->requests->push_back(sreq);
   }else{
     smpi_datatype_copy(origin_addr, origin_count, origin_datatype, recv_addr, target_count, target_datatype);
   }
@@ -198,13 +194,13 @@ int smpi_mpi_get( void *origin_addr, int origin_count, MPI_Datatype origin_datat
     smpi_mpi_start(sreq);
 
     //push request to receiver's win
-    xbt_dynar_push_as(send_win->requests, MPI_Request, sreq);
+    send_win->requests->push_back(sreq);
 
     //start recv
     smpi_mpi_start(rreq);
 
     //push request to sender's win
-    xbt_dynar_push_as(win->requests, MPI_Request, rreq);
+    win->requests->push_back(rreq);
   }else{
     smpi_datatype_copy(send_addr, target_count, target_datatype, origin_addr, origin_count, origin_datatype);
   }
@@ -233,12 +229,12 @@ int smpi_mpi_accumulate( void *origin_addr, int origin_count, MPI_Datatype origi
     MPI_Request rreq = smpi_rma_recv_init(recv_addr, target_count, target_datatype,
         smpi_process_index(), smpi_group_index(smpi_comm_group(win->comm),target_rank), RMA_TAG+3, recv_win->comm, op);
     //push request to receiver's win
-    xbt_dynar_push_as(recv_win->requests, MPI_Request, rreq);
+    recv_win->requests->push_back(rreq);
     //start send
     smpi_mpi_start(sreq);
 
     //push request to sender's win
-    xbt_dynar_push_as(win->requests, MPI_Request, sreq);
+    win->requests->push_back(sreq);
 
   return MPI_SUCCESS;
 }
@@ -339,22 +335,19 @@ int smpi_mpi_win_complete(MPI_Win win){
 
   //now we can finish RMA calls
 
-  xbt_dynar_t reqqs = win->requests;
-  size = xbt_dynar_length(reqqs);
+  std::vector<MPI_Request> *reqqs = win->requests;
+  size = static_cast<int>(reqqs->size());
 
   XBT_DEBUG("Win_complete - Finishing %d RMA calls", size);
-  unsigned int cpt=0;
-  MPI_Request req;
   // start all requests that have been prepared by another process
-  xbt_dynar_foreach(reqqs, cpt, req){
+  for (auto req: *reqqs){
     if (req->flags & PREPARED) 
       smpi_mpi_start(req);
   }
 
-  MPI_Request* treqs = static_cast<MPI_Request*>(xbt_dynar_to_array(reqqs));
-  win->requests=xbt_dynar_new(sizeof(MPI_Request), nullptr);
+  MPI_Request* treqs = &(*reqqs)[0];
   smpi_mpi_waitall(size,treqs,MPI_STATUSES_IGNORE);
-  xbt_free(treqs);
+  delete reqqs;
   smpi_group_unuse(win->group);
   win->opened--; //we're closed for business !
   return MPI_SUCCESS;
@@ -384,23 +377,20 @@ int smpi_mpi_win_wait(MPI_Win win){
   }
   xbt_free(reqs);
 
-  xbt_dynar_t reqqs = win->requests;
-  size = xbt_dynar_length(reqqs);
+  std::vector<MPI_Request> *reqqs = win->requests;
+  size = static_cast<int>(reqqs->size());
 
   XBT_DEBUG("Win_complete - Finishing %d RMA calls", size);
 
-  unsigned int cpt=0;
-  MPI_Request req;
   // start all requests that have been prepared by another process
-  xbt_dynar_foreach(reqqs, cpt, req){
+  for(auto req: *reqqs){
     if (req->flags & PREPARED) 
       smpi_mpi_start(req);
   }
 
-  MPI_Request* treqs = static_cast<MPI_Request*>(xbt_dynar_to_array(reqqs));
-  win->requests=xbt_dynar_new(sizeof(MPI_Request), nullptr);
+  MPI_Request* treqs = &(*reqqs)[0];
   smpi_mpi_waitall(size,treqs,MPI_STATUSES_IGNORE);
-  xbt_free(treqs);
+  delete reqqs;
   smpi_group_unuse(win->group);
   win->opened--; //we're opened for business !
   return MPI_SUCCESS;