Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
be even more informative to the user
[simgrid.git] / src / smpi / smpi_mpi_dt.cpp
index 5f66b31..91a8ee7 100644 (file)
@@ -186,26 +186,26 @@ int smpi_datatype_dup(MPI_Datatype datatype, MPI_Datatype* new_t)
   if(datatype->name)
     (*new_t)->name = xbt_strdup(datatype->name);
   if(datatype->attributes !=nullptr){
-      (*new_t)->attributes=xbt_dict_new();
-      xbt_dict_cursor_t cursor = nullptr;
-      int *key;
-      int flag;
-      void* value_in;
-      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,  reinterpret_cast<const char*>(key), sizeof(int)));
-        if(elem != nullptr && elem->copy_fn!=MPI_NULL_COPY_FN){
-          ret = elem->copy_fn(datatype, *key, nullptr, value_in, &value_out, &flag );
-          if(ret!=MPI_SUCCESS){
-            smpi_datatype_unuse(*new_t);
-            *new_t=MPI_DATATYPE_NULL;
-            xbt_dict_cursor_free(&cursor);
-            return ret;
-          }
-          if(flag)
-            xbt_dict_set_ext((*new_t)->attributes, reinterpret_cast<const char*>(key), sizeof(int),value_out, nullptr);
+    (*new_t)->attributes     = xbt_dict_new_homogeneous(nullptr);
+    xbt_dict_cursor_t cursor = nullptr;
+    int* key;
+    int flag;
+    void* value_in;
+    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, reinterpret_cast<const char*>(key), sizeof(int)));
+      if (elem != nullptr && elem->copy_fn != MPI_NULL_COPY_FN) {
+        ret = elem->copy_fn(datatype, *key, nullptr, value_in, &value_out, &flag);
+        if (ret != MPI_SUCCESS) {
+          smpi_datatype_unuse(*new_t);
+          *new_t = MPI_DATATYPE_NULL;
+          xbt_dict_cursor_free(&cursor);
+          return ret;
         }
+        if (flag)
+          xbt_dict_set_ext((*new_t)->attributes, reinterpret_cast<const char*>(key), sizeof(int), value_out, nullptr);
+      }
       }
     }
   return ret;
@@ -436,7 +436,11 @@ void smpi_datatype_use(MPI_Datatype type){
 #endif
 }
 
