X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6ce33e125842a4cad0537273a154dbf7e4f1e81c..1b791d40a387d97aebc05cf4dd0b5760777de150:/src/smpi/bindings/smpi_f77.cpp diff --git a/src/smpi/bindings/smpi_f77.cpp b/src/smpi/bindings/smpi_f77.cpp index 8594d517e8..0cd960050a 100644 --- a/src/smpi/bindings/smpi_f77.cpp +++ b/src/smpi/bindings/smpi_f77.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2010-2022. 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. */ @@ -13,6 +13,8 @@ #include "smpi_win.hpp" #include "src/smpi/include/smpi_actor.hpp" +#include + static int running_processes = 0; void smpi_init_fortran_types() @@ -21,11 +23,10 @@ void smpi_init_fortran_types() MPI_COMM_WORLD->add_f(); MPI_BYTE->add_f(); // MPI_BYTE MPI_CHAR->add_f(); // MPI_CHARACTER + MPI_C_BOOL->add_f(); // MPI_LOGICAL if (sizeof(void*) == 8) { - MPI_C_BOOL->add_f(); // MPI_LOGICAL MPI_INT->add_f(); // MPI_INTEGER } else { - MPI_C_BOOL->add_f(); // MPI_LOGICAL MPI_LONG->add_f(); // MPI_INTEGER } MPI_INT8_T->add_f(); // MPI_INTEGER1 @@ -75,6 +76,7 @@ void smpi_init_fortran_types() MPI_LB->add_f(); MPI_UB->add_f(); + simgrid::smpi::F2C::finish_initialization(); } } @@ -157,9 +159,6 @@ void mpi_win_free_(int* win, int* ierr) { MPI_Win tmp = simgrid::smpi::Win::f2c(*win); *ierr = MPI_Win_free(&tmp); - if(*ierr == MPI_SUCCESS) { - simgrid::smpi::F2C::free_f(*win); - } } void mpi_win_create_(int* base, MPI_Aint* size, int* disp_unit, int* info, int* comm, int* win, int* ierr) @@ -167,7 +166,7 @@ void mpi_win_create_(int* base, MPI_Aint* size, int* disp_unit, int* info, int* MPI_Win tmp; *ierr = MPI_Win_create( static_cast(base), *size, *disp_unit, simgrid::smpi::Info::f2c(*info), simgrid::smpi::Comm::f2c(*comm),&tmp); if (*ierr == MPI_SUCCESS) { - *win = tmp->add_f(); + *win = tmp->c2f(); } } @@ -200,11 +199,8 @@ void mpi_win_set_name_(int* win, char* name, int* ierr, int size) size--; name++; } - char* tname = xbt_new(char,size+1); - strncpy(tname, name, size); - tname[size]='\0'; - *ierr = MPI_Win_set_name(simgrid::smpi::Win::f2c(*win), tname); - xbt_free(tname); + std::string tname(name, size); + *ierr = MPI_Win_set_name(simgrid::smpi::Win::f2c(*win), tname.c_str()); } void mpi_win_get_name_(int* win, char* name, int* len, int* ierr) @@ -220,7 +216,7 @@ void mpi_win_allocate_(MPI_Aint* size, int* disp_unit, int* info, int* comm, voi *ierr = MPI_Win_allocate(*size, *disp_unit, simgrid::smpi::Info::f2c(*info), simgrid::smpi::Comm::f2c(*comm), base, &tmp); if(*ierr == MPI_SUCCESS) { - *win = tmp->add_f(); + *win = tmp->c2f(); } } @@ -234,7 +230,7 @@ void mpi_win_create_dynamic_(int* info, int* comm, int* win, int* ierr) MPI_Win tmp; *ierr = MPI_Win_create_dynamic( simgrid::smpi::Info::f2c(*info), simgrid::smpi::Comm::f2c(*comm),&tmp); if(*ierr == MPI_SUCCESS) { - *win = tmp->add_f(); + *win = tmp->c2f(); } } @@ -253,7 +249,7 @@ void mpi_win_get_info_(int* win, int* info, int* ierr) MPI_Info tmp; *ierr = MPI_Win_get_info(simgrid::smpi::Win::f2c(*win), &tmp); if (*ierr == MPI_SUCCESS) { - *info = tmp->add_f(); + *info = tmp->c2f(); } } @@ -262,35 +258,35 @@ void mpi_win_get_group_(int* win, int* group, int* ierr) MPI_Group tmp; *ierr = MPI_Win_get_group(simgrid::smpi::Win::f2c(*win), &tmp); if (*ierr == MPI_SUCCESS) { - *group = tmp->add_f(); + *group = tmp->c2f(); } } -void mpi_win_get_attr_(int* win, int* type_keyval, MPI_Aint* attribute_val, int* flag, int* ierr) +void mpi_win_get_attr_(int* win, int* win_keyval, MPI_Aint* attribute_val, int* flag, int* ierr) { MPI_Aint* value = nullptr; - *ierr = MPI_Win_get_attr(simgrid::smpi::Win::f2c(*win), *type_keyval, &value, flag); + *ierr = MPI_Win_get_attr(simgrid::smpi::Win::f2c(*win), *win_keyval, &value, flag); if (*flag == 1) *attribute_val = *value; } -void mpi_win_set_attr_(int* win, int* type_keyval, MPI_Aint* att, int* ierr) +void mpi_win_set_attr_(int* win, int* win_keyval, MPI_Aint* att, int* ierr) { - auto* val = static_cast(xbt_malloc(sizeof(MPI_Aint))); + auto* val = xbt_new(MPI_Aint, 1); *val = *att; - *ierr = MPI_Win_set_attr(simgrid::smpi::Win::f2c(*win), *type_keyval, val); + *ierr = MPI_Win_set_attr(simgrid::smpi::Win::f2c(*win), *win_keyval, val); } -void mpi_win_delete_attr_(int* win, int* comm_keyval, int* ierr) +void mpi_win_delete_attr_(int* win, int* win_keyval, int* ierr) { - *ierr = MPI_Win_delete_attr (simgrid::smpi::Win::f2c(*win), *comm_keyval); + *ierr = MPI_Win_delete_attr(simgrid::smpi::Win::f2c(*win), *win_keyval); } void mpi_win_create_keyval_(void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) { smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast(copy_fn)}; smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast(delete_fn)}; - *ierr = simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); + *ierr = simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state, true); } void mpi_win_free_keyval_(int* keyval, int* ierr) @@ -358,7 +354,7 @@ void mpi_info_create_(int* info, int* ierr) MPI_Info tmp; *ierr = MPI_Info_create(&tmp); if(*ierr == MPI_SUCCESS) { - *info = tmp->add_f(); + *info = tmp->c2f(); } } @@ -371,9 +367,7 @@ void mpi_info_set_(int* info, char* key, char* value, int* ierr, unsigned int ke keylen--; key++; } - char* tkey = xbt_new(char,keylen+1); - strncpy(tkey, key, keylen); - tkey[keylen]='\0'; + std::string tkey(key, keylen); while(value[valuelen-1]==' ') valuelen--; @@ -381,13 +375,9 @@ void mpi_info_set_(int* info, char* key, char* value, int* ierr, unsigned int ke valuelen--; value++; } - char* tvalue = xbt_new(char,valuelen+1); - strncpy(tvalue, value, valuelen); - tvalue[valuelen]='\0'; + std::string tvalue(value, valuelen); - *ierr = MPI_Info_set( simgrid::smpi::Info::f2c(*info), tkey, tvalue); - xbt_free(tkey); - xbt_free(tvalue); + *ierr = MPI_Info_set(simgrid::smpi::Info::f2c(*info), tkey.c_str(), tvalue.c_str()); } void mpi_info_get_(int* info, char* key, int* valuelen, char* value, int* flag, int* ierr, unsigned int keylen) @@ -398,11 +388,8 @@ void mpi_info_get_(int* info, char* key, int* valuelen, char* value, int* flag, keylen--; key++; } - char* tkey = xbt_new(char,keylen+1); - strncpy(tkey, key, keylen); - tkey[keylen]='\0'; - *ierr = MPI_Info_get(simgrid::smpi::Info::f2c(*info),tkey,*valuelen, value, flag); - xbt_free(tkey); + std::string tkey(key, keylen); + *ierr = MPI_Info_get(simgrid::smpi::Info::f2c(*info), tkey.c_str(), *valuelen, value, flag); if(*flag!=0){ int replace=0; for (int i = 0; i < *valuelen; i++) { @@ -437,7 +424,7 @@ void mpi_rget_(int* origin_addr, int* origin_count, int* origin_datatype, int* t *ierr = MPI_Rget( static_cast(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank, *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win), &req); if(*ierr == MPI_SUCCESS) { - *request = req->add_f(); + *request = req->c2f(); } } @@ -456,7 +443,7 @@ void mpi_raccumulate_(int* origin_addr, int* origin_count, int* origin_datatype, *ierr = MPI_Raccumulate( static_cast(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank, *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Op::f2c(*op), simgrid::smpi::Win::f2c(*win),&req); if(*ierr == MPI_SUCCESS) { - *request = req->add_f(); + *request = req->c2f(); } } @@ -474,7 +461,7 @@ void mpi_rput_(int* origin_addr, int* origin_count, int* origin_datatype, int* t *ierr = MPI_Rput( static_cast(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank, *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win),&req); if(*ierr == MPI_SUCCESS) { - *request = req->add_f(); + *request = req->c2f(); } } @@ -516,7 +503,7 @@ void mpi_rget_accumulate_(int* origin_addr, int* origin_count, int* origin_datat *target_count, simgrid::smpi::Datatype::f2c(*target_datatype), simgrid::smpi::Op::f2c(*op), simgrid::smpi::Win::f2c(*win), &req); if(*ierr == MPI_SUCCESS) { - *request = req->add_f(); + *request = req->c2f(); } } @@ -564,7 +551,7 @@ void mpi_op_create_(void* function, int* commute, int* op, int* ierr) *ierr = MPI_Op_create(reinterpret_cast(function), *commute, &tmp); if (*ierr == MPI_SUCCESS) { tmp->set_fortran_op(); - *op = tmp->add_f(); + *op = tmp->c2f(); } } @@ -572,9 +559,6 @@ void mpi_op_free_(int* op, int* ierr) { MPI_Op tmp= simgrid::smpi::Op::f2c(*op); *ierr = MPI_Op_free(& tmp); - if(*ierr == MPI_SUCCESS) { - simgrid::smpi::F2C::free_f(*op); - } } void mpi_op_commutative_(int* op, int* commute, int* ierr) @@ -585,11 +569,7 @@ void mpi_op_commutative_(int* op, int* commute, int* ierr) void mpi_group_free_(int* group, int* ierr) { MPI_Group tmp = simgrid::smpi::Group::f2c(*group); - if(tmp != MPI_COMM_WORLD->group() && tmp != MPI_GROUP_EMPTY){ - simgrid::smpi::Group::unref(tmp); - simgrid::smpi::F2C::free_f(*group); - } - *ierr = MPI_SUCCESS; + *ierr = MPI_Group_free(&tmp); } void mpi_group_size_(int* group, int* size, int* ierr) @@ -617,7 +597,7 @@ void mpi_group_union_(int* group1, int* group2, int* newgroup, int* ierr) MPI_Group tmp; *ierr = MPI_Group_union(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp); if (*ierr == MPI_SUCCESS) { - *newgroup = tmp->add_f(); + *newgroup = tmp->c2f(); } } @@ -626,7 +606,7 @@ void mpi_group_intersection_(int* group1, int* group2, int* newgroup, int* ierr) MPI_Group tmp; *ierr = MPI_Group_intersection(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp); if (*ierr == MPI_SUCCESS) { - *newgroup = tmp->add_f(); + *newgroup = tmp->c2f(); } } @@ -635,7 +615,7 @@ void mpi_group_difference_(int* group1, int* group2, int* newgroup, int* ierr) MPI_Group tmp; *ierr = MPI_Group_difference(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp); if (*ierr == MPI_SUCCESS) { - *newgroup = tmp->add_f(); + *newgroup = tmp->c2f(); } } @@ -644,7 +624,7 @@ void mpi_group_excl_(int* group, int* n, int* ranks, int* newgroup, int* ierr) MPI_Group tmp; *ierr = MPI_Group_excl(simgrid::smpi::Group::f2c(*group), *n, ranks, &tmp); if (*ierr == MPI_SUCCESS) { - *newgroup = tmp->add_f(); + *newgroup = tmp->c2f(); } } @@ -653,7 +633,7 @@ void mpi_group_range_incl_ (int* group, int* n, int ranges[][3], int* newgroup, MPI_Group tmp; *ierr = MPI_Group_range_incl(simgrid::smpi::Group::f2c(*group), *n, ranges, &tmp); if (*ierr == MPI_SUCCESS) { - *newgroup = tmp->add_f(); + *newgroup = tmp->c2f(); } } @@ -662,16 +642,13 @@ void mpi_group_range_excl_ (int* group, int* n, int ranges[][3], int* newgroup, MPI_Group tmp; *ierr = MPI_Group_range_excl(simgrid::smpi::Group::f2c(*group), *n, ranges, &tmp); if(*ierr == MPI_SUCCESS) { - *newgroup = tmp->add_f(); + *newgroup = tmp->c2f(); } } void mpi_request_free_ (int* request, int* ierr){ MPI_Request tmp=simgrid::smpi::Request::f2c(*request); *ierr = MPI_Request_free(&tmp); - if(*ierr == MPI_SUCCESS) { - simgrid::smpi::Request::free_f(*request); - } } void mpi_pack_size_ (int* incount, int* datatype, int* comm, int* size, int* ierr) { @@ -686,7 +663,7 @@ void mpi_cart_create_ (int* comm_old, int* ndims, int* dims, int* periods, int* MPI_Comm tmp; *ierr = MPI_Cart_create(simgrid::smpi::Comm::f2c(*comm_old), *ndims, dims, periods, *reorder, &tmp); if(*ierr == MPI_SUCCESS) { - *comm_cart = tmp->add_f(); + *comm_cart = tmp->c2f(); } } @@ -710,7 +687,7 @@ void mpi_cart_sub_ (int* comm, int* remain_dims, int* comm_new, int* ierr) { MPI_Comm tmp; *ierr = MPI_Cart_sub(simgrid::smpi::Comm::f2c(*comm), remain_dims, &tmp); if(*ierr == MPI_SUCCESS) { - *comm_new = tmp->add_f(); + *comm_new = tmp->c2f(); } } @@ -722,7 +699,7 @@ void mpi_graph_create_ (int* comm_old, int* nnodes, int* index, int* edges, int* MPI_Comm tmp; *ierr = MPI_Graph_create(simgrid::smpi::Comm::f2c(*comm_old), *nnodes, index, edges, *reorder, &tmp); if(*ierr == MPI_SUCCESS) { - *comm_graph = tmp->add_f(); + *comm_graph = tmp->c2f(); } } @@ -803,7 +780,7 @@ void mpi_intercomm_create_ (int* local_comm, int *local_leader, int* peer_comm, *ierr = MPI_Intercomm_create(simgrid::smpi::Comm::f2c(*local_comm), *local_leader, simgrid::smpi::Comm::f2c(*peer_comm), *remote_leader, *tag, &tmp); if(*ierr == MPI_SUCCESS) { - *comm_out = tmp->add_f(); + *comm_out = tmp->c2f(); } } @@ -811,7 +788,7 @@ void mpi_intercomm_merge_ (int* comm, int* high, int* comm_out, int* ierr) { MPI_Comm tmp; *ierr = MPI_Intercomm_merge(simgrid::smpi::Comm::f2c(*comm), *high, &tmp); if(*ierr == MPI_SUCCESS) { - *comm_out = tmp->add_f(); + *comm_out = tmp->c2f(); } } @@ -820,7 +797,7 @@ void mpi_attr_delete_ (int* comm, int* keyval, int* ierr) { } void mpi_attr_put_ (int* comm, int* keyval, int* attr_value, int* ierr) { - auto* val = static_cast(xbt_malloc(sizeof(int))); + auto* val = xbt_new(int, 1); *val = *attr_value; *ierr = MPI_Attr_put(simgrid::smpi::Comm::f2c(*comm), *keyval, val); } @@ -828,7 +805,7 @@ void mpi_attr_put_ (int* comm, int* keyval, int* attr_value, int* ierr) { void mpi_keyval_create_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) { smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast(copy_fn),nullptr,nullptr}; smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast(delete_fn),nullptr,nullptr}; - *ierr = simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state); + *ierr = simgrid::smpi::Keyval::keyval_create(_copy_fn, _delete_fn, keyval, extra_state, true); } void mpi_keyval_free_ (int* keyval, int* ierr) { @@ -863,7 +840,7 @@ void mpi_info_dup_ (int* info, int* newinfo, int* ierr){ MPI_Info tmp; *ierr = MPI_Info_dup(simgrid::smpi::Info::f2c(*info), &tmp); if(*ierr==MPI_SUCCESS){ - *newinfo= tmp->add_f(); + *newinfo= tmp->c2f(); } } @@ -874,11 +851,8 @@ void mpi_info_get_valuelen_ ( int* info, char *key, int *valuelen, int *flag, in keylen--; key++; } - char* tkey = xbt_new(char, keylen+1); - strncpy(tkey, key, keylen); - tkey[keylen]='\0'; - *ierr = MPI_Info_get_valuelen( simgrid::smpi::Info::f2c(*info), tkey, valuelen, flag); - xbt_free(tkey); + std::string tkey(key, keylen); + *ierr = MPI_Info_get_valuelen(simgrid::smpi::Info::f2c(*info), tkey.c_str(), valuelen, flag); } void mpi_info_delete_ (int* info, char *key, int* ierr, unsigned int keylen){ @@ -888,11 +862,8 @@ void mpi_info_delete_ (int* info, char *key, int* ierr, unsigned int keylen){ keylen--; key++; } - char* tkey = xbt_new(char, keylen+1); - strncpy(tkey, key, keylen); - tkey[keylen]='\0'; - *ierr = MPI_Info_delete(simgrid::smpi::Info::f2c(*info), tkey); - xbt_free(tkey); + std::string tkey(key, keylen); + *ierr = MPI_Info_delete(simgrid::smpi::Info::f2c(*info), tkey.c_str()); } void mpi_info_get_nkeys_ ( int* info, int *nkeys, int* ierr){ @@ -922,7 +893,7 @@ void mpi_grequest_start_ ( void *query_fn, void *free_fn, void *cancel_fn, void *ierr = MPI_Grequest_start( reinterpret_cast(query_fn), reinterpret_cast(free_fn), reinterpret_cast(cancel_fn), extra_state, &tmp); if(*ierr == MPI_SUCCESS) { - *request = tmp->add_f(); + *request = tmp->c2f(); } } @@ -958,6 +929,15 @@ void mpi_close_port_ ( char *port_name, int* ierr){ *ierr = MPI_Close_port( port_name); } +void mpi_alloc_mem_(int* size, int* info, void *baseptr, int* ierr){ + *ierr = MPI_Alloc_mem(*size, simgrid::smpi::Info::f2c(*info), baseptr); +} + +void mpi_free_mem_(void *baseptr, int* ierr){ + *ierr = MPI_Free_mem(baseptr); +} + + void smpi_execute_flops_(double* flops){ smpi_execute_flops(*flops); }