-template <typename T> int smpi_add_f(T t, xbt_dict_t dict, int* id) {
- char key[KEY_SIZE];
- xbt_dict_set(dict, get_key(key, *id), t, nullptr);
- (*id)++;
- return *id-1;
-}
-
-template <> int smpi_add_f<MPI_Comm>(MPI_Comm comm, xbt_dict_t dict, int* id) {
- char key[KEY_SIZE];
- xbt_dict_set(dict, comm==MPI_COMM_WORLD? get_key(key, *id) : get_key_id(key, *id), comm, nullptr);
- (*id)++;
- return *id-1;
-}
-
-template <> int smpi_add_f<MPI_Request>(MPI_Request request, xbt_dict_t dict, int* id) {
- char key[KEY_SIZE];
- xbt_dict_set(dict, get_key_id(key, *id), request, nullptr);
- (*id)++;
- return *id-1;
-}
-
-template <typename T> int smpi_c2f(T t, xbt_dict_t dict, int* id) {
- char* existing_key = xbt_dict_get_key(dict, t);
- if(existing_key!=nullptr)
- return atoi(existing_key);
- else
- return smpi_add_f<T>(t,dict,id);
-}
-
-template <typename T> void free_f(int id, xbt_dict_t dict) {
- char key[KEY_SIZE];
- xbt_dict_remove(dict, get_key(key, id));
-}
-
-template <> void free_f<MPI_Comm>(int id, xbt_dict_t dict) {
- char key[KEY_SIZE];
- xbt_dict_remove(dict, id==0? get_key(key, id) : get_key_id(key, id));
-}
-
-template <> void free_f<MPI_Request>(int id, xbt_dict_t dict) {
- char key[KEY_SIZE];
- if(id!=MPI_FORTRAN_REQUEST_NULL)
- xbt_dict_remove(dict, get_key_id(key, id));
-}
-
-template <typename T> T smpi_f2c(int , xbt_dict_t ) {
- return NULL;
-}
-
-template <> MPI_Datatype smpi_f2c<MPI_Datatype>(int id, xbt_dict_t dict) {
- smpi_init_fortran_types();
- char key[KEY_SIZE];
- return id >= 0 ? static_cast<MPI_Datatype>(xbt_dict_get_or_null(dict, get_key(key, id))): MPI_DATATYPE_NULL;
-}
-
-template <> MPI_Op smpi_f2c<MPI_Op> (int id, xbt_dict_t dict) {
- smpi_init_fortran_types();
- char key[KEY_SIZE];
- return id >= 0 ? static_cast<MPI_Op>(xbt_dict_get_or_null(dict, get_key(key, id))): MPI_OP_NULL;
-}
-
-template <> MPI_Info smpi_f2c<MPI_Info>(int id, xbt_dict_t dict) {
- smpi_init_fortran_types();
- char key[KEY_SIZE];
- return id >= 0 ? static_cast<MPI_Info>(xbt_dict_get_or_null(dict, get_key(key, id))): MPI_INFO_NULL;
-}
-
-template <> MPI_Win smpi_f2c<MPI_Win>(int id, xbt_dict_t dict) {
- smpi_init_fortran_types();
- char key[KEY_SIZE];
- return id >= 0 ? static_cast<MPI_Win>(xbt_dict_get_or_null(dict, get_key(key, id))): MPI_WIN_NULL;
-}
-
-template <> MPI_Comm smpi_f2c<MPI_Comm>(int comm, xbt_dict_t dict) {
- smpi_init_fortran_types();
- if(comm == -2) {
- return MPI_COMM_SELF;
- } else if(comm==0){
- return MPI_COMM_WORLD;
- } else if(dict != nullptr && comm >= 0) {
- char key[KEY_SIZE];
- MPI_Comm tmp = static_cast<MPI_Comm>(xbt_dict_get_or_null(dict,get_key_id(key, comm)));
- return tmp != nullptr ? tmp : MPI_COMM_NULL ;
- } else {
- return MPI_COMM_NULL;
- }
-}
-
-template <> MPI_Group smpi_f2c<MPI_Group>(int group, xbt_dict_t dict) {
- smpi_init_fortran_types();
- if(group == -2) {
- return MPI_GROUP_EMPTY;
- } else if(dict != nullptr && group >= 0) {
- char key[KEY_SIZE];
- return static_cast<MPI_Group>(xbt_dict_get_or_null(dict, get_key(key, group)));
- } else {
- return MPI_GROUP_NULL;
- }
-}
-
-template <> MPI_Request smpi_f2c<MPI_Request>(int request, xbt_dict_t dict) {
- smpi_init_fortran_types();
- char key[KEY_SIZE];
- if(request==MPI_FORTRAN_REQUEST_NULL)
- return MPI_REQUEST_NULL;
- return static_cast<MPI_Request>(xbt_dict_get(dict, get_key_id(key, request)));
-}
-
-#define SMPI_F2C_C2F(type, name)\
-int smpi_##name##_add_f(type name){\
- return smpi_add_f<type>(name, name##_lookup, &name##_id);\
-}\
-int smpi_##name##_c2f(type name){\
- return smpi_c2f<type>(name, name##_lookup, &name##_id);\
-}\
-static void free_##name(int id) {\
- free_f<type>(id, name##_lookup);\
-}\
-type smpi_##name##_f2c(int id){\
- return smpi_f2c<type>(id, name##_lookup);\
-}
-