-void smpi_datatype_unuse(MPI_Datatype type){
+void smpi_datatype_unuse(MPI_Datatype type)
+{
+  if (type == MPI_DATATYPE_NULL)
+    return;
+
   if (type->in_use > 0)
     type->in_use--;
 
@@ -444,9 +448,9 @@ void smpi_datatype_unuse(MPI_Datatype type){
     static_cast<s_smpi_subtype_t *>((type)->substruct)->subtype_free(&type);  
   }
 
-  if(type != MPI_DATATYPE_NULL && type->in_use == 0){
+  if (type->in_use == 0)
     smpi_datatype_free(&type);
-  }
+
 #if HAVE_MC
   if(MC_is_active())
     MC_ignore(&(type->in_use), sizeof(type->in_use));
@@ -1252,6 +1256,10 @@ static void sum_func(void *a, void *b, int *length, MPI_Datatype * datatype)
     APPLY_FUNC(a, b, length, unsigned short, SUM_OP)
   } else if (*datatype == MPI_UNSIGNED) {
     APPLY_FUNC(a, b, length, unsigned int, SUM_OP)
+  } else if (*datatype == MPI_UNSIGNED_LONG_LONG) {
+    APPLY_FUNC(a, b, length, unsigned long long, SUM_OP)
+  } else if (*datatype == MPI_LONG_LONG) {
+    APPLY_FUNC(a, b, length, long long, SUM_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
     APPLY_FUNC(a, b, length, unsigned long, SUM_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
@@ -1289,6 +1297,10 @@ static void prod_func(void *a, void *b, int *length, MPI_Datatype * datatype)
     APPLY_FUNC(a, b, length, unsigned int, PROD_OP)
   } else if (*datatype == MPI_UNSIGNED_LONG) {
     APPLY_FUNC(a, b, length, unsigned long, PROD_OP)
+  } else if (*datatype == MPI_UNSIGNED_LONG_LONG) {
+    APPLY_FUNC(a, b, length, unsigned long long, PROD_OP)
+  } else if (*datatype == MPI_LONG_LONG) {
+    APPLY_FUNC(a, b, length, long long, PROD_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
     APPLY_FUNC(a, b, length, unsigned char, PROD_OP)
   } else if (*datatype == MPI_FLOAT) {
@@ -1326,6 +1338,10 @@ static void land_func(void *a, void *b, int *length, MPI_Datatype * datatype)
     APPLY_FUNC(a, b, length, unsigned long, LAND_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
     APPLY_FUNC(a, b, length, unsigned char, LAND_OP)
+  } else if (*datatype == MPI_UNSIGNED_LONG_LONG) {
+    APPLY_FUNC(a, b, length, unsigned long long, LAND_OP)
+  } else if (*datatype == MPI_LONG_LONG) {
+    APPLY_FUNC(a, b, length, long long, LAND_OP)
   } else if (*datatype == MPI_C_BOOL) {
     APPLY_FUNC(a, b, length, bool, LAND_OP)
   } else {
@@ -1351,6 +1367,10 @@ static void lor_func(void *a, void *b, int *length, MPI_Datatype * datatype)
     APPLY_FUNC(a, b, length, unsigned long, LOR_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
     APPLY_FUNC(a, b, length, unsigned char, LOR_OP)
+  } else if (*datatype == MPI_UNSIGNED_LONG_LONG) {
+    APPLY_FUNC(a, b, length, unsigned long long, LOR_OP)
+  } else if (*datatype == MPI_LONG_LONG) {
+    APPLY_FUNC(a, b, length, long long, LOR_OP)
   } else if (*datatype == MPI_C_BOOL) {
     APPLY_FUNC(a, b, length, bool, LOR_OP)
   } else {
@@ -1376,6 +1396,10 @@ static void lxor_func(void *a, void *b, int *length, MPI_Datatype * datatype)
     APPLY_FUNC(a, b, length, unsigned long, LXOR_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
     APPLY_FUNC(a, b, length, unsigned char, LXOR_OP)
+  } else if (*datatype == MPI_UNSIGNED_LONG_LONG) {
+    APPLY_FUNC(a, b, length, unsigned long long, LXOR_OP)
+  } else if (*datatype == MPI_LONG_LONG) {
+    APPLY_FUNC(a, b, length, long long, LXOR_OP)
   } else if (*datatype == MPI_C_BOOL) {
     APPLY_FUNC(a, b, length, bool, LXOR_OP)
   } else {
@@ -1401,6 +1425,10 @@ static void band_func(void *a, void *b, int *length, MPI_Datatype * datatype)
     APPLY_FUNC(a, b, length, unsigned long, BAND_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
     APPLY_FUNC(a, b, length, unsigned char, BAND_OP)
+  } else if (*datatype == MPI_UNSIGNED_LONG_LONG) {
+    APPLY_FUNC(a, b, length, unsigned long long, BAND_OP)
+  } else if (*datatype == MPI_LONG_LONG) {
+    APPLY_FUNC(a, b, length, long long, BAND_OP)
   } else if (*datatype == MPI_BYTE) {
     APPLY_FUNC(a, b, length, uint8_t, BAND_OP)
   } else {
@@ -1426,6 +1454,10 @@ static void bor_func(void *a, void *b, int *length, MPI_Datatype * datatype)
     APPLY_FUNC(a, b, length, unsigned long, BOR_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
     APPLY_FUNC(a, b, length, unsigned char, BOR_OP)
+  } else if (*datatype == MPI_UNSIGNED_LONG_LONG) {
+    APPLY_FUNC(a, b, length, unsigned long long, BOR_OP)
+  } else if (*datatype == MPI_LONG_LONG) {
+    APPLY_FUNC(a, b, length, long long, BOR_OP)
   } else if (*datatype == MPI_BYTE) {
     APPLY_FUNC(a, b, length, uint8_t, BOR_OP)
   } else {
@@ -1451,6 +1483,10 @@ static void bxor_func(void *a, void *b, int *length, MPI_Datatype * datatype)
     APPLY_FUNC(a, b, length, unsigned long, BXOR_OP)
   } else if (*datatype == MPI_UNSIGNED_CHAR) {
     APPLY_FUNC(a, b, length, unsigned char, BXOR_OP)
+  } else if (*datatype == MPI_UNSIGNED_LONG_LONG) {
+    APPLY_FUNC(a, b, length, unsigned long long, BXOR_OP)
+  } else if (*datatype == MPI_LONG_LONG) {
+    APPLY_FUNC(a, b, length, long long, BXOR_OP)
   } else if (*datatype == MPI_BYTE) {
     APPLY_FUNC(a, b, length, uint8_t, BXOR_OP)
   } else {
@@ -1606,7 +1642,7 @@ int smpi_type_attr_get(MPI_Datatype type, int keyval, void* attr_value, int* fla
 
 int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){
   if(smpi_type_keyvals==nullptr)
-    smpi_type_keyvals = xbt_dict_new();
+    smpi_type_keyvals = xbt_dict_new_homogeneous(nullptr);
   smpi_type_key_elem 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==nullptr)
@@ -1620,7 +1656,7 @@ int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){
       return ret;
   }
   if(type->attributes==nullptr)
-    type->attributes=xbt_dict_new();
+    type->attributes = xbt_dict_new_homogeneous(nullptr);
 
   xbt_dict_set_ext(type->attributes, reinterpret_cast<const char*>(&keyval), sizeof(int), attr_value, nullptr);
   return MPI_SUCCESS;
@@ -1629,7 +1665,7 @@ int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){
 int smpi_type_keyval_create(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
                             void* extra_state){
   if(smpi_type_keyvals==nullptr)
-    smpi_type_keyvals = xbt_dict_new();
+    smpi_type_keyvals = xbt_dict_new_homogeneous(nullptr);
 
   smpi_type_key_elem value = (smpi_type_key_elem) xbt_new0(s_smpi_mpi_type_key_elem_t,1);