Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finally free MPI_Info from the dreaded smpi_pmpi.cpp file.
authordegomme <augustin.degomme@unibas.ch>
Fri, 10 Mar 2017 16:09:20 +0000 (17:09 +0100)
committerdegomme <augustin.degomme@unibas.ch>
Sat, 11 Mar 2017 15:12:53 +0000 (16:12 +0100)
include/smpi/forward.hpp
include/smpi/smpi.h
src/smpi/private.h
src/smpi/smpi_info.cpp [new file with mode: 0644]
src/smpi/smpi_info.hpp [new file with mode: 0644]
src/smpi/smpi_pmpi.cpp
src/smpi/smpi_win.cpp

index a42bf91..59603d2 100644 (file)
@@ -16,6 +16,7 @@ namespace smpi {
 class Comm;
 class Datatype;
 class Group;
+class Info;
 class Op;
 class Request;
 class Topo;
@@ -36,6 +37,7 @@ class Win;
 typedef simgrid::smpi::Comm SMPI_Comm;
 typedef simgrid::smpi::Datatype SMPI_Datatype;
 typedef simgrid::smpi::Group SMPI_Group;
+typedef simgrid::smpi::Info SMPI_Info;
 typedef simgrid::smpi::Op SMPI_Op;
 typedef simgrid::smpi::Request SMPI_Request;
 typedef simgrid::smpi::Topo SMPI_Topology;
@@ -55,6 +57,7 @@ typedef simgrid::smpi::Type_Vector SMPI_Type_Vector;
 typedef struct SMPI_Comm SMPI_Comm;
 typedef struct SMPI_Datatype SMPI_Datatype;
 typedef struct SMPI_Group SMPI_Group;
+typedef struct SMPI_Info SMPI_Info;
 typedef struct SMPI_Op SMPI_Op;
 typedef struct SMPI_Request SMPI_Request;
 typedef struct SMPI_Topology SMPI_Topology;
index 0c6d952..5043251 100644 (file)
@@ -174,7 +174,7 @@ SG_BEGIN_DECL()
 #define MPI_TYPECLASS_INTEGER 1
 #define MPI_TYPECLASS_COMPLEX 2
 #define MPI_ROOT 0
-#define MPI_INFO_NULL NULL
+#define MPI_INFO_NULL ((MPI_Info)NULL)
 #define MPI_COMM_TYPE_SHARED    1
 #define MPI_WIN_NULL ((MPI_Win)NULL)
 
@@ -249,8 +249,7 @@ typedef struct {
 } MPI_Status;
 
 typedef SMPI_Win* MPI_Win;
-struct s_smpi_mpi_info;
-typedef struct s_smpi_mpi_info *MPI_Info;
+typedef SMPI_Info* MPI_Info;
 
 #define MPI_STATUS_IGNORE ((MPI_Status*)NULL)
 #define MPI_STATUSES_IGNORE ((MPI_Status*)NULL)
index 2213177..67abdbd 100644 (file)
@@ -17,6 +17,7 @@
 #include "xbt/xbt_os_time.h"
 #include "src/smpi/smpi_group.hpp"
 #include "src/smpi/smpi_comm.hpp"
+#include "src/smpi/smpi_info.hpp"
 #include "src/smpi/smpi_op.hpp"
 #include "src/smpi/smpi_datatype.hpp"
 #include "src/smpi/smpi_datatype_derived.hpp"
@@ -80,11 +81,6 @@ typedef struct s_smpi_mpi_type_key_elem {
 } s_smpi_mpi_type_key_elem_t; 
 typedef struct s_smpi_mpi_type_key_elem *smpi_type_key_elem;
 
-typedef struct s_smpi_mpi_info {
-  xbt_dict_t info_dict;
-  int refcount;
-} s_smpi_mpi_info_t; 
-
 XBT_PRIVATE void smpi_process_destroy();
 XBT_PRIVATE void smpi_process_finalize();
 XBT_PRIVATE int smpi_process_finalized();
diff --git a/src/smpi/smpi_info.cpp b/src/smpi/smpi_info.cpp
new file mode 100644 (file)
index 0000000..0171e11
--- /dev/null
@@ -0,0 +1,106 @@
+/* Copyright (c) 2007-2015. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* 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 "private.h"
+#include <vector>
+#include <xbt/ex.hpp>
+
+namespace simgrid{
+namespace smpi{
+
+MPI_Info Info::null_id_=MPI_INFO_NULL;
+
+Info::Info():refcount_(1){
+  dict_= xbt_dict_new_homogeneous(xbt_free_f);
+}
+
+Info::Info(Info* info):refcount_(1){
+  dict_= xbt_dict_new_homogeneous(xbt_free_f);
+  xbt_dict_cursor_t cursor = nullptr;
+  char* key;
+  void* data;
+  xbt_dict_foreach(info->dict_,cursor,key,data){
+    xbt_dict_set(dict_, key, xbt_strdup(static_cast<char*>(data)), nullptr);
+  }
+}
+
+Info::~Info(){
+  xbt_dict_free(&dict_);
+}
+
+void Info::ref(Info* info){
+  info->refcount_++;
+}
+
+void Info::unref(Info* info){
+  info->refcount_--;
+  if(info->refcount_==0){
+    delete info;
+  }
+}
+
+void Info::set(char *key, char *value){
+  xbt_dict_set(dict_, key, xbt_strdup(value), nullptr);
+}
+
+
+
+int Info::get(char *key, int valuelen, char *value, int *flag){
+  *flag=false;
+  char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(dict_, key));
+  if(tmpvalue){
+    memset(value, 0, valuelen);
+    memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
+    *flag=true;
+  }
+  return MPI_SUCCESS;
+}
+
+
+int Info::remove(char *key){
+  try {
+    xbt_dict_remove(dict_, key);
+  }
+  catch(xbt_ex& e){
+    return MPI_ERR_INFO_NOKEY;
+  }
+  return MPI_SUCCESS;
+}
+
+int Info::get_nkeys(int *nkeys){
+  *nkeys=xbt_dict_size(dict_);
+  return MPI_SUCCESS;
+}
+
+int Info::get_nthkey(int n, char *key){
+  xbt_dict_cursor_t cursor = nullptr;
+  char *keyn;
+  void* data;
+  int num=0;
+  xbt_dict_foreach(dict_,cursor,keyn,data){
+    if(num==n){
+      strncpy(key,keyn,strlen(keyn)+1);
+      xbt_dict_cursor_free(&cursor);
+      return MPI_SUCCESS;
+    }
+    num++;
+  }
+  return MPI_ERR_ARG;
+}
+
+int Info::get_valuelen(char *key, int *valuelen, int *flag){
+  *flag=false;
+  char* tmpvalue=(char*)xbt_dict_get_or_null(dict_, key);
+  if(tmpvalue){
+    *valuelen=strlen(tmpvalue);
+    *flag=true;
+  }
+  return MPI_SUCCESS;
+}
+
+}
+}
+
diff --git a/src/smpi/smpi_info.hpp b/src/smpi/smpi_info.hpp
new file mode 100644 (file)
index 0000000..8e1f525
--- /dev/null
@@ -0,0 +1,40 @@
+/* Copyright (c) 2009-2010, 2012-2014. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* 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. */
+
+#ifndef SMPI_INFO_HPP
+#define SMPI_INFO_HPP
+
+#include <xbt/base.h>
+
+#include "private.h"
+
+namespace simgrid{
+namespace smpi{
+
+class Info : public F2C{
+  private:
+    xbt_dict_t dict_;
+    int refcount_;
+  public:
+    static MPI_Info null_id_;
+
+    Info();
+    Info(Info* orig);
+    ~Info();
+    static void ref(MPI_Info info);
+    static void unref(MPI_Info info);
+    void set(char *key, char *value);
+    int get(char *key,int valuelen, char *value, int *flag);
+    int remove(char* key);
+    int get_nkeys(int *nkeys);
+    int get_nthkey(int n, char *key);
+    int get_valuelen(char *key, int *valuelen, int *flag);
+};
+
+}
+}
+
+#endif
index 30f0f1b..73ed8e5 100644 (file)
@@ -2903,28 +2903,21 @@ int PMPI_Type_free_keyval(int* keyval) {
 int PMPI_Info_create( MPI_Info *info){
   if (info == nullptr)
     return MPI_ERR_ARG;
-  *info = xbt_new(s_smpi_mpi_info_t, 1);
-  (*info)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
-  (*info)->refcount=1;
+  *info = new Info();
   return MPI_SUCCESS;
 }
 
 int PMPI_Info_set( MPI_Info info, char *key, char *value){
   if (info == nullptr || key == nullptr || value == nullptr)
     return MPI_ERR_ARG;
-
-  xbt_dict_set(info->info_dict, key, xbt_strdup(value), nullptr);
+  info->set(key, value);
   return MPI_SUCCESS;
 }
 
 int PMPI_Info_free( MPI_Info *info){
   if (info == nullptr || *info==nullptr)
     return MPI_ERR_ARG;
-  (*info)->refcount--;
-  if((*info)->refcount==0){
-    xbt_dict_free(&((*info)->info_dict));
-    xbt_free(*info);
-  }
+  Info::unref(*info);
   *info=MPI_INFO_NULL;
   return MPI_SUCCESS;
 }
@@ -2935,78 +2928,39 @@ int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
     return MPI_ERR_ARG;
   if (value == nullptr)
     return MPI_ERR_INFO_VALUE;
-  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);
-    *flag=true;
-  }
-  return MPI_SUCCESS;
+  return info->get(key, valuelen, value, flag);
 }
 
 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
   if (info == nullptr || newinfo==nullptr)
     return MPI_ERR_ARG;
