Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
some more files for sonar
authordegomme <augustin.degomme@unibas.ch>
Sun, 29 May 2016 13:50:55 +0000 (15:50 +0200)
committerdegomme <augustin.degomme@unibas.ch>
Sun, 29 May 2016 13:50:55 +0000 (15:50 +0200)
16 files changed:
examples/smpi/replay/replay.tesh
examples/smpi/replay_multiple/replay_multiple.tesh
src/smpi/instr_smpi.cpp
src/smpi/private.h
src/smpi/smpi_base.cpp
src/smpi/smpi_bench.cpp
src/smpi/smpi_c99.cpp
src/smpi/smpi_comm.cpp
src/smpi/smpi_f77.cpp
src/smpi/smpi_global.cpp
src/smpi/smpi_group.cpp
src/smpi/smpi_mpi_dt.cpp
src/smpi/smpi_pmpi.cpp
src/smpi/smpi_replay.cpp
src/smpi/smpi_rma.cpp
src/smpi/smpi_topo.cpp

index d2ffb96..2ef38c6 100644 (file)
@@ -231,8 +231,8 @@ $ ../../smpi_script/bin/smpirun -ext smpi_replay --log=replay.thresh:critical --
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'SMPI'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/TCP-gamma' to '4194304'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'smpi/cpu-threshold' to '-1'
-> [Tremblay:0:(1) 0.164463] [smpi_replay/VERBOSE] 0 send 1 1e6 0.164463
 > [Jupiter:1:(2) 0.164463] [smpi_replay/VERBOSE] 1 recv 0 1e6 0.164463
+> [Tremblay:0:(1) 0.164463] [smpi_replay/VERBOSE] 0 send 1 1e6 0.164463
 > [Jupiter:1:(2) 13.271310] [smpi_replay/VERBOSE] 1 compute 1e9 13.106847
 > [Jupiter:1:(2) 13.271310] [smpi_replay/VERBOSE] 1 Isend 0 1e6 0.000000
 > [Jupiter:1:(2) 13.271310] [smpi_replay/VERBOSE] 1 Irecv 0 1e6 0.000000
@@ -253,8 +253,8 @@ $ ../../smpi_script/bin/smpirun -ext smpi_replay --log=replay.thresh:critical --
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'SMPI'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/TCP-gamma' to '4194304'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'smpi/cpu-threshold' to '-1'
-> [Tremblay:0:(1) 1.491472] [smpi_replay/VERBOSE] 0 send 1 1e7 1.491472
 > [Jupiter:1:(2) 1.491472] [smpi_replay/VERBOSE] 1 recv 0 1e7 1.491472
+> [Tremblay:0:(1) 1.491472] [smpi_replay/VERBOSE] 0 send 1 1e7 1.491472
 > [Tremblay:0:(1) 1.493448] [smpi_replay/VERBOSE] 0 barrier 0.001976
 > [Jupiter:1:(2) 1.494910] [smpi_replay/VERBOSE] 1 barrier 0.003438
 > [Fafard:2:(3) 1.495424] [smpi_replay/VERBOSE] 2 barrier 1.495424
index ee4943e..568cdd6 100644 (file)
@@ -8,8 +8,9 @@ $ ./replay_multiple description_file ${srcdir:=.}/../../platforms/small_platform
 > [0.000000] [msg_test/INFO] Initializing instance 1 of size 32
 > [0.000000] [msg_test/INFO] Initializing instance 2 of size 32
 > [0.000000] [smpi_kernel/INFO] You did not set the power of the host running the simulation.  The timings will certainly not be accurate.  Use the option "--cfg=smpi/running-power:<flops>" to set its value.Check http://simgrid.org/simgrid/latest/doc/options.html#options_smpi_bench for more information.
-> [Jupiter:2:(52) 1140688.626959] [smpi_replay/INFO] Simulation time 1124371.274298
-> [1140688.626959] [msg_test/INFO] Simulation time 1.14069e+06
+> [Jupiter:2:(52) 1140688.585057] [smpi_replay/INFO] Simulation time 1124371.232395
+> [1140688.585057] [msg_test/INFO] Simulation time 1.14069e+06
+
 
 
 
