-/* Copyright (c) 2010-2019. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2010-2020. 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.hpp"
#include "smpi_comm.hpp"
+#include "smpi_errhandler.hpp"
#include "smpi_info.hpp"
+#include <string>
+
extern "C" { // This should really use the C linkage to be usable from Fortran
void mpi_comm_rank_(int* comm, int* rank, int* ierr) {
void mpi_comm_create_(int* comm, int* group, int* newcomm, int* ierr) {
MPI_Comm tmp;
-
*ierr = MPI_Comm_create(simgrid::smpi::Comm::f2c(*comm),simgrid::smpi::Group::f2c(*group), &tmp);
if(*ierr == MPI_SUCCESS) {
*newcomm = tmp->add_f();
void mpi_comm_group_(int* comm, int* group_out, int* ierr) {
MPI_Group tmp;
-
*ierr = MPI_Comm_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
if(*ierr == MPI_SUCCESS) {
*group_out = tmp->c2f();
}
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);
+ auto* val = static_cast<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){
-
*ierr = MPI_Comm_delete_attr (simgrid::smpi::Comm::f2c(*comm), *comm_keyval);
}
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)
- for(int i = *len; i<MPI_MAX_OBJECT_NAME+1; i++)
- name[i]=' ';
+ for(int i = *len; i<MPI_MAX_OBJECT_NAME+1; i++)
+ name[i]=' ';
}
void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
-
*ierr = MPI_Comm_compare(simgrid::smpi::Comm::f2c(*comm1), simgrid::smpi::Comm::f2c(*comm2), result);
}
}
}
-void mpi_comm_set_errhandler_ (int* comm, void* errhandler, int* ierr) {
- *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(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<MPI_Errhandler*>(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) {
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);
+ std::string tname(name, count);
+ *ierr = MPI_Comm_set_name(simgrid::smpi::Comm::f2c(*comm), tname.c_str());
}
void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
}
}
-void mpi_comm_create_errhandler_ ( void *function, void *errhandler, int* ierr){
- *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), static_cast<MPI_Errhandler*>(errhandler));
+void mpi_comm_create_errhandler_ ( void *function, int *errhandler, int* ierr){
+ MPI_Errhandler tmp;
+ *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), &tmp);
+ if(*ierr==MPI_SUCCESS){
+ *errhandler = tmp->c2f();
+ }
}
void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){