From 0a25f3e55e2d9677c56ffcf328c9cd4ef4ae1387 Mon Sep 17 00:00:00 2001 From: degomme Date: Wed, 15 Mar 2017 23:26:07 +0100 Subject: [PATCH] Expand the Keyval mechanism to Win. --- include/smpi/smpi.h | 19 ++++++++++++++ src/smpi/smpi_mpi.cpp | 6 +++++ src/smpi/smpi_pmpi.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ src/smpi/smpi_win.cpp | 29 +++++++++++++++++++++ src/smpi/smpi_win.hpp | 8 +++++- 5 files changed, 120 insertions(+), 1 deletion(-) diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index b52e36696f..507122a2d9 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -201,6 +201,10 @@ SG_BEGIN_DECL() #define MPI_SEEK_END 604 #define MPI_MAX_DATAREP_STRING 128 +#define MPI_WIN_BASE -1 +#define MPI_WIN_SIZE -2 +#define MPI_WIN_DISP_UNIT -3 + // FIXME : used nowhere... typedef enum MPIR_Combiner_enum{ MPI_COMBINER_NAMED, @@ -378,10 +382,15 @@ typedef int MPI_Delete_function(MPI_Comm comm, int keyval, void* attribute_val, typedef int MPI_Type_copy_attr_function(MPI_Datatype type, int keyval, void* extra_state, void* attribute_val_in, void* attribute_val_out, int* flag); typedef int MPI_Type_delete_attr_function(MPI_Datatype type, int keyval, void* attribute_val, void* extra_state); +typedef int MPI_Win_copy_attr_function(MPI_Win win, int keyval, void* extra_state, void* attribute_val_in, + void* attribute_val_out, int* flag); +typedef int MPI_Win_delete_attr_function(MPI_Win win, int keyval, void* attribute_val, void* extra_state); #define MPI_COMM_NULL_COPY_FN ((MPI_Comm_copy_attr_function*)0) #define MPI_COMM_NULL_DELETE_FN ((MPI_Comm_delete_attr_function*)0) #define MPI_TYPE_NULL_COPY_FN ((MPI_Type_copy_attr_function*)0) #define MPI_TYPE_NULL_DELETE_FN ((MPI_Type_delete_attr_function*)0) +#define MPI_WIN_NULL_COPY_FN ((MPI_Win_copy_attr_function*)0) +#define MPI_WIN_NULL_DELETE_FN ((MPI_Win_delete_attr_function*)0) MPI_CALL(XBT_PUBLIC(int), MPI_Init, (int *argc, char ***argv)); @@ -530,6 +539,13 @@ MPI_CALL(XBT_PUBLIC(int), MPI_Win_set_name,(MPI_Win win, char * name)); MPI_CALL(XBT_PUBLIC(int), MPI_Win_get_name,(MPI_Win win, char * name, int* len)); MPI_CALL(XBT_PUBLIC(int), MPI_Win_get_group,(MPI_Win win, MPI_Group * group)); MPI_CALL(XBT_PUBLIC(int), MPI_Win_fence,( int assert, MPI_Win win)); +MPI_CALL(XBT_PUBLIC(int), MPI_Win_get_attr, (MPI_Win type, int type_keyval, void *attribute_val, int* flag)); +MPI_CALL(XBT_PUBLIC(int), MPI_Win_set_attr, (MPI_Win type, int type_keyval, void *att)); +MPI_CALL(XBT_PUBLIC(int), MPI_Win_delete_attr, (MPI_Win type, int comm_keyval)); +MPI_CALL(XBT_PUBLIC(int), MPI_Win_create_keyval,(MPI_Win_copy_attr_function* copy_fn, + MPI_Win_delete_attr_function* delete_fn, int* keyval, void* extra_state)); +MPI_CALL(XBT_PUBLIC(int), MPI_Win_free_keyval,(int* keyval)); + MPI_CALL(XBT_PUBLIC(int), 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)); @@ -565,6 +581,9 @@ typedef int MPI_Grequest_free_function(void *extra_state); typedef int MPI_Grequest_cancel_function(void *extra_state, int complete); #define MPI_DUP_FN MPI_Comm_dup +#define MPI_WIN_DUP_FN ((MPI_Win_copy_attr_function*)MPI_DUP_FN) +#define MPI_TYPE_DUP_FN ((MPI_Type_copy_attr_function*)MPI_DUP_FN) +#define MPI_COMM_DUP_FN ((MPI_Comm_copy_attr_function *)MPI_DUP_FN) typedef MPI_Comm_errhandler_function MPI_Comm_errhandler_fn; #define MPI_INFO_ENV 1 XBT_PUBLIC_DATA( const MPI_Datatype ) MPI_PACKED; diff --git a/src/smpi/smpi_mpi.cpp b/src/smpi/smpi_mpi.cpp index 2ca0704bfa..67c315c056 100644 --- a/src/smpi/smpi_mpi.cpp +++ b/src/smpi/smpi_mpi.cpp @@ -190,6 +190,12 @@ WRAPPED_PMPI_CALL(int,MPI_Win_post,(MPI_Group group, int assert, MPI_Win win),(g WRAPPED_PMPI_CALL(int,MPI_Win_set_name,(MPI_Win win, char * name),(win, name)) WRAPPED_PMPI_CALL(int,MPI_Win_start,(MPI_Group group, int assert, MPI_Win win),(group, assert, win)) WRAPPED_PMPI_CALL(int,MPI_Win_wait,(MPI_Win win),(win)) +WRAPPED_PMPI_CALL(int,MPI_Win_get_attr, (MPI_Win type, int type_keyval, void *attribute_val, int* flag), (type, type_keyval, attribute_val, flag)) +WRAPPED_PMPI_CALL(int,MPI_Win_set_attr, (MPI_Win type, int type_keyval, void *att), (type, type_keyval, att)) +WRAPPED_PMPI_CALL(int,MPI_Win_delete_attr, (MPI_Win type, int comm_keyval), (type, comm_keyval)) +WRAPPED_PMPI_CALL(int,MPI_Win_create_keyval,(MPI_Win_copy_attr_function* copy_fn, + MPI_Win_delete_attr_function* delete_fn, int* keyval, void* extra_state), (copy_fn, delete_fn, keyval, extra_state)) +WRAPPED_PMPI_CALL(int,MPI_Win_free_keyval,(int* keyval), (keyval)) WRAPPED_PMPI_CALL(MPI_Comm, MPI_Comm_f2c,(MPI_Fint comm),(comm)) WRAPPED_PMPI_CALL(MPI_Datatype, MPI_Type_f2c,(MPI_Fint datatype),(datatype)) WRAPPED_PMPI_CALL(MPI_Fint, MPI_Comm_c2f,(MPI_Comm comm),(comm)) diff --git a/src/smpi/smpi_pmpi.cpp b/src/smpi/smpi_pmpi.cpp index 81395f16a1..6e728550f8 100644 --- a/src/smpi/smpi_pmpi.cpp +++ b/src/smpi/smpi_pmpi.cpp @@ -2905,6 +2905,65 @@ int PMPI_Type_free_keyval(int* keyval) { return Keyval::keyval_free(keyval); } +int PMPI_Win_get_attr (MPI_Win win, int keyval, void *attribute_val, int* flag) +{ + static MPI_Aint size; + static int disp_unit; + if (win==MPI_WIN_NULL) + return MPI_ERR_TYPE; + else{ + switch (keyval) { + case MPI_WIN_BASE : + *static_cast(attribute_val) = win->base(); + *flag = 1; + return MPI_SUCCESS; + case MPI_WIN_SIZE : + size = win->size(); + *static_cast(attribute_val) = &size; + *flag = 1; + return MPI_SUCCESS; + case MPI_WIN_DISP_UNIT : + disp_unit=win->disp_unit(); + *static_cast(attribute_val) = &disp_unit; + *flag = 1; + return MPI_SUCCESS; + default: + return win->attr_get(keyval, attribute_val, flag); + } +} + +} + +int PMPI_Win_set_attr (MPI_Win win, int type_keyval, void *attribute_val) +{ + if (win==MPI_WIN_NULL) + return MPI_ERR_TYPE; + else + return win->attr_put(type_keyval, attribute_val); +} + +int PMPI_Win_delete_attr (MPI_Win win, int type_keyval) +{ + if (win==MPI_WIN_NULL) + return MPI_ERR_TYPE; + else + return win->attr_delete(type_keyval); +} + +int PMPI_Win_create_keyval(MPI_Win_copy_attr_function* copy_fn, MPI_Win_delete_attr_function* delete_fn, int* keyval, + void* extra_state) +{ + smpi_copy_fn _copy_fn; + smpi_delete_fn _delete_fn; + _copy_fn.win_copy_fn = copy_fn; + _delete_fn.win_delete_fn = delete_fn; + return Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); +} + +int PMPI_Win_free_keyval(int* keyval) { + return Keyval::keyval_free(keyval); +} + int PMPI_Info_create( MPI_Info *info){ if (info == nullptr) return MPI_ERR_ARG; diff --git a/src/smpi/smpi_win.cpp b/src/smpi/smpi_win.cpp index c12c4581b5..a2c2220a3e 100644 --- a/src/smpi/smpi_win.cpp +++ b/src/smpi/smpi_win.cpp @@ -11,6 +11,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA o namespace simgrid{ namespace smpi{ +std::unordered_map Win::keyvals_; +int Win::keyval_id_=0; Win::Win(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm): base_(base), size_(size), disp_unit_(disp_unit), assert_(0), info_(info), comm_(comm){ int comm_size = comm->size(); @@ -56,6 +58,20 @@ Win::~Win(){ if(rank == 0) MSG_barrier_destroy(bar_); xbt_mutex_destroy(mut_); + + if(!attributes_.empty()){ + int flag; + for(auto it = attributes_.begin(); it != attributes_.end(); it++){ + try{ + smpi_key_elem elem = keyvals_.at((*it).first); + if (elem != nullptr && elem->delete_fn.win_delete_fn != nullptr) + elem->delete_fn.win_delete_fn(this, (*it).first, (*it).second, &flag); + }catch(const std::out_of_range& oor) { + //already deleted, not a problem; + } + } + } + } void Win::get_name(char* name, int* length){ @@ -76,6 +92,19 @@ void Win::get_group(MPI_Group* group){ } } +MPI_Aint Win::size(){ + return size_; +} + +void* Win::base(){ + return base_; +} + +int Win::disp_unit(){ + return disp_unit_; +} + + void Win::set_name(char* name){ name_ = xbt_strdup(name); } diff --git a/src/smpi/smpi_win.hpp b/src/smpi/smpi_win.hpp index c821210253..8185d5c37e 100644 --- a/src/smpi/smpi_win.hpp +++ b/src/smpi/smpi_win.hpp @@ -13,7 +13,7 @@ namespace simgrid{ namespace smpi{ -class Win : public F2C { +class Win : public F2C, public Keyval { private : void* base_; MPI_Aint size_; @@ -31,6 +31,9 @@ class Win : public F2C { int count_; //for ordering the accs public: + static std::unordered_map keyvals_; + static int keyval_id_; + Win(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm); ~Win(); void get_name( char* name, int* length); @@ -40,6 +43,9 @@ public: int post(MPI_Group group, int assert); int complete(); int wait(); + MPI_Aint size(); + void* base(); + int disp_unit(); int fence(int assert); int 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); -- 2.20.1