-  *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
-  (*newinfo)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
-  (*newinfo)->refcount=1;
-  xbt_dict_cursor_t cursor = nullptr;
-  char* key;
-  void* data;
-  xbt_dict_foreach(info->info_dict,cursor,key,data){
-    xbt_dict_set((*newinfo)->info_dict, key, xbt_strdup(static_cast<char*>(data)), nullptr);
-  }
+  *newinfo = new Info(info);
   return MPI_SUCCESS;
 }
 
 int PMPI_Info_delete(MPI_Info info, char *key){
   if (info == nullptr || key==nullptr)
     return MPI_ERR_ARG;
-  try {
-    xbt_dict_remove(info->info_dict, key);
-  }
-  catch(xbt_ex& e){
-    return MPI_ERR_INFO_NOKEY;
-  }
-  return MPI_SUCCESS;
+  return info->remove(key);
 }
 
 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
   if (info == nullptr || nkeys==nullptr)
     return MPI_ERR_ARG;
-  *nkeys=xbt_dict_size(info->info_dict);
-  return MPI_SUCCESS;
+  return info->get_nkeys(nkeys);
 }
 
 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
   if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY)
     return MPI_ERR_ARG;
-
-  xbt_dict_cursor_t cursor = nullptr;
-  char *keyn;
-  void* data;
-  int num=0;
-  xbt_dict_foreach(info->info_dict,cursor,keyn,data){
-    if(num==n){
-      strncpy(key,keyn,strlen(keyn)+1);
-      xbt_dict_cursor_free(&cursor);
-      return MPI_SUCCESS;
-    }
-    num++;
-  }
-  return MPI_ERR_ARG;
+  return info->get_nthkey(n, key);
 }
 
 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
   *flag=false;
   if (info == nullptr || key == nullptr || valuelen==nullptr)
     return MPI_ERR_ARG;
-  char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
-  if(tmpvalue){
-    *valuelen=strlen(tmpvalue);
-    *flag=true;
-  }
-  return MPI_SUCCESS;
+  return info->get_valuelen(key, valuelen, flag);
 }
 
 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
index fa26e84..1e1b413 100644 (file)
@@ -17,7 +17,7 @@ Win::Win(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm)
   int rank      = comm->rank();
   XBT_DEBUG("Creating window");
   if(info!=MPI_INFO_NULL)
-    info->refcount++;
+    Info::ref(info);
   name_ = nullptr;
   opened_ = 0;
   group_ = MPI_GROUP_NULL;