Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please sonar
[simgrid.git] / src / smpi / bindings / smpi_pmpi_comm.cpp
index 8916ec9..9cefd11 100644 (file)
@@ -7,6 +7,8 @@
 
 #include "private.hpp"
 #include "smpi_comm.hpp"
+#include "smpi_info.hpp"
+#include "smpi_errhandler.hpp"
 #include "src/smpi/include/smpi_actor.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
@@ -15,93 +17,84 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
 
 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
 {
-  if (comm == MPI_COMM_NULL) {
-    return MPI_ERR_COMM;
-  } else if (rank == nullptr) {
-    return MPI_ERR_ARG;
-  } else {
-    *rank = comm->rank();
-    return MPI_SUCCESS;
-  }
+  CHECK_COMM(1)
+  CHECK_NULL(2, MPI_ERR_ARG, rank)
+  *rank = comm->rank();
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_size(MPI_Comm comm, int *size)
 {
-  if (comm == MPI_COMM_NULL) {
-    return MPI_ERR_COMM;
-  } else if (size == nullptr) {
-    return MPI_ERR_ARG;
-  } else {
-    *size = comm->size();
-    return MPI_SUCCESS;
-  }
+  CHECK_COMM(1)
+  CHECK_NULL(2, MPI_ERR_ARG, size)
+  *size = comm->size();
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
 {
-  if (comm == MPI_COMM_NULL)  {
-    return MPI_ERR_COMM;
-  } else if (name == nullptr || len == nullptr)  {
-    return MPI_ERR_ARG;
-  } else {
-    comm->get_name(name, len);
-    return MPI_SUCCESS;
-  }
+  CHECK_COMM(1)
+  CHECK_NULL(2, MPI_ERR_ARG, name)
+  CHECK_NULL(3, MPI_ERR_ARG, len)
+  comm->get_name(name, len);
+  return MPI_SUCCESS;
+}
+
+int PMPI_Comm_set_name (MPI_Comm comm, const char* name)
+{
+  CHECK_COMM(1)
+  CHECK_NULL(2, MPI_ERR_ARG, name)
+  comm->set_name(name);
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
 {
-  if (comm == MPI_COMM_NULL) {
-    return MPI_ERR_COMM;
-  } else if (group == nullptr) {
-    return MPI_ERR_ARG;
-  } else {
-    *group = comm->group();
-    if (*group != MPI_COMM_WORLD->group() && *group != MPI_GROUP_NULL && *group != MPI_GROUP_EMPTY)
-      (*group)->ref();
-    return MPI_SUCCESS;
-  }
+  CHECK_COMM(1)
+  CHECK_NULL(2, MPI_ERR_ARG, group)
+  *group = comm->group();
+  if (*group != MPI_COMM_WORLD->group() && *group != MPI_GROUP_NULL && *group != MPI_GROUP_EMPTY)
+    (*group)->ref();
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
 {
-  if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
-    return MPI_ERR_COMM;
-  } else if (result == nullptr) {
-    return MPI_ERR_ARG;
+  CHECK_COMM2(1, comm1)
+  CHECK_COMM2(2, comm2)
+  CHECK_NULL(3, MPI_ERR_ARG, result)
+  if (comm1 == comm2) {       /* Same communicators means same groups */
+    *result = MPI_IDENT;
   } else {
-    if (comm1 == comm2) {       /* Same communicators means same groups */
-      *result = MPI_IDENT;
-    } else {
-      *result = comm1->group()->compare(comm2->group());
-      if (*result == MPI_IDENT) {
-        *result = MPI_CONGRUENT;
-      }
+    *result = comm1->group()->compare(comm2->group());
+    if (*result == MPI_IDENT) {
+      *result = MPI_CONGRUENT;
     }
-    return MPI_SUCCESS;
   }
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
 {
-  if (comm == MPI_COMM_NULL) {
-    return MPI_ERR_COMM;
-  } else if (newcomm == nullptr) {
-    return MPI_ERR_ARG;
-  } else {
-    return comm->dup(newcomm);
-  }
+  CHECK_COMM(1)
+  CHECK_NULL(2, MPI_ERR_ARG, newcomm)
+  return comm->dup(newcomm);
+}
+
+int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm)
+{
+  CHECK_COMM(1)
+  CHECK_NULL(2, MPI_ERR_ARG, newcomm)
+  comm->dup_with_info(info, newcomm);
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
 {
-  if (comm == MPI_COMM_NULL) {
-    return MPI_ERR_COMM;
-  } else if (group == MPI_GROUP_NULL) {
-    return MPI_ERR_GROUP;
-  } else if (newcomm == nullptr) {
-    return MPI_ERR_ARG;
-  } else if (group->rank(simgrid::s4u::this_actor::get_pid()) == MPI_UNDEFINED) {
+  CHECK_COMM(1)
+  CHECK_GROUP(2, group)
+  CHECK_NULL(3, MPI_ERR_ARG, newcomm)
+  if (group->rank(simgrid::s4u::this_actor::get_pid()) == MPI_UNDEFINED) {
     *newcomm= MPI_COMM_NULL;
     return MPI_SUCCESS;
   }else{
@@ -113,89 +106,63 @@ int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
 
 int PMPI_Comm_free(MPI_Comm * comm)
 {
-  if (comm == nullptr) {
-    return MPI_ERR_ARG;
-  } else if (*comm == MPI_COMM_NULL) {
-    return MPI_ERR_COMM;
-  } else {
-    simgrid::smpi::Comm::destroy(*comm);
-    *comm = MPI_COMM_NULL;
-    return MPI_SUCCESS;
-  }
+  CHECK_NULL(1, MPI_ERR_ARG, comm)
+  CHECK_COMM2(1, *comm)
+  simgrid::smpi::Comm::destroy(*comm);
+  *comm = MPI_COMM_NULL;
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_disconnect(MPI_Comm * comm)
 {
   /* TODO: wait until all communication in comm are done */
-  if (comm == nullptr) {
-    return MPI_ERR_ARG;
-  } else if (*comm == MPI_COMM_NULL) {
-    return MPI_ERR_COMM;
-  } else {
-    simgrid::smpi::Comm::destroy(*comm);
-    *comm = MPI_COMM_NULL;
-    return MPI_SUCCESS;
-  }
+  CHECK_NULL(1, MPI_ERR_ARG, comm)
+  CHECK_COMM2(1, *comm)
+  simgrid::smpi::Comm::destroy(*comm);
+  *comm = MPI_COMM_NULL;
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
 {
-  int retval = 0;
+  CHECK_NULL(4, MPI_ERR_ARG, comm_out)
+  CHECK_COMM2(1, comm)
   smpi_bench_end();
-
-  if (comm_out == nullptr) {
-    retval = MPI_ERR_ARG;
-  } else if (comm == MPI_COMM_NULL) {
-    retval = MPI_ERR_COMM;
-  } else {
-    *comm_out = comm->split(color, key);
-    retval = MPI_SUCCESS;
-  }
+  *comm_out = comm->split(color, key);
   smpi_bench_begin();
-
-  return retval;
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm)
 {
-  int retval = 0;
+  CHECK_COMM(1)
+  CHECK_NULL(5, MPI_ERR_ARG, newcomm)
   smpi_bench_end();
-
-  if (newcomm == nullptr) {
-    retval = MPI_ERR_ARG;
-  } else if (comm == MPI_COMM_NULL) {
-    retval = MPI_ERR_COMM;
-  } else {
-    *newcomm = comm->split_type(split_type, key, info);
-    retval = MPI_SUCCESS;
-  }
+  *newcomm = comm->split_type(split_type, key, info);
   smpi_bench_begin();
-
-  return retval;
+  return MPI_SUCCESS;
 }
 
 int PMPI_Comm_create_group(MPI_Comm comm, MPI_Group group, int, MPI_Comm* comm_out)
 {
-  int retval = 0;
+  CHECK_COMM(1)
+  CHECK_GROUP(2, group)
+  CHECK_NULL(5, MPI_ERR_ARG, comm_out)
   smpi_bench_end();
-
-  if (comm_out == nullptr) {
-    retval = MPI_ERR_ARG;
-  } else if (comm == MPI_COMM_NULL) {
-    retval = MPI_ERR_COMM;
-  } else {
-    retval = MPI_Comm_create(comm, group, comm_out);
-  }
+  int retval = MPI_Comm_create(comm, group, comm_out);
   smpi_bench_begin();
-
   return retval;
 }
 
 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
+  if(comm==-1)
+    return MPI_COMM_NULL;
   return static_cast<MPI_Comm>(simgrid::smpi::Comm::f2c(comm));
 }
 
 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
+  if(comm==MPI_COMM_NULL)
+    return -1;
   return comm->c2f();
 }
 
@@ -209,6 +176,21 @@ int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
   return PMPI_Attr_put(comm, comm_keyval, attribute_val);
 }
 
+int PMPI_Comm_get_info(MPI_Comm comm, MPI_Info* info)
+{
+  CHECK_COMM(1)
+  CHECK_NULL(2, MPI_ERR_ARG, info)
+  *info = comm->info();
+  return MPI_SUCCESS;
+}
+
+int PMPI_Comm_set_info(MPI_Comm  comm, MPI_Info info)
+{
+  CHECK_COMM(1)
+  comm->set_info(info);
+  return MPI_SUCCESS;
+}
+
 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
 {
   return PMPI_Attr_delete(comm, comm_keyval);
@@ -225,11 +207,10 @@ int PMPI_Comm_free_keyval(int* keyval) {
 }
 
 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
+  CHECK_COMM(1)
   if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
        ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
     return MPI_ERR_ARG;
-  else if (comm==MPI_COMM_NULL)
-    return MPI_ERR_COMM;
   else
     return comm->attr_delete<simgrid::smpi::Comm>(keyval);
 }
@@ -239,11 +220,11 @@ int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
   static int zero = 0;
   static int tag_ub = INT_MAX;
   static int last_used_code = MPI_ERR_LASTCODE;
+  static int universe_size;
 
-  if (comm==MPI_COMM_NULL){
-    *flag = 0;
-    return MPI_ERR_COMM;
-  }
+  CHECK_NULL(4, MPI_ERR_ARG, flag)
+  *flag = 0;
+  CHECK_COMM(1)
 
   switch (keyval) {
   case MPI_HOST:
@@ -254,7 +235,8 @@ int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
     return MPI_SUCCESS;
   case MPI_UNIVERSE_SIZE:
     *flag = 1;
-    *static_cast<int**>(attr_value) = &smpi_universe_size;
+    universe_size                   = smpi_get_universe_size();
+    *static_cast<int**>(attr_value) = &universe_size;
     return MPI_SUCCESS;
   case MPI_LASTUSEDCODE:
     *flag = 1;
@@ -274,11 +256,52 @@ int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
 }
 
 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
+  CHECK_COMM(1)
   if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
        ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
     return MPI_ERR_ARG;
-  else if (comm==MPI_COMM_NULL)
-    return MPI_ERR_COMM;
   else
-  return comm->attr_put<simgrid::smpi::Comm>(keyval, attr_value);
+    return comm->attr_put<simgrid::smpi::Comm>(keyval, attr_value);
+}
+
+int PMPI_Errhandler_free(MPI_Errhandler* errhandler){
+  CHECK_NULL(1, MPI_ERR_ARG, errhandler)
+  simgrid::smpi::Errhandler::unref(*errhandler);
+  return MPI_SUCCESS;
+}
+
+int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler){
+  CHECK_NULL(2, MPI_ERR_ARG, errhandler)
+  *errhandler=new simgrid::smpi::Errhandler(function);
+  return MPI_SUCCESS;
+}
+
+int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler){
+  CHECK_COMM(1)
+  CHECK_NULL(1, MPI_ERR_ARG, errhandler)
+  *errhandler=comm->errhandler();
+  return MPI_SUCCESS;
+}
+
+int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler){
+  CHECK_COMM(1)
+  CHECK_NULL(1, MPI_ERR_ARG, errhandler)
+  comm->set_errhandler(errhandler);
+  return MPI_SUCCESS;
+}
+
+int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
+  CHECK_COMM(1)
+  comm->errhandler()->call(comm, errorcode);
+  return MPI_SUCCESS;
+}
+
+int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
+  return MPI_Errhandler_create(function, errhandler);
+}
+int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler){
+  return PMPI_Errhandler_get(comm, errhandler);
+}
+int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler){
+  return PMPI_Errhandler_set(comm, errhandler);
 }