index e69f0de..36ee8d5 100644 (file)
@@ -75,7 +75,7 @@ static const char *instr_find_color (const char *state)
   const char *current = smpi_colors[i];
   while ((current != NULL)){
     if (strcmp (state, current) == 0 //exact match
-        || strstr(target, current) ){//as substring
+        || strstr(target, current) != 0 ){//as substring
          ret = smpi_colors[i+1]; 
          break; 
     }
@@ -156,7 +156,8 @@ static void cleanup_extra_data (instr_extra_data extra){
 
 void TRACE_internal_smpi_set_category (const char *category)
 {
-  if (!TRACE_smpi_is_enabled()) return;
+  if (!TRACE_smpi_is_enabled())
+    return;
 
   //declare category
   TRACE_category (category);
@@ -171,7 +172,8 @@ void TRACE_internal_smpi_set_category (const char *category)
 
 const char *TRACE_internal_smpi_get_category (void)
 {
-  if (!TRACE_smpi_is_enabled()) return NULL;
+  if (!TRACE_smpi_is_enabled())
+    return NULL;
 
   char processid[INSTR_DEFAULT_STR_SIZE];
   snprintf (processid, INSTR_DEFAULT_STR_SIZE, "%p", SIMIX_process_self());
@@ -192,7 +194,8 @@ void TRACE_smpi_release(void)
 
 void TRACE_smpi_init(int rank)
 {
-  if (!TRACE_smpi_is_enabled()) return;
+  if (!TRACE_smpi_is_enabled())
+    return;
 
   char str[INSTR_DEFAULT_STR_SIZE];
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
@@ -210,7 +213,8 @@ void TRACE_smpi_init(int rank)
 
 void TRACE_smpi_finalize(int rank)
 {
-  if (!TRACE_smpi_is_enabled()) return;
+  if (!TRACE_smpi_is_enabled())
+    return;
 
   char str[INSTR_DEFAULT_STR_SIZE];
   container_t container = PJ_container_get(smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE));
@@ -231,12 +235,13 @@ void TRACE_smpi_collective_in(int rank, int root, const char *operation, instr_e
   type_t type = PJ_type_get ("MPI_STATE", container->type);
   const char *color = instr_find_color (operation);
   val_t value = PJ_value_get_or_new (operation, color, type);
-   new_pajePushStateWithExtra (SIMIX_get_clock(), container, type, value, (void*)extra);
+   new_pajePushStateWithExtra (SIMIX_get_clock(), container, type, value, static_cast<void*>(extra));
 }
 
 void TRACE_smpi_collective_out(int rank, int root, const char *operation)
 {
-  if (!TRACE_smpi_is_enabled()) return;
+  if (!TRACE_smpi_is_enabled()) 
+    return;
 
   char str[INSTR_DEFAULT_STR_SIZE];
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
@@ -249,9 +254,8 @@ void TRACE_smpi_collective_out(int rank, int root, const char *operation)
 void TRACE_smpi_computing_init(int rank)
 {
  //first use, initialize the color in the trace
- //TODO : check with lucas and Pierre how to generalize this approach
-  //to avoid unnecessary access to the color array
-  if (!TRACE_smpi_is_enabled() || !TRACE_smpi_is_computing()) return;
+  if (!TRACE_smpi_is_enabled() || !TRACE_smpi_is_computing()) 
+    return;
 
   char str[INSTR_DEFAULT_STR_SIZE];
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
@@ -275,12 +279,13 @@ void TRACE_smpi_computing_in(int rank, instr_extra_data extra)
   container_t container = PJ_container_get (str);
   type_t type = PJ_type_get ("MPI_STATE", container->type);
   val_t value = PJ_value_get_or_new ("computing", NULL, type);
-  new_pajePushStateWithExtra  (SIMIX_get_clock(), container, type, value, (void*)extra);
+  new_pajePushStateWithExtra  (SIMIX_get_clock(), container, type, value, static_cast<void*>(extra));
 }
 
 void TRACE_smpi_computing_out(int rank)
 {
-  if (!TRACE_smpi_is_enabled()|| !TRACE_smpi_is_computing()) return;
+  if (!TRACE_smpi_is_enabled()|| !TRACE_smpi_is_computing())
+    return;
   char str[INSTR_DEFAULT_STR_SIZE];
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
   container_t container = PJ_container_get (str);
@@ -290,10 +295,9 @@ void TRACE_smpi_computing_out(int rank)
 
 void TRACE_smpi_sleeping_init(int rank)
 {
- //first use, initialize the color in the trace
- //TODO : check with lucas and Pierre how to generalize this approach
-  //to avoid unnecessary access to the color array
-  if (!TRACE_smpi_is_enabled() || !TRACE_smpi_is_sleeping()) return;
+  //first use, initialize the color in the trace
+  if (!TRACE_smpi_is_enabled() || !TRACE_smpi_is_sleeping())
+    return;
 
   char str[INSTR_DEFAULT_STR_SIZE];
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
@@ -317,12 +321,13 @@ void TRACE_smpi_sleeping_in(int rank, instr_extra_data extra)
   container_t container = PJ_container_get (str);
   type_t type = PJ_type_get ("MPI_STATE", container->type);
   val_t value = PJ_value_get_or_new ("sleeping", NULL, type);
-  new_pajePushStateWithExtra  (SIMIX_get_clock(), container, type, value, (void*)extra);
+  new_pajePushStateWithExtra  (SIMIX_get_clock(), container, type, value, static_cast<void*>(extra));
 }
 
 void TRACE_smpi_sleeping_out(int rank)
 {
-  if (!TRACE_smpi_is_enabled()|| !TRACE_smpi_is_sleeping()) return;
+  if (!TRACE_smpi_is_enabled()|| !TRACE_smpi_is_sleeping())
+    return;
   char str[INSTR_DEFAULT_STR_SIZE];
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
   container_t container = PJ_container_get (str);
@@ -343,12 +348,13 @@ void TRACE_smpi_testing_in(int rank, instr_extra_data extra)
   container_t container = PJ_container_get (str);
   type_t type = PJ_type_get ("MPI_STATE", container->type);
   val_t value = PJ_value_get_or_new ("test", NULL, type);
-  new_pajePushStateWithExtra  (SIMIX_get_clock(), container, type, value, (void*)extra);
+  new_pajePushStateWithExtra  (SIMIX_get_clock(), container, type, value, static_cast<void*>(extra));
 }
 
 void TRACE_smpi_testing_out(int rank)
 {
-  if (!TRACE_smpi_is_enabled()) return;
+  if (!TRACE_smpi_is_enabled())
+    return;
   char str[INSTR_DEFAULT_STR_SIZE];
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
   container_t container = PJ_container_get (str);
@@ -369,12 +375,13 @@ void TRACE_smpi_ptp_in(int rank, int src, int dst, const char *operation, instr_
   type_t type = PJ_type_get ("MPI_STATE", container->type);
   const char *color = instr_find_color (operation);
   val_t value = PJ_value_get_or_new (operation, color, type);
-  new_pajePushStateWithExtra (SIMIX_get_clock(), container, type, value, (void*)extra);
+  new_pajePushStateWithExtra (SIMIX_get_clock(), container, type, value, static_cast<void*>(extra));
 }
 
 void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
 {
-  if (!TRACE_smpi_is_enabled()) return;
+  if (!TRACE_smpi_is_enabled())
+    return;
 
   char str[INSTR_DEFAULT_STR_SIZE];
   smpi_container(rank, str, INSTR_DEFAULT_STR_SIZE);
@@ -386,7 +393,8 @@ void TRACE_smpi_ptp_out(int rank, int src, int dst, const char *operation)
 
 void TRACE_smpi_send(int rank, int src, int dst, int size)
 {
-  if (!TRACE_smpi_is_enabled()) return;
+  if (!TRACE_smpi_is_enabled())
+    return;
 
   char key[INSTR_DEFAULT_STR_SIZE] = {0};
   TRACE_smpi_put_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
@@ -401,7 +409,8 @@ void TRACE_smpi_send(int rank, int src, int dst, int size)
 
 void TRACE_smpi_recv(int rank, int src, int dst)
 {
-  if (!TRACE_smpi_is_enabled()) return;
+  if (!TRACE_smpi_is_enabled())
+    return;
 
   char key[INSTR_DEFAULT_STR_SIZE] = {0};
   TRACE_smpi_get_key(src, dst, key, INSTR_DEFAULT_STR_SIZE);
index fd70eba..3232522 100644 (file)
@@ -194,7 +194,7 @@ XBT_PRIVATE void smpi_global_init(void);
 XBT_PRIVATE void smpi_global_destroy(void);
 XBT_PRIVATE double smpi_mpi_wtime(void);
 
-XBT_PRIVATE int is_datatype_valid(MPI_Datatype datatype);
+XBT_PRIVATE bool is_datatype_valid(MPI_Datatype datatype);
 
 XBT_PRIVATE size_t smpi_datatype_size(MPI_Datatype datatype);
 XBT_PRIVATE MPI_Aint smpi_datatype_lb(MPI_Datatype datatype);
@@ -237,7 +237,7 @@ XBT_PRIVATE void smpi_empty_status(MPI_Status * status);
 XBT_PRIVATE MPI_Op smpi_op_new(MPI_User_function * function, int commute);
 XBT_PRIVATE int smpi_op_is_commute(MPI_Op op);
 XBT_PRIVATE void smpi_op_destroy(MPI_Op op);
-XBT_PRIVATE void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len, MPI_Datatype * datatype);
+XBT_PRIVATE void smpi_op_apply(MPI_Op op, const void *invec, void *inoutvec, int *len, MPI_Datatype * datatype);
 
 XBT_PRIVATE MPI_Group smpi_group_new(int size);
 XBT_PRIVATE MPI_Group smpi_group_copy(MPI_Group origin);
index 9ad4177..f2f102b 100644 (file)
@@ -420,7 +420,7 @@ void smpi_mpi_start(MPI_Request request)
       sleeptime = ((request->flags & ISEND) != 0)? smpi_ois(request->size) : smpi_os(request->size);
     }
 
-    if(sleeptime != 0.0){
+    if(sleeptime >= 0.0){
         simcall_process_sleep(sleeptime);
         XBT_DEBUG("sending size of %zu : sleep %f ", request->size, smpi_os(request->size));
     }
index de5c96e..b321e24 100644 (file)
@@ -155,7 +155,7 @@ static size_t shm_size(int fd) {
   if(fstat(fd, &st) < 0) {
     xbt_die("Could not stat fd %d: %s", fd, strerror(errno));
   }
-  return (size_t)st.st_size;
+  return static_cast<size_t>(st.st_size);
 }
 
 #ifndef WIN32
@@ -164,10 +164,8 @@ static void* shm_map(int fd, size_t size, shared_data_key_type* data) {
   char loc[PTR_STRLEN];
   shared_metadata_t meta;
 
-  if(size > shm_size(fd)) {
-    if(ftruncate(fd, (off_t)size) < 0) {
+  if(size > shm_size(fd) && (ftruncate(fd, static_cast<off_t>(size)) < 0)) {
       xbt_die("Could not truncate fd %d to %zu: %s", fd, size, strerror(errno));
-    }
   }
 
   mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
@@ -255,7 +253,6 @@ void smpi_bench_end(void)
   double speedup = 1;
   xbt_os_timer_t timer = smpi_process_timer();
   xbt_os_threadtimer_stop(timer);
-//  smpi_switch_data_segment(smpi_process_count());
   if (smpi_process_get_sampling()) {
     XBT_CRITICAL("Cannot do recursive benchmarks.");
     XBT_CRITICAL("Are you trying to make a call to MPI within a SMPI_SAMPLE_ block?");
@@ -304,12 +301,12 @@ static unsigned int private_sleep(double secs)
 
 unsigned int smpi_sleep(unsigned int secs)
 {
-  return private_sleep((double)secs);
+  return private_sleep(static_cast<double>(secs));
 }
 
 int smpi_usleep(useconds_t usecs)
 {
-  return (int)private_sleep((double)usecs / 1000000.0);
+  return static_cast<int>(private_sleep(static_cast<double>(usecs) / 1000000.0));
 }
 
 int smpi_gettimeofday(struct timeval *tv, void* tz)
@@ -318,11 +315,11 @@ int smpi_gettimeofday(struct timeval *tv, void* tz)
   smpi_bench_end();
   now = SIMIX_get_clock();
   if (tv) {
-    tv->tv_sec = (time_t)now;
+    tv->tv_sec = static_cast<time_t>(now);
 #ifdef WIN32
-    tv->tv_usec = (useconds_t)((now - tv->tv_sec) * 1e6);
+    tv->tv_usec = static_cast<useconds_t>((now - tv->tv_sec) * 1e6);
 #else
-    tv->tv_usec = (suseconds_t)((now - tv->tv_sec) * 1e6);
+    tv->tv_usec = static_cast<suseconds_t>((now - tv->tv_sec) * 1e6);
 #endif
   }
   smpi_bench_begin();
@@ -335,7 +332,7 @@ unsigned long long smpi_rastro_resolution (void)
   smpi_bench_end();
   double resolution = (1/sg_surf_precision);
   smpi_bench_begin();
-  return (unsigned long long)resolution;
+  return static_cast<unsigned long long>(resolution);
 }
 
 unsigned long long smpi_rastro_timestamp (void)
@@ -346,7 +343,7 @@ unsigned long long smpi_rastro_timestamp (void)
   unsigned long long sec = (unsigned long long)now;
   unsigned long long pre = (now - sec) * smpi_rastro_resolution();
   smpi_bench_begin();
-  return (unsigned long long)sec * smpi_rastro_resolution() + pre;
+  return static_cast<unsigned long long>(sec) * smpi_rastro_resolution() + pre;
 }
 
 /* ****************************** Functions related to the SMPI_SAMPLE_ macros ************************************/
@@ -390,14 +387,14 @@ void smpi_sample_1(int global, const char *file, int line, int iters, double thr
   smpi_bench_end();     /* Take time from previous, unrelated computation into account */
   smpi_process_set_sampling(1);
 
-  if (!samples)
+  if (samples==NULL)
     samples = xbt_dict_new_homogeneous(free);
 
   data = static_cast<local_data_t *>(xbt_dict_get_or_null(samples, loc));
-  if (!data) {
+  if (data==NULL) {
     xbt_assert(threshold>0 || iters>0,
         "You should provide either a positive amount of iterations to bench, or a positive maximal stderr (or both)");
-    data = (local_data_t *) xbt_new(local_data_t, 1);
+    data = static_cast<local_data_t *>( xbt_new(local_data_t, 1));
     data->count = 0;
     data->sum = 0.0;
     data->sum_pow2 = 0.0;
@@ -476,10 +473,10 @@ void smpi_sample_3(int global, const char *file, int line)
   sample = xbt_os_timer_elapsed(smpi_process_timer());
   data->sum += sample;
   data->sum_pow2 += sample * sample;
-  n = (double)data->count;
+  n = static_cast<double>(data->count);
   data->mean = data->sum / n;
   data->relstderr = sqrt((data->sum_pow2 / n - data->mean * data->mean) / n) / data->mean;
-  if (!sample_enough_benchs(data)) {
+  if (sample_enough_benchs(data)==0) {
     data->mean = sample; // Still in benching process; We want sample_2 to simulate the exact time of this loop
                          // occurrence before leaving, not the mean over the history
   }
@@ -507,12 +504,10 @@ void *smpi_shared_malloc(size_t size, const char *file, int line)
       snprintf(shmname, 31, "/shmalloc%p", &*data);
       fd = shm_open(shmname, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
       if (fd < 0) {
-        switch(errno) {
-          case EEXIST:
-            xbt_die("Please cleanup /dev/shm/%s", shmname);
-          default:
-            xbt_die("An unhandled error occurred while opening %s. shm_open: %s", shmname, strerror(errno));
-        }
+        if(errno==EEXIST)
+          xbt_die("Please cleanup /dev/shm/%s", shmname);
+        else
+          xbt_die("An unhandled error occurred while opening %s. shm_open: %s", shmname, strerror(errno));
       }
       data->second.fd = fd;
       data->second.count = 1;
@@ -569,7 +564,7 @@ int smpi_shared_known_call(const char* func, const char* input)
   xbt_ex_t ex;
   int known = 0;
 
-  if (!calls) {
+  if (calls==NULL) {
     calls = xbt_dict_new_homogeneous(NULL);
   }
   TRY {
@@ -591,11 +586,11 @@ void* smpi_shared_get_call(const char* func, const char* input) {
    char* loc = bprintf("%s:%s", func, input);
    void* data;
 
-   if(!calls) {
+   if(calls==NULL) {
       calls = xbt_dict_new_homogeneous(NULL);
    }
    data = xbt_dict_get(calls, loc);
-   free(loc);
+   xbt_free(loc);
    return data;
 }
 
@@ -606,7 +601,7 @@ void* smpi_shared_set_call(const char* func, const char* input, void* data) {
       calls = xbt_dict_new_homogeneous(NULL);
    }
    xbt_dict_set(calls, loc, data, NULL);
-   free(loc);
+   xbt_free(loc);
    return data;
 }
 
@@ -671,7 +666,7 @@ void smpi_initialize_global_memory_segments(){
   }
 
   smpi_privatisation_regions =
-    (smpi_privatisation_region_t) malloc(smpi_process_count() * sizeof(struct s_smpi_privatisation_region));
+    static_cast<smpi_privatisation_region_t>( xbt_malloc(smpi_process_count() * sizeof(struct s_smpi_privatisation_region)));
 
   for (int i=0; i< smpi_process_count(); i++){
       //create SIMIX_process_count() mappings of this size with the same data inside
index 15e49df..689ac88 100644 (file)
@@ -17,14 +17,14 @@ static xbt_dynar_t registered_static_stack = NULL;
 void smpi_register_static(void* arg, void_f_pvoid_t free_fn)
 {
   s_smpi_static_t elm = { arg, free_fn };
-  if (!registered_static_stack)
+  if (registered_static_stack==NULL)
     registered_static_stack = xbt_dynar_new(sizeof(s_smpi_static_t), NULL);
   xbt_dynar_push_as(registered_static_stack, s_smpi_static_t, elm);
 }
 
 void smpi_free_static(void)
 {
-  while (!xbt_dynar_is_empty(registered_static_stack)) {
+  while (xbt_dynar_is_empty(registered_static_stack)==0) {
     s_smpi_static_t elm =
       xbt_dynar_pop_as(registered_static_stack, s_smpi_static_t);
     elm.free_fn(elm.ptr);
index ffc2d3c..ec94c1e 100644 (file)
@@ -39,8 +39,8 @@ typedef struct s_smpi_mpi_communicator {
 
 static int smpi_compare_rankmap(const void *a, const void *b)
 {
-  const int* x = (const int*)a;
-  const int* y = (const int*)b;
+  const int* x = static_cast<const int*>(a);
+  const int* y = static_cast<const int*>(b);
 
   if (x[1] < y[1]) {
     return -1;
@@ -91,25 +91,7 @@ int smpi_comm_dup(MPI_Comm comm, MPI_Comm* newcomm){
   MPI_Group cp=smpi_group_copy(smpi_comm_group(comm));
   (*newcomm) = smpi_comm_new(cp, smpi_comm_topo(comm));
   int ret = MPI_SUCCESS;
-  //todo: faire en sorte que Ã§a fonctionne avec un communicator dupliqué (refaire un init_smp ?)
-  
- /* MPI_Comm tmp=smpi_comm_get_intra_comm(comm);
-  if( tmp != MPI_COMM_NULL)
-    smpi_comm_set_intra_comm((*newcomm), smpi_comm_dup(tmp));
-  tmp=smpi_comm_get_leaders_comm(comm);
-  if( tmp != MPI_COMM_NULL)
-    smpi_comm_set_leaders_comm((*newcomm), smpi_comm_dup(tmp));
-  if(comm->non_uniform_map !=NULL){
-    (*newcomm)->non_uniform_map= 
-      xbt_malloc(smpi_comm_size(comm->leaders_comm)*sizeof(int));
-    memcpy((*newcomm)->non_uniform_map,
-      comm->non_uniform_map,smpi_comm_size(comm->leaders_comm)*sizeof(int) );
-  }
-  if(comm->leaders_map !=NULL){
-    (*newcomm)->leaders_map=xbt_malloc(smpi_comm_size(comm)*sizeof(int));
-    memcpy((*newcomm)->leaders_map, 
-      comm->leaders_map,smpi_comm_size(comm)*sizeof(int) );
-  }*/
+
   if(comm->attributes !=NULL){
       (*newcomm)->attributes=xbt_dict_new();
       xbt_dict_cursor_t cursor = NULL;
@@ -119,8 +101,8 @@ int smpi_comm_dup(MPI_Comm comm, MPI_Comm* newcomm){
       void* value_out;
       xbt_dict_foreach(comm->attributes, cursor, key, value_in){
         smpi_comm_key_elem elem =
-           static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, (const char*)key, sizeof(int)));
-        if(elem && elem->copy_fn!=MPI_NULL_COPY_FN){
+           static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(key), sizeof(int)));
+        if(elem!=NULL && elem->copy_fn!=MPI_NULL_COPY_FN){
           ret = elem->copy_fn(comm, *key, NULL, value_in, &value_out, &flag );
           if(ret!=MPI_SUCCESS){
             smpi_comm_destroy(*newcomm);
@@ -128,7 +110,7 @@ int smpi_comm_dup(MPI_Comm comm, MPI_Comm* newcomm){
             return ret;
           }
           if(flag)
-            xbt_dict_set_ext((*newcomm)->attributes, (const char*)key, sizeof(int),value_out, NULL);
+            xbt_dict_set_ext((*newcomm)->attributes, reinterpret_cast<const char*>(key), sizeof(int),value_out, NULL);
         }
       }
     }
@@ -167,7 +149,7 @@ void smpi_comm_get_name (MPI_Comm comm, char* name, int* len)
   if (comm == MPI_COMM_UNINITIALIZED)
     comm = smpi_process_comm_world();
   if(comm == MPI_COMM_WORLD) {
-    strcpy(name, "WORLD");
+    strncpy(name, "WORLD",5);
     *len = 5;
   } else {
     *len = snprintf(name, MPI_MAX_NAME_STRING, "%p", comm);
@@ -233,7 +215,8 @@ MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key)
   MPI_Group* group_snd;
   MPI_Request* requests;
 
-  group_root = group_out = NULL;
+  group_root = NULL;
+  group_out = NULL;
   group = smpi_comm_group(comm);
   rank = smpi_comm_rank(comm);
   size = smpi_comm_size(comm);
@@ -253,46 +236,46 @@ MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key)
     group_snd = xbt_new(MPI_Group, size);
     rankmap = xbt_new(int, 2 * size);
     for(i = 0; i < size; i++) {
-      if(recvbuf[2 * i] == MPI_UNDEFINED) {
-        continue;
-      }
-      count = 0;
-      for(j = i + 1; j < size; j++)  {
-        if(recvbuf[2 * i] == recvbuf[2 * j]) {
-          recvbuf[2 * j] = MPI_UNDEFINED;
-          rankmap[2 * count] = j;
-          rankmap[2 * count + 1] = recvbuf[2 * j + 1];
-          count++;
+      if(recvbuf[2 * i] != MPI_UNDEFINED) {
+      
+        count = 0;
+        for(j = i + 1; j < size; j++)  {
+          if(recvbuf[2 * i] == recvbuf[2 * j]) {
+            recvbuf[2 * j] = MPI_UNDEFINED;
+            rankmap[2 * count] = j;
+            rankmap[2 * count + 1] = recvbuf[2 * j + 1];
+            count++;
+          }
         }
-      }
-      /* Add self in the group */
-      recvbuf[2 * i] = MPI_UNDEFINED;
-      rankmap[2 * count] = i;
-      rankmap[2 * count + 1] = recvbuf[2 * i + 1];
-      count++;
-      qsort(rankmap, count, 2 * sizeof(int), &smpi_compare_rankmap);
-      group_out = smpi_group_new(count);
-      if(i == 0) {
-        group_root = group_out; /* Save root's group */
-      }
-      for(j = 0; j < count; j++) {
-        index = smpi_group_index(group, rankmap[2 * j]);
-        smpi_group_set_mapping(group_out, index, j);
-      }
-      requests = xbt_new(MPI_Request, count);
-      reqs = 0;
-      for(j = 0; j < count; j++) {
-        if(rankmap[2 * j] != 0) {
-          group_snd[reqs]=smpi_group_copy(group_out);
-          requests[reqs] = smpi_mpi_isend(&(group_snd[reqs]), 1, MPI_PTR, rankmap[2 * j], system_tag, comm);
-          reqs++;
+        /* Add self in the group */
+        recvbuf[2 * i] = MPI_UNDEFINED;
+        rankmap[2 * count] = i;
+        rankmap[2 * count + 1] = recvbuf[2 * i + 1];
+        count++;
+        qsort(rankmap, count, 2 * sizeof(int), &smpi_compare_rankmap);
+        group_out = smpi_group_new(count);
+        if(i == 0) {
+          group_root = group_out; /* Save root's group */
         }
+        for(j = 0; j < count; j++) {
+          index = smpi_group_index(group, rankmap[2 * j]);
+          smpi_group_set_mapping(group_out, index, j);
+        }
+        requests = xbt_new(MPI_Request, count);
+        reqs = 0;
+        for(j = 0; j < count; j++) {
+          if(rankmap[2 * j] != 0) {
+            group_snd[reqs]=smpi_group_copy(group_out);
+            requests[reqs] = smpi_mpi_isend(&(group_snd[reqs]), 1, MPI_PTR, rankmap[2 * j], system_tag, comm);
+            reqs++;
+          }
+        }
+        if(i != 0) {
+          smpi_group_destroy(group_out);
+        }
+        smpi_mpi_waitall(reqs, requests, MPI_STATUS_IGNORE);
+        xbt_free(requests);
       }
-      if(i != 0) {
-        smpi_group_destroy(group_out);
-      }
-      smpi_mpi_waitall(reqs, requests, MPI_STATUS_IGNORE);
-      xbt_free(requests);
     }
     xbt_free(recvbuf);
     xbt_free(rankmap);
@@ -303,7 +286,7 @@ MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key)
       smpi_mpi_recv(&group_out, 1, MPI_PTR, 0, system_tag, comm, MPI_STATUS_IGNORE);
     } /* otherwise, exit with group_out == NULL */
   }
-  return group_out ? smpi_comm_new(group_out, NULL) : MPI_COMM_NULL;
+  return group_out!=NULL ? smpi_comm_new(group_out, NULL) : MPI_COMM_NULL;
 }
 
 void smpi_comm_use(MPI_Comm comm){
@@ -321,8 +304,8 @@ void smpi_comm_cleanup_attributes(MPI_Comm comm){
     int flag;
     xbt_dict_foreach(comm->attributes, cursor, key, value){
       smpi_comm_key_elem elem =
-         static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null(smpi_comm_keyvals, (const char*)key));
-      if(elem &&  elem->delete_fn)
+         static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null(smpi_comm_keyvals, reinterpret_cast<const char*>(key)));
+      if(elem!=NULL &&  elem->delete_fn)
         elem->delete_fn(comm, *key, value, &flag);
     }
     xbt_dict_free(&comm->attributes);
@@ -355,10 +338,10 @@ void smpi_comm_unuse(MPI_Comm comm){
 
 static int compare_ints (const void *a, const void *b)
 {
-  const int *da = (const int *) a;
-  const int *db = (const int *) b;
+  const int *da = static_cast<const int *>(a);
+  const int *db = static_cast<const int *>(b);
 
-  return (*da > *db) - (*da < *db);
+  return static_cast<int>(*da > *db) - static_cast<int>(*da < *db);
 }
 
 void smpi_comm_init_smp(MPI_Comm comm){
@@ -384,18 +367,10 @@ void smpi_comm_init_smp(MPI_Comm comm){
   //get the indexes of all processes sharing the same simix host
   xbt_swag_t process_list = SIMIX_host_self()->processes();
   int intra_comm_size = 0;
-  //only one process/node, disable SMP support and return
-//  if(intra_comm_size==1){
-//      smpi_comm_set_intra_comm(comm, MPI_COMM_SELF);
-//      //smpi_comm_set_leaders_comm(comm, comm);
-//      smpi_process_set_comm_intra(MPI_COMM_SELF);
-//      return;
-//  }
   int i =0;
   int min_index=INT_MAX;//the minimum index will be the leader
   smx_process_t process = NULL;
   xbt_swag_foreach(process, process_list) {
-    //is_in_comm=0;
     int index = SIMIX_process_get_PID(process) -1;
 
     if(smpi_group_rank(smpi_comm_group(comm),  index)!=MPI_UNDEFINED){
@@ -411,7 +386,6 @@ void smpi_comm_init_smp(MPI_Comm comm){
   i=0;
   process = NULL;
   xbt_swag_foreach(process, process_list) {
-    //is_in_comm=0;
     int index = SIMIX_process_get_PID(process) -1;
     if(smpi_group_rank(smpi_comm_group(comm),  index)!=MPI_UNDEFINED){
       smpi_group_set_mapping(group_intra, index, i);
@@ -420,14 +394,10 @@ void smpi_comm_init_smp(MPI_Comm comm){
   }
 
   MPI_Comm comm_intra = smpi_comm_new(group_intra, NULL);
-  //MPI_Comm shmem_comm = smpi_process_comm_intra();
-  //int intra_rank = smpi_comm_rank(shmem_comm);
-
-  //if(smpi_process_index()==min_index)
   leader=min_index;
 
-  int * leaders_map= (int*)xbt_malloc0(sizeof(int)*comm_size);
-  int * leader_list= (int*)xbt_malloc0(sizeof(int)*comm_size);
+  int * leaders_map= static_cast<int*>(xbt_malloc0(sizeof(int)*comm_size));
+  int * leader_list= static_cast<int*>(xbt_malloc0(sizeof(int)*comm_size));
   for(i=0; i<comm_size; i++){
       leader_list[i]=-1;
   }
@@ -438,7 +408,7 @@ void smpi_comm_init_smp(MPI_Comm comm){
      smpi_switch_data_segment(smpi_process_index());
    }
 
-  if(!comm->leaders_map){
+  if(comm->leaders_map==NULL){
     comm->leaders_map= leaders_map;
   }else{
     xbt_free(leaders_map);
@@ -452,7 +422,7 @@ void smpi_comm_init_smp(MPI_Comm comm){
             already_done=1;
         }
       }
-      if(!already_done){
+      if(already_done==0){
         leader_list[leader_group_size]=comm->leaders_map[i];
         leader_group_size++;
       }
@@ -471,7 +441,6 @@ void smpi_comm_init_smp(MPI_Comm comm){
     smpi_comm_set_intra_comm(comm, comm_intra);
 
    //create intracommunicator
-   // smpi_comm_set_intra_comm(comm, smpi_comm_split(comm, *(int*)SIMIX_host_self(), comm_rank));
   }else{
     for (i=0; i< leader_group_size;i++)
       smpi_group_set_mapping(leaders_group, leader_list[i], i);
@@ -500,7 +469,7 @@ void smpi_comm_init_smp(MPI_Comm comm){
         break;
       }
     }
-    if(!is_uniform && smpi_comm_is_uniform(comm)){
+    if(is_uniform==0 && smpi_comm_is_uniform(comm)!=0){
         comm->non_uniform_map= non_uniform_map;
     }else{
         xbt_free(non_uniform_map);
@@ -542,28 +511,29 @@ void smpi_comm_init_smp(MPI_Comm comm){
 
 int smpi_comm_attr_delete(MPI_Comm comm, int keyval){
   smpi_comm_key_elem elem =
-     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, (const char*)&keyval, sizeof(int)));
-  if(!elem)
+     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
+  if(elem==NULL)
     return MPI_ERR_ARG;
   if(elem->delete_fn!=MPI_NULL_DELETE_FN){
     void * value;
     int flag;
     if(smpi_comm_attr_get(comm, keyval, &value, &flag)==MPI_SUCCESS){
       int ret = elem->delete_fn(comm, keyval, value, &flag);
-      if(ret!=MPI_SUCCESS) return ret;
+      if(ret!=MPI_SUCCESS) 
+        return ret;
     }
   }
   if(comm->attributes==NULL)
     return MPI_ERR_ARG;
 
-  xbt_dict_remove_ext(comm->attributes, (const char*)&keyval, sizeof(int));
+  xbt_dict_remove_ext(comm->attributes, reinterpret_cast<const char*>(&keyval), sizeof(int));
   return MPI_SUCCESS;
 }
 
 int smpi_comm_attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag){
   smpi_comm_key_elem elem =
-    static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, (const char*)&keyval, sizeof(int)));
-  if(!elem)
+    static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
+  if(elem==NULL)
     return MPI_ERR_ARG;
   xbt_ex_t ex;
   if(comm->attributes==NULL){
@@ -571,7 +541,8 @@ int smpi_comm_attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag){
     return MPI_SUCCESS;
   }
   TRY {
-    *(void**)attr_value = xbt_dict_get_ext(comm->attributes,  (const char*)&keyval, sizeof(int));
+    *static_cast<void**>(attr_value) = xbt_dict_get_ext(comm->attributes, 
+                            reinterpret_cast<const char*>(&keyval), sizeof(int));
     *flag=1;
   } CATCH(ex) {
     *flag=0;
@@ -581,49 +552,49 @@ int smpi_comm_attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag){
 }
 
 int smpi_comm_attr_put(MPI_Comm comm, int keyval, void* attr_value){
-  if(!smpi_comm_keyvals)
-  smpi_comm_keyvals = xbt_dict_new();
+  if(smpi_comm_keyvals==NULL)
+    smpi_comm_keyvals = xbt_dict_new();
   smpi_comm_key_elem elem =
-    static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  (const char*)&keyval, sizeof(int)));
-  if(!elem )
+    static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(&keyval), sizeof(int)));
+  if(elem==NULL)
     return MPI_ERR_ARG;
   int flag;
   void* value;
   smpi_comm_attr_get(comm, keyval, &value, &flag);
-  if(flag && elem->delete_fn!=MPI_NULL_DELETE_FN){
+  if(flag!=0 && elem->delete_fn!=MPI_NULL_DELETE_FN){
     int ret = elem->delete_fn(comm, keyval, value, &flag);
-    if(ret!=MPI_SUCCESS) return ret;
+    if(ret!=MPI_SUCCESS) 
+      return ret;
   }
   if(comm->attributes==NULL)
     comm->attributes=xbt_dict_new();
 
-  xbt_dict_set_ext(comm->attributes,  (const char*)&keyval, sizeof(int), attr_value, NULL);
+  xbt_dict_set_ext(comm->attributes,  reinterpret_cast<const char*>(&keyval), sizeof(int), attr_value, NULL);
   return MPI_SUCCESS;
 }
 
 int smpi_comm_keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
                             void* extra_state){
-  if(!smpi_comm_keyvals)
-  smpi_comm_keyvals = xbt_dict_new();
+  if(smpi_comm_keyvals==NULL)
+    smpi_comm_keyvals = xbt_dict_new();
 
-  smpi_comm_key_elem value = (smpi_comm_key_elem) xbt_new0(s_smpi_mpi_comm_key_elem_t,1);
+  smpi_comm_key_elem value = static_cast<smpi_comm_key_elem>(xbt_new0(s_smpi_mpi_comm_key_elem_t,1));
 
   value->copy_fn=copy_fn;
   value->delete_fn=delete_fn;
 
   *keyval = comm_keyval_id;
-  xbt_dict_set_ext(smpi_comm_keyvals, (const char*)keyval, sizeof(int),(void*)value, NULL);
+  xbt_dict_set_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(keyval), sizeof(int),static_cast<void*>(value), NULL);
   comm_keyval_id++;
   return MPI_SUCCESS;
 }
 
 int smpi_comm_keyval_free(int* keyval){
   smpi_comm_key_elem elem =
-     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  (const char*)keyval, sizeof(int)));
-  if(!elem){
+     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(keyval), sizeof(int)));
+  if(elem==NULL)
     return MPI_ERR_ARG;
-  }
-  xbt_dict_remove_ext(smpi_comm_keyvals,  (const char*)keyval, sizeof(int));
+  xbt_dict_remove_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(keyval), sizeof(int));
   xbt_free(elem);
   return MPI_SUCCESS;
 }
index 09cb210..8f174f8 100644 (file)
@@ -58,7 +58,7 @@ static char* get_key_id(char* key, int id) {
 }
 
 static void smpi_init_fortran_types(){
-   if(!comm_lookup){
+   if(comm_lookup == NULL){
      comm_lookup = xbt_dict_new_homogeneous(NULL);
      smpi_comm_c2f(MPI_COMM_WORLD);
      group_lookup = xbt_dict_new_homogeneous(NULL);
@@ -68,13 +68,13 @@ static void smpi_init_fortran_types(){
      info_lookup = xbt_dict_new_homogeneous(NULL);
      smpi_type_c2f(MPI_BYTE);//MPI_BYTE
      smpi_type_c2f(MPI_CHAR);//MPI_CHARACTER
-     #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
+#if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
      smpi_type_c2f(MPI_INT);//MPI_LOGICAL
      smpi_type_c2f(MPI_INT);//MPI_INTEGER
-     #else
+#else
      smpi_type_c2f(MPI_LONG);//MPI_LOGICAL
      smpi_type_c2f(MPI_LONG);//MPI_INTEGER
-     #endif
+#endif
      smpi_type_c2f(MPI_INT8_T);//MPI_INTEGER1
      smpi_type_c2f(MPI_INT16_T);//MPI_INTEGER2
      smpi_type_c2f(MPI_INT32_T);//MPI_INTEGER4
@@ -85,11 +85,11 @@ static void smpi_init_fortran_types(){
      smpi_type_c2f(MPI_DOUBLE);//MPI_DOUBLE_PRECISION
      smpi_type_c2f(MPI_C_FLOAT_COMPLEX);//MPI_COMPLEX
      smpi_type_c2f(MPI_C_DOUBLE_COMPLEX);//MPI_DOUBLE_COMPLEX
-     #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
+#if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
      smpi_type_c2f(MPI_2INT);//MPI_2INTEGER
-     #else
+#else
      smpi_type_c2f(MPI_2LONG);//MPI_2INTEGER
-     #endif
+#endif
      smpi_type_c2f(MPI_UINT8_T);//MPI_LOGICAL1
      smpi_type_c2f(MPI_UINT16_T);//MPI_LOGICAL2
      smpi_type_c2f(MPI_UINT32_T);//MPI_LOGICAL4
@@ -137,14 +137,15 @@ MPI_Comm smpi_comm_f2c(int comm) {
   smpi_init_fortran_types();
   if(comm == -2) {
     return MPI_COMM_SELF;
-  }else if(comm==0){
+  } else if(comm==0){
     return MPI_COMM_WORLD;
-  } else if(comm_lookup && comm >= 0) {
+  } else if(comm_lookup != NULL && comm >= 0) {
       char key[KEY_SIZE];
-      MPI_Comm tmp =  (MPI_Comm)xbt_dict_get_or_null(comm_lookup,get_key_id(key, comm));
+      MPI_Comm tmp =  static_cast<MPI_Comm>(xbt_dict_get_or_null(comm_lookup,get_key_id(key, comm)));
       return tmp != NULL ? tmp : MPI_COMM_NULL ;
+  } else {
+    return MPI_COMM_NULL;
   }
-  return MPI_COMM_NULL;
 }
 
 int smpi_group_c2f(MPI_Group group) {
@@ -159,11 +160,12 @@ MPI_Group smpi_group_f2c(int group) {
   smpi_init_fortran_types();
   if(group == -2) {
     return MPI_GROUP_EMPTY;
-  } else if(group_lookup && group >= 0) {
+  } else if(group_lookup != NULL && group >= 0) {
     char key[KEY_SIZE];
-    return (MPI_Group)xbt_dict_get_or_null(group_lookup, get_key(key, group));
+    return static_cast<MPI_Group>(xbt_dict_get_or_null(group_lookup, get_key(key, group)));
+  } else {
+    return MPI_GROUP_NULL;
   }
-  return MPI_GROUP_NULL;
 }
 
 static void free_group(int group) {
@@ -182,8 +184,9 @@ int smpi_request_c2f(MPI_Request req) {
 MPI_Request smpi_request_f2c(int req) {
   smpi_init_fortran_types();
   char key[KEY_SIZE];
-  if(req==MPI_FORTRAN_REQUEST_NULL)return MPI_REQUEST_NULL;
-  return (MPI_Request)xbt_dict_get(request_lookup, get_key_id(key, req));
+  if(req==MPI_FORTRAN_REQUEST_NULL)
+    return MPI_REQUEST_NULL;
+  return static_cast<MPI_Request>(xbt_dict_get(request_lookup, get_key_id(key, req)));
 }
 
 static void free_request(int request) {
@@ -203,7 +206,7 @@ int smpi_type_c2f(MPI_Datatype datatype) {
 MPI_Datatype smpi_type_f2c(int datatype) {
   smpi_init_fortran_types();
   char key[KEY_SIZE];
-  return datatype >= 0 ? (MPI_Datatype)xbt_dict_get_or_null(datatype_lookup, get_key(key, datatype)): MPI_DATATYPE_NULL;
+  return datatype >= 0 ? static_cast<MPI_Datatype>(xbt_dict_get_or_null(datatype_lookup, get_key(key, datatype))): MPI_DATATYPE_NULL;
 }
 
 static void free_datatype(int datatype) {
@@ -222,7 +225,7 @@ int smpi_op_c2f(MPI_Op op) {
 MPI_Op smpi_op_f2c(int op) {
   smpi_init_fortran_types();
   char key[KEY_SIZE];
-   return op >= 0 ? (MPI_Op)xbt_dict_get_or_null(op_lookup,  get_key(key, op)): MPI_OP_NULL;
+   return op >= 0 ? static_cast<MPI_Op>(xbt_dict_get_or_null(op_lookup,  get_key(key, op))): MPI_OP_NULL;
 }
 
 static void free_op(int op) {
@@ -241,7 +244,7 @@ int smpi_win_c2f(MPI_Win win) {
 MPI_Win smpi_win_f2c(int win) {
   smpi_init_fortran_types();
   char key[KEY_SIZE];
-   return win >= 0 ? (MPI_Win)xbt_dict_get_or_null(win_lookup,  get_key(key, win)) : MPI_WIN_NULL;
+   return win >= 0 ? static_cast<MPI_Win>(xbt_dict_get_or_null(win_lookup,  get_key(key, win))) : MPI_WIN_NULL;
 }
 
 static void free_win(int win) {
@@ -260,7 +263,7 @@ int smpi_info_c2f(MPI_Info info) {
 MPI_Info smpi_info_f2c(int info) {
   smpi_init_fortran_types();
   char key[KEY_SIZE];
-   return info >= 0 ? (MPI_Info)xbt_dict_get_or_null(info_lookup,  get_key(key, info)) : MPI_INFO_NULL;
+   return info >= 0 ? static_cast<MPI_Info>(xbt_dict_get_or_null(info_lookup,  get_key(key, info))) : MPI_INFO_NULL;
 }
 
 static void free_info(int info) {
@@ -369,7 +372,7 @@ void mpi_initialized_(int* flag, int* ierr){
 
 void mpi_send_init_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) {
   MPI_Request req;
-  buf = (char *) FORT_BOTTOM(buf);
+  buf = static_cast<char *>(FORT_BOTTOM(buf));
   *ierr = MPI_Send_init(buf, *count, smpi_type_f2c(*datatype), *dst, *tag, smpi_comm_f2c(*comm), &req);
   if(*ierr == MPI_SUCCESS) {
     *request = smpi_request_c2f(req);
@@ -378,7 +381,7 @@ void mpi_send_init_(void *buf, int* count, int* datatype, int* dst, int* tag, in
 
 void mpi_isend_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) {
   MPI_Request req;
-  buf = (char *) FORT_BOTTOM(buf);
+  buf = static_cast<char *>(FORT_BOTTOM(buf));
   *ierr = MPI_Isend(buf, *count, smpi_type_f2c(*datatype), *dst, *tag, smpi_comm_f2c(*comm), &req);
   if(*ierr == MPI_SUCCESS) {
     *request = smpi_request_c2f(req);
@@ -387,7 +390,7 @@ void mpi_isend_(void *buf, int* count, int* datatype, int* dst, int* tag, int* c
 
 void mpi_irsend_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) {
   MPI_Request req;
-  buf = (char *) FORT_BOTTOM(buf);
+  buf = static_cast<char *>(FORT_BOTTOM(buf));
   *ierr = MPI_Irsend(buf, *count, smpi_type_f2c(*datatype), *dst, *tag, smpi_comm_f2c(*comm), &req);
   if(*ierr == MPI_SUCCESS) {
     *request = smpi_request_c2f(req);
@@ -395,26 +398,26 @@ void mpi_irsend_(void *buf, int* count, int* datatype, int* dst, int* tag, int*
 }
 
 void mpi_send_(void* buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* ierr) {
-  buf = (char *) FORT_BOTTOM(buf);
+  buf = static_cast<char *>(FORT_BOTTOM(buf));
    *ierr = MPI_Send(buf, *count, smpi_type_f2c(*datatype), *dst, *tag, smpi_comm_f2c(*comm));
 }
 
 void mpi_rsend_(void* buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* ierr) {
-  buf = (char *) FORT_BOTTOM(buf);
+  buf = static_cast<char *>(FORT_BOTTOM(buf));
    *ierr = MPI_Rsend(buf, *count, smpi_type_f2c(*datatype), *dst, *tag, smpi_comm_f2c(*comm));
 }
 
 void mpi_sendrecv_(void* sendbuf, int* sendcount, int* sendtype, int* dst, int* sendtag, void *recvbuf, int* recvcount,
                    int* recvtype, int* src, int* recvtag, int* comm, MPI_Status* status, int* ierr) {
-  sendbuf = (char *) FORT_BOTTOM(sendbuf);
-  recvbuf = (char *) FORT_BOTTOM(recvbuf);
+  sendbuf = static_cast<char *>( FORT_BOTTOM(sendbuf));
+  recvbuf = static_cast<char *>( FORT_BOTTOM(recvbuf));
    *ierr = MPI_Sendrecv(sendbuf, *sendcount, smpi_type_f2c(*sendtype), *dst, *sendtag, recvbuf, *recvcount,
                         smpi_type_f2c(*recvtype), *src, *recvtag, smpi_comm_f2c(*comm), FORT_STATUS_IGNORE(status));
 }
 
 void mpi_recv_init_(void *buf, int* count, int* datatype, int* src, int* tag, int* comm, int* request, int* ierr) {
   MPI_Request req;
-  buf = (char *) FORT_BOTTOM(buf);
+  buf = static_cast<char *>( FORT_BOTTOM(buf));
   *ierr = MPI_Recv_init(buf, *count, smpi_type_f2c(*datatype), *src, *tag, smpi_comm_f2c(*comm), &req);
   if(*ierr == MPI_SUCCESS) {
     *request = smpi_request_c2f(req);
@@ -423,7 +426,7 @@ void mpi_recv_init_(void *buf, int* count, int* datatype, int* src, int* tag, in
 
 void mpi_irecv_(void *buf, int* count, int* datatype, int* src, int* tag, int* comm, int* request, int* ierr) {
   MPI_Request req;
-  buf = (char *) FORT_BOTTOM(buf);
+  buf = static_cast<char *>( FORT_BOTTOM(buf));
   *ierr = MPI_Irecv(buf, *count, smpi_type_f2c(*datatype), *src, *tag, smpi_comm_f2c(*comm), &req);
   if(*ierr == MPI_SUCCESS) {
     *request = smpi_request_c2f(req);
@@ -431,7 +434,7 @@ void mpi_irecv_(void *buf, int* count, int* datatype, int* src, int* tag, int* c
 }
 
 void mpi_recv_(void* buf, int* count, int* datatype, int* src, int* tag, int* comm, MPI_Status* status, int* ierr) {
-  buf = (char *) FORT_BOTTOM(buf);
+  buf = static_cast<char *>( FORT_BOTTOM(buf));
   *ierr = MPI_Recv(buf, *count, smpi_type_f2c(*datatype), *src, *tag, smpi_comm_f2c(*comm), status);
 }
 
@@ -450,7 +453,7 @@ void mpi_startall_(int* count, int* requests, int* ierr) {
     reqs[i] = smpi_request_f2c(requests[i]);
   }
   *ierr = MPI_Startall(*count, reqs);
-  free(reqs);
+  xbt_free(reqs);
 }
 
 void mpi_wait_(int* request, MPI_Status* status, int* ierr) {
@@ -476,7 +479,7 @@ void mpi_waitany_(int* count, int* requests, int* index, MPI_Status* status, int
       free_request(requests[*index]);
       requests[*index]=MPI_FORTRAN_REQUEST_NULL;
   }
-  free(reqs);
+  xbt_free(reqs);
 }
 
 void mpi_waitall_(int* count, int* requests, MPI_Status* status, int* ierr) {
@@ -495,7 +498,7 @@ void mpi_waitall_(int* count, int* requests, MPI_Status* status, int* ierr) {
       }
   }
 
-  free(reqs);
+  xbt_free(reqs);
 }
 
 void mpi_barrier_(int* comm, int* ierr) {
@@ -507,65 +510,65 @@ void mpi_bcast_(void *buf, int* count, int* datatype, int* root, int* comm, int*
 }
 
 void mpi_reduce_(void* sendbuf, void* recvbuf, int* count, int* datatype, int* op, int* root, int* comm, int* ierr) {
-  sendbuf = (char *) FORT_IN_PLACE(sendbuf);
-  sendbuf = (char *) FORT_BOTTOM(sendbuf);
-  recvbuf = (char *) FORT_BOTTOM(recvbuf);
+  sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
+  sendbuf = static_cast<char *>( FORT_BOTTOM(sendbuf));
+  recvbuf = static_cast<char *>( FORT_BOTTOM(recvbuf));
   *ierr = MPI_Reduce(sendbuf, recvbuf, *count, smpi_type_f2c(*datatype), smpi_op_f2c(*op), *root, smpi_comm_f2c(*comm));
 }
 
 void mpi_allreduce_(void* sendbuf, void* recvbuf, int* count, int* datatype, int* op, int* comm, int* ierr) {
-  sendbuf = (char *) FORT_IN_PLACE(sendbuf);
+  sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
   *ierr = MPI_Allreduce(sendbuf, recvbuf, *count, smpi_type_f2c(*datatype), smpi_op_f2c(*op), smpi_comm_f2c(*comm));
 }
 
 void mpi_reduce_scatter_(void* sendbuf, void* recvbuf, int* recvcounts, int* datatype, int* op, int* comm, int* ierr) {
-  sendbuf = (char *) FORT_IN_PLACE(sendbuf);
+  sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
   *ierr = MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, smpi_type_f2c(*datatype),
                         smpi_op_f2c(*op), smpi_comm_f2c(*comm));
 }
 
 void mpi_scatter_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcount, int* recvtype,
                    int* root, int* comm, int* ierr) {
-  recvbuf = (char *) FORT_IN_PLACE(recvbuf);
+  recvbuf = static_cast<char *>( FORT_IN_PLACE(recvbuf));
   *ierr = MPI_Scatter(sendbuf, *sendcount, smpi_type_f2c(*sendtype),
                       recvbuf, *recvcount, smpi_type_f2c(*recvtype), *root, smpi_comm_f2c(*comm));
 }
 
 void mpi_scatterv_(void* sendbuf, int* sendcounts, int* displs, int* sendtype,
                    void* recvbuf, int* recvcount, int* recvtype, int* root, int* comm, int* ierr) {
-  recvbuf = (char *) FORT_IN_PLACE(recvbuf);
+  recvbuf = static_cast<char *>( FORT_IN_PLACE(recvbuf));
   *ierr = MPI_Scatterv(sendbuf, sendcounts, displs, smpi_type_f2c(*sendtype),
                       recvbuf, *recvcount, smpi_type_f2c(*recvtype), *root, smpi_comm_f2c(*comm));
 }
 
 void mpi_gather_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcount, int* recvtype,
                   int* root, int* comm, int* ierr) {
-  sendbuf = (char *) FORT_IN_PLACE(sendbuf);
-  sendbuf = (char *) FORT_BOTTOM(sendbuf);
-  recvbuf = (char *) FORT_BOTTOM(recvbuf);
+  sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
+  sendbuf = static_cast<char *>( FORT_BOTTOM(sendbuf));
+  recvbuf = static_cast<char *>( FORT_BOTTOM(recvbuf));
   *ierr = MPI_Gather(sendbuf, *sendcount, smpi_type_f2c(*sendtype),
                      recvbuf, *recvcount, smpi_type_f2c(*recvtype), *root, smpi_comm_f2c(*comm));
 }
 
 void mpi_gatherv_(void* sendbuf, int* sendcount, int* sendtype,
                   void* recvbuf, int* recvcounts, int* displs, int* recvtype, int* root, int* comm, int* ierr) {
-  sendbuf = (char *) FORT_IN_PLACE(sendbuf);
-  sendbuf = (char *) FORT_BOTTOM(sendbuf);
-  recvbuf = (char *) FORT_BOTTOM(recvbuf);
+  sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
+  sendbuf = static_cast<char *>( FORT_BOTTOM(sendbuf));
+  recvbuf = static_cast<char *>( FORT_BOTTOM(recvbuf));
   *ierr = MPI_Gatherv(sendbuf, *sendcount, smpi_type_f2c(*sendtype),
                      recvbuf, recvcounts, displs, smpi_type_f2c(*recvtype), *root, smpi_comm_f2c(*comm));
 }
 
 void mpi_allgather_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcount, int* recvtype,
                      int* comm, int* ierr) {
-  sendbuf = (char *) FORT_IN_PLACE(sendbuf);
+  sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
   *ierr = MPI_Allgather(sendbuf, *sendcount, smpi_type_f2c(*sendtype),
                         recvbuf, *recvcount, smpi_type_f2c(*recvtype), smpi_comm_f2c(*comm));
 }
 
 void mpi_allgatherv_(void* sendbuf, int* sendcount, int* sendtype,
                      void* recvbuf, int* recvcounts,int* displs, int* recvtype, int* comm, int* ierr) {
-  sendbuf = (char *) FORT_IN_PLACE(sendbuf);
+  sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
   *ierr = MPI_Allgatherv(sendbuf, *sendcount, smpi_type_f2c(*sendtype),
                         recvbuf, recvcounts, displs, smpi_type_f2c(*recvtype), smpi_comm_f2c(*comm));
 }
@@ -704,7 +707,7 @@ void mpi_win_free_( int* win, int* ierr){
 
 void mpi_win_create_( int *base, MPI_Aint* size, int* disp_unit, int* info, int* comm, int *win, int* ierr){
   MPI_Win tmp;
-  *ierr =  MPI_Win_create( (void*)base, *size, *disp_unit, smpi_info_f2c(*info), smpi_comm_f2c(*comm),&tmp);
+  *ierr =  MPI_Win_create( static_cast<void*>(base), *size, *disp_unit, smpi_info_f2c(*info), smpi_comm_f2c(*comm),&tmp);
  if(*ierr == MPI_SUCCESS) {
    *win = smpi_win_c2f(tmp);
  }
@@ -727,22 +730,24 @@ void mpi_win_wait_(int* win, int* ierr){
 }
 
 void mpi_win_set_name_ (int*  win, char * name, int* ierr, int size){
- //handle trailing blanks
- while(name[size-1]==' ')size--;
- while(*name==' '){//handle leading blanks
-   size --;
-   name++;
- }
- char* tname = xbt_new(char,size+1);
- strncpy(tname, name, size);
- tname[size]='\0';
- *ierr = MPI_Win_set_name(smpi_win_f2c(*win), tname);
- xbt_free(tname);
+  //handle trailing blanks
+  while(name[size-1]==' ')
+    size--;
+  while(*name==' '){//handle leading blanks
+    size--;
+    name++;
+  }
+  char* tname = xbt_new(char,size+1);
+  strncpy(tname, name, size);
+  tname[size]='\0';
+  *ierr = MPI_Win_set_name(smpi_win_f2c(*win), tname);
+  xbt_free(tname);
 }
 
 void mpi_win_get_name_ (int*  win, char * name, int* len, int* ierr){
- *ierr = MPI_Win_get_name(smpi_win_f2c(*win),name,len);
- if(*len>0) name[*len]=' ';//blank padding, not \0
+  *ierr = MPI_Win_get_name(smpi_win_f2c(*win),name,len);
+  if(*len>0) 
+    name[*len]=' ';//blank padding, not \0
 }
 
 void mpi_info_create_( int *info, int* ierr){
@@ -754,48 +759,53 @@ void mpi_info_create_( int *info, int* ierr){
 }
 
 void mpi_info_set_( int *info, char *key, char *value, int* ierr, unsigned int keylen, unsigned int valuelen){
- //handle trailing blanks
- while(key[keylen-1]==' ')keylen--;
- while(*key==' '){//handle leading blanks
-   keylen --;
-   key++;
- }
- char* tkey = xbt_new(char,keylen+1);
- strncpy(tkey, key, keylen);
- tkey[keylen]='\0';  
- while(value[valuelen-1]==' ')valuelen--;
- while(*value==' '){//handle leading blanks
-   valuelen --;
-   value++;
- }
- char* tvalue = xbt_new(char,valuelen+1);
- strncpy(tvalue, value, valuelen);
- tvalue[valuelen]='\0'; 
- *ierr =  MPI_Info_set( smpi_info_f2c(*info), tkey, tvalue);
- xbt_free(tkey);
+  //handle trailing blanks
+  while(key[keylen-1]==' ')
+    keylen--;
+  while(*key==' '){//handle leading blanks
+    keylen--;
+    key++;
+  }
+  char* tkey = xbt_new(char,keylen+1);
+  strncpy(tkey, key, keylen);
+  tkey[keylen]='\0';  
+
+  while(value[valuelen-1]==' ')
+    valuelen--;
+  while(*value==' '){//handle leading blanks
+    valuelen--;
+    value++;
+  }
+  char* tvalue = xbt_new(char,valuelen+1);
+  strncpy(tvalue, value, valuelen);
+
+  tvalue[valuelen]='\0'; 
+  *ierr =  MPI_Info_set( smpi_info_f2c(*info), tkey, tvalue);
+  xbt_free(tkey);
 }
 
 void mpi_info_get_ (int* info,char *key,int* valuelen, char *value, int *flag, int* ierr, unsigned int keylen ){
- while(key[keylen-1]==' ')keylen--;
- while(*key==' '){//handle leading blanks
-   keylen --;
-   key++;
- }  char* tkey = xbt_new(char,keylen+1);
- strncpy(tkey, key, keylen);
- tkey[keylen]='\0';
- *ierr = MPI_Info_get(smpi_info_f2c(*info),tkey,*valuelen, value, flag);
- xbt_free(tkey);
- if(*flag==true){
-   int replace=0, i=0;
-   for (i=0; i<*valuelen; i++){
-     if(value[i]=='\0')
-       replace=1;
-     if(replace)
-       value[i]=' ';
-   }
- } 
+  while(key[keylen-1]==' ')
+    keylen--;
+  while(*key==' '){//handle leading blanks
+    keylen--;
+    key++;
+  }  
+  char* tkey = xbt_new(char,keylen+1);
+  strncpy(tkey, key, keylen);
+  tkey[keylen]='\0';
+  *ierr = MPI_Info_get(smpi_info_f2c(*info),tkey,*valuelen, value, flag);
+  xbt_free(tkey);
+  if(*flag==true){
+    int replace=0;
+    int i=0;
+    for (i=0; i<*valuelen; i++){
+      if(value[i]=='\0')
+        replace=1;
+      if(replace)
+        value[i]=' ';
+    }
+  } 
 }
 
 void mpi_info_free_(int* info, int* ierr){
@@ -808,19 +818,19 @@ void mpi_info_free_(int* info, int* ierr){
 
 void mpi_get_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* ierr){
-  *ierr =  MPI_Get( (void*)origin_addr,*origin_count, smpi_type_f2c(*origin_datatype),*target_rank,
+  *ierr =  MPI_Get( static_cast<void*>(origin_addr),*origin_count, smpi_type_f2c(*origin_datatype),*target_rank,
       *target_disp, *target_count,smpi_type_f2c(*tarsmpi_type_f2c), smpi_win_f2c(*win));
 }
 
 void mpi_accumulate_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* op, int* win, int* ierr){
-  *ierr =  MPI_Accumulate( (void*)origin_addr,*origin_count, smpi_type_f2c(*origin_datatype),*target_rank,
+  *ierr =  MPI_Accumulate( static_cast<void *>(origin_addr),*origin_count, smpi_type_f2c(*origin_datatype),*target_rank,
       *target_disp, *target_count,smpi_type_f2c(*tarsmpi_type_f2c), smpi_op_f2c(*op), smpi_win_f2c(*win));
 }
 
 void mpi_put_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* ierr){
-  *ierr =  MPI_Put( (void*)origin_addr,*origin_count, smpi_type_f2c(*origin_datatype),*target_rank,
+  *ierr =  MPI_Put( static_cast<void *>(origin_addr),*origin_count, smpi_type_f2c(*origin_datatype),*target_rank,
       *target_disp, *target_count,smpi_type_f2c(*tarsmpi_type_f2c), smpi_win_f2c(*win));
 }
 
@@ -874,7 +884,8 @@ void mpi_type_set_name_ (int*  datatype, char * name, int* ierr, int size){
 
 void mpi_type_get_name_ (int*  datatype, char * name, int* len, int* ierr){
  *ierr = MPI_Type_get_name(smpi_type_f2c(*datatype),name,len);
-  if(*len>0) name[*len]=' ';
+  if(*len>0) 
+    name[*len]=' ';
 }
 
 void mpi_type_get_attr_ (int* type, int* type_keyval, void *attribute_val, int* flag, int* ierr){
@@ -894,7 +905,7 @@ void mpi_type_delete_attr_ (int* type, int* type_keyval, int* ierr){
 
 void mpi_type_create_keyval_ (void* copy_fn, void*  delete_fn, int* keyval, void* extra_state, int* ierr){
 
- *ierr = MPI_Type_create_keyval((MPI_Type_copy_attr_function*)copy_fn, (MPI_Type_delete_attr_function*) delete_fn,
+ *ierr = MPI_Type_create_keyval(reinterpret_cast<MPI_Type_copy_attr_function*>(copy_fn), reinterpret_cast<MPI_Type_delete_attr_function*>(delete_fn),
                                 keyval,  extra_state) ;
 }
 
@@ -903,7 +914,7 @@ void mpi_type_free_keyval_ (int* keyval, int* ierr) {
 }
 
 void mpi_pcontrol_ (int* level , int* ierr){
- *ierr = MPI_Pcontrol(*(const int*)level);
+ *ierr = MPI_Pcontrol(*static_cast<const int*>(level));
 }
 
 void mpi_type_get_extent_ (int* datatype, MPI_Aint * lb, MPI_Aint * extent, int* ierr){
@@ -918,7 +929,7 @@ void mpi_type_get_true_extent_ (int* datatype, MPI_Aint * lb, MPI_Aint * extent,
 
 void mpi_op_create_ (void * function, int* commute, int* op, int* ierr){
   MPI_Op tmp;
- *ierr = MPI_Op_create((MPI_User_function*)function,* commute, &tmp);
+ *ierr = MPI_Op_create(reinterpret_cast<MPI_User_function*>(function),*commute, &tmp);
  if(*ierr == MPI_SUCCESS) {
    *op = smpi_op_c2f(tmp);
  }
@@ -1028,7 +1039,7 @@ void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){
 
 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
 
- *ierr = MPI_Comm_create_keyval((MPI_Comm_copy_attr_function*)copy_fn,  (MPI_Comm_delete_attr_function*)delete_fn,
+ *ierr = MPI_Comm_create_keyval(reinterpret_cast<MPI_Comm_copy_attr_function*>(copy_fn),  reinterpret_cast<MPI_Comm_delete_attr_function*>(delete_fn),
          keyval,  extra_state) ;
 }
 
@@ -1038,7 +1049,8 @@ void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
 
 void mpi_comm_get_name_ (int* comm, char* name, int* len, int* ierr){
  *ierr = MPI_Comm_get_name(smpi_comm_f2c(*comm), name, len);
-  if(*len>0) name[*len]=' ';
+  if(*len>0) 
+    name[*len]=' ';
 }
 
 void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
@@ -1079,12 +1091,11 @@ void mpi_testany_ (int* count, int* requests, int *index, int *flag, MPI_Status*
     reqs[i] = smpi_request_f2c(requests[i]);
   }
   *ierr = MPI_Testany(*count, reqs, index, flag, FORT_STATUS_IGNORE(status));
-  if(*index!=MPI_UNDEFINED)
-  if(reqs[*index]==MPI_REQUEST_NULL){
+  if(*index!=MPI_UNDEFINED && reqs[*index]==MPI_REQUEST_NULL){
     free_request(requests[*index]);
     requests[*index]=MPI_FORTRAN_REQUEST_NULL;
   }
-  free(reqs);
+  xbt_free(reqs);
 }
 
 void mpi_waitsome_ (int* incount, int* requests, int *outcount, int *indices, MPI_Status* status, int* ierr)
@@ -1103,7 +1114,7 @@ void mpi_waitsome_ (int* incount, int* requests, int *outcount, int *indices, MP
         requests[indices[i]]=MPI_FORTRAN_REQUEST_NULL;
     }
   }
-  free(reqs);
+  xbt_free(reqs);
 }
 
 void mpi_reduce_local_ (void *inbuf, void *inoutbuf, int* count, int* datatype, int* op, int* ierr){
@@ -1114,7 +1125,7 @@ void mpi_reduce_local_ (void *inbuf, void *inoutbuf, int* count, int* datatype,
 void mpi_reduce_scatter_block_ (void *sendbuf, void *recvbuf, int* recvcount, int* datatype, int* op, int* comm,
                                 int* ierr)
 {
-  sendbuf = (char *) FORT_IN_PLACE(sendbuf);
+  sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
  *ierr = MPI_Reduce_scatter_block(sendbuf, recvbuf, *recvcount, smpi_type_f2c(*datatype), smpi_op_f2c(*op),
                                   smpi_comm_f2c(*comm));
 }
@@ -1200,27 +1211,27 @@ void mpi_error_class_ (int* errorcode, int* errorclass, int* ierr) {
 }
 
 void mpi_errhandler_create_ (void* function, void* errhandler, int* ierr) {
- *ierr = MPI_Errhandler_create((MPI_Handler_function*)function, (MPI_Errhandler*)errhandler);
+ *ierr = MPI_Errhandler_create(reinterpret_cast<MPI_Handler_function*>(function), static_cast<MPI_Errhandler*>(errhandler));
 }
 
 void mpi_errhandler_free_ (void* errhandler, int* ierr) {
- *ierr = MPI_Errhandler_free((MPI_Errhandler*)errhandler);
+ *ierr = MPI_Errhandler_free(static_cast<MPI_Errhandler*>(errhandler));
 }
 
 void mpi_errhandler_get_ (int* comm, void* errhandler, int* ierr) {
- *ierr = MPI_Errhandler_get(smpi_comm_f2c(*comm), (MPI_Errhandler*) errhandler);
+ *ierr = MPI_Errhandler_get(smpi_comm_f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
 }
 
 void mpi_errhandler_set_ (int* comm, void* errhandler, int* ierr) {
- *ierr = MPI_Errhandler_set(smpi_comm_f2c(*comm), *(MPI_Errhandler*)errhandler);
+ *ierr = MPI_Errhandler_set(smpi_comm_f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
 }
 
 void mpi_comm_set_errhandler_ (int* comm, void* errhandler, int* ierr) {
- *ierr = MPI_Errhandler_set(smpi_comm_f2c(*comm), *(MPI_Errhandler*)errhandler);
+ *ierr = MPI_Errhandler_set(smpi_comm_f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
 }
 
 void mpi_comm_get_errhandler_ (int* comm, void* errhandler, int* ierr) {
- *ierr = MPI_Errhandler_set(smpi_comm_f2c(*comm), (MPI_Errhandler*)errhandler);
+ *ierr = MPI_Errhandler_set(smpi_comm_f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
 }
 
 void mpi_type_contiguous_ (int* count, int* old_type, int*  newtype, int* ierr) {
@@ -1255,14 +1266,12 @@ void mpi_testsome_ (int* incount, int*  requests, int* outcount, int* indices, M
   }
   *ierr = MPI_Testsome(*incount, reqs, outcount, indices, FORT_STATUSES_IGNORE(statuses));
   for(i=0;i<*incount;i++){
-    if(indices[i]){
-      if(reqs[indices[i]]==MPI_REQUEST_NULL){
-          free_request(requests[indices[i]]);
-          requests[indices[i]]=MPI_FORTRAN_REQUEST_NULL;
-      }
+    if(indices[i] && reqs[indices[i]]==MPI_REQUEST_NULL){
+      free_request(requests[indices[i]]);
+      requests[indices[i]]=MPI_FORTRAN_REQUEST_NULL;
     }
   }
-  free(reqs);
+  xbt_free(reqs);
 }
 
 void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) {
@@ -1333,7 +1342,7 @@ void mpi_type_create_indexed_block_ (int* count, int* blocklength, int* indices,
 void mpi_type_struct_ (int* count, int* blocklens, MPI_Aint* indices, int* old_types, int*  newtype, int* ierr) {
   MPI_Datatype tmp;
   int i=0;
-  MPI_Datatype* types = (MPI_Datatype*)xbt_malloc(*count*sizeof(MPI_Datatype));
+  MPI_Datatype* types = static_cast<MPI_Datatype*>(xbt_malloc(*count*sizeof(MPI_Datatype)));
   for(i=0; i< *count; i++){
     types[i] = smpi_type_f2c(old_types[i]);
   }
@@ -1347,7 +1356,7 @@ void mpi_type_struct_ (int* count, int* blocklens, MPI_Aint* indices, int* old_t
 void mpi_type_create_struct_(int* count, int* blocklens, MPI_Aint* indices, int*  old_types, int*  newtype, int* ierr){
   MPI_Datatype tmp;
   int i=0;
-  MPI_Datatype* types = (MPI_Datatype*)xbt_malloc(*count*sizeof(MPI_Datatype));
+  MPI_Datatype* types = static_cast<MPI_Datatype*>(xbt_malloc(*count*sizeof(MPI_Datatype)));
   for(i=0; i< *count; i++){
     types[i] = smpi_type_f2c(old_types[i]);
   }
@@ -1449,7 +1458,7 @@ void mpi_rsend_init_ (void* buf, int* count, int* datatype, int *dest, int* tag,
 }
 
 void mpi_keyval_create_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) {
- *ierr = MPI_Keyval_create((MPI_Copy_function*)copy_fn, (MPI_Delete_function*)delete_fn, keyval, extra_state);
+ *ierr = MPI_Keyval_create(reinterpret_cast<MPI_Copy_function*>(copy_fn),reinterpret_cast<MPI_Delete_function*>(delete_fn), keyval, extra_state);
 }
 
 void mpi_keyval_free_ (int* keyval, int* ierr) {
@@ -1486,7 +1495,7 @@ void mpi_type_get_contents_ (int* datatype, int* max_integers, int* max_addresse
                              int* array_of_integers, MPI_Aint* array_of_addresses,
  int* array_of_datatypes, int* ierr){
  *ierr = MPI_Type_get_contents(smpi_type_f2c(*datatype), *max_integers, *max_addresses,*max_datatypes,
-                               array_of_integers, array_of_addresses, (MPI_Datatype*)array_of_datatypes);
+                               array_of_integers, array_of_addresses, reinterpret_cast<MPI_Datatype*>(array_of_datatypes));
 }
 
 void mpi_type_create_darray_ (int* size, int* rank, int* ndims, int* array_of_gsizes, int* array_of_distribs,
@@ -1529,8 +1538,8 @@ void mpi_type_match_size_ (int* typeclass,int* size,int* datatype, int* ierr){
 
 void mpi_alltoallw_ ( void *sendbuf, int *sendcnts, int *sdispls, int* sendtypes, void *recvbuf, int *recvcnts,
                       int *rdispls, int* recvtypes, int* comm, int* ierr){
- *ierr = MPI_Alltoallw( sendbuf, sendcnts, sdispls, (MPI_Datatype*) sendtypes, recvbuf, recvcnts, rdispls,
-                        (MPI_Datatype*)recvtypes, smpi_comm_f2c(*comm));
+ *ierr = MPI_Alltoallw( sendbuf, sendcnts, sdispls, reinterpret_cast<MPI_Datatype*>(sendtypes), recvbuf, recvcnts, rdispls,
+                        reinterpret_cast<MPI_Datatype*>(recvtypes), smpi_comm_f2c(*comm));
 }
 
 void mpi_exscan_ (void *sendbuf, void *recvbuf, int* count, int* datatype, int* op, int* comm, int* ierr){
@@ -1574,7 +1583,7 @@ void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
 }
 
 void mpi_comm_create_errhandler_ ( void *function, void *errhandler, int* ierr){
- *ierr = MPI_Comm_create_errhandler( (MPI_Comm_errhandler_fn*) function, (MPI_Errhandler*)errhandler);
+ *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), static_cast<MPI_Errhandler*>(errhandler));
 }
 
 void mpi_add_error_class_ ( int *errorclass, int* ierr){
@@ -1602,29 +1611,31 @@ void mpi_info_dup_ (int* info, int* newinfo, int* ierr){
 }
 
 void mpi_info_get_valuelen_ ( int* info, char *key, int *valuelen, int *flag, int* ierr, unsigned int keylen){
- while(key[keylen-1]==' ')keylen--;
- while(*key==' '){//handle leading blanks
-   keylen --;
-   key++;
- }
- char* tkey = xbt_new(char, keylen+1);
- strncpy(tkey, key, keylen);
- tkey[keylen]='\0';
- *ierr = MPI_Info_get_valuelen( smpi_info_f2c(*info), tkey, valuelen, flag);
- xbt_free(tkey);
+  while(key[keylen-1]==' ')
+    keylen--;
+  while(*key==' '){//handle leading blanks
+    keylen--;
+    key++;
+  }
+  char* tkey = xbt_new(char, keylen+1);
+  strncpy(tkey, key, keylen);
+  tkey[keylen]='\0';
+  *ierr = MPI_Info_get_valuelen( smpi_info_f2c(*info), tkey, valuelen, flag);
+  xbt_free(tkey);
 }
 
 void mpi_info_delete_ (int* info, char *key, int* ierr, unsigned int keylen){
- while(key[keylen-1]==' ')keylen--;
- while(*key==' '){//handle leading blanks
-   keylen --;
-   key++;
- }
- char* tkey = xbt_new(char, keylen+1);
- strncpy(tkey, key, keylen);
- tkey[keylen]='\0';
- *ierr = MPI_Info_delete(smpi_info_f2c(*info), tkey);
- xbt_free(tkey);
+  while(key[keylen-1]==' ')
+    keylen--;
+  while(*key==' '){//handle leading blanks
+    keylen--;
+    key++;
+  }
+  char* tkey = xbt_new(char, keylen+1);
+  strncpy(tkey, key, keylen);
+  tkey[keylen]='\0';
+  *ierr = MPI_Info_delete(smpi_info_f2c(*info), tkey);
+  xbt_free(tkey);
 }
 
 void mpi_info_get_nkeys_ ( int* info, int *nkeys, int* ierr){
@@ -1632,10 +1643,10 @@ void mpi_info_get_nkeys_ ( int* info, int *nkeys, int* ierr){
 }
 
 void mpi_info_get_nthkey_ ( int* info, int* n, char *key, int* ierr, unsigned int keylen){
- *ierr = MPI_Info_get_nthkey( smpi_info_f2c(*info), *n, key);
- unsigned int i = 0;
- for (i=strlen(key); i<keylen; i++)
- key[i]=' ';
 *ierr = MPI_Info_get_nthkey( smpi_info_f2c(*info), *n, key);
 unsigned int i = 0;
 for (i=strlen(key); i<keylen; i++)
   key[i]=' ';
 }
 
 void mpi_get_version_ (int *version,int *subversion, int* ierr){
@@ -1652,8 +1663,8 @@ void mpi_request_get_status_ ( int* request, int *flag, MPI_Status* status, int*
 
 void mpi_grequest_start_ ( void *query_fn, void *free_fn, void *cancel_fn, void *extra_state, int*request, int* ierr){
   MPI_Request tmp;
-  *ierr = MPI_Grequest_start( (MPI_Grequest_query_function*)query_fn, (MPI_Grequest_free_function*)free_fn,
-                              (MPI_Grequest_cancel_function*)cancel_fn, extra_state, &tmp);
+  *ierr = MPI_Grequest_start( reinterpret_cast<MPI_Grequest_query_function*>(query_fn), reinterpret_cast<MPI_Grequest_free_function*>(free_fn),
+                              reinterpret_cast<MPI_Grequest_cancel_function*>(cancel_fn), extra_state, &tmp);
  if(*ierr == MPI_SUCCESS) {
    *request = smpi_request_c2f(tmp);
  }
@@ -1673,22 +1684,22 @@ void mpi_status_set_elements_ ( MPI_Status* status, int* datatype, int* count, i
 
 void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
   MPI_Comm tmp;
-  *ierr = MPI_Comm_connect( port_name, *(MPI_Info*)info, *root, smpi_comm_f2c(*comm), &tmp);
+  *ierr = MPI_Comm_connect( port_name, *reinterpret_cast<MPI_Info*>(info), *root, smpi_comm_f2c(*comm), &tmp);
   if(*ierr == MPI_SUCCESS) {
     *newcomm = smpi_comm_c2f(tmp);
   }
 }
 
 void mpi_publish_name_ ( char *service_name, int* info, char *port_name, int* ierr){
- *ierr = MPI_Publish_name( service_name, *(MPI_Info*)info, port_name);
+ *ierr = MPI_Publish_name( service_name, *reinterpret_cast<MPI_Info*>(info), port_name);
 }
 
 void mpi_unpublish_name_ ( char *service_name, int* info, char *port_name, int* ierr){
- *ierr = MPI_Unpublish_name( service_name, *(MPI_Info*)info, port_name);
+ *ierr = MPI_Unpublish_name( service_name, *reinterpret_cast<MPI_Info*>(info), port_name);
 }
 
 void mpi_lookup_name_ ( char *service_name, int* info, char *port_name, int* ierr){
- *ierr = MPI_Lookup_name( service_name, *(MPI_Info*)info, port_name);
+ *ierr = MPI_Lookup_name( service_name, *reinterpret_cast<MPI_Info*>(info), port_name);
 }
 
 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
@@ -1700,7 +1711,7 @@ void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
 }
 
 void mpi_open_port_ ( int* info, char *port_name, int* ierr){
- *ierr = MPI_Open_port( *(MPI_Info*)info,port_name);
+ *ierr = MPI_Open_port( *reinterpret_cast<MPI_Info*>(info),port_name);
 }
 
 void mpi_close_port_ ( char *port_name, int* ierr){
@@ -1709,7 +1720,7 @@ void mpi_close_port_ ( char *port_name, int* ierr){
 
 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
   MPI_Comm tmp;
-  *ierr = MPI_Comm_accept( port_name, *(MPI_Info*)info, *root, smpi_comm_f2c(*comm), &tmp);
+  *ierr = MPI_Comm_accept( port_name, *reinterpret_cast<MPI_Info*>(info), *root, smpi_comm_f2c(*comm), &tmp);
   if(*ierr == MPI_SUCCESS) {
     *newcomm = smpi_comm_c2f(tmp);
   }
@@ -1718,7 +1729,7 @@ void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*ne
 void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm,
                        int* array_of_errcodes, int* ierr){
   MPI_Comm tmp;
-  *ierr = MPI_Comm_spawn( command, NULL, *maxprocs, *(MPI_Info*)info, *root, smpi_comm_f2c(*comm), &tmp,
+  *ierr = MPI_Comm_spawn( command, NULL, *maxprocs, *reinterpret_cast<MPI_Info*>(info), *root, smpi_comm_f2c(*comm), &tmp,
                           array_of_errcodes);
   if(*ierr == MPI_SUCCESS) {
     *intercomm = smpi_comm_c2f(tmp);
@@ -1730,7 +1741,7 @@ void mpi_comm_spawn_multiple_ ( int* count, char *array_of_commands, char** arra
  int* comm, int* intercomm, int* array_of_errcodes, int* ierr){
  MPI_Comm tmp;
  *ierr = MPI_Comm_spawn_multiple(* count, &array_of_commands, &array_of_argv, array_of_maxprocs,
(MPI_Info*)array_of_info, *root, smpi_comm_f2c(*comm), &tmp, array_of_errcodes);
reinterpret_cast<MPI_Info*>(array_of_info), *root, smpi_comm_f2c(*comm), &tmp, array_of_errcodes);
  if(*ierr == MPI_SUCCESS) {
    *intercomm = smpi_comm_c2f(tmp);
  }
index e2bc344..1a008f9 100644 (file)
@@ -67,13 +67,13 @@ MPI_Errhandler *MPI_ERRHANDLER_NULL = NULL;
 
 static char *get_mailbox_name(char *str, int index)
 {
-  snprintf(str, MAILBOX_NAME_MAXLEN, "SMPI-%0*x", (int) (sizeof(int) * 2), index);
+  snprintf(str, MAILBOX_NAME_MAXLEN, "SMPI-%0*x", static_cast<int> (sizeof(int) * 2), index);
   return str;
 }
 
 static char *get_mailbox_name_small(char *str, int index)
 {
-  snprintf(str, MAILBOX_NAME_MAXLEN, "small%0*x", (int) (sizeof(int) * 2), index);
+  snprintf(str, MAILBOX_NAME_MAXLEN, "small%0*x", static_cast<int> (sizeof(int) * 2), index);
   return str;
 }
 
@@ -83,16 +83,15 @@ void smpi_process_init(int *argc, char ***argv)
   smpi_process_data_t data;
   smx_process_t proc;
 
-  if (argc && argv) {
+  if (argc != NULL && argv != NULL) {
     proc = SIMIX_process_self();
-    //FIXME: dirty cleanup method to avoid using msg cleanup functions on these processes when using MSG+SMPI
     SIMIX_process_set_cleanup_function(proc, MSG_process_cleanup_from_SIMIX);
     char* instance_id = (*argv)[1];
     int rank = xbt_str_parse_int((*argv)[2], "Invalid rank: %s");
     index = smpi_process_index_of_smx_process(proc);
 
-    if(!index_to_process_data){
-      index_to_process_data=(int*)xbt_malloc(SIMIX_process_count()*sizeof(int));
+    if(index_to_process_data == NULL){
+      index_to_process_data=static_cast<int*>(xbt_malloc(SIMIX_process_count()*sizeof(int)));
     }
 
     if(smpi_privatize_global_variables){
@@ -107,11 +106,11 @@ void smpi_process_init(int *argc, char ***argv)
     smpi_deployment_register_process(instance_id, rank, index, &temp_comm_world, &temp_bar);
     data              = smpi_process_remote_data(index);
     data->comm_world  = temp_comm_world;
-    if(temp_bar != NULL) data->finalization_barrier = temp_bar;
+    if(temp_bar != NULL) 
+      data->finalization_barrier = temp_bar;
     data->index       = index;
     data->instance_id = instance_id;
     data->replaying   = false;
-    //xbt_free(simcall_process_get_data(proc));
 
     simdata_process_t simdata = static_cast<simdata_process_t>(simcall_process_get_data(proc));
     simdata->data             = data;
@@ -134,7 +133,7 @@ void smpi_process_init(int *argc, char ***argv)
       "MPI-2, this is currently not supported by SMPI.");
 }
 
-void smpi_process_destroy(void)
+void smpi_process_destroy()
 {
   int index = smpi_process_index();
   if(smpi_privatize_global_variables){
@@ -145,7 +144,7 @@ void smpi_process_destroy(void)
 }
 
 /** @brief Prepares the current process for termination. */
-void smpi_process_finalize(void)
+void smpi_process_finalize()
 {
     // This leads to an explosion of the search graph which cannot be reduced:
     if(MC_is_active() || MC_record_replay_is_active())
@@ -167,9 +166,9 @@ int smpi_process_finalized()
 }
 
 /** @brief Check if a process is initialized */
-int smpi_process_initialized(void)
+int smpi_process_initialized()
 {
-  if (!index_to_process_data){
+  if (index_to_process_data == NULL){
     return false;
   } else{
     int index = smpi_process_index();
@@ -178,7 +177,7 @@ int smpi_process_initialized(void)
 }
 
 /** @brief Mark a process as initialized (=MPI_Init called) */
-void smpi_process_mark_as_initialized(void)
+void smpi_process_mark_as_initialized()
 {
   int index = smpi_process_index();
   if ((index != MPI_UNDEFINED) && (process_data[index_to_process_data[index]]->state != SMPI_FINALIZED))
@@ -198,7 +197,7 @@ bool smpi_process_get_replaying(){
   else return (_xbt_replay_is_active() != 0);
 }
 
-int smpi_global_size(void)
+int smpi_global_size()
 {
   char *value = getenv("SMPI_GLOBAL_SIZE");
   xbt_assert(value,"Please set env var SMPI_GLOBAL_SIZE to the expected number of processes.");
@@ -206,7 +205,7 @@ int smpi_global_size(void)
   return xbt_str_parse_int(value, "SMPI_GLOBAL_SIZE contains a non-numerical value: %s");
 }
 
-smpi_process_data_t smpi_process_data(void)
+smpi_process_data_t smpi_process_data()
 {
   simdata_process_t simdata = static_cast<simdata_process_t>(SIMIX_process_self_get_data());
   return static_cast<smpi_process_data_t>(simdata->data);
@@ -229,7 +228,7 @@ void *smpi_process_get_user_data()
   return process_data->data;
 }
 
-int smpi_process_count(void)
+int smpi_process_count()
 {
   return process_count;
 }
@@ -240,39 +239,39 @@ int smpi_process_count(void)
  *
  * \see smpi_trace_set_call_location
  */
-smpi_trace_call_location_t* smpi_process_get_call_location(void)
+smpi_trace_call_location_t* smpi_process_get_call_location()
 {
   smpi_process_data_t process_data = smpi_process_data();
   return process_data->trace_call_loc;
 }
 
-int smpi_process_index(void)
+int smpi_process_index()
 {
   smpi_process_data_t data = smpi_process_data();
   //return -1 if not initialized
-  return data ? data->index : MPI_UNDEFINED;
+  return data != NULL ? data->index : MPI_UNDEFINED;
 }
 
-MPI_Comm smpi_process_comm_world(void)
+MPI_Comm smpi_process_comm_world()
 {
   smpi_process_data_t data = smpi_process_data();
   //return MPI_COMM_NULL if not initialized
-  return data ? *data->comm_world : MPI_COMM_NULL;
+  return data != NULL ? *data->comm_world : MPI_COMM_NULL;
 }
 
-smx_mailbox_t smpi_process_mailbox(void)
+smx_mailbox_t smpi_process_mailbox()
 {
   smpi_process_data_t data = smpi_process_data();
   return data->mailbox;
 }
 
-smx_mailbox_t smpi_process_mailbox_small(void)
+smx_mailbox_t smpi_process_mailbox_small()
 {
   smpi_process_data_t data = smpi_process_data();
   return data->mailbox_small;
 }
 
-xbt_mutex_t smpi_process_mailboxes_mutex(void)
+xbt_mutex_t smpi_process_mailboxes_mutex()
 {
   smpi_process_data_t data = smpi_process_data();
   return data->mailboxes_mutex;
@@ -296,25 +295,25 @@ xbt_mutex_t smpi_process_remote_mailboxes_mutex(int index)
   return data->mailboxes_mutex;
 }
 
-xbt_os_timer_t smpi_process_timer(void)
+xbt_os_timer_t smpi_process_timer()
 {
   smpi_process_data_t data = smpi_process_data();
   return data->timer;
 }
 
-void smpi_process_simulated_start(void)
+void smpi_process_simulated_start()
 {
   smpi_process_data_t data = smpi_process_data();
   data->simulated = SIMIX_get_clock();
 }
 
-double smpi_process_simulated_elapsed(void)
+double smpi_process_simulated_elapsed()
 {
   smpi_process_data_t data = smpi_process_data();
   return SIMIX_get_clock() - data->simulated;
 }
 
-MPI_Comm smpi_process_comm_self(void)
+MPI_Comm smpi_process_comm_self()
 {
   smpi_process_data_t data = smpi_process_data();
   if(data->comm_self==MPI_COMM_NULL){
@@ -326,7 +325,7 @@ MPI_Comm smpi_process_comm_self(void)
   return data->comm_self;
 }
 
-MPI_Comm smpi_process_get_comm_intra(void)
+MPI_Comm smpi_process_get_comm_intra()
 {
   smpi_process_data_t data = smpi_process_data();
   return data->comm_intra;
@@ -344,7 +343,7 @@ void smpi_process_set_sampling(int s)
   data->sampling = s;
 }
 
-int smpi_process_get_sampling(void)
+int smpi_process_get_sampling()
 {
   smpi_process_data_t data = smpi_process_data();
   return data->sampling;
@@ -362,21 +361,21 @@ void smpi_comm_copy_buffer_callback(smx_synchro_t synchro, void *buff, size_t bu
   void* tmpbuff=buff;
   simgrid::simix::Comm *comm = dynamic_cast<simgrid::simix::Comm*>(synchro);
 
-  if((smpi_privatize_global_variables) && ((char*)buff >= smpi_start_data_exe)
-      && ((char*)buff < smpi_start_data_exe + smpi_size_data_exe )
+  if((smpi_privatize_global_variables) && (static_cast<char*>(buff) >= smpi_start_data_exe)
+      && (static_cast<char*>(buff) < smpi_start_data_exe + smpi_size_data_exe )
     ){
        XBT_DEBUG("Privatization : We are copying from a zone inside global memory... Saving data to temp buffer !");
 
 
-       smpi_switch_data_segment(((smpi_process_data_t)(((simdata_process_t)SIMIX_process_get_data(comm->src_proc))->data))->index);
-       tmpbuff = (void*)xbt_malloc(buff_size);
+       smpi_switch_data_segment((static_cast<smpi_process_data_t>((static_cast<simdata_process_t>(SIMIX_process_get_data(comm->src_proc))->data))->index));
+       tmpbuff = static_cast<void*>(xbt_malloc(buff_size));
        memcpy(tmpbuff, buff, buff_size);
   }
 
   if((smpi_privatize_global_variables) && ((char*)comm->dst_buff >= smpi_start_data_exe)
       && ((char*)comm->dst_buff < smpi_start_data_exe + smpi_size_data_exe )){
        XBT_DEBUG("Privatization : We are copying to a zone inside global memory - Switch data segment");
-       smpi_switch_data_segment(((smpi_process_data_t)(((simdata_process_t)SIMIX_process_get_data(comm->dst_proc))->data))->index);
+       smpi_switch_data_segment((static_cast<smpi_process_data_t>((static_cast<simdata_process_t>(SIMIX_process_get_data(comm->dst_proc))->data))->index));
   }
 
   memcpy(comm->dst_buff, tmpbuff, buff_size);
@@ -410,11 +409,11 @@ static void smpi_check_options(){
    }
 }
 
-int smpi_enabled(void) {
+int smpi_enabled() {
   return process_data != NULL;
 }
 
-void smpi_global_init(void)
+void smpi_global_init()
 {
   int i;
   MPI_Group group;
@@ -455,7 +454,6 @@ void smpi_global_init(void)
   process_data = xbt_new0(smpi_process_data_t, process_count);
   for (i = 0; i < process_count; i++) {
     process_data[i]                       = xbt_new(s_smpi_process_data_t, 1);
-    //process_data[i]->index              = i;
     process_data[i]->argc                 = NULL;
     process_data[i]->argv                 = NULL;
     process_data[i]->mailbox              = simcall_mbox_create(get_mailbox_name(name, i));
@@ -481,7 +479,7 @@ void smpi_global_init(void)
   if(smpirun){
     group = smpi_group_new(process_count);
     MPI_COMM_WORLD = smpi_comm_new(group, NULL);
-    MPI_Attr_put(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, (void *)(MPI_Aint)process_count);
+    MPI_Attr_put(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, reinterpret_cast<void *>(process_count));
     xbt_bar_t bar=xbt_barrier_init(process_count);
 
     for (i = 0; i < process_count; i++) {
@@ -491,7 +489,7 @@ void smpi_global_init(void)
   }
 }
 
-void smpi_global_destroy(void)
+void smpi_global_destroy()
 {
   int count = smpi_process_count();
   int i;
@@ -597,55 +595,55 @@ static void smpi_init_logs(){
 
 static void smpi_init_options(){
   int gather_id = find_coll_description(mpi_coll_gather_description, xbt_cfg_get_string("smpi/gather"),"gather");
-    mpi_coll_gather_fun = (int (*)(void *, int, MPI_Datatype, void *, int, MPI_Datatype, int, MPI_Comm))
-        mpi_coll_gather_description[gather_id].coll;
+    mpi_coll_gather_fun = reinterpret_cast<int (*)(void *, int, MPI_Datatype, void *, int, MPI_Datatype, int, MPI_Comm)>
+        (mpi_coll_gather_description[gather_id].coll);
 
     int allgather_id = find_coll_description(mpi_coll_allgather_description,
                                              xbt_cfg_get_string("smpi/allgather"),"allgather");
-    mpi_coll_allgather_fun = (int (*)(void *, int, MPI_Datatype, void *, int, MPI_Datatype, MPI_Comm))
-        mpi_coll_allgather_description[allgather_id].coll;
+    mpi_coll_allgather_fun = reinterpret_cast<int (*)(void *, int, MPI_Datatype, void *, int, MPI_Datatype, MPI_Comm)>
+        (mpi_coll_allgather_description[allgather_id].coll);
 
     int allgatherv_id = find_coll_description(mpi_coll_allgatherv_description,
                                               xbt_cfg_get_string("smpi/allgatherv"),"allgatherv");
-    mpi_coll_allgatherv_fun = (int (*)(void *, int, MPI_Datatype, void *, int *, int *, MPI_Datatype, MPI_Comm))
-        mpi_coll_allgatherv_description[allgatherv_id].coll;
+    mpi_coll_allgatherv_fun = reinterpret_cast<int (*)(void *, int, MPI_Datatype, void *, int *, int *, MPI_Datatype, MPI_Comm)>
+        (mpi_coll_allgatherv_description[allgatherv_id].coll);
 
     int allreduce_id = find_coll_description(mpi_coll_allreduce_description,
                                              xbt_cfg_get_string("smpi/allreduce"),"allreduce");
-    mpi_coll_allreduce_fun = (int (*)(void *sbuf, void *rbuf, int rcount, MPI_Datatype dtype, MPI_Op op, MPI_Comm comm))
-        mpi_coll_allreduce_description[allreduce_id].coll;
+    mpi_coll_allreduce_fun = reinterpret_cast<int (*)(void *sbuf, void *rbuf, int rcount, MPI_Datatype dtype, MPI_Op op, MPI_Comm comm)>
+        (mpi_coll_allreduce_description[allreduce_id].coll);
 
     int alltoall_id = find_coll_description(mpi_coll_alltoall_description,
                                             xbt_cfg_get_string("smpi/alltoall"),"alltoall");
-    mpi_coll_alltoall_fun = (int (*)(void *, int, MPI_Datatype, void *, int, MPI_Datatype, MPI_Comm))
-        mpi_coll_alltoall_description[alltoall_id].coll;
+    mpi_coll_alltoall_fun = reinterpret_cast<int (*)(void *, int, MPI_Datatype, void *, int, MPI_Datatype, MPI_Comm)>
+        (mpi_coll_alltoall_description[alltoall_id].coll);
 
     int alltoallv_id = find_coll_description(mpi_coll_alltoallv_description,
                                              xbt_cfg_get_string("smpi/alltoallv"),"alltoallv");
-    mpi_coll_alltoallv_fun = (int (*)(void *, int *, int *, MPI_Datatype, void *, int *, int *, MPI_Datatype, MPI_Comm))
-        mpi_coll_alltoallv_description[alltoallv_id].coll;
+    mpi_coll_alltoallv_fun = reinterpret_cast<int (*)(void *, int *, int *, MPI_Datatype, void *, int *, int *, MPI_Datatype, MPI_Comm)>
+        (mpi_coll_alltoallv_description[alltoallv_id].coll);
 
     int bcast_id = find_coll_description(mpi_coll_bcast_description, xbt_cfg_get_string("smpi/bcast"),"bcast");
-    mpi_coll_bcast_fun = (int (*)(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm com))
-        mpi_coll_bcast_description[bcast_id].coll;
+    mpi_coll_bcast_fun = reinterpret_cast<int (*)(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm com)>
+        (mpi_coll_bcast_description[bcast_id].coll);
 
     int reduce_id = find_coll_description(mpi_coll_reduce_description, xbt_cfg_get_string("smpi/reduce"),"reduce");
-    mpi_coll_reduce_fun = (int (*)(void *buf, void *rbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,
-                                    MPI_Comm comm)) mpi_coll_reduce_description[reduce_id].coll;
+    mpi_coll_reduce_fun = reinterpret_cast<int (*)(void *buf, void *rbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)>
+        (mpi_coll_reduce_description[reduce_id].coll);
 
     int reduce_scatter_id =
         find_coll_description(mpi_coll_reduce_scatter_description,
                               xbt_cfg_get_string("smpi/reduce-scatter"),"reduce_scatter");
-    mpi_coll_reduce_scatter_fun = (int (*)(void *sbuf, void *rbuf, int *rcounts,MPI_Datatype dtype, MPI_Op op,
-                                           MPI_Comm comm)) mpi_coll_reduce_scatter_description[reduce_scatter_id].coll;
+    mpi_coll_reduce_scatter_fun = reinterpret_cast<int (*)(void *sbuf, void *rbuf, int *rcounts,MPI_Datatype dtype, MPI_Op op, MPI_Comm comm)>
+        (mpi_coll_reduce_scatter_description[reduce_scatter_id].coll);
 
     int scatter_id = find_coll_description(mpi_coll_scatter_description, xbt_cfg_get_string("smpi/scatter"),"scatter");
-    mpi_coll_scatter_fun = (int (*)(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,
-                                    int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm))
-        mpi_coll_scatter_description[scatter_id].coll;
+    mpi_coll_scatter_fun = reinterpret_cast<int (*)(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)>
+        (mpi_coll_scatter_description[scatter_id].coll);
 
     int barrier_id = find_coll_description(mpi_coll_barrier_description, xbt_cfg_get_string("smpi/barrier"),"barrier");
-    mpi_coll_barrier_fun = (int (*)(MPI_Comm comm)) mpi_coll_barrier_description[barrier_id].coll;
+    mpi_coll_barrier_fun = reinterpret_cast<int (*)(MPI_Comm comm)>
+        (mpi_coll_barrier_description[barrier_id].coll);
 
     smpi_coll_cleanup_callback=NULL;
     smpi_cpu_threshold = xbt_cfg_get_double("smpi/cpu-threshold");
index ea72ca5..36e94c0 100644 (file)
@@ -62,8 +62,8 @@ MPI_Group smpi_group_copy(MPI_Group origin)
       }
 
       xbt_dict_foreach(origin->index_to_rank_map, cursor, key, ptr_rank) {
-        int * cp = (int*)xbt_malloc(sizeof(int));
-        *cp=*(int*)ptr_rank;
+        int * cp = static_cast<int*>(xbt_malloc(sizeof(int)));
+        *cp=*reinterpret_cast<int*>(ptr_rank);
         xbt_dict_set(group->index_to_rank_map, key, cp, NULL);
       }
     }
@@ -86,12 +86,12 @@ void smpi_group_set_mapping(MPI_Group group, int index, int rank)
   if (rank < group->size) {
     group->rank_to_index_map[rank] = index;
     if (index!=MPI_UNDEFINED ) {
-      val_rank = (int *) malloc(sizeof(int));
+      val_rank = static_cast<int *>(xbt_malloc(sizeof(int)));
       *val_rank = rank;
 
       char * key = bprintf("%d", index);
       xbt_dict_set(group->index_to_rank_map, key, val_rank, NULL);
-      free(key);
+      xbt_free(key);
     }
   }
 }
index 6e6410f..25f4454 100644 (file)
@@ -1,6 +1,4 @@
-/* smpi_mpi_dt.c -- MPI primitives to handle datatypes                        */
-/* FIXME: a very incomplete implementation                                    */
-
+/* smpi_mpi_dt.c -- MPI primitives to handle datatypes                      */
 /* Copyright (c) 2009-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
@@ -154,8 +152,8 @@ CREATE_MPI_DATATYPE(MPI_PACKED, char);
 CREATE_MPI_DATATYPE(MPI_PTR, void*);
 
 /** Check if the datatype is usable for communications */
-int is_datatype_valid(MPI_Datatype datatype) {
-    return datatype != MPI_DATATYPE_NULL && (datatype->flags & DT_FLAG_COMMITED);
+bool is_datatype_valid(MPI_Datatype datatype) {
+    return datatype != MPI_DATATYPE_NULL && ((datatype->flags & DT_FLAG_COMMITED) != 0);
 }
 
 size_t smpi_datatype_size(MPI_Datatype datatype)
@@ -195,8 +193,8 @@ int smpi_datatype_dup(MPI_Datatype datatype, MPI_Datatype* new_t)
       void* value_out;
       xbt_dict_foreach(datatype->attributes, cursor, key, value_in){
         smpi_type_key_elem elem =
-          static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals,  (const char*)key, sizeof(int)));
-        if(elem && elem->copy_fn!=MPI_NULL_COPY_FN){
+          static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals,  reinterpret_cast<const char*>(key), sizeof(int)));
+        if(elem != NULL && elem->copy_fn!=MPI_NULL_COPY_FN){
           ret = elem->copy_fn(datatype, *key, NULL, value_in, &value_out, &flag );
           if(ret!=MPI_SUCCESS){
             smpi_datatype_unuse(*new_t);
@@ -205,7 +203,7 @@ int smpi_datatype_dup(MPI_Datatype datatype, MPI_Datatype* new_t)
             return ret;
           }
           if(flag)
-            xbt_dict_set_ext((*new_t)->attributes, (const char*)key, sizeof(int),value_out, NULL);
+            xbt_dict_set_ext((*new_t)->attributes, reinterpret_cast<const char*>(key), sizeof(int),value_out, NULL);
         }
       }
     }
@@ -233,13 +231,13 @@ MPI_Aint smpi_datatype_get_extent(MPI_Datatype datatype){
 
 void smpi_datatype_get_name(MPI_Datatype datatype, char* name, int* length){
   *length = strlen(datatype->name);
-  strcpy(name, datatype->name);
+  strncpy(name, datatype->name, *length+1);
 }
 
 void smpi_datatype_set_name(MPI_Datatype datatype, char* name){
-  if(datatype->name!=NULL &&  !(datatype->flags & DT_FLAG_PREDEFINED))
+  if(datatype->name!=NULL &&  (datatype->flags & DT_FLAG_PREDEFINED) == 0)
     xbt_free(datatype->name);
-  datatype->name = xbt_strdup(name);;
+  datatype->name = xbt_strdup(name);
 }
 
 int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
@@ -257,7 +255,8 @@ int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     count = sendcount < recvcount ? sendcount : recvcount;
 
     if(sendtype->sizeof_substruct == 0 && recvtype->sizeof_substruct == 0) {
-      if(!smpi_process_get_replaying()) memcpy(recvbuf, sendbuf, count);
+      if(!smpi_process_get_replaying()) 
+        memcpy(recvbuf, sendbuf, count);
     }
     else if (sendtype->sizeof_substruct == 0)
     {
@@ -277,7 +276,7 @@ int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
       subtype =  static_cast<s_smpi_subtype_t*>(recvtype->substruct);
       subtype->unserialize( buf_tmp, recvbuf,count/smpi_datatype_size(recvtype), subtype, MPI_REPLACE);
 
-      free(buf_tmp);
+      xbt_free(buf_tmp);
     }
   }
 
@@ -295,16 +294,16 @@ int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
  */
 void serialize_vector( const void *noncontiguous_vector, void *contiguous_vector, int count, void *type)
 {
-  s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)type;
+  s_smpi_mpi_vector_t* type_c = reinterpret_cast<s_smpi_mpi_vector_t*>(type);
   int i;
-  char* contiguous_vector_char = (char*)contiguous_vector;
-  char* noncontiguous_vector_char = (char*)noncontiguous_vector;
+  char* contiguous_vector_char = static_cast<char*>(contiguous_vector);
+  const char* noncontiguous_vector_char = static_cast<const char*>(noncontiguous_vector);
 
   for (i = 0; i < type_c->block_count * count; i++) {
       if (type_c->old_type->sizeof_substruct == 0)
         memcpy(contiguous_vector_char, noncontiguous_vector_char, type_c->block_length * type_c->size_oldtype);
       else
-        ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
+        static_cast<s_smpi_subtype_t*>(type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
                                                                      contiguous_vector_char,
                                                                      type_c->block_length, type_c->old_type->substruct);
 
@@ -327,20 +326,18 @@ void serialize_vector( const void *noncontiguous_vector, void *contiguous_vector
  */
 void unserialize_vector( const void *contiguous_vector, void *noncontiguous_vector, int count, void *type, MPI_Op op)
 {
-  s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)type;
+  s_smpi_mpi_vector_t* type_c = reinterpret_cast<s_smpi_mpi_vector_t*>(type);
   int i;
 
-  char* contiguous_vector_char = (char*)contiguous_vector;
-  char* noncontiguous_vector_char = (char*)noncontiguous_vector;
+  const char* contiguous_vector_char = static_cast<const char*>(contiguous_vector);
+  char* noncontiguous_vector_char = static_cast<char*>(noncontiguous_vector);
 
   for (i = 0; i < type_c->block_count * count; i++) {
     if (type_c->old_type->sizeof_substruct == 0)
       smpi_op_apply(op, contiguous_vector_char, noncontiguous_vector_char, &type_c->block_length,
           &type_c->old_type);
-     /* memcpy(noncontiguous_vector_char,
-             contiguous_vector_char, type_c->block_length * type_c->size_oldtype);*/
     else
-      ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize(contiguous_vector_char, noncontiguous_vector_char,
+      static_cast<s_smpi_subtype_t*>(type_c->old_type->substruct)->unserialize(contiguous_vector_char, noncontiguous_vector_char,
                                                                     type_c->block_length,type_c->old_type->substruct,
                                                                     op);
     contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
@@ -392,7 +389,8 @@ void smpi_datatype_create(MPI_Datatype* new_type, int size,int lb, int ub, int s
 void smpi_datatype_free(MPI_Datatype* type){
   xbt_assert((*type)->in_use >= 0);
 
-  if((*type)->flags & DT_FLAG_PREDEFINED)return;
+  if((*type)->flags & DT_FLAG_PREDEFINED)
+    return;
 
   //if still used, mark for deletion
   if((*type)->in_use!=0){
@@ -407,8 +405,8 @@ void smpi_datatype_free(MPI_Datatype* type){
     int flag;
     xbt_dict_foreach((*type)->attributes, cursor, key, value){
       smpi_type_key_elem elem =
-          static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, (const char*)key, sizeof(int)));
-      if(elem &&  elem->delete_fn)
+          static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast<const char*>(key), sizeof(int)));
+      if(elem!=NULL &&  elem->delete_fn)
         elem->delete_fn(*type,*key, value, &flag);
     }
     xbt_dict_free(&(*type)->attributes);
@@ -425,10 +423,11 @@ void smpi_datatype_free(MPI_Datatype* type){
 
 void smpi_datatype_use(MPI_Datatype type){
 
-  if(type)type->in_use++;
+  if(type != MPI_DATATYPE_NULL)
+    type->in_use++;
 
   if(type->sizeof_substruct!=0){
-    ((s_smpi_subtype_t *)(type)->substruct)->subtype_use(&type);  
+    static_cast<s_smpi_subtype_t *>((type)->substruct)->subtype_use(&type);  
   }
 #if HAVE_MC
   if(MC_is_active())
@@ -441,10 +440,10 @@ void smpi_datatype_unuse(MPI_Datatype type){
     type->in_use--;
 
   if(type->sizeof_substruct!=0){
-    ((s_smpi_subtype_t *)(type)->substruct)->subtype_free(&type);  
+    static_cast<s_smpi_subtype_t *>((type)->substruct)->subtype_free(&type);  
   }
 
-  if(type && type->in_use == 0){
+  if(type != MPI_DATATYPE_NULL && type->in_use == 0){
     smpi_datatype_free(&type);
   }
 #if HAVE_MC
@@ -465,9 +464,9 @@ void smpi_datatype_unuse(MPI_Datatype type){
  */
 void serialize_contiguous( const void *noncontiguous_hvector, void *contiguous_hvector, int count, void *type)
 {
-  s_smpi_mpi_contiguous_t* type_c = (s_smpi_mpi_contiguous_t*)type;
-  char* contiguous_vector_char = (char*)contiguous_hvector;
-  char* noncontiguous_vector_char = (char*)noncontiguous_hvector+type_c->lb;
+  s_smpi_mpi_contiguous_t* type_c = reinterpret_cast<s_smpi_mpi_contiguous_t*>(type);
+  char* contiguous_vector_char = static_cast<char*>(contiguous_hvector);
+  const char* noncontiguous_vector_char = static_cast<const char*>(noncontiguous_hvector)+type_c->lb;
   memcpy(contiguous_vector_char, noncontiguous_vector_char, count* type_c->block_count * type_c->size_oldtype);
 }
 /* Copies contiguous data into noncontiguous memory.
@@ -480,27 +479,27 @@ void serialize_contiguous( const void *noncontiguous_hvector, void *contiguous_h
  */
 void unserialize_contiguous(const void *contiguous_vector, void *noncontiguous_vector, int count, void *type, MPI_Op op)
 {
-  s_smpi_mpi_contiguous_t* type_c = (s_smpi_mpi_contiguous_t*)type;
-  char* contiguous_vector_char = (char*)contiguous_vector;
-  char* noncontiguous_vector_char = (char*)noncontiguous_vector+type_c->lb;
+  s_smpi_mpi_contiguous_t* type_c = reinterpret_cast<s_smpi_mpi_contiguous_t*>(type);
+  const char* contiguous_vector_char = static_cast<const char*>(contiguous_vector);
+  char* noncontiguous_vector_char = static_cast<char*>(noncontiguous_vector)+type_c->lb;
   int n= count* type_c->block_count;
   smpi_op_apply(op, contiguous_vector_char, noncontiguous_vector_char, &n, &type_c->old_type);
-  /*memcpy(noncontiguous_vector_char, contiguous_vector_char, count*  type_c->block_count * type_c->size_oldtype);*/
 }
 
 void free_contiguous(MPI_Datatype* d){
-  smpi_datatype_unuse(((s_smpi_mpi_contiguous_t *)(*d)->substruct)->old_type);
+  smpi_datatype_unuse(reinterpret_cast<s_smpi_mpi_contiguous_t*>((*d)->substruct)->old_type);
 }
 
 void use_contiguous(MPI_Datatype* d){
-  smpi_datatype_use(((s_smpi_mpi_contiguous_t *)(*d)->substruct)->old_type);
+  smpi_datatype_use(reinterpret_cast<s_smpi_mpi_contiguous_t*>((*d)->substruct)->old_type);
 }
 
 /* Create a Sub type contiguous to be able to serialize and unserialize it the structure s_smpi_mpi_contiguous_t is
  * erived from s_smpi_subtype which required the functions unserialize and serialize */
 s_smpi_mpi_contiguous_t* smpi_datatype_contiguous_create( MPI_Aint lb, int block_count, MPI_Datatype old_type,
                                                   int size_oldtype){
-  if(block_count==0)return NULL;
+  if(block_count==0)
+    return NULL;
   s_smpi_mpi_contiguous_t *new_t= xbt_new(s_smpi_mpi_contiguous_t,1);
   new_t->base.serialize = &serialize_contiguous;
   new_t->base.unserialize = &unserialize_contiguous;
@@ -534,14 +533,15 @@ int smpi_datatype_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new
 int smpi_datatype_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type)
 {
   int retval;
-  if (blocklen<0) return MPI_ERR_ARG;
+  if (blocklen<0) 
+    return MPI_ERR_ARG;
   MPI_Aint lb = 0;
   MPI_Aint ub = 0;
   if(count>0){
     lb=smpi_datatype_lb(old_type);
     ub=((count-1)*stride+blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
   }
-  if(old_type->sizeof_substruct || stride != blocklen){
+  if(old_type->sizeof_substruct != 0 || stride != blocklen){
 
     s_smpi_mpi_vector_t* subtype = smpi_datatype_vector_create(stride, blocklen, count, old_type,
                                                                 smpi_datatype_size(old_type));
@@ -558,11 +558,11 @@ int smpi_datatype_vector(int count, int blocklen, int stride, MPI_Datatype old_t
 }
 
 void free_vector(MPI_Datatype* d){
-  smpi_datatype_unuse(((s_smpi_mpi_indexed_t *)(*d)->substruct)->old_type);
+  smpi_datatype_unuse(reinterpret_cast<s_smpi_mpi_indexed_t*>((*d)->substruct)->old_type);
 }
 
 void use_vector(MPI_Datatype* d){
-  smpi_datatype_use(((s_smpi_mpi_indexed_t *)(*d)->substruct)->old_type);
+  smpi_datatype_use(reinterpret_cast<s_smpi_mpi_indexed_t*>((*d)->substruct)->old_type);
 }
 
 /* Hvector Implementation - Vector with stride in bytes */
@@ -577,16 +577,16 @@ void use_vector(MPI_Datatype* d){
  */
 void serialize_hvector( const void *noncontiguous_hvector, void *contiguous_hvector, int count, void *type)
 {
-  s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
+  s_smpi_mpi_hvector_t* type_c = reinterpret_cast<s_smpi_mpi_hvector_t*>(type);
   int i;
-  char* contiguous_vector_char = (char*)contiguous_hvector;
-  char* noncontiguous_vector_char = (char*)noncontiguous_hvector;
+  char* contiguous_vector_char = static_cast<char*>(contiguous_hvector);
+  const char* noncontiguous_vector_char = static_cast<const char*>(noncontiguous_hvector);
 
   for (i = 0; i < type_c->block_count * count; i++) {
     if (type_c->old_type->sizeof_substruct == 0)
       memcpy(contiguous_vector_char, noncontiguous_vector_char, type_c->block_length * type_c->size_oldtype);
     else
-      ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
+      static_cast<s_smpi_subtype_t*>(type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
                                                                    contiguous_vector_char,
                                                                    type_c->block_length, type_c->old_type->substruct);
 
@@ -607,19 +607,17 @@ void serialize_hvector( const void *noncontiguous_hvector, void *contiguous_hvec
  */
 void unserialize_hvector( const void *contiguous_vector, void *noncontiguous_vector, int count, void *type, MPI_Op op)
 {
-  s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
+  s_smpi_mpi_hvector_t* type_c = reinterpret_cast<s_smpi_mpi_hvector_t*>(type);
   int i;
 
-  char* contiguous_vector_char = (char*)contiguous_vector;
-  char* noncontiguous_vector_char = (char*)noncontiguous_vector;
+  const char* contiguous_vector_char = static_cast<const char*>(contiguous_vector);
+  char* noncontiguous_vector_char = static_cast<char*>(noncontiguous_vector);
 
   for (i = 0; i < type_c->block_count * count; i++) {
     if (type_c->old_type->sizeof_substruct == 0)
       smpi_op_apply(op, contiguous_vector_char, noncontiguous_vector_char, &type_c->block_length, &type_c->old_type);
-             /*memcpy(noncontiguous_vector_char,
-           contiguous_vector_char, type_c->block_length * type_c->size_oldtype);*/
     else
-      ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_vector_char, noncontiguous_vector_char,
+      static_cast<s_smpi_subtype_t*>(type_c->old_type->substruct)->unserialize( contiguous_vector_char, noncontiguous_vector_char,
                                                                      type_c->block_length, type_c->old_type->substruct,
                                                                      op);
     contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
@@ -652,24 +650,25 @@ s_smpi_mpi_hvector_t* smpi_datatype_hvector_create( MPI_Aint block_stride, int b
 
 //do nothing for vector types
 void free_hvector(MPI_Datatype* d){
-  smpi_datatype_unuse(((s_smpi_mpi_hvector_t *)(*d)->substruct)->old_type);
+  smpi_datatype_unuse(reinterpret_cast<s_smpi_mpi_hvector_t*>((*d)->substruct)->old_type);
 }
 
 void use_hvector(MPI_Datatype* d){
-  smpi_datatype_use(((s_smpi_mpi_hvector_t *)(*d)->substruct)->old_type);
+  smpi_datatype_use(reinterpret_cast<s_smpi_mpi_hvector_t*>((*d)->substruct)->old_type);
 }
 
 int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type)
 {
   int retval;
-  if (blocklen<0) return MPI_ERR_ARG;
+  if (blocklen<0) 
+    return MPI_ERR_ARG;
   MPI_Aint lb = 0;
   MPI_Aint ub = 0;
   if(count>0){
     lb=smpi_datatype_lb(old_type);
     ub=((count-1)*stride)+(blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
   }
-  if(old_type->sizeof_substruct || stride != blocklen*smpi_datatype_get_extent(old_type)){
+  if(old_type->sizeof_substruct != 0 || stride != blocklen*smpi_datatype_get_extent(old_type)){
     s_smpi_mpi_hvector_t* subtype = smpi_datatype_hvector_create( stride, blocklen, count, old_type,
                                                                   smpi_datatype_size(old_type));
 
@@ -695,16 +694,16 @@ int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype
  */
 void serialize_indexed( const void *noncontiguous_indexed, void *contiguous_indexed, int count, void *type)
 {
-  s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
+  s_smpi_mpi_indexed_t* type_c = reinterpret_cast<s_smpi_mpi_indexed_t*>(type);
   int i,j;
-  char* contiguous_indexed_char = (char*)contiguous_indexed;
-  char* noncontiguous_indexed_char = (char*)noncontiguous_indexed+type_c->block_indices[0] * type_c->size_oldtype;
+  char* contiguous_indexed_char = static_cast<char*>(contiguous_indexed);
+  const char* noncontiguous_indexed_char = static_cast<const char*>(noncontiguous_indexed)+type_c->block_indices[0] * type_c->size_oldtype;
   for(j=0; j<count;j++){
     for (i = 0; i < type_c->block_count; i++) {
       if (type_c->old_type->sizeof_substruct == 0)
         memcpy(contiguous_indexed_char, noncontiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
       else
-        ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_indexed_char,
+        static_cast<s_smpi_subtype_t*>(type_c->old_type->substruct)->serialize( noncontiguous_indexed_char,
                                                                      contiguous_indexed_char,
                                                                      type_c->block_lengths[i],
                                                                      type_c->old_type->substruct);
@@ -712,11 +711,11 @@ void serialize_indexed( const void *noncontiguous_indexed, void *contiguous_inde
       contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
       if (i<type_c->block_count-1)
         noncontiguous_indexed_char =
-          (char*)noncontiguous_indexed + type_c->block_indices[i+1]*smpi_datatype_get_extent(type_c->old_type);
+          static_cast<const char*>(noncontiguous_indexed) + type_c->block_indices[i+1]*smpi_datatype_get_extent(type_c->old_type);
       else
         noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
     }
-    noncontiguous_indexed=(void*)noncontiguous_indexed_char;
+    noncontiguous_indexed=static_cast<const void*>(noncontiguous_indexed_char);
   }
 }
 /* Copies contiguous data into noncontiguous memory.
@@ -729,20 +728,18 @@ void serialize_indexed( const void *noncontiguous_indexed, void *contiguous_inde
  */
 void unserialize_indexed( const void *contiguous_indexed, void *noncontiguous_indexed, int count, void *type, MPI_Op op)
 {
-  s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
+  s_smpi_mpi_indexed_t* type_c = reinterpret_cast<s_smpi_mpi_indexed_t*>(type);
   int i,j;
-  char* contiguous_indexed_char = (char*)contiguous_indexed;
+  const char* contiguous_indexed_char = static_cast<const char*>(contiguous_indexed);
   char* noncontiguous_indexed_char =
-    (char*)noncontiguous_indexed+type_c->block_indices[0]*smpi_datatype_get_extent(type_c->old_type);
+    static_cast<char*>(noncontiguous_indexed)+type_c->block_indices[0]*smpi_datatype_get_extent(type_c->old_type);
   for(j=0; j<count;j++){
     for (i = 0; i < type_c->block_count; i++) {
       if (type_c->old_type->sizeof_substruct == 0)
         smpi_op_apply(op, contiguous_indexed_char, noncontiguous_indexed_char, &type_c->block_lengths[i],
                     &type_c->old_type);
-               /*memcpy(noncontiguous_indexed_char ,
-             contiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);*/
       else
-        ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_indexed_char,
+        static_cast<s_smpi_subtype_t*>(type_c->old_type->substruct)->unserialize( contiguous_indexed_char,
                                                                        noncontiguous_indexed_char,
                                                                        type_c->block_lengths[i],
                                                                        type_c->old_type->substruct, op);
@@ -750,24 +747,24 @@ void unserialize_indexed( const void *contiguous_indexed, void *noncontiguous_in
       contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
       if (i<type_c->block_count-1)
         noncontiguous_indexed_char =
-          (char*)noncontiguous_indexed + type_c->block_indices[i+1]*smpi_datatype_get_extent(type_c->old_type);
+          static_cast<char*>(noncontiguous_indexed) + type_c->block_indices[i+1]*smpi_datatype_get_extent(type_c->old_type);
       else
         noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
     }
-    noncontiguous_indexed=(void*)noncontiguous_indexed_char;
+    noncontiguous_indexed=static_cast<void*>(noncontiguous_indexed_char);
   }
 }
 
 void free_indexed(MPI_Datatype* type){
   if((*type)->in_use==0){
-    xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_lengths);
-    xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_indices);
+    xbt_free(reinterpret_cast<s_smpi_mpi_indexed_t*>((*type)->substruct)->block_lengths);
+    xbt_free(reinterpret_cast<s_smpi_mpi_indexed_t*>((*type)->substruct)->block_indices);
   }
-  smpi_datatype_unuse(((s_smpi_mpi_indexed_t *)(*type)->substruct)->old_type);
+  smpi_datatype_unuse(reinterpret_cast<s_smpi_mpi_indexed_t*>((*type)->substruct)->old_type);
 }
 
 void use_indexed(MPI_Datatype* type){
-  smpi_datatype_use(((s_smpi_mpi_indexed_t *)(*type)->substruct)->old_type);
+  smpi_datatype_use(reinterpret_cast<s_smpi_mpi_indexed_t*>((*type)->substruct)->old_type);
 }
 
 
@@ -817,7 +814,8 @@ int smpi_datatype_indexed(int count, int* blocklens, int* indices, MPI_Datatype
     if(indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type)>ub)
       ub = indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type);
 
-    if ( (i< count -1) && (indices[i]+blocklens[i] != indices[i+1]) )contiguous=0;
+    if ( (i< count -1) && (indices[i]+blocklens[i] != indices[i+1]) )
+      contiguous=0;
   }
   if (old_type->sizeof_substruct != 0)
     contiguous=0;
@@ -847,27 +845,27 @@ int smpi_datatype_indexed(int count, int* blocklens, int* indices, MPI_Datatype
  */
 void serialize_hindexed( const void *noncontiguous_hindexed, void *contiguous_hindexed, int count, void *type)
 {
-  s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
+  s_smpi_mpi_hindexed_t* type_c = reinterpret_cast<s_smpi_mpi_hindexed_t*>(type);
   int i,j;
-  char* contiguous_hindexed_char = (char*)contiguous_hindexed;
-  char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed+ type_c->block_indices[0];
+  char* contiguous_hindexed_char = static_cast<char*>(contiguous_hindexed);
+  const char* noncontiguous_hindexed_char = static_cast<const char*>(noncontiguous_hindexed)+ type_c->block_indices[0];
   for(j=0; j<count;j++){
     for (i = 0; i < type_c->block_count; i++) {
       if (type_c->old_type->sizeof_substruct == 0)
         memcpy(contiguous_hindexed_char, noncontiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
       else
-        ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_hindexed_char,
+        static_cast<s_smpi_subtype_t*>(type_c->old_type->substruct)->serialize( noncontiguous_hindexed_char,
                                                                      contiguous_hindexed_char,
                                                                      type_c->block_lengths[i],
                                                                      type_c->old_type->substruct);
 
       contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
       if (i<type_c->block_count-1)
-        noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
+        noncontiguous_hindexed_char = static_cast<const char*>(noncontiguous_hindexed) + type_c->block_indices[i+1];
       else
         noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
     }
-    noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
+    noncontiguous_hindexed=reinterpret_cast<const void*>(noncontiguous_hindexed_char);
   }
 }
 /* Copies contiguous data into noncontiguous memory.
@@ -881,43 +879,42 @@ void serialize_hindexed( const void *noncontiguous_hindexed, void *contiguous_hi
 void unserialize_hindexed( const void *contiguous_hindexed, void *noncontiguous_hindexed, int count, void *type,
                          MPI_Op op)
 {
-  s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
+  s_smpi_mpi_hindexed_t* type_c = reinterpret_cast<s_smpi_mpi_hindexed_t*>(type);
   int i,j;
 
-  char* contiguous_hindexed_char = (char*)contiguous_hindexed;
-  char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed+ type_c->block_indices[0];
+  const char* contiguous_hindexed_char = static_cast<const char*>(contiguous_hindexed);
+  char* noncontiguous_hindexed_char = static_cast<char*>(noncontiguous_hindexed)+ type_c->block_indices[0];
   for(j=0; j<count;j++){
     for (i = 0; i < type_c->block_count; i++) {
       if (type_c->old_type->sizeof_substruct == 0)
         smpi_op_apply(op, contiguous_hindexed_char, noncontiguous_hindexed_char, &type_c->block_lengths[i],
                             &type_c->old_type);
-        /*memcpy(noncontiguous_hindexed_char,contiguous_hindexed_char,type_c->block_lengths[i]*type_c->size_oldtype);*/
       else
-        ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_hindexed_char,
+        static_cast<s_smpi_subtype_t*>(type_c->old_type->substruct)->unserialize( contiguous_hindexed_char,
                                                                        noncontiguous_hindexed_char,
                                                                        type_c->block_lengths[i],
                                                                        type_c->old_type->substruct, op);
 
       contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
       if (i<type_c->block_count-1)
-        noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
+        noncontiguous_hindexed_char = static_cast<char*>(noncontiguous_hindexed) + type_c->block_indices[i+1];
       else
         noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
     }
-    noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
+    noncontiguous_hindexed=reinterpret_cast<void*>(noncontiguous_hindexed_char);
   }
 }
 
 void free_hindexed(MPI_Datatype* type){
   if((*type)->in_use==0){
-    xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_lengths);
-    xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_indices);
+    xbt_free(reinterpret_cast<s_smpi_mpi_hindexed_t*>((*type)->substruct)->block_lengths);
+    xbt_free(reinterpret_cast<s_smpi_mpi_hindexed_t*>((*type)->substruct)->block_indices);
   }
-  smpi_datatype_unuse(((s_smpi_mpi_indexed_t *)(*type)->substruct)->old_type);
+  smpi_datatype_unuse(reinterpret_cast<s_smpi_mpi_hindexed_t*>((*type)->substruct)->old_type);
 }
 
 void use_hindexed(MPI_Datatype* type){
-  smpi_datatype_use(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->old_type);
+  smpi_datatype_use(reinterpret_cast<s_smpi_mpi_hindexed_t*>((*type)->substruct)->old_type);
 }
 
 /* Create a Sub type hindexed to be able to serialize and unserialize it the structure s_smpi_mpi_hindexed_t is derived
@@ -961,10 +958,12 @@ int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Dat
       return MPI_ERR_ARG;
     size += blocklens[i];
 
-    if(indices[i]+smpi_datatype_lb(old_type)<lb) lb = indices[i]+smpi_datatype_lb(old_type);
-    if(indices[i]+blocklens[i]*smpi_datatype_ub(old_type)>ub) ub = indices[i]+blocklens[i]*smpi_datatype_ub(old_type);
+    if(indices[i]+smpi_datatype_lb(old_type)<lb) 
+      lb = indices[i]+smpi_datatype_lb(old_type);
+    if(indices[i]+blocklens[i]*smpi_datatype_ub(old_type)>ub) 
+      ub = indices[i]+blocklens[i]*smpi_datatype_ub(old_type);
 
-    if ( (i< count -1) && (indices[i]+blocklens[i]*static_cast<int>(smpi_datatype_size(old_type)) != indices[i+1]) )
+    if ( (i< count -1) && (indices[i]+blocklens[i]*(static_cast<int>(smpi_datatype_size(old_type))) != indices[i+1]) )
       contiguous=0;
   }
   if (old_type->sizeof_substruct != 0 || lb!=0)
@@ -995,17 +994,17 @@ int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Dat
  */
 void serialize_struct( const void *noncontiguous_struct, void *contiguous_struct, int count, void *type)
 {
-  s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
+  s_smpi_mpi_struct_t* type_c = reinterpret_cast<s_smpi_mpi_struct_t*>(type);
   int i,j;
-  char* contiguous_struct_char = (char*)contiguous_struct;
-  char* noncontiguous_struct_char = (char*)noncontiguous_struct+ type_c->block_indices[0];
+  char* contiguous_struct_char = static_cast<char*>(contiguous_struct);
+  const char* noncontiguous_struct_char = static_cast<const char*>(noncontiguous_struct)+ type_c->block_indices[0];
   for(j=0; j<count;j++){
     for (i = 0; i < type_c->block_count; i++) {
       if (type_c->old_types[i]->sizeof_substruct == 0)
         memcpy(contiguous_struct_char, noncontiguous_struct_char,
                type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));
       else
-        ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->serialize( noncontiguous_struct_char,
+        static_cast<s_smpi_subtype_t*>(type_c->old_types[i]->substruct)->serialize( noncontiguous_struct_char,
                                                                          contiguous_struct_char,
                                                                          type_c->block_lengths[i],
                                                                          type_c->old_types[i]->substruct);
@@ -1013,11 +1012,11 @@ void serialize_struct( const void *noncontiguous_struct, void *contiguous_struct
 
       contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
       if (i<type_c->block_count-1)
-        noncontiguous_struct_char = (char*)noncontiguous_struct + type_c->block_indices[i+1];
+        noncontiguous_struct_char = static_cast<const char*>(noncontiguous_struct) + type_c->block_indices[i+1];
       else //let's hope this is MPI_UB ?
         noncontiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_types[i]);
     }
-    noncontiguous_struct=(void*)noncontiguous_struct_char;
+    noncontiguous_struct=reinterpret_cast<const void*>(noncontiguous_struct_char);
   }
 }
 
@@ -1031,49 +1030,47 @@ void serialize_struct( const void *noncontiguous_struct, void *contiguous_struct
  */
 void unserialize_struct( const void *contiguous_struct, void *noncontiguous_struct, int count, void *type, MPI_Op op)
 {
-  s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
+  s_smpi_mpi_struct_t* type_c = reinterpret_cast<s_smpi_mpi_struct_t*>(type);
   int i,j;
 
-  char* contiguous_struct_char = (char*)contiguous_struct;
-  char* noncontiguous_struct_char = (char*)noncontiguous_struct+ type_c->block_indices[0];
+  const char* contiguous_struct_char = static_cast<const char*>(contiguous_struct);
+  char* noncontiguous_struct_char = static_cast<char*>(noncontiguous_struct)+ type_c->block_indices[0];
   for(j=0; j<count;j++){
     for (i = 0; i < type_c->block_count; i++) {
       if (type_c->old_types[i]->sizeof_substruct == 0)
         smpi_op_apply(op, contiguous_struct_char, noncontiguous_struct_char, &type_c->block_lengths[i],
            & type_c->old_types[i]);
-      /*memcpy(noncontiguous_struct_char,
-               contiguous_struct_char, type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));*/
       else
-        ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->unserialize( contiguous_struct_char,
+        static_cast<s_smpi_subtype_t*>(type_c->old_types[i]->substruct)->unserialize( contiguous_struct_char,
                                                                            noncontiguous_struct_char,
                                                                            type_c->block_lengths[i],
                                                                            type_c->old_types[i]->substruct, op);
 
       contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
       if (i<type_c->block_count-1)
-        noncontiguous_struct_char =  (char*)noncontiguous_struct + type_c->block_indices[i+1];
+        noncontiguous_struct_char =  static_cast<char*>(noncontiguous_struct) + type_c->block_indices[i+1];
       else
         noncontiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_types[i]);
     }
-    noncontiguous_struct=(void*)noncontiguous_struct_char;
+    noncontiguous_struct=reinterpret_cast<void*>(noncontiguous_struct_char);
   }
 }
 
 void free_struct(MPI_Datatype* type){
   int i=0;
-  for (i = 0; i < ((s_smpi_mpi_struct_t *)(*type)->substruct)->block_count; i++)
-    smpi_datatype_unuse(((s_smpi_mpi_struct_t *)(*type)->substruct)->old_types[i]);
+  for (i = 0; i < reinterpret_cast<s_smpi_mpi_struct_t*>((*type)->substruct)->block_count; i++)
+    smpi_datatype_unuse(reinterpret_cast<s_smpi_mpi_struct_t*>((*type)->substruct)->old_types[i]);
   if((*type)->in_use==0){
-    xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_lengths);
-    xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_indices);
-    xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->old_types);
+    xbt_free(reinterpret_cast<s_smpi_mpi_struct_t*>((*type)->substruct)->block_lengths);
+    xbt_free(reinterpret_cast<s_smpi_mpi_struct_t*>((*type)->substruct)->block_indices);
+    xbt_free(reinterpret_cast<s_smpi_mpi_struct_t*>((*type)->substruct)->old_types);
   }
 }
 
 void use_struct(MPI_Datatype* type){
   int i=0;
-  for (i = 0; i < ((s_smpi_mpi_struct_t *)(*type)->substruct)->block_count; i++)
-    smpi_datatype_use(((s_smpi_mpi_struct_t *)(*type)->substruct)->old_types[i]);
+  for (i = 0; i < reinterpret_cast<s_smpi_mpi_struct_t*>((*type)->substruct)->block_count; i++)
+    smpi_datatype_use(reinterpret_cast<s_smpi_mpi_struct_t*>((*type)->substruct)->old_types[i]);
 }
 
 /* Create a Sub type struct to be able to serialize and unserialize it the structure s_smpi_mpi_struct_t is derived
@@ -1130,7 +1127,8 @@ int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datat
       forced_ub=1;
     }
 
-    if(!forced_lb && indices[i]+smpi_datatype_lb(old_types[i])<lb) lb = indices[i];
+    if(!forced_lb && indices[i]+smpi_datatype_lb(old_types[i])<lb) 
+      lb = indices[i];
     if(!forced_ub &&  indices[i]+blocklens[i]*smpi_datatype_ub(old_types[i])>ub)
       ub = indices[i]+blocklens[i]*smpi_datatype_ub(old_types[i]);
 
@@ -1138,7 +1136,7 @@ int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datat
       contiguous=0;
   }
 
-  if(!contiguous){
+  if(contiguous==0){
     s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocklens, indices, count, old_types);
 
     smpi_datatype_create(new_type,  size, lb, ub,sizeof(s_smpi_mpi_struct_t), subtype, DT_FLAG_DATA);
@@ -1185,304 +1183,328 @@ typedef struct s_smpi_mpi_op {
 static void max_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, MAX_OP);
+    APPLY_FUNC(a, b, length, char, MAX_OP)
   } else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, MAX_OP);
+    APPLY_FUNC(a, b, length, short, MAX_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, MAX_OP);
+    APPLY_FUNC(a, b, length, int, MAX_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, MAX_OP);
+    APPLY_FUNC(a, b, length, long, MAX_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, MAX_OP);
+    APPLY_FUNC(a, b, length, unsigned short, MAX_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, MAX_OP);
+    APPLY_FUNC(a, b, length, unsigned int, MAX_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, MAX_OP);
+    APPLY_FUNC(a, b, length, unsigned long, MAX_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, MAX_OP);
+    APPLY_FUNC(a, b, length, unsigned char, MAX_OP)
   } else if (*datatype == MPI_FLOAT) {
-    APPLY_FUNC(a, b, length, float, MAX_OP);
+    APPLY_FUNC(a, b, length, float, MAX_OP)
   } else if (*datatype == MPI_DOUBLE) {
-    APPLY_FUNC(a, b, length, double, MAX_OP);
+    APPLY_FUNC(a, b, length, double, MAX_OP)
   } else if (*datatype == MPI_LONG_DOUBLE) {
-    APPLY_FUNC(a, b, length, long double, MAX_OP);
+    APPLY_FUNC(a, b, length, long double, MAX_OP)
+  } else {
+    xbt_die("Failed to apply MAX_OP to type %s", (*datatype)->name);
   }
 }
 
 static void min_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, MIN_OP);
+    APPLY_FUNC(a, b, length, char, MIN_OP)
   } else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, MIN_OP);
+    APPLY_FUNC(a, b, length, short, MIN_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, MIN_OP);
+    APPLY_FUNC(a, b, length, int, MIN_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, MIN_OP);
+    APPLY_FUNC(a, b, length, long, MIN_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, MIN_OP);
+    APPLY_FUNC(a, b, length, unsigned short, MIN_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, MIN_OP);
+    APPLY_FUNC(a, b, length, unsigned int, MIN_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, MIN_OP);
+    APPLY_FUNC(a, b, length, unsigned long, MIN_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, MIN_OP);
+    APPLY_FUNC(a, b, length, unsigned char, MIN_OP)
   } else if (*datatype == MPI_FLOAT) {
-    APPLY_FUNC(a, b, length, float, MIN_OP);
+    APPLY_FUNC(a, b, length, float, MIN_OP)
   } else if (*datatype == MPI_DOUBLE) {
-    APPLY_FUNC(a, b, length, double, MIN_OP);
+    APPLY_FUNC(a, b, length, double, MIN_OP)
   } else if (*datatype == MPI_LONG_DOUBLE) {
-    APPLY_FUNC(a, b, length, long double, MIN_OP);
+    APPLY_FUNC(a, b, length, long double, MIN_OP)
+  } else {
+    xbt_die("Failed to apply MIN_OP to type %s", (*datatype)->name);
   }
 }
 
 static void sum_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, SUM_OP);
+    APPLY_FUNC(a, b, length, char, SUM_OP)
   } else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, SUM_OP);
+    APPLY_FUNC(a, b, length, short, SUM_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, SUM_OP);
+    APPLY_FUNC(a, b, length, int, SUM_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, SUM_OP);
+    APPLY_FUNC(a, b, length, long, SUM_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, SUM_OP);
+    APPLY_FUNC(a, b, length, unsigned short, SUM_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, SUM_OP);
+    APPLY_FUNC(a, b, length, unsigned int, SUM_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, SUM_OP);
+    APPLY_FUNC(a, b, length, unsigned long, SUM_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, SUM_OP);
+    APPLY_FUNC(a, b, length, unsigned char, SUM_OP)
   } else if (*datatype == MPI_FLOAT) {
-    APPLY_FUNC(a, b, length, float, SUM_OP);
+    APPLY_FUNC(a, b, length, float, SUM_OP)
   } else if (*datatype == MPI_DOUBLE) {
-    APPLY_FUNC(a, b, length, double, SUM_OP);
+    APPLY_FUNC(a, b, length, double, SUM_OP)
   } else if (*datatype == MPI_LONG_DOUBLE) {
-    APPLY_FUNC(a, b, length, long double, SUM_OP);
+    APPLY_FUNC(a, b, length, long double, SUM_OP)
   } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
-    APPLY_FUNC(a, b, length, float _Complex, SUM_OP);
+    APPLY_FUNC(a, b, length, float _Complex, SUM_OP)
   } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
-    APPLY_FUNC(a, b, length, double _Complex, SUM_OP);
+    APPLY_FUNC(a, b, length, double _Complex, SUM_OP)
   } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
-    APPLY_FUNC(a, b, length, long double _Complex, SUM_OP);
+    APPLY_FUNC(a, b, length, long double _Complex, SUM_OP)
+  } else {
+    xbt_die("Failed to apply SUM_OP to type %s", (*datatype)->name);
   }
 }
 
 static void prod_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, PROD_OP);
+    APPLY_FUNC(a, b, length, char, PROD_OP)
   } else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, PROD_OP);
+    APPLY_FUNC(a, b, length, short, PROD_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, PROD_OP);
+    APPLY_FUNC(a, b, length, int, PROD_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, PROD_OP);
+    APPLY_FUNC(a, b, length, long, PROD_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, PROD_OP);
+    APPLY_FUNC(a, b, length, unsigned short, PROD_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, PROD_OP);
+    APPLY_FUNC(a, b, length, unsigned int, PROD_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, PROD_OP);
+    APPLY_FUNC(a, b, length, unsigned long, PROD_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, PROD_OP);
+    APPLY_FUNC(a, b, length, unsigned char, PROD_OP)
   } else if (*datatype == MPI_FLOAT) {
-    APPLY_FUNC(a, b, length, float, PROD_OP);
+    APPLY_FUNC(a, b, length, float, PROD_OP)
   } else if (*datatype == MPI_DOUBLE) {
-    APPLY_FUNC(a, b, length, double, PROD_OP);
+    APPLY_FUNC(a, b, length, double, PROD_OP)
   } else if (*datatype == MPI_LONG_DOUBLE) {
-    APPLY_FUNC(a, b, length, long double, PROD_OP);
+    APPLY_FUNC(a, b, length, long double, PROD_OP)
   } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
-    APPLY_FUNC(a, b, length, float _Complex, PROD_OP);
+    APPLY_FUNC(a, b, length, float _Complex, PROD_OP)
   } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
-    APPLY_FUNC(a, b, length, double _Complex, PROD_OP);
+    APPLY_FUNC(a, b, length, double _Complex, PROD_OP)
   } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
-    APPLY_FUNC(a, b, length, long double _Complex, PROD_OP);
+    APPLY_FUNC(a, b, length, long double _Complex, PROD_OP)
+  } else {
+    xbt_die("Failed to apply PROD_OP to type %s", (*datatype)->name);
   }
 }
 
 static void land_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, LAND_OP);
+    APPLY_FUNC(a, b, length, char, LAND_OP)
   } else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, LAND_OP);
+    APPLY_FUNC(a, b, length, short, LAND_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, LAND_OP);
+    APPLY_FUNC(a, b, length, int, LAND_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, LAND_OP);
+    APPLY_FUNC(a, b, length, long, LAND_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, LAND_OP);
+    APPLY_FUNC(a, b, length, unsigned short, LAND_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, LAND_OP);
+    APPLY_FUNC(a, b, length, unsigned int, LAND_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, LAND_OP);
+    APPLY_FUNC(a, b, length, unsigned long, LAND_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, LAND_OP);
+    APPLY_FUNC(a, b, length, unsigned char, LAND_OP)
   } else if (*datatype == MPI_C_BOOL) {
-    APPLY_FUNC(a, b, length, bool, LAND_OP);
+    APPLY_FUNC(a, b, length, bool, LAND_OP)
+  } else {
+    xbt_die("Failed to apply LAND_OP to type %s", (*datatype)->name);
   }
 }
 
 static void lor_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, LOR_OP);
+    APPLY_FUNC(a, b, length, char, LOR_OP)
   } else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, LOR_OP);
+    APPLY_FUNC(a, b, length, short, LOR_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, LOR_OP);
+    APPLY_FUNC(a, b, length, int, LOR_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, LOR_OP);
+    APPLY_FUNC(a, b, length, long, LOR_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, LOR_OP);
+    APPLY_FUNC(a, b, length, unsigned short, LOR_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, LOR_OP);
+    APPLY_FUNC(a, b, length, unsigned int, LOR_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, LOR_OP);
+    APPLY_FUNC(a, b, length, unsigned long, LOR_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, LOR_OP);
+    APPLY_FUNC(a, b, length, unsigned char, LOR_OP)
   } else if (*datatype == MPI_C_BOOL) {
-    APPLY_FUNC(a, b, length, bool, LOR_OP);
+    APPLY_FUNC(a, b, length, bool, LOR_OP)
+  } else {
+    xbt_die("Failed to apply LOR_OP to type %s", (*datatype)->name);
   }
 }
 
 static void lxor_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, LXOR_OP);
+    APPLY_FUNC(a, b, length, char, LXOR_OP)
   } else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, LXOR_OP);
+    APPLY_FUNC(a, b, length, short, LXOR_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, LXOR_OP);
+    APPLY_FUNC(a, b, length, int, LXOR_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, LXOR_OP);
+    APPLY_FUNC(a, b, length, long, LXOR_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, LXOR_OP);
+    APPLY_FUNC(a, b, length, unsigned short, LXOR_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, LXOR_OP);
+    APPLY_FUNC(a, b, length, unsigned int, LXOR_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, LXOR_OP);
+    APPLY_FUNC(a, b, length, unsigned long, LXOR_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, LXOR_OP);
+    APPLY_FUNC(a, b, length, unsigned char, LXOR_OP)
   } else if (*datatype == MPI_C_BOOL) {
-    APPLY_FUNC(a, b, length, bool, LXOR_OP);
+    APPLY_FUNC(a, b, length, bool, LXOR_OP)
+  } else {
+    xbt_die("Failed to apply LXOR_OP to type %s", (*datatype)->name);
   }
 }
 
 static void band_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, BAND_OP);
+    APPLY_FUNC(a, b, length, char, BAND_OP)
   }else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, BAND_OP);
+    APPLY_FUNC(a, b, length, short, BAND_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, BAND_OP);
+    APPLY_FUNC(a, b, length, int, BAND_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, BAND_OP);
+    APPLY_FUNC(a, b, length, long, BAND_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, BAND_OP);
+    APPLY_FUNC(a, b, length, unsigned short, BAND_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, BAND_OP);
+    APPLY_FUNC(a, b, length, unsigned int, BAND_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, BAND_OP);
+    APPLY_FUNC(a, b, length, unsigned long, BAND_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, BAND_OP);
+    APPLY_FUNC(a, b, length, unsigned char, BAND_OP)
   } else if (*datatype == MPI_BYTE) {
-    APPLY_FUNC(a, b, length, uint8_t, BAND_OP);
+    APPLY_FUNC(a, b, length, uint8_t, BAND_OP)
+  } else {
+    xbt_die("Failed to apply BAND_OP to type %s", (*datatype)->name);
   }
 }
 
 static void bor_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, BOR_OP);
+    APPLY_FUNC(a, b, length, char, BOR_OP)
   } else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, BOR_OP);
+    APPLY_FUNC(a, b, length, short, BOR_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, BOR_OP);
+    APPLY_FUNC(a, b, length, int, BOR_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, BOR_OP);
+    APPLY_FUNC(a, b, length, long, BOR_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, BOR_OP);
+    APPLY_FUNC(a, b, length, unsigned short, BOR_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, BOR_OP);
+    APPLY_FUNC(a, b, length, unsigned int, BOR_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, BOR_OP);
+    APPLY_FUNC(a, b, length, unsigned long, BOR_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, BOR_OP);
+    APPLY_FUNC(a, b, length, unsigned char, BOR_OP)
   } else if (*datatype == MPI_BYTE) {
-    APPLY_FUNC(a, b, length, uint8_t, BOR_OP);
+    APPLY_FUNC(a, b, length, uint8_t, BOR_OP)
+  } else {
+    xbt_die("Failed to apply BOR_OP to type %s", (*datatype)->name);
   }
 }
 
 static void bxor_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_CHAR) {
-    APPLY_FUNC(a, b, length, char, BXOR_OP);
+    APPLY_FUNC(a, b, length, char, BXOR_OP)
   } else if (*datatype == MPI_SHORT) {
-    APPLY_FUNC(a, b, length, short, BXOR_OP);
+    APPLY_FUNC(a, b, length, short, BXOR_OP)
   } else if (*datatype == MPI_INT) {
-    APPLY_FUNC(a, b, length, int, BXOR_OP);
+    APPLY_FUNC(a, b, length, int, BXOR_OP)
   } else if (*datatype == MPI_LONG) {
-    APPLY_FUNC(a, b, length, long, BXOR_OP);
+    APPLY_FUNC(a, b, length, long, BXOR_OP)
   } else if (*datatype == MPI_UNSIGNED_SHORT) {
-    APPLY_FUNC(a, b, length, unsigned short, BXOR_OP);
+    APPLY_FUNC(a, b, length, unsigned short, BXOR_OP)
   } else if (*datatype == MPI_UNSIGNED) {
-    APPLY_FUNC(a, b, length, unsigned int, BXOR_OP);
+    APPLY_FUNC(a, b, length, unsigned int, BXOR_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
-    APPLY_FUNC(a, b, length, unsigned long, BXOR_OP);
+    APPLY_FUNC(a, b, length, unsigned long, BXOR_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
-    APPLY_FUNC(a, b, length, unsigned char, BXOR_OP);
+    APPLY_FUNC(a, b, length, unsigned char, BXOR_OP)
   } else if (*datatype == MPI_BYTE) {
-    APPLY_FUNC(a, b, length, uint8_t, BXOR_OP);
+    APPLY_FUNC(a, b, length, uint8_t, BXOR_OP)
+  } else {
+    xbt_die("Failed to apply BXOR_OP to type %s", (*datatype)->name);
   }
 }
 
 static void minloc_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_FLOAT_INT) {
-    APPLY_FUNC(a, b, length, float_int, MINLOC_OP);
+    APPLY_FUNC(a, b, length, float_int, MINLOC_OP)
   } else if (*datatype == MPI_LONG_INT) {
-    APPLY_FUNC(a, b, length, long_int, MINLOC_OP);
+    APPLY_FUNC(a, b, length, long_int, MINLOC_OP)
   } else if (*datatype == MPI_DOUBLE_INT) {
-    APPLY_FUNC(a, b, length, double_int, MINLOC_OP);
+    APPLY_FUNC(a, b, length, double_int, MINLOC_OP)
   } else if (*datatype == MPI_SHORT_INT) {
-    APPLY_FUNC(a, b, length, short_int, MINLOC_OP);
+    APPLY_FUNC(a, b, length, short_int, MINLOC_OP)
   } else if (*datatype == MPI_2LONG) {
-    APPLY_FUNC(a, b, length, long_long, MINLOC_OP);
+    APPLY_FUNC(a, b, length, long_long, MINLOC_OP)
   } else if (*datatype == MPI_2INT) {
-    APPLY_FUNC(a, b, length, int_int, MINLOC_OP);
+    APPLY_FUNC(a, b, length, int_int, MINLOC_OP)
   } else if (*datatype == MPI_LONG_DOUBLE_INT) {
-    APPLY_FUNC(a, b, length, long_double_int, MINLOC_OP);
+    APPLY_FUNC(a, b, length, long_double_int, MINLOC_OP)
   } else if (*datatype == MPI_2FLOAT) {
-    APPLY_FUNC(a, b, length, float_float, MINLOC_OP);
+    APPLY_FUNC(a, b, length, float_float, MINLOC_OP)
   } else if (*datatype == MPI_2DOUBLE) {
-    APPLY_FUNC(a, b, length, double_double, MINLOC_OP);
+    APPLY_FUNC(a, b, length, double_double, MINLOC_OP)
+  } else {
+    xbt_die("Failed to apply MINLOC_OP to type %s", (*datatype)->name);
   }
 }
 
 static void maxloc_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
   if (*datatype == MPI_FLOAT_INT) {
-    APPLY_FUNC(a, b, length, float_int, MAXLOC_OP);
+    APPLY_FUNC(a, b, length, float_int, MAXLOC_OP)
   } else if (*datatype == MPI_LONG_INT) {
-    APPLY_FUNC(a, b, length, long_int, MAXLOC_OP);
+    APPLY_FUNC(a, b, length, long_int, MAXLOC_OP)
   } else if (*datatype == MPI_DOUBLE_INT) {
-    APPLY_FUNC(a, b, length, double_int, MAXLOC_OP);
+    APPLY_FUNC(a, b, length, double_int, MAXLOC_OP)
   } else if (*datatype == MPI_SHORT_INT) {
-    APPLY_FUNC(a, b, length, short_int, MAXLOC_OP);
+    APPLY_FUNC(a, b, length, short_int, MAXLOC_OP)
   } else if (*datatype == MPI_2LONG) {
-    APPLY_FUNC(a, b, length, long_long, MAXLOC_OP);
+    APPLY_FUNC(a, b, length, long_long, MAXLOC_OP)
   } else if (*datatype == MPI_2INT) {
-    APPLY_FUNC(a, b, length, int_int, MAXLOC_OP);
+    APPLY_FUNC(a, b, length, int_int, MAXLOC_OP)
   } else if (*datatype == MPI_LONG_DOUBLE_INT) {
-    APPLY_FUNC(a, b, length, long_double_int, MAXLOC_OP);
+    APPLY_FUNC(a, b, length, long_double_int, MAXLOC_OP)
   } else if (*datatype == MPI_2FLOAT) {
-    APPLY_FUNC(a, b, length, float_float, MAXLOC_OP);
+    APPLY_FUNC(a, b, length, float_float, MAXLOC_OP)
   } else if (*datatype == MPI_2DOUBLE) {
-    APPLY_FUNC(a, b, length, double_double, MAXLOC_OP);
+    APPLY_FUNC(a, b, length, double_double, MAXLOC_OP)
+  } else {
+    xbt_die("Failed to apply MAXLOC_OP to type %s", (*datatype)->name);
   }
 }
 
@@ -1528,7 +1550,7 @@ void smpi_op_destroy(MPI_Op op)
   xbt_free(op);
 }
 
-void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len, MPI_Datatype * datatype)
+void smpi_op_apply(MPI_Op op, const void *invec, void *inoutvec, int *len, MPI_Datatype * datatype)
 {
   if(op==MPI_OP_NULL)
     return;
@@ -1539,32 +1561,33 @@ void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len, MPI_Datatyp
   }
 
   if(!smpi_process_get_replaying())
-  op->func(invec, inoutvec, len, datatype);
+    op->func(const_cast<void*>(invec), inoutvec, len, datatype);
 }
 
 int smpi_type_attr_delete(MPI_Datatype type, int keyval){
   smpi_type_key_elem elem =
-    static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, (const char*)&keyval, sizeof(int)));
-  if(!elem)
+    static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
+  if(elem==NULL)
     return MPI_ERR_ARG;
   if(elem->delete_fn!=MPI_NULL_DELETE_FN){
     void * value;
     int flag;
     if(smpi_type_attr_get(type, keyval, &value, &flag)==MPI_SUCCESS){
       int ret = elem->delete_fn(type, keyval, value, &flag);
-      if(ret!=MPI_SUCCESS) return ret;
+      if(ret!=MPI_SUCCESS) 
+        return ret;
     }
   }  
   if(type->attributes==NULL)
     return MPI_ERR_ARG;
 
-  xbt_dict_remove_ext(type->attributes, (const char*)&keyval, sizeof(int));
+  xbt_dict_remove_ext(type->attributes, reinterpret_cast<const char*>(&keyval), sizeof(int));
   return MPI_SUCCESS;
 }
 
 int smpi_type_attr_get(MPI_Datatype type, int keyval, void* attr_value, int* flag){
   smpi_type_key_elem elem =
-    static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, (const char*)&keyval, sizeof(int)));
+    static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
   if(!elem)
     return MPI_ERR_ARG;
   xbt_ex_t ex;
@@ -1573,7 +1596,7 @@ int smpi_type_attr_get(MPI_Datatype type, int keyval, void* attr_value, int* fla
     return MPI_SUCCESS;
   }
   TRY {
-    *(void**)attr_value = xbt_dict_get_ext(type->attributes, (const char*)&keyval, sizeof(int));
+    *static_cast<void**>(attr_value) = xbt_dict_get_ext(type->attributes, reinterpret_cast<const char*>(&keyval), sizeof(int));
     *flag=1;
   }
   CATCH(ex) {
@@ -1587,20 +1610,21 @@ int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){
   if(!smpi_type_keyvals)
   smpi_type_keyvals = xbt_dict_new();
   smpi_type_key_elem elem =
-     static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, (const char*)&keyval, sizeof(int)));
-  if(!elem )
+     static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
+  if(elem==NULL)
     return MPI_ERR_ARG;
   int flag;
   void* value;
   smpi_type_attr_get(type, keyval, &value, &flag);
   if(flag && elem->delete_fn!=MPI_NULL_DELETE_FN){
     int ret = elem->delete_fn(type, keyval, value, &flag);
-    if(ret!=MPI_SUCCESS) return ret;
+    if(ret!=MPI_SUCCESS) 
+      return ret;
   }
   if(type->attributes==NULL)
     type->attributes=xbt_dict_new();
 
-  xbt_dict_set_ext(type->attributes, (const char*)&keyval, sizeof(int), attr_value, NULL);
+  xbt_dict_set_ext(type->attributes, reinterpret_cast<const char*>(&keyval), sizeof(int), attr_value, NULL);
   return MPI_SUCCESS;
 }
 
@@ -1615,18 +1639,18 @@ int smpi_type_keyval_create(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delet
   value->delete_fn=delete_fn;
 
   *keyval = type_keyval_id;
-  xbt_dict_set_ext(smpi_type_keyvals,(const char*)keyval, sizeof(int),(void*)value, NULL);
+  xbt_dict_set_ext(smpi_type_keyvals,reinterpret_cast<const char*>(keyval), sizeof(int),reinterpret_cast<void*>(value), NULL);
   type_keyval_id++;
   return MPI_SUCCESS;
 }
 
 int smpi_type_keyval_free(int* keyval){
   smpi_type_key_elem elem =
-    static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, (const char*)keyval, sizeof(int)));
+    static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast<const char*>(keyval), sizeof(int)));
   if(!elem){
     return MPI_ERR_ARG;
   }
-  xbt_dict_remove_ext(smpi_type_keyvals, (const char*)keyval, sizeof(int));
+  xbt_dict_remove_ext(smpi_type_keyvals, reinterpret_cast<const char*>(keyval), sizeof(int));
   xbt_free(elem);
   return MPI_SUCCESS;
 }
@@ -1635,7 +1659,7 @@ int smpi_mpi_pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int
   size_t size = smpi_datatype_size(type);
   if (outcount - *position < incount*static_cast<int>(size))
     return MPI_ERR_BUFFER;
-  smpi_datatype_copy(inbuf, incount, type, (char*)outbuf + *position, outcount, MPI_CHAR);
+  smpi_datatype_copy(inbuf, incount, type, static_cast<char*>(outbuf) + *position, outcount, MPI_CHAR);
   *position += incount * size;
   return MPI_SUCCESS;
 }
@@ -1644,7 +1668,7 @@ int smpi_mpi_unpack(void* inbuf, int insize, int* position, void* outbuf, int ou
   int size = static_cast<int>(smpi_datatype_size(type));
   if (outcount*size> insize)
     return MPI_ERR_BUFFER;
-  smpi_datatype_copy((char*)inbuf + *position, insize, MPI_CHAR, outbuf, outcount, type);
+  smpi_datatype_copy(static_cast<char*>(inbuf) + *position, insize, MPI_CHAR, outbuf, outcount, type);
   *position += outcount * size;
   return MPI_SUCCESS;
 }
index 4d87717..83213f4 100644 (file)
@@ -138,10 +138,10 @@ int PMPI_Address(void *location, MPI_Aint * address)
 {
   int retval = 0;
 
-  if (!address) {
+  if (address==NULL) {
     retval = MPI_ERR_ARG;
   } else {
-    *address = (MPI_Aint) location;
+    *address = reinterpret_cast<MPI_Aint>(location);
     retval = MPI_SUCCESS;
   }
   return retval;
@@ -174,7 +174,7 @@ int PMPI_Type_size(MPI_Datatype datatype, int *size)
   } else if (size == NULL) {
     retval = MPI_ERR_ARG;
   } else {
-    *size = (int) smpi_datatype_size(datatype);
+    *size = static_cast<int>(smpi_datatype_size(datatype));
     retval = MPI_SUCCESS;
   }
   return retval;
@@ -444,7 +444,8 @@ int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgro
   } else if (newgroup == NULL) {
     retval = MPI_ERR_ARG;
   } else {
-    size = size2 = smpi_group_size(group1);
+    size = smpi_group_size(group1);
+    size2 = size;
     for (i = 0; i < size2; i++) {
       proc1 = smpi_group_index(group1, i);
       proc2 = smpi_group_rank(group2, proc1);
@@ -851,7 +852,7 @@ int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag
       retval = MPI_SUCCESS;
   }
   smpi_bench_begin();
-  if (retval != MPI_SUCCESS && request)
+  if (retval != MPI_SUCCESS && request != NULL)
     *request = MPI_REQUEST_NULL;
   return retval;
 }
@@ -874,7 +875,7 @@ int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag
     retval = MPI_SUCCESS;
   }
   smpi_bench_begin();
-  if (retval != MPI_SUCCESS && request)
+  if (retval != MPI_SUCCESS && request != NULL)
     *request = MPI_REQUEST_NULL;
   return retval;
 }
@@ -897,7 +898,7 @@ int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int ta
     retval = MPI_SUCCESS;
   }
   smpi_bench_begin();
-  if (retval != MPI_SUCCESS && request)
+  if (retval != MPI_SUCCESS && request != NULL)
     *request = MPI_REQUEST_NULL;
   return retval;
 }
@@ -969,9 +970,7 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MP
     retval = MPI_SUCCESS;
   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
     retval = MPI_ERR_RANK;
-  } else if (count < 0) {
-    retval = MPI_ERR_COUNT;
-  } else if (buf==NULL && count > 0) {
+  } else if ((count < 0) || (buf==NULL && count > 0)) {
     retval = MPI_ERR_COUNT;
   } else if (!is_datatype_valid(datatype)) {
       retval = MPI_ERR_TYPE;
@@ -989,7 +988,7 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MP
     int known=0;
     extra->datatype1 = encode_datatype(datatype, &known);
     int dt_size_send = 1;
-    if(!known)
+    if(known==0)
       dt_size_send = smpi_datatype_size(datatype);
     extra->send_size = count*dt_size_send;
     TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
@@ -1002,7 +1001,7 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MP
   }
 
   smpi_bench_begin();
-  if (retval != MPI_SUCCESS && request)
+  if (retval != MPI_SUCCESS && request != NULL)
     *request = MPI_REQUEST_NULL;
   return retval;
 }
@@ -1022,9 +1021,7 @@ int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MP
     retval = MPI_SUCCESS;
   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
     retval = MPI_ERR_RANK;
-  } else if (count < 0) {
-    retval = MPI_ERR_COUNT;
-  } else if (buf==NULL && count > 0) {
+  } else if ((count < 0) || (buf==NULL && count > 0)) {
     retval = MPI_ERR_COUNT;
   } else if (!is_datatype_valid(datatype)) {
       retval = MPI_ERR_TYPE;
@@ -1041,7 +1038,7 @@ int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MP
     int known=0;
     extra->datatype1 = encode_datatype(datatype, &known);
     int dt_size_send = 1;
-    if(!known)
+    if(known==0)
       dt_size_send = smpi_datatype_size(datatype);
     extra->send_size = count*dt_size_send;
     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
@@ -1055,7 +1052,7 @@ int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MP
   }
 
   smpi_bench_begin();
-  if (retval != MPI_SUCCESS && request)
+  if (retval != MPI_SUCCESS && request!=NULL)
     *request = MPI_REQUEST_NULL;
   return retval;
 }
@@ -1074,9 +1071,7 @@ int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, M
     retval = MPI_SUCCESS;
   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
     retval = MPI_ERR_RANK;
-  } else if (count < 0) {
-    retval = MPI_ERR_COUNT;
-  } else if (buf==NULL && count > 0) {
+  } else if ((count < 0)|| (buf==NULL && count > 0)) {
     retval = MPI_ERR_COUNT;
   } else if (!is_datatype_valid(datatype)) {
       retval = MPI_ERR_TYPE;
@@ -1093,7 +1088,7 @@ int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, M
     int known=0;
     extra->datatype1 = encode_datatype(datatype, &known);
     int dt_size_send = 1;
-    if(!known)
+    if(known==0)
       dt_size_send = smpi_datatype_size(datatype);
     extra->send_size = count*dt_size_send;
     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
@@ -1107,7 +1102,7 @@ int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, M
   }
 
   smpi_bench_begin();
-  if (retval != MPI_SUCCESS && request)
+  if (retval != MPI_SUCCESS && request!=NULL)
     *request = MPI_REQUEST_NULL;
   return retval;
 }
@@ -1125,9 +1120,7 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
     retval = MPI_SUCCESS;
   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
     retval = MPI_ERR_RANK;
-  } else if (count < 0) {
-    retval = MPI_ERR_COUNT;
-  } else if (buf==NULL && count > 0) {
+  } else if ((count < 0) || (buf==NULL && count > 0)) {
     retval = MPI_ERR_COUNT;
   } else if (!is_datatype_valid(datatype)) {
       retval = MPI_ERR_TYPE;
@@ -1143,7 +1136,7 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
   int known=0;
   extra->datatype1 = encode_datatype(datatype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = count*dt_size_send;
   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
@@ -1177,9 +1170,7 @@ int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI
     retval = MPI_SUCCESS;
   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
     retval = MPI_ERR_RANK;
-  } else if (count < 0) {
-    retval = MPI_ERR_COUNT;
-  } else if (buf==NULL && count > 0) {
+  } else if ((count < 0) || (buf==NULL && count > 0)) {
     retval = MPI_ERR_COUNT;
   } else if (!is_datatype_valid(datatype)) {
       retval = MPI_ERR_TYPE;
@@ -1196,7 +1187,7 @@ int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI
   int known=0;
   extra->datatype1 = encode_datatype(datatype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = count*dt_size_send;
   TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
@@ -1227,9 +1218,7 @@ int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MP
      retval = MPI_SUCCESS;
    } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
      retval = MPI_ERR_RANK;
-   } else if (count < 0) {
-     retval = MPI_ERR_COUNT;
-   } else if (buf==NULL && count > 0) {
+   } else if ((count < 0) || (buf==NULL && count > 0)) {
      retval = MPI_ERR_COUNT;
    } else if (!is_datatype_valid(datatype)){
      retval = MPI_ERR_TYPE;
@@ -1246,7 +1235,7 @@ int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MP
    int known=0;
    extra->datatype1 = encode_datatype(datatype, &known);
    int dt_size_send = 1;
-   if(!known)
+   if(known==0)
      dt_size_send = smpi_datatype_size(datatype);
    extra->send_size = count*dt_size_send;
    TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
@@ -1280,9 +1269,8 @@ int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst,
   }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
       (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
     retval = MPI_ERR_RANK;
-  } else if (sendcount < 0 || recvcount<0) {
-      retval = MPI_ERR_COUNT;
-  } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
+  } else if ((sendcount < 0 || recvcount<0) || 
+      (sendbuf==NULL && sendcount > 0) || (recvbuf==NULL && recvcount>0)) {
     retval = MPI_ERR_COUNT;
   } else if((sendtag<0 && sendtag !=  MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
     retval = MPI_ERR_TAG;
@@ -1298,12 +1286,12 @@ int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst,
   int known=0;
   extra->datatype1 = encode_datatype(sendtype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(sendtype);
   extra->send_size = sendcount*dt_size_send;
   extra->datatype2 = encode_datatype(recvtype, &known);
   int dt_size_recv = 1;
-  if(!known)
+  if(known==0)
     dt_size_recv = smpi_datatype_size(recvtype);
   extra->recv_size = recvcount*dt_size_recv;
 
@@ -1325,7 +1313,6 @@ int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst,
 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
                          MPI_Comm comm, MPI_Status * status)
 {
-  //TODO: suboptimal implementation
   void *recvbuf;
   int retval = 0;
   if (!is_datatype_valid(datatype)) {
@@ -1356,7 +1343,7 @@ int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
     smpi_empty_status(status);
     retval = MPI_SUCCESS;
   } else {
-    int rank = request && (*request)->comm != MPI_COMM_NULL ? smpi_process_index() : -1;
+    int rank = (request!=NULL && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
 
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
     extra->type = TRACING_TEST;
@@ -1425,9 +1412,7 @@ int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* statu
   int retval = 0;
   smpi_bench_end();
 
-  if (flag == NULL) {
-    retval = MPI_ERR_ARG;
-  } else if (status == NULL) {
+  if ((flag == NULL) || (status == NULL)) {
     retval = MPI_ERR_ARG;
   } else if (comm == MPI_COMM_NULL) {
     retval = MPI_ERR_COMM;
@@ -1458,7 +1443,7 @@ int PMPI_Wait(MPI_Request * request, MPI_Status * status)
     retval = MPI_SUCCESS;
   } else {
 
-    int rank = request && (*request)->comm != MPI_COMM_NULL ? smpi_process_index() : -1;
+    int rank = (request!=NULL && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
 
     int src_traced = (*request)->src;
     int dst_traced = (*request)->dst;
@@ -1552,7 +1537,6 @@ int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
   int *valid = xbt_new0(int, count);
   MPI_Comm *comms = xbt_new0(MPI_Comm, count);
 
-  //int valid_count = 0;
   for (i = 0; i < count; i++) {
     MPI_Request req = requests[i];
     if(req!=MPI_REQUEST_NULL){
@@ -1575,7 +1559,6 @@ int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
 
   for (i = 0; i < count; i++) {
     if(valid[i]){
-    //int src_traced = srcs[*index];
     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
       int src_traced = srcs[i];
       int dst_traced = dsts[i];
@@ -1650,7 +1633,7 @@ int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm c
   int known=0;
   extra->datatype1 = encode_datatype(datatype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = count*dt_size_send;
   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
@@ -1705,7 +1688,7 @@ int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbu
     retval = MPI_ERR_COUNT;
   } else {
 
-    char* sendtmpbuf = (char*) sendbuf;
+    char* sendtmpbuf = static_cast<char*>(sendbuf);
     int sendtmpcount = sendcount;
     MPI_Datatype sendtmptype = sendtype;
     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
@@ -1720,12 +1703,12 @@ int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbu
   int known=0;
   extra->datatype1 = encode_datatype(sendtmptype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(sendtmptype);
   extra->send_size = sendtmpcount*dt_size_send;
   extra->datatype2 = encode_datatype(recvtype, &known);
   int dt_size_recv = 1;
-  if((smpi_comm_rank(comm)==root) && !known)
+  if((smpi_comm_rank(comm)==root) && known==0)
     dt_size_recv = smpi_datatype_size(recvtype);
   extra->recv_size = recvcount*dt_size_recv;
 
@@ -1758,7 +1741,7 @@ int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recv
   } else if (recvcounts == NULL || displs == NULL) {
     retval = MPI_ERR_ARG;
   } else {
-    char* sendtmpbuf = (char*) sendbuf;
+    char* sendtmpbuf = static_cast<char*>(sendbuf);
     int sendtmpcount = sendcount;
     MPI_Datatype sendtmptype = sendtype;
     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
@@ -1777,12 +1760,12 @@ int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recv
   int known=0;
   extra->datatype1 = encode_datatype(sendtmptype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(sendtype);
   extra->send_size = sendtmpcount*dt_size_send;
   extra->datatype2 = encode_datatype(recvtype, &known);
   int dt_size_recv = 1;
-  if(!known)
+  if(known==0)
     dt_size_recv = smpi_datatype_size(recvtype);
   if((smpi_comm_rank(comm)==root)){
   extra->recvcounts= xbt_new(int,size);
@@ -1817,7 +1800,7 @@ int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     retval = MPI_ERR_COUNT;
   } else {
     if(sendbuf == MPI_IN_PLACE) {
-      sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
+      sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
       sendcount=recvcount;
       sendtype=recvtype;
     }
@@ -1827,12 +1810,12 @@ int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
   int known=0;
   extra->datatype1 = encode_datatype(sendtype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(sendtype);
   extra->send_size = sendcount*dt_size_send;
   extra->datatype2 = encode_datatype(recvtype, &known);
   int dt_size_recv = 1;
-  if(!known)
+  if(known==0)
     dt_size_recv = smpi_datatype_size(recvtype);
   extra->recv_size = recvcount*dt_size_recv;
 
@@ -1865,7 +1848,7 @@ int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
   } else {
 
     if(sendbuf == MPI_IN_PLACE) {
-      sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
+      sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
       sendcount=recvcounts[smpi_comm_rank(comm)];
       sendtype=recvtype;
     }
@@ -1878,12 +1861,12 @@ int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
   int known=0;
   extra->datatype1 = encode_datatype(sendtype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(sendtype);
   extra->send_size = sendcount*dt_size_send;
   extra->datatype2 = encode_datatype(recvtype, &known);
   int dt_size_recv = 1;
-  if(!known)
+  if(known==0)
     dt_size_recv = smpi_datatype_size(recvtype);
   extra->recvcounts= xbt_new(int, size);
   for(i=0; i< size; i++)//copy data to avoid bad free
@@ -1929,12 +1912,12 @@ int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
   int known=0;
   extra->datatype1 = encode_datatype(sendtype, &known);
   int dt_size_send = 1;
-  if((smpi_comm_rank(comm)==root) && !known)
+  if((smpi_comm_rank(comm)==root) && known==0)
     dt_size_send = smpi_datatype_size(sendtype);
   extra->send_size = sendcount*dt_size_send;
   extra->datatype2 = encode_datatype(recvtype, &known);
   int dt_size_recv = 1;
-  if(!known)
+  if(known==0)
     dt_size_recv = smpi_datatype_size(recvtype);
   extra->recv_size = recvcount*dt_size_recv;
   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
@@ -1978,7 +1961,7 @@ int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
   int known=0;
   extra->datatype1 = encode_datatype(sendtype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(sendtype);
   if((smpi_comm_rank(comm)==root)){
   extra->sendcounts= xbt_new(int, size);
@@ -1987,7 +1970,7 @@ int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
   }
   extra->datatype2 = encode_datatype(recvtype, &known);
   int dt_size_recv = 1;
-  if(!known)
+  if(known==0)
     dt_size_recv = smpi_datatype_size(recvtype);
   extra->recv_size = recvcount*dt_size_recv;
   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
@@ -2020,7 +2003,7 @@ int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
   int known=0;
   extra->datatype1 = encode_datatype(datatype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = count*dt_size_send;
   extra->root = root_traced;
@@ -2065,9 +2048,9 @@ int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatyp
     retval = MPI_ERR_OP;
   } else {
 
-    char* sendtmpbuf = (char*) sendbuf;
+    char* sendtmpbuf = static_cast<char*>(sendbuf);
     if( sendbuf == MPI_IN_PLACE ) {
-      sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
+      sendtmpbuf = static_cast<char*>(xbt_malloc(count*smpi_datatype_get_extent(datatype)));
       smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
     }
   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
@@ -2076,7 +2059,7 @@ int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatyp
   int known=0;
   extra->datatype1 = encode_datatype(datatype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = count*dt_size_send;
 
@@ -2114,7 +2097,7 @@ int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MP
   int known=0;
   extra->datatype1 = encode_datatype(datatype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = count*dt_size_send;
 
@@ -2148,7 +2131,7 @@ int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
   int known=0;
   extra->datatype1 = encode_datatype(datatype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = count*dt_size_send;
   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
@@ -2185,7 +2168,7 @@ int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datat
   int known=0;
   extra->datatype1 = encode_datatype(datatype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = 0;
   extra->recvcounts= xbt_new(int, size);
@@ -2230,7 +2213,7 @@ int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
   int known=0;
   extra->datatype1 = encode_datatype(datatype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = 0;
   extra->recvcounts= xbt_new(int, count);
@@ -2239,8 +2222,9 @@ int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
 
   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
 
-  int* recvcounts=(int*)xbt_malloc(count);
-    for (i=0; i<count;i++)recvcounts[i]=recvcount;
+  int* recvcounts=static_cast<int*>(xbt_malloc(count));
+    for (i=0; i<count;i++)
+      recvcounts[i]=recvcount;
     mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts, datatype,  op, comm);
     xbt_free(recvcounts);
     retval = MPI_SUCCESS;
@@ -2270,12 +2254,12 @@ int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
   extra->type = TRACING_ALLTOALL;
   int known=0;
   extra->datatype1 = encode_datatype(sendtype, &known);
-  if(!known)
+  if(known==0)
     extra->send_size = sendcount*smpi_datatype_size(sendtype);
   else
     extra->send_size = sendcount;
   extra->datatype2 = encode_datatype(recvtype, &known);
-  if(!known)
+  if(known==0)
     extra->recv_size = recvcount*smpi_datatype_size(recvtype);
   else
     extra->recv_size = recvcount;
@@ -2316,11 +2300,11 @@ int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,MPI_Datatype s
   int known=0;
   extra->datatype1 = encode_datatype(sendtype, &known);
   int dt_size_send = 1;
-  if(!known)
+  if(known==0)
     dt_size_send = smpi_datatype_size(sendtype);
   int dt_size_recv = 1;
   extra->datatype2 = encode_datatype(recvtype, &known);
-  if(!known)
+  if(known==0)
     dt_size_recv = smpi_datatype_size(recvtype);
   for(i=0; i< size; i++){//copy data to avoid bad free
     extra->send_size += sendcounts[i]*dt_size_send;
@@ -2466,8 +2450,9 @@ int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI
   } else if (count<0){
     retval = MPI_ERR_COUNT;
   } else {
-    int* blocklens=(int*)xbt_malloc(blocklength*count);
-    for (i=0; i<count;i++)blocklens[i]=blocklength;
+    int* blocklens=static_cast<int*>(xbt_malloc(blocklength*count));
+    for (i=0; i<count;i++)
+      blocklens[i]=blocklength;
     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
     xbt_free(blocklens);
   }
@@ -2738,9 +2723,8 @@ int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
     retval = MPI_ERR_RANK;
   } else if (target_disp <0){
       retval = MPI_ERR_ARG;
-  } else if (origin_count < 0 || target_count < 0) {
-    retval = MPI_ERR_COUNT;
-  } else if (origin_addr==NULL && origin_count > 0){
+  } else if ((origin_count < 0 || target_count < 0) ||
+             (origin_addr==NULL && origin_count > 0)){
     retval = MPI_ERR_COUNT;
   } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
     retval = MPI_ERR_TYPE;
@@ -2772,9 +2756,8 @@ int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
     retval = MPI_ERR_RANK;
   } else if (target_disp <0){
     retval = MPI_ERR_ARG;
-  } else if (origin_count < 0 || target_count < 0) {
-    retval = MPI_ERR_COUNT;
-  } else if (origin_addr==NULL && origin_count > 0){
+  } else if ((origin_count < 0 || target_count < 0) ||
+            (origin_addr==NULL && origin_count > 0)){
     retval = MPI_ERR_COUNT;
   } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
     retval = MPI_ERR_TYPE;
@@ -2807,9 +2790,8 @@ int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_da
     retval = MPI_ERR_RANK;
   } else if (target_disp <0){
     retval = MPI_ERR_ARG;
-  } else if (origin_count < 0 || target_count < 0) {
-    retval = MPI_ERR_COUNT;
-  } else if (origin_addr==NULL && origin_count > 0){
+  } else if ((origin_count < 0 || target_count < 0) ||
+             (origin_addr==NULL && origin_count > 0)){
     retval = MPI_ERR_COUNT;
   } else if ((!is_datatype_valid(origin_datatype)) ||
             (!is_datatype_valid(target_datatype))) {
@@ -2906,10 +2888,10 @@ int PMPI_Win_wait(MPI_Win win){
 
 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
   void *ptr = xbt_malloc(size);
-  if(!ptr)
+  if(ptr==NULL)
     return MPI_ERR_NO_MEM;
   else {
-    *(void **)baseptr = ptr;
+    *static_cast<void**>(baseptr) = ptr;
     return MPI_SUCCESS;
   }
 }
@@ -3038,23 +3020,23 @@ int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
   case MPI_IO:
   case MPI_APPNUM:
     *flag = 1;
-    *(int**)attr_value = &zero;
+    *static_cast<int**>(attr_value) = &zero;
     return MPI_SUCCESS;
   case MPI_UNIVERSE_SIZE:
     *flag = 1;
-    *(int**)attr_value = &smpi_universe_size;
+    *static_cast<int**>(attr_value) = &smpi_universe_size;
     return MPI_SUCCESS;
   case MPI_LASTUSEDCODE:
     *flag = 1;
-    *(int**)attr_value = &last_used_code;
+    *static_cast<int**>(attr_value) = &last_used_code;
     return MPI_SUCCESS;
   case MPI_TAG_UB:
     *flag=1;
-    *(int**)attr_value = &tag_ub;
+    *static_cast<int**>(attr_value) = &tag_ub;
     return MPI_SUCCESS;
   case MPI_WTIME_IS_GLOBAL:
     *flag = 1;
-    *(int**)attr_value = &one;
+    *static_cast<int**>(attr_value) = &one;
     return MPI_SUCCESS;
   default:
     return smpi_comm_attr_get(comm, keyval, attr_value, flag);
@@ -3165,7 +3147,7 @@ int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
     return MPI_ERR_ARG;
   if (value == NULL)
     return MPI_ERR_INFO_VALUE;
-  char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
+  char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(info->info_dict, key));
   if(tmpvalue){
     memset(value, 0, valuelen);
     memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
@@ -3184,7 +3166,7 @@ int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
   int *key;
   void* data;
   xbt_dict_foreach(info->info_dict,cursor,key,data){
-    xbt_dict_set((*newinfo)->info_dict, (char*)key, data, NULL);
+    xbt_dict_set((*newinfo)->info_dict, reinterpret_cast<char*>(key), data, NULL);
   }
   return MPI_SUCCESS;
 }
@@ -3219,7 +3201,7 @@ int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
   int num=0;
   xbt_dict_foreach(info->info_dict,cursor,keyn,data){
     if(num==n){
-      strcpy(key,keyn);
+      strncpy(key,keyn,strlen(keyn)+1);
       xbt_dict_cursor_free(&cursor);
       return MPI_SUCCESS;
     }
index 7975f1c..3929b82 100644 (file)
@@ -29,15 +29,15 @@ static void log_timed_action (const char *const *action, double clock){
   if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){
     char *name = xbt_str_join_array(action, " ");
     XBT_VERB("%s %f", name, smpi_process_simulated_elapsed()-clock);
-    free(name);
+    xbt_free(name);
   }
 }
 
 static xbt_dynar_t get_reqq_self()
 {
    char * key = bprintf("%d", smpi_process_index());
-   xbt_dynar_t dynar_mpi_request = (xbt_dynar_t) xbt_dict_get(reqq, key);
-   free(key);
+   xbt_dynar_t dynar_mpi_request = static_cast<xbt_dynar_t>(xbt_dict_get(reqq, key));
+   xbt_free(key);
  
    return dynar_mpi_request;
 }
@@ -46,7 +46,7 @@ static void set_reqq_self(xbt_dynar_t mpi_request)
 {
    char * key = bprintf("%d", smpi_process_index());
    xbt_dict_set(reqq, key, mpi_request, free);
-   free(key);
+   xbt_free(key);
 }
 
 //allocate a single buffer for all sends, growing it if needed
@@ -124,7 +124,8 @@ const char* encode_datatype(MPI_Datatype datatype, int* known)
 {
   //default type for output is set to MPI_BYTE
   // MPI_DEFAULT_TYPE is not set for output, use directly MPI_BYTE
-  if(known)*known=1;
+  if(known!=NULL)
+    *known=1;
   if (datatype==MPI_BYTE){
       return "";
   }
@@ -141,7 +142,8 @@ const char* encode_datatype(MPI_Datatype datatype, int* known)
   if(datatype==MPI_FLOAT)
       return "5";
   //tell that the datatype is not handled by replay, and that its size should be measured and replayed as size*MPI_BYTE
-  if(known)*known=0;
+  if(known!=NULL)
+    *known=0;
   // default - not implemented.
   // do not warn here as we pass in this function even for other trace formats
   return "-1";
@@ -161,8 +163,9 @@ const char* encode_datatype(MPI_Datatype datatype, int* known)
 static void action_init(const char *const *action)
 {
   XBT_DEBUG("Initialize the counters");
-  CHECK_ACTION_PARAMS(action, 0, 1);
-  if(action[2]) MPI_DEFAULT_TYPE= MPI_DOUBLE; // default MPE dataype 
+  CHECK_ACTION_PARAMS(action, 0, 1)
+  if(action[2]) 
+    MPI_DEFAULT_TYPE=MPI_DOUBLE; // default MPE dataype 
   else MPI_DEFAULT_TYPE= MPI_BYTE; // default TAU datatype
 
   /* start a simulated timer */
@@ -170,7 +173,7 @@ static void action_init(const char *const *action)
   /*initialize the number of active processes */
   active_processes = smpi_process_count();
 
-  if (!reqq) {
+  if (reqq==NULL) {
     reqq = xbt_dict_new();
   }
 
@@ -179,6 +182,7 @@ static void action_init(const char *const *action)
 
 static void action_finalize(const char *const *action)
 {
+  /* do nothing */
 }
 
 static void action_comm_size(const char *const *action)
@@ -205,7 +209,7 @@ static void action_comm_dup(const char *const *action)
 
 static void action_compute(const char *const *action)
 {
-  CHECK_ACTION_PARAMS(action, 1, 0);
+  CHECK_ACTION_PARAMS(action, 1, 0)
   double clock = smpi_process_simulated_elapsed();
   double flops= parse_double(action[2]);
   int rank = smpi_process_index();
@@ -222,16 +226,15 @@ static void action_compute(const char *const *action)
 
 static void action_send(const char *const *action)
 {
-  CHECK_ACTION_PARAMS(action, 2, 1);
+  CHECK_ACTION_PARAMS(action, 2, 1)
   int to = atoi(action[2]);
   double size=parse_double(action[3]);
   double clock = smpi_process_simulated_elapsed();
 
-  if(action[4]) {
+  if(action[4])
     MPI_CURRENT_TYPE=decode_datatype(action[4]);
-  } else {
+  else
     MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
-  }
 
   int rank = smpi_process_index();
 
@@ -256,14 +259,16 @@ static void action_send(const char *const *action)
 
 static void action_Isend(const char *const *action)
 {
-  CHECK_ACTION_PARAMS(action, 2, 1);
+  CHECK_ACTION_PARAMS(action, 2, 1)
   int to = atoi(action[2]);
   double size=parse_double(action[3]);
   double clock = smpi_process_simulated_elapsed();
   MPI_Request request;
 
-  if(action[4]) MPI_CURRENT_TYPE=decode_datatype(action[4]);
-  else MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
+  if(action[4]) 
+    MPI_CURRENT_TYPE=decode_datatype(action[4]);
+  else 
+    MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
 
   int rank = smpi_process_index();
   int dst_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), to);
@@ -289,14 +294,16 @@ static void action_Isend(const char *const *action)
 }
 
 static void action_recv(const char *const *action) {
-  CHECK_ACTION_PARAMS(action, 2, 1);
+  CHECK_ACTION_PARAMS(action, 2, 1)
   int from = atoi(action[2]);
   double size=parse_double(action[3]);
   double clock = smpi_process_simulated_elapsed();
   MPI_Status status;
 
-  if(action[4]) MPI_CURRENT_TYPE=decode_datatype(action[4]);
-  else MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
+  if(action[4]) 
+    MPI_CURRENT_TYPE=decode_datatype(action[4]);
+  else 
+    MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
 
   int rank = smpi_process_index();
   int src_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), from);
@@ -310,7 +317,7 @@ static void action_recv(const char *const *action) {
   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
 
   //unknow size from the receiver pov
-  if(size==-1){
+  if(size<=0.0){
       smpi_mpi_probe(from, 0, MPI_COMM_WORLD, &status);
       size=status.count;
   }
@@ -327,14 +334,16 @@ static void action_recv(const char *const *action) {
 
 static void action_Irecv(const char *const *action)
 {
-  CHECK_ACTION_PARAMS(action, 2, 1);
+  CHECK_ACTION_PARAMS(action, 2, 1)
   int from = atoi(action[2]);
   double size=parse_double(action[3]);
   double clock = smpi_process_simulated_elapsed();
   MPI_Request request;
 
-  if(action[4]) MPI_CURRENT_TYPE=decode_datatype(action[4]);
-  else MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
+  if(action[4]) 
+    MPI_CURRENT_TYPE=decode_datatype(action[4]);
+  else 
+    MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
 
   int rank = smpi_process_index();
   int src_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), from);
@@ -347,7 +356,7 @@ static void action_Irecv(const char *const *action)
   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
   MPI_Status status;
   //unknow size from the receiver pov
-  if(size==-1){
+  if(size<=0.0){
       smpi_mpi_probe(from, 0, MPI_COMM_WORLD, &status);
       size=status.count;
   }
@@ -362,7 +371,7 @@ static void action_Irecv(const char *const *action)
 }
 
 static void action_test(const char *const *action){
-  CHECK_ACTION_PARAMS(action, 0, 0);
+  CHECK_ACTION_PARAMS(action, 0, 0)
   double clock = smpi_process_simulated_elapsed();
   MPI_Request request;
   MPI_Status status;
@@ -372,7 +381,7 @@ static void action_test(const char *const *action){
   //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.
-  if(request){
+  if(request!=NULL){
     int rank = smpi_process_index();
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
     extra->type=TRACING_TEST;
@@ -390,7 +399,7 @@ static void action_test(const char *const *action){
 }
 
 static void action_wait(const char *const *action){
-  CHECK_ACTION_PARAMS(action, 0, 0);
+  CHECK_ACTION_PARAMS(action, 0, 0)
   double clock = smpi_process_simulated_elapsed();
   MPI_Request request;
   MPI_Status status;
@@ -400,7 +409,7 @@ static void action_wait(const char *const *action){
       xbt_str_join_array(action," "));
   request = xbt_dynar_pop_as(get_reqq_self(),MPI_Request);
 
-  if (!request){
+  if (request==NULL){
     /* Assume that the trace is well formed, meaning the comm might have been caught by a MPI_test. Then just return.*/
     return;
   }
@@ -424,7 +433,7 @@ static void action_wait(const char *const *action){
 }
 
 static void action_waitall(const char *const *action){
-  CHECK_ACTION_PARAMS(action, 0, 0);
+  CHECK_ACTION_PARAMS(action, 0, 0)
   double clock = smpi_process_simulated_elapsed();
   int count_requests=0;
   unsigned int i=0;
@@ -443,7 +452,7 @@ static void action_waitall(const char *const *action){
    xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), NULL);
    xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), NULL);
    xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), NULL);
-   for (i = 0; (int)i < count_requests; i++) {
+   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);
@@ -473,7 +482,7 @@ static void action_waitall(const char *const *action){
 
    smpi_mpi_waitall(count_requests, requests, status);
 
-   for (i = 0; (int)i < count_requests; i++) {
+   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);
@@ -487,8 +496,6 @@ static void action_waitall(const char *const *action){
    xbt_dynar_free(&srcs);
    xbt_dynar_free(&dsts);
    xbt_dynar_free(&recvs);
-
-   //TODO xbt_dynar_free_container(get_reqq_self());
    set_reqq_self(xbt_dynar_new(sizeof(MPI_Request),&xbt_free_ref));
   }
   log_timed_action (action, clock);
@@ -509,7 +516,7 @@ static void action_barrier(const char *const *action){
 
 static void action_bcast(const char *const *action)
 {
-  CHECK_ACTION_PARAMS(action, 1, 2);
+  CHECK_ACTION_PARAMS(action, 1, 2)
   double size = parse_double(action[2]);
   double clock = smpi_process_simulated_elapsed();
   int root=0;
@@ -542,7 +549,7 @@ static void action_bcast(const char *const *action)
 
 static void action_reduce(const char *const *action)
 {
-  CHECK_ACTION_PARAMS(action, 2, 2);
+  CHECK_ACTION_PARAMS(action, 2, 2)
   double comm_size = parse_double(action[2]);
   double comp_size = parse_double(action[3]);
   double clock = smpi_process_simulated_elapsed();
@@ -577,12 +584,14 @@ static void action_reduce(const char *const *action)
 }
 
 static void action_allReduce(const char *const *action) {
-  CHECK_ACTION_PARAMS(action, 2, 1);
+  CHECK_ACTION_PARAMS(action, 2, 1)
   double comm_size = parse_double(action[2]);
   double comp_size = parse_double(action[3]);
 
-  if(action[4]) MPI_CURRENT_TYPE=decode_datatype(action[4]);
-  else MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
+  if(action[4])
+    MPI_CURRENT_TYPE=decode_datatype(action[4]);
+  else
+    MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
 
   double clock = smpi_process_simulated_elapsed();
   int rank = smpi_process_index();
@@ -603,7 +612,7 @@ static void action_allReduce(const char *const *action) {
 }
 
 static void action_allToAll(const char *const *action) {
-  CHECK_ACTION_PARAMS(action, 2, 2); //two mandatory (send and recv volumes)
+  CHECK_ACTION_PARAMS(action, 2, 2) //two mandatory (send and recv volumes)
                                      //two optional (corresponding datatypes)
   double clock = smpi_process_simulated_elapsed();
   int comm_size = smpi_comm_size(MPI_COMM_WORLD);
@@ -650,7 +659,7 @@ static void action_gather(const char *const *action) {
   4) 0 is the send datatype id, see decode_datatype()
   5) 0 is the recv datatype id, see decode_datatype()
   */
-  CHECK_ACTION_PARAMS(action, 2, 3);
+  CHECK_ACTION_PARAMS(action, 2, 3)
   double clock = smpi_process_simulated_elapsed();
   int comm_size = smpi_comm_size(MPI_COMM_WORLD);
   int send_size = parse_double(action[2]);
@@ -703,7 +712,7 @@ static void action_gatherv(const char *const *action) {
 
   double clock = smpi_process_simulated_elapsed();
   int comm_size = smpi_comm_size(MPI_COMM_WORLD);
-  CHECK_ACTION_PARAMS(action, comm_size+1, 2);
+  CHECK_ACTION_PARAMS(action, comm_size+1, 2)
   int send_size = parse_double(action[2]);
   int *disps = xbt_new0(int, comm_size);
   int *recvcounts = xbt_new0(int, comm_size);
@@ -726,7 +735,7 @@ static void action_gatherv(const char *const *action) {
   }
 
   int root=atoi(action[3+comm_size]);
-  int rank = smpi_comm_rank(MPI_COMM_WORLD);;
+  int rank = smpi_comm_rank(MPI_COMM_WORLD);
 
   if(rank==root)
     recv = smpi_get_tmp_recvbuffer(recv_sum* smpi_datatype_size(MPI_CURRENT_TYPE2));
@@ -764,7 +773,7 @@ static void action_reducescatter(const char *const *action) {
   We analyze a MPI_Reduce_scatter call to one MPI_Reduce and one MPI_Scatterv. */
   double clock = smpi_process_simulated_elapsed();
   int comm_size = smpi_comm_size(MPI_COMM_WORLD);
-  CHECK_ACTION_PARAMS(action, comm_size+1, 1);
+  CHECK_ACTION_PARAMS(action, comm_size+1, 1)
   int comp_size = parse_double(action[2+comm_size]);
   int *recvcounts = xbt_new0(int, comm_size);  
   int *disps = xbt_new0(int, comm_size);  
@@ -816,7 +825,7 @@ static void action_allgather(const char *const *action) {
   3) No more values mean that the datatype for sent and receive buffer is the default one, see decode_datatype().  */
   double clock = smpi_process_simulated_elapsed();
 
-  CHECK_ACTION_PARAMS(action, 2, 2);
+  CHECK_ACTION_PARAMS(action, 2, 2)
   int sendcount=atoi(action[2]); 
   int recvcount=atoi(action[3]); 
 
@@ -861,7 +870,7 @@ static void action_allgatherv(const char *const *action) {
   double clock = smpi_process_simulated_elapsed();
 
   int comm_size = smpi_comm_size(MPI_COMM_WORLD);
-  CHECK_ACTION_PARAMS(action, comm_size+1, 2);
+  CHECK_ACTION_PARAMS(action, comm_size+1, 2)
   int i=0;
   int sendcount=atoi(action[2]);
   int *recvcounts = xbt_new0(int, comm_size);  
@@ -918,7 +927,7 @@ static void action_allToAllv(const char *const *action) {
   double clock = smpi_process_simulated_elapsed();
 
   int comm_size = smpi_comm_size(MPI_COMM_WORLD);
-  CHECK_ACTION_PARAMS(action, 2*comm_size+2, 2);
+  CHECK_ACTION_PARAMS(action, 2*comm_size+2, 2)
   int send_buf_size=0,recv_buf_size=0,i=0;
   int *sendcounts = xbt_new0(int, comm_size);  
   int *recvcounts = xbt_new0(int, comm_size);  
@@ -989,9 +998,9 @@ void smpi_replay_run(int *argc, char***argv){
   char *operation =bprintf("%s_init",__FUNCTION__);
   TRACE_smpi_collective_in(rank, -1, operation, extra);
   TRACE_smpi_collective_out(rank, -1, operation);
-  free(operation);
+  xbt_free(operation);
 
-  if (!_xbt_replay_action_init()) {
+  if (_xbt_replay_action_init()==0) {
     xbt_replay_action_register("init",       action_init);
     xbt_replay_action_register("finalize",   action_finalize);
     xbt_replay_action_register("comm_size",  action_comm_size);
@@ -1039,7 +1048,7 @@ void smpi_replay_run(int *argc, char***argv){
   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())){
+  if (xbt_dynar_is_empty(get_reqq_self())==0){
     int count_requests=xbt_dynar_length(get_reqq_self());
     MPI_Request requests[count_requests];
     MPI_Status status[count_requests];
@@ -1052,20 +1061,14 @@ void smpi_replay_run(int *argc, char***argv){
     active_processes--;
   }
 
-  if(!active_processes){
+  if(active_processes==0){
     /* Last process alive speaking */
     /* end the simulated timer */
     sim_time = smpi_process_simulated_elapsed();
-  }
-
-  //TODO xbt_dynar_free_container(get_reqq_self()));
-
-  if(!active_processes){
     XBT_INFO("Simulation time %f", sim_time);
     _xbt_replay_action_exit();
     xbt_free(sendbuffer);
     xbt_free(recvbuffer);
-    //xbt_free(reqq);
     xbt_dict_free(&reqq); //not need, data have been freed ???
     reqq = NULL;
   }
@@ -1080,5 +1083,5 @@ void smpi_replay_run(int *argc, char***argv){
   TRACE_smpi_collective_out(rank, -1, operation);
   TRACE_smpi_finalize(smpi_process_index());
   smpi_process_destroy();
-  free(operation);
+  xbt_free(operation);
 }
index 87c8a8a..d4c51f4 100644 (file)
@@ -93,7 +93,7 @@ void smpi_mpi_win_get_name(MPI_Win win, char* name, int* length){
     return;
   }
   *length = strlen(win->name);
-  strcpy(name, win->name);
+  strncpy(name, win->name, *length+1);
 }
 
 void smpi_mpi_win_get_group(MPI_Win win, MPI_Group* group){
@@ -103,12 +103,12 @@ void smpi_mpi_win_get_group(MPI_Win win, MPI_Group* group){
 }
 
 void smpi_mpi_win_set_name(MPI_Win win, char* name){
-  win->name = xbt_strdup(name);;
+  win->name = xbt_strdup(name);
 }
 
 int smpi_mpi_win_fence( int assert,  MPI_Win win){
   XBT_DEBUG("Entering fence");
-  if(!win->opened)
+  if(win->opened==0)
     win->opened=1;
   if(assert != MPI_MODE_NOPRECEDE){
     xbt_barrier_wait(win->bar);
@@ -119,7 +119,8 @@ int smpi_mpi_win_fence( int assert,  MPI_Win win){
     MPI_Request req;
     // start all requests that have been prepared by another process
     xbt_dynar_foreach(reqs, cpt, req){
-      if (req->flags & PREPARED) smpi_mpi_start(req);
+      if (req->flags & PREPARED) 
+        smpi_mpi_start(req);
     }
 
     MPI_Request* treqs = static_cast<MPI_Request*>(xbt_dynar_to_array(reqs));
@@ -139,12 +140,12 @@ int smpi_mpi_win_fence( int assert,  MPI_Win win){
 int smpi_mpi_put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win)
 {
-  if(!win->opened)//check that post/start has been done
+  if(win->opened==0)//check that post/start has been done
     return MPI_ERR_WIN;
   //get receiver pointer
   MPI_Win recv_win = win->connected_wins[target_rank];
 
-  void* recv_addr = (void*) ( ((char*)recv_win->base) + target_disp * recv_win->disp_unit);
+  void* recv_addr = static_cast<void*> ( static_cast<char*>(recv_win->base) + target_disp * recv_win->disp_unit);
   XBT_DEBUG("Entering MPI_Put to %d", target_rank);
 
   if(target_rank != smpi_comm_rank(win->comm)){
@@ -174,12 +175,12 @@ int smpi_mpi_put( void *origin_addr, int origin_count, MPI_Datatype origin_datat
 int smpi_mpi_get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win)
 {
-  if(!win->opened)//check that post/start has been done
+  if(win->opened==0)//check that post/start has been done
     return MPI_ERR_WIN;
   //get sender pointer
   MPI_Win send_win = win->connected_wins[target_rank];
 
-  void* send_addr = (void*)( ((char*)send_win->base) + target_disp * send_win->disp_unit);
+  void* send_addr = static_cast<void*>(static_cast<char*>(send_win->base) + target_disp * send_win->disp_unit);
   XBT_DEBUG("Entering MPI_Get from %d", target_rank);
 
   if(target_rank != smpi_comm_rank(win->comm)){
@@ -215,13 +216,13 @@ int smpi_mpi_get( void *origin_addr, int origin_count, MPI_Datatype origin_datat
 int smpi_mpi_accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win)
 {
-  if(!win->opened)//check that post/start has been done
+  if(win->opened==0)//check that post/start has been done
     return MPI_ERR_WIN;
   //FIXME: local version 
   //get receiver pointer
   MPI_Win recv_win = win->connected_wins[target_rank];
 
-  void* recv_addr = (void*)( ((char*)recv_win->base) + target_disp * recv_win->disp_unit);
+  void* recv_addr = static_cast<void*>(static_cast<char*>(recv_win->base) + target_disp * recv_win->disp_unit);
   XBT_DEBUG("Entering MPI_Accumulate to %d", target_rank);
 
     //prepare send_request
@@ -260,7 +261,6 @@ int smpi_mpi_win_start(MPI_Group group, int assert, MPI_Win win){
   int size = smpi_group_size(group);
   MPI_Request* reqs = xbt_new0(MPI_Request, size);
 
-//  for(i=0;i<size;i++){
   while(j!=size){
     int src=smpi_group_index(group,j);
     if(src!=smpi_process_index()){
@@ -313,10 +313,6 @@ int smpi_mpi_win_post(MPI_Group group, int assert, MPI_Win win){
 int smpi_mpi_win_complete(MPI_Win win){
   if(win->opened==0)
     xbt_die("Complete called on already opened MPI_Win");
-//  xbt_barrier_wait(win->bar);
-  //MPI_Comm comm = smpi_comm_new(win->group, NULL);
-  //mpi_coll_barrier_fun(comm);
-  //smpi_comm_destroy(comm);
 
   XBT_DEBUG("Entering MPI_Win_Complete");
   int i=0,j=0;
@@ -351,7 +347,8 @@ int smpi_mpi_win_complete(MPI_Win win){
   MPI_Request req;
   // start all requests that have been prepared by another process
   xbt_dynar_foreach(reqqs, cpt, req){
-    if (req->flags & PREPARED) smpi_mpi_start(req);
+    if (req->flags & PREPARED) 
+      smpi_mpi_start(req);
   }
 
   MPI_Request* treqs = static_cast<MPI_Request*>(xbt_dynar_to_array(reqqs));
@@ -364,17 +361,12 @@ int smpi_mpi_win_complete(MPI_Win win){
 }
 
 int smpi_mpi_win_wait(MPI_Win win){
-//  xbt_barrier_wait(win->bar);
-  //MPI_Comm comm = smpi_comm_new(win->group, NULL);
-  //mpi_coll_barrier_fun(comm);
-  //smpi_comm_destroy(comm);
   //naive, blocking implementation.
   XBT_DEBUG("Entering MPI_Win_Wait");
   int i=0,j=0;
   int size = smpi_group_size(win->group);
   MPI_Request* reqs = xbt_new0(MPI_Request, size);
 
-//  for(i=0;i<size;i++){
   while(j!=size){
     int src=smpi_group_index(win->group,j);
     if(src!=smpi_process_index()){
@@ -401,7 +393,8 @@ int smpi_mpi_win_wait(MPI_Win win){
   MPI_Request req;
   // start all requests that have been prepared by another process
   xbt_dynar_foreach(reqqs, cpt, req){
-    if (req->flags & PREPARED) smpi_mpi_start(req);
+    if (req->flags & PREPARED) 
+      smpi_mpi_start(req);
   }
 
   MPI_Request* treqs = static_cast<MPI_Request*>(xbt_dynar_to_array(reqqs));
index 16b8cfa..bdcd9b6 100644 (file)
@@ -79,15 +79,15 @@ MPI_Topology smpi_topo_create(MPIR_Topo_type kind) {
 void smpi_cart_topo_destroy(MPIR_Cart_Topology cart) {
     if (cart) {
         if(cart->dims) {
-            free(cart->dims);
+            xbt_free(cart->dims);
         }
         if(cart->periodic) {
-            free(cart->periodic);
+            xbt_free(cart->periodic);
         }
         if(cart->position) {
-            free(cart->position);
+            xbt_free(cart->position);
         }
-        free(cart);
+        xbt_free(cart);
     }
 }
 
@@ -132,9 +132,6 @@ int smpi_mpi_cart_create(MPI_Comm comm_old, int ndims, int dims[], int periods[]
 
         newCart->topo.cart->nnodes = newSize;
 
-        /* memcpy(newCart->topo.cart->dims, dims, ndims * sizeof(*newCart->topo.cart->dims)); */
-        /* memcpy(newCart->topo.cart->periodic, periods, ndims * sizeof(*newCart->topo.cart->periodic)); */
-
         //  FIXME : code duplication... See smpi_mpi_cart_coords
         nranks = newSize;
         for (i=0; i<ndims; i++) {
@@ -168,7 +165,8 @@ int smpi_mpi_cart_sub(MPI_Comm comm, const int remain_dims[], MPI_Comm *newcomm)
     }
     newNDims = 0;
     for (i = 0 ; i < oldNDims ; i++) {
-        if (remain_dims[i]) newNDims++;
+        if (remain_dims[i]) 
+            newNDims++;
     }
   
     if (newNDims > 0) {
@@ -236,7 +234,8 @@ int smpi_mpi_cart_rank(MPI_Comm comm, int* coords, int* rank) {
         } else if (coord <  0) {
             if(topo->topo.cart->periodic[i]) {
                 coord = coord % topo->topo.cart->dims[i];
-                if (coord) coord = topo->topo.cart->dims[i] + coord;
+                if (coord) 
+                    coord = topo->topo.cart->dims[i] + coord;
             } else {
                 *rank = -1;
                 return MPI_ERR_ARG;