Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SMPI] Alignment cosmetics in smpi_base.cpp
[simgrid.git] / src / smpi / smpi_base.cpp
index 4d36a02..11325c4 100644 (file)
@@ -82,6 +82,8 @@ xbt_dynar_t smpi_ois_values = NULL;
 
 static simgrid::config::Flag<double> smpi_wtime_sleep(
   "smpi/wtime", "Minimum time to inject inside a call to MPI_Wtime", 0.0);
 
 static simgrid::config::Flag<double> smpi_wtime_sleep(
   "smpi/wtime", "Minimum time to inject inside a call to MPI_Wtime", 0.0);
+static simgrid::config::Flag<double> smpi_init_sleep(
+  "smpi/init", "Time to inject inside a call to MPI_Init", 0.0);
 static simgrid::config::Flag<double> smpi_iprobe_sleep(
   "smpi/iprobe", "Minimum time to inject inside a call to MPI_Iprobe", 1e-4);
 static simgrid::config::Flag<double> smpi_test_sleep(
 static simgrid::config::Flag<double> smpi_iprobe_sleep(
   "smpi/iprobe", "Minimum time to inject inside a call to MPI_Iprobe", 1e-4);
 static simgrid::config::Flag<double> smpi_test_sleep(
@@ -136,7 +138,7 @@ static xbt_dynar_t parse_factor(const char *smpi_coef_string)
 
 static double smpi_os(double size)
 {
 
 static double smpi_os(double size)
 {
-  if (smpi_os_values == NULL) {
+  if (smpi_os_values == nullptr) {
     smpi_os_values = parse_factor(xbt_cfg_get_string("smpi/os"));
     smpi_register_static(smpi_os_values, xbt_dynar_free_voidp);
   }
     smpi_os_values = parse_factor(xbt_cfg_get_string("smpi/os"));
     smpi_register_static(smpi_os_values, xbt_dynar_free_voidp);
   }
@@ -165,7 +167,7 @@ static double smpi_os(double size)
 
 static double smpi_ois(double size)
 {
 
 static double smpi_ois(double size)
 {
-  if (smpi_ois_values == NULL) {
+  if (smpi_ois_values == nullptr) {
     smpi_ois_values = parse_factor(xbt_cfg_get_string("smpi/ois"));
     smpi_register_static(smpi_ois_values, xbt_dynar_free_voidp);
   }
     smpi_ois_values = parse_factor(xbt_cfg_get_string("smpi/ois"));
     smpi_register_static(smpi_ois_values, xbt_dynar_free_voidp);
   }
@@ -192,7 +194,7 @@ static double smpi_ois(double size)
 
 static double smpi_or(double size)
 {
 
 static double smpi_or(double size)
 {
-  if (smpi_or_values == NULL) {
+  if (smpi_or_values == nullptr) {
     smpi_or_values = parse_factor(xbt_cfg_get_string("smpi/or"));
     smpi_register_static(smpi_or_values, xbt_dynar_free_voidp);
   }
     smpi_or_values = parse_factor(xbt_cfg_get_string("smpi/or"));
     smpi_register_static(smpi_or_values, xbt_dynar_free_voidp);
   }
@@ -218,6 +220,11 @@ static double smpi_or(double size)
   return current;
 }
 
   return current;
 }
 
+void smpi_mpi_init() {
+  if(smpi_init_sleep > 0) 
+    simcall_process_sleep(smpi_init_sleep);
+}
+
 double smpi_mpi_wtime(){
   double time;
   if (smpi_process_initialized() != 0 && 
 double smpi_mpi_wtime(){
   double time;
   if (smpi_process_initialized() != 0 && 
@@ -260,32 +267,32 @@ static MPI_Request build_request(void *buf, int count, MPI_Datatype datatype, in
     }
   }
 
     }
   }
 
-  request->buf = buf;
+  request->buf      = buf;
   // This part handles the problem of non-contiguous memory (for the unserialisation at the reception)
   // This part handles the problem of non-contiguous memory (for the unserialisation at the reception)
-  request->old_buf = old_buf;
+  request->old_buf  = old_buf;
   request->old_type = datatype;
 
   request->size = smpi_datatype_size(datatype) * count;
   smpi_datatype_use(datatype);
   request->old_type = datatype;
 
   request->size = smpi_datatype_size(datatype) * count;
   smpi_datatype_use(datatype);
-  request->src = src;
-  request->dst = dst;
-  request->tag = tag;
+  request->src  = src;
+  request->dst  = dst;
+  request->tag  = tag;
   request->comm = comm;
   smpi_comm_use(request->comm);
   request->comm = comm;
   smpi_comm_use(request->comm);
-  request->action = NULL;
-  request->flags = flags;
-  request->detached = 0;
+  request->action          = NULL;
+  request->flags           = flags;
+  request->detached        = 0;
   request->detached_sender = NULL;
   request->detached_sender = NULL;
-  request->real_src = 0;
+  request->real_src        = 0;
 
   request->truncated = 0;
   request->real_size = 0;
 
   request->truncated = 0;
   request->real_size = 0;
-  request->real_tag = 0;
-  if(flags & PERSISTENT)
+  request->real_tag  = 0;
+  if (flags & PERSISTENT)
     request->refcount = 1;
   else
     request->refcount = 0;
     request->refcount = 1;
   else
     request->refcount = 0;
-  request->op = MPI_REPLACE;
+  request->op   = MPI_REPLACE;
   request->send = 0;
   request->recv = 0;
 
   request->send = 0;
   request->recv = 0;
 
@@ -364,11 +371,11 @@ void smpi_mpi_start(MPI_Request request)
       XBT_DEBUG("Is there a corresponding send already posted in the small mailbox %p (in case of SSEND)?", mailbox);
       smx_synchro_t action = simcall_comm_iprobe(mailbox, 0, request->src,request->tag, &match_recv, static_cast<void*>(request));
     
       XBT_DEBUG("Is there a corresponding send already posted in the small mailbox %p (in case of SSEND)?", mailbox);
       smx_synchro_t action = simcall_comm_iprobe(mailbox, 0, request->src,request->tag, &match_recv, static_cast<void*>(request));
     
-      if(action ==NULL){
+      if(action == nullptr){
         mailbox = smpi_process_mailbox();
         XBT_DEBUG("No, nothing in the small mailbox test the other one : %p", mailbox);
         action = simcall_comm_iprobe(mailbox, 0, request->src,request->tag, &match_recv, static_cast<void*>(request));
         mailbox = smpi_process_mailbox();
         XBT_DEBUG("No, nothing in the small mailbox test the other one : %p", mailbox);
         action = simcall_comm_iprobe(mailbox, 0, request->src,request->tag, &match_recv, static_cast<void*>(request));
-        if(action ==NULL){
+        if(action == nullptr){
           XBT_DEBUG("Still nothing, switch back to the small mailbox : %p", mailbox);
           mailbox = smpi_process_mailbox_small();
           }
           XBT_DEBUG("Still nothing, switch back to the small mailbox : %p", mailbox);
           mailbox = smpi_process_mailbox_small();
           }
@@ -380,7 +387,7 @@ void smpi_mpi_start(MPI_Request request)
       XBT_DEBUG("Is there a corresponding send already posted the small mailbox?");
     smx_synchro_t action = simcall_comm_iprobe(mailbox, 0, request->src,request->tag, &match_recv, (void*)request);
     
       XBT_DEBUG("Is there a corresponding send already posted the small mailbox?");
     smx_synchro_t action = simcall_comm_iprobe(mailbox, 0, request->src,request->tag, &match_recv, (void*)request);
     
-      if(action ==NULL){
+      if(action == nullptr){
         XBT_DEBUG("No, nothing in the permanent receive mailbox");
         mailbox = smpi_process_mailbox();
       }else{
         XBT_DEBUG("No, nothing in the permanent receive mailbox");
         mailbox = smpi_process_mailbox();
       }else{
@@ -439,7 +446,7 @@ void smpi_mpi_start(MPI_Request request)
       mailbox = smpi_process_remote_mailbox(receiver);
       XBT_DEBUG("Is there a corresponding recv already posted in the large mailbox %p?", mailbox);
       smx_synchro_t action = simcall_comm_iprobe(mailbox, 1,request->dst, request->tag, &match_send, static_cast<void*>(request));
       mailbox = smpi_process_remote_mailbox(receiver);
       XBT_DEBUG("Is there a corresponding recv already posted in the large mailbox %p?", mailbox);
       smx_synchro_t action = simcall_comm_iprobe(mailbox, 1,request->dst, request->tag, &match_send, static_cast<void*>(request));
-      if(action ==NULL){
+      if(action == nullptr){
        if ((request->flags & SSEND) == 0){
          mailbox = smpi_process_remote_mailbox_small(receiver);
          XBT_DEBUG("No, nothing in the large mailbox, message is to be sent on the small one %p", mailbox);
        if ((request->flags & SSEND) == 0){
          mailbox = smpi_process_remote_mailbox_small(receiver);
          XBT_DEBUG("No, nothing in the large mailbox, message is to be sent on the small one %p", mailbox);
@@ -447,7 +454,7 @@ void smpi_mpi_start(MPI_Request request)
          mailbox = smpi_process_remote_mailbox_small(receiver);
          XBT_DEBUG("SSEND : Is there a corresponding recv already posted in the small mailbox %p?", mailbox);
          action = simcall_comm_iprobe(mailbox, 1,request->dst, request->tag, &match_send, static_cast<void*>(request));
          mailbox = smpi_process_remote_mailbox_small(receiver);
          XBT_DEBUG("SSEND : Is there a corresponding recv already posted in the small mailbox %p?", mailbox);
          action = simcall_comm_iprobe(mailbox, 1,request->dst, request->tag, &match_send, static_cast<void*>(request));
-         if(action ==NULL){
+         if(action == nullptr){
            XBT_DEBUG("No, we are first, send to large mailbox");
            mailbox = smpi_process_remote_mailbox(receiver);
          }
            XBT_DEBUG("No, we are first, send to large mailbox");
            mailbox = smpi_process_remote_mailbox(receiver);
          }
@@ -494,7 +501,7 @@ void smpi_mpi_start(MPI_Request request)
                          request->detached);
     XBT_DEBUG("send simcall posted");
 
                          request->detached);
     XBT_DEBUG("send simcall posted");
 
-    /* FIXME: detached sends are not traceable (request->action == NULL) */
+    /* FIXME: detached sends are not traceable (request->action == nullptr) */
     if (request->action)
       simcall_set_category(request->action, TRACE_internal_smpi_get_category());
 
     if (request->action)
       simcall_set_category(request->action, TRACE_internal_smpi_get_category());
 
@@ -505,7 +512,7 @@ void smpi_mpi_start(MPI_Request request)
 
 void smpi_mpi_startall(int count, MPI_Request * requests)
 {
 
 void smpi_mpi_startall(int count, MPI_Request * requests)
 {
-  if(requests==NULL
+  if(requests== nullptr
     return;
 
   for(int i = 0; i < count; i++) {
     return;
 
   for(int i = 0; i < count; i++) {
@@ -835,7 +842,7 @@ void smpi_mpi_probe(int source, int tag, MPI_Comm comm, MPI_Status* status){
 
 void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status){
 
 
 void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status){
 
-  MPI_Request request =build_request(NULL, 0, MPI_CHAR, source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE :
+  MPI_Request request = build_request(NULL, 0, MPI_CHAR, source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE :
                  smpi_group_index(smpi_comm_group(comm), source), smpi_comm_rank(comm), tag, comm, PERSISTENT | RECV);
 
   // to avoid deadlock, we have to sleep some time here, or the timer won't advance and we will only do iprobe simcalls
                  smpi_group_index(smpi_comm_group(comm), source), smpi_comm_rank(comm), tag, comm, PERSISTENT | RECV);
 
   // to avoid deadlock, we have to sleep some time here, or the timer won't advance and we will only do iprobe simcalls
@@ -849,28 +856,29 @@ void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status*
 
   print_request("New iprobe", request);
   // We have to test both mailboxes as we don't know if we will receive one one or another
 
   print_request("New iprobe", request);
   // We have to test both mailboxes as we don't know if we will receive one one or another
-  if (xbt_cfg_get_int("smpi/async-small-thresh")>0){
+  if (xbt_cfg_get_int("smpi/async-small-thresh") > 0){
       mailbox = smpi_process_mailbox_small();
       mailbox = smpi_process_mailbox_small();
-      XBT_DEBUG("trying to probe the perm recv mailbox");
+      XBT_DEBUG("Trying to probe the perm recv mailbox");
       request->action = simcall_comm_iprobe(mailbox, 0, request->src, request->tag, &match_recv, static_cast<void*>(request));
   }
       request->action = simcall_comm_iprobe(mailbox, 0, request->src, request->tag, &match_recv, static_cast<void*>(request));
   }
-  if (request->action==NULL){
-  mailbox = smpi_process_mailbox();
-      XBT_DEBUG("trying to probe the other mailbox");
-      request->action = simcall_comm_iprobe(mailbox, 0, request->src,request->tag, &match_recv, static_cast<void*>(request));
+
+  if (request->action == nullptr){
+    mailbox = smpi_process_mailbox();
+    XBT_DEBUG("trying to probe the other mailbox");
+    request->action = simcall_comm_iprobe(mailbox, 0, request->src,request->tag, &match_recv, static_cast<void*>(request));
   }
 
   if (request->action){
     simgrid::simix::Comm *sync_comm = static_cast<simgrid::simix::Comm*>(request->action);
   }
 
   if (request->action){
     simgrid::simix::Comm *sync_comm = static_cast<simgrid::simix::Comm*>(request->action);
-    MPI_Request req = static_cast<MPI_Request>(sync_comm->src_data);
+    MPI_Request req                 = static_cast<MPI_Request>(sync_comm->src_data);
     *flag = 1;
     *flag = 1;
-    if(status != MPI_STATUS_IGNORE && (req->flags & PREPARED)==0) {
+    if(status != MPI_STATUS_IGNORE && (req->flags & PREPARED) == 0) {
       status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(comm), req->src);
       status->MPI_TAG    = req->tag;
       status->MPI_ERROR  = MPI_SUCCESS;
       status->count      = req->real_size;
     }
       status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(comm), req->src);
       status->MPI_TAG    = req->tag;
       status->MPI_ERROR  = MPI_SUCCESS;
       status->count      = req->real_size;
     }
-    nsleeps=1;//reset the number of sleeps we will do next time
+    nsleeps = 1;//reset the number of sleeps we will do next time
   }
   else {
     *flag = 0;
   }
   else {
     *flag = 0;