class Comm;
class Datatype;
class Group;
+class Info;
class Op;
class Request;
class Topo;
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;
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;
#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)
} 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)
#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"
} 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();
--- /dev/null
+/* 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;
+}
+
+}
+}
+
--- /dev/null
+/* 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
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;
}
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) {
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;