X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/43f7ca1cac5ab1858e318fdd6239d0a0c3b3d893..21fe278c8460849931b37ccde22e944edec46f71:/src/smpi/bindings/smpi_f77_comm.cpp diff --git a/src/smpi/bindings/smpi_f77_comm.cpp b/src/smpi/bindings/smpi_f77_comm.cpp index f0f56d0d2a..afca7860ab 100644 --- a/src/smpi/bindings/smpi_f77_comm.cpp +++ b/src/smpi/bindings/smpi_f77_comm.cpp @@ -1,10 +1,11 @@ -/* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2010-2019. 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 "private.hpp" #include "smpi_comm.hpp" +#include "smpi_errhandler.hpp" #include "smpi_info.hpp" extern "C" { // This should really use the C linkage to be usable from Fortran @@ -37,12 +38,11 @@ void mpi_comm_create_(int* comm, int* group, int* newcomm, int* ierr) { void mpi_comm_free_(int* comm, int* ierr) { MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm); - - *ierr = MPI_Comm_free(&tmp); - - if(*ierr == MPI_SUCCESS) { + if(tmp != MPI_COMM_WORLD && tmp != MPI_COMM_NULL) { + simgrid::smpi::Comm::destroy(tmp); simgrid::smpi::Comm::free_f(*comm); } + *ierr = MPI_SUCCESS; } void mpi_comm_split_(int* comm, int* color, int* key, int* comm_out, int* ierr) { @@ -71,14 +71,17 @@ void mpi_comm_create_group_ (int* comm, int* group, int i, int* comm_out, int* i } } -void mpi_comm_get_attr_ (int* comm, int* comm_keyval, void *attribute_val, int *flag, int* ierr){ - - *ierr = MPI_Comm_get_attr (simgrid::smpi::Comm::f2c(*comm), *comm_keyval, attribute_val, flag); +void mpi_comm_get_attr_ (int* comm, int* comm_keyval, int *attribute_val, int *flag, int* ierr){ + int* value = nullptr; + *ierr = MPI_Comm_get_attr (simgrid::smpi::Comm::f2c(*comm), *comm_keyval, &value, flag); + if (*flag == 1) + *attribute_val = *value; } -void mpi_comm_set_attr_ (int* comm, int* comm_keyval, void *attribute_val, int* ierr){ - - *ierr = MPI_Comm_set_attr ( simgrid::smpi::Comm::f2c(*comm), *comm_keyval, attribute_val); +void mpi_comm_set_attr_ (int* comm, int* comm_keyval, int *attribute_val, int* ierr){ + int* val = (int*)xbt_malloc(sizeof(int)); + *val=*attribute_val; + *ierr = MPI_Comm_set_attr ( simgrid::smpi::Comm::f2c(*comm), *comm_keyval, val); } void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){ @@ -87,9 +90,9 @@ void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){ } void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){ - - *ierr = MPI_Comm_create_keyval(reinterpret_cast(copy_fn), reinterpret_cast(delete_fn), - keyval, extra_state) ; + 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); } void mpi_comm_free_keyval_ (int* keyval, int* ierr) { @@ -98,8 +101,8 @@ void mpi_comm_free_keyval_ (int* keyval, int* ierr) { void mpi_comm_get_name_ (int* comm, char* name, int* len, int* ierr){ *ierr = MPI_Comm_get_name(simgrid::smpi::Comm::f2c(*comm), name, len); - if(*len>0) - name[*len]=' '; + for(int i = *len; i(errhandler)); +void mpi_comm_set_errhandler_ (int* comm, int* errhandler, int* ierr) { + *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Errhandler::f2c(*errhandler)); } -void mpi_comm_get_errhandler_ (int* comm, void* errhandler, int* ierr) { - *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), static_cast(errhandler)); +void mpi_comm_get_errhandler_ (int* comm, int* errhandler, int* ierr) { + MPI_Errhandler tmp; + *ierr = MPI_Errhandler_get(simgrid::smpi::Comm::f2c(*comm), &tmp); + if(*ierr == MPI_SUCCESS) { + *errhandler = tmp->c2f(); + } } void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) { @@ -139,10 +146,13 @@ void mpi_comm_remote_size_ (int* comm, int* size, int* ierr) { *ierr = MPI_Comm_remote_size(simgrid::smpi::Comm::f2c(*comm), size); } -void mpi_comm_set_name_ (int* comm, char* name, int* ierr, int size){ - char* tname = xbt_new(char, size+1); - strncpy(tname, name, size); - tname[size]='\0'; +void mpi_comm_set_name_ (int* comm, char* name, int* ierr){ + int count; + for(count=MPI_MAX_OBJECT_NAME-1; count>=0 && name[count]==' '; count--); + count+=1; + char* tname = xbt_new(char, count+1); + strncpy(tname, name, count); + tname[count]='\0'; *ierr = MPI_Comm_set_name (simgrid::smpi::Comm::f2c(*comm), tname); xbt_free(tname); } @@ -175,8 +185,12 @@ void mpi_comm_get_info_ (int* comm, int* info, int* ierr){ } } -void mpi_comm_create_errhandler_ ( void *function, void *errhandler, int* ierr){ - *ierr = MPI_Comm_create_errhandler( reinterpret_cast(function), static_cast(errhandler)); +void mpi_comm_create_errhandler_ ( void *function, int *errhandler, int* ierr){ + MPI_Errhandler tmp; + *ierr = MPI_Comm_create_errhandler( reinterpret_cast(function), &tmp); + if(*ierr==MPI_SUCCESS){ + *errhandler = tmp->c2f(); + } } void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){ @@ -185,7 +199,7 @@ void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){ void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){ MPI_Comm tmp; - *ierr = MPI_Comm_connect( port_name, *reinterpret_cast(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp); + *ierr = MPI_Comm_connect( port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp); if(*ierr == MPI_SUCCESS) { *newcomm = tmp->add_f(); } @@ -202,7 +216,7 @@ void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){ void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){ MPI_Comm tmp; - *ierr = MPI_Comm_accept( port_name, *reinterpret_cast(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp); + *ierr = MPI_Comm_accept( port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp); if(*ierr == MPI_SUCCESS) { *newcomm = tmp->add_f(); } @@ -211,7 +225,7 @@ void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*ne void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm, int* array_of_errcodes, int* ierr){ MPI_Comm tmp; - *ierr = MPI_Comm_spawn( command, nullptr, *maxprocs, *reinterpret_cast(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, + *ierr = MPI_Comm_spawn( command, &argv, *maxprocs, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, array_of_errcodes); if(*ierr == MPI_SUCCESS) { *intercomm = tmp->add_f();