Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add support for huge pages in shared malloc.
[simgrid.git] / src / smpi / smpi_op.cpp
index e3d4e2a..599c0c2 100644 (file)
@@ -3,9 +3,10 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "mc/mc.h"
-#include "private.h"
-#include "smpi_mpi_dt_private.h"
+#include "src/smpi/private.h"
+#include "src/smpi/smpi_datatype.hpp"
+#include "src/smpi/smpi_op.hpp"
+#include "src/smpi/smpi_process.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_op, smpi, "Logging specific to SMPI (op)");
 
@@ -19,8 +20,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_op, smpi, "Logging specific to SMPI (op)");
 #define BAND_OP(a, b) (b) &= (a)
 #define BOR_OP(a, b)  (b) |= (a)
 #define BXOR_OP(a, b) (b) ^= (a)
-#define MAXLOC_OP(a, b)  (b) = (a.value) < (b.value) ? (b) : (a)
-#define MINLOC_OP(a, b)  (b) = (a.value) < (b.value) ? (a) : (b)
+#define MAXLOC_OP(a, b)  (b) = (a.value) < (b.value) ? (b) : ((a.value) == (b.value) ? ((a.index) < (b.index) ? (a) : (b)) : (a))
+#define MINLOC_OP(a, b)  (b) = (a.value) < (b.value) ? (a) : ((a.value) == (b.value) ? ((a.index) < (b.index) ? (a) : (b)) : (b))
 
 #define APPLY_FUNC(a, b, length, type, func) \
 {                                          \
@@ -97,7 +98,7 @@ APPLY_OP_LOOP(MPI_2LONG, long_long,op)
 
 #define APPLY_END_OP_LOOP(op)\
   {\
-    xbt_die("Failed to apply " #op " to type %s", (*datatype)->name);\
+    xbt_die("Failed to apply " #op " to type %s", (*datatype)->name());\
   }
 
 static void max_func(void *a, void *b, int *length, MPI_Datatype * datatype)
@@ -186,7 +187,12 @@ static void maxloc_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 
 static void replace_func(void *a, void *b, int *length, MPI_Datatype * datatype)
 {
-  memcpy(b, a, *length * smpi_datatype_size(*datatype));
+  memcpy(b, a, *length * (*datatype)->size());
+}
+
+static void no_func(void *a, void *b, int *length, MPI_Datatype * datatype)
+{
+  /* obviously a no-op */
 }
 
 #define CREATE_MPI_OP(name, func)                             \
@@ -206,6 +212,7 @@ CREATE_MPI_OP(MPI_BXOR, bxor_func);
 CREATE_MPI_OP(MPI_MAXLOC, maxloc_func);
 CREATE_MPI_OP(MPI_MINLOC, minloc_func);
 CREATE_MPI_OP(MPI_REPLACE, replace_func);
+CREATE_MPI_OP(MPI_NO_OP, no_func);
 
 namespace simgrid{
 namespace smpi{
@@ -231,18 +238,19 @@ void Op::set_fortran_op()
   is_fortran_op_ = true;
 }
 
-void Op::apply(void *invec, void *inoutvec, int *len, MPI_Datatype datatype)
+void Op::apply(void *invec, void *inoutvec, int *len, MPI_Datatype datatype)
 {
-  if(smpi_privatize_global_variables){//we need to switch as the called function may silently touch global variables
+  if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){//we need to switch as the called function may silently touch global variables
     XBT_DEBUG("Applying operation, switch to the right data frame ");
-    smpi_switch_data_segment(smpi_process_index());
+    smpi_switch_data_segment(smpi_process()->index());
   }
 
-  if(!smpi_process_get_replaying()){
+  if(!smpi_process()->replaying() && *len > 0){
     if(! is_fortran_op_)
-      this->func_(invec, inoutvec, len, datatype);
+      this->func_(invec, inoutvec, len, &datatype);
     else{
-      int tmp = smpi_type_c2f(*datatype);
+      XBT_DEBUG("Applying operation of length %d from %p and from/to %p", *len, invec, inoutvec);
+      int tmp = datatype->c2f();
       /* Unfortunately, the C and Fortran version of the MPI standard do not agree on the type here,
          thus the reinterpret_cast. */
       this->func_(invec, inoutvec, len, reinterpret_cast<MPI_Datatype*>(&tmp) );
@@ -250,5 +258,9 @@ void Op::apply(void *invec, void *inoutvec, int *len, MPI_Datatype * datatype)
   }
 }
 
+Op* Op::f2c(int id){
+  return static_cast<Op*>(F2C::f2c(id));
+}
+
 }
 }