Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[smpi args cleanup] internal changes for clean-up
[simgrid.git] / src / smpi / bindings / smpi_pmpi.cpp
index c92f7e4..76da5cd 100644 (file)
@@ -8,9 +8,9 @@
 #include "simgrid/s4u/Host.hpp"
 #include "smpi_comm.hpp"
 #include "smpi_datatype_derived.hpp"
-#include "smpi_process.hpp"
 #include "smpi_status.hpp"
 #include "src/simix/ActorImpl.hpp"
+#include "src/smpi/include/smpi_actor.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi, "Logging specific to SMPI (pmpi)");
 
@@ -19,7 +19,8 @@ void TRACE_smpi_set_category(const char *category)
 {
   //need to end bench otherwise categories for execution tasks are wrong
   smpi_bench_end();
-  TRACE_internal_smpi_set_category (category);
+  if (category != nullptr)
+    TRACE_internal_smpi_set_category(category);
   //begin bench after changing process's category
   smpi_bench_begin();
 }
@@ -30,19 +31,20 @@ int PMPI_Init(int *argc, char ***argv)
 {
   xbt_assert(simgrid::s4u::Engine::is_initialized(),
              "Your MPI program was not properly initialized. The easiest is to use smpirun to start it.");
-  // PMPI_Init is called only once per SMPI process
-  int already_init;
-  MPI_Initialized(&already_init);
-  if(already_init == 0){
-    simgrid::smpi::Process::init(argc, argv);
-    smpi_process()->mark_as_initialized();
-    int rank = simgrid::s4u::this_actor::get_pid();
-    TRACE_smpi_init(rank);
-    TRACE_smpi_comm_in(rank, __func__, new simgrid::instr::NoOpTIData("init"));
-    TRACE_smpi_comm_out(rank);
-    TRACE_smpi_computing_init(rank);
-    TRACE_smpi_sleeping_init(rank);
+
+  // Init is called only once per SMPI process
+  if (not smpi_process()->initializing()){
+    simgrid::smpi::ActorExt::init();
+  }
+  if (not smpi_process()->initialized()){
+    int rank_traced = simgrid::s4u::this_actor::get_pid();
+    TRACE_smpi_init(rank_traced);
+    TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::NoOpTIData("init"));
+    TRACE_smpi_comm_out(rank_traced);
+    TRACE_smpi_computing_init(rank_traced);
+    TRACE_smpi_sleeping_init(rank_traced);
     smpi_bench_begin();
+    smpi_process()->mark_as_initialized();
   }
 
   smpi_mpi_init();
@@ -53,13 +55,13 @@ int PMPI_Init(int *argc, char ***argv)
 int PMPI_Finalize()
 {
   smpi_bench_end();
-  int rank = simgrid::s4u::this_actor::get_pid();
-  TRACE_smpi_comm_in(rank, __func__, new simgrid::instr::NoOpTIData("finalize"));
+  int rank_traced = simgrid::s4u::this_actor::get_pid();
+  TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::NoOpTIData("finalize"));
 
   smpi_process()->finalize();
 
-  TRACE_smpi_comm_out(rank);
-  TRACE_smpi_finalize(rank);
+  TRACE_smpi_comm_out(rank_traced);
+  TRACE_smpi_finalize(rank_traced);
   return MPI_SUCCESS;
 }
 
@@ -209,40 +211,21 @@ int PMPI_Error_class(int errorcode, int* errorclass) {
 }
 
 int PMPI_Error_string(int errorcode, char* string, int* resultlen){
-//TODO: put this somewhere else ?
-  const char* smpi_error_strings[] {
-    "MPI_SUCCESS","MPI_ERR_COMM","MPI_ERR_ARG","MPI_ERR_TYPE","MPI_ERR_REQUEST",
-    "MPI_ERR_INTERN","MPI_ERR_COUNT","MPI_ERR_RANK","MPI_ERR_TAG",
-    "MPI_ERR_TRUNCATE","MPI_ERR_GROUP","MPI_ERR_OP","MPI_ERR_OTHER",
-    "MPI_ERR_IN_STATUS","MPI_ERR_PENDING","MPI_ERR_BUFFER","MPI_ERR_NAME",
-    "MPI_ERR_DIMS","MPI_ERR_TOPOLOGY","MPI_ERR_NO_MEM","MPI_ERR_WIN",
-    "MPI_ERR_INFO_VALUE","MPI_ERR_INFO_KEY","MPI_ERR_INFO_NOKEY","MPI_ERR_ROOT",
-    "MPI_ERR_UNKNOWN","MPI_ERR_KEYVAL","MPI_ERR_BASE","MPI_ERR_SPAWN",
-    "MPI_ERR_PORT","MPI_ERR_SERVICE","MPI_ERR_SIZE","MPI_ERR_DISP","MPI_ERR_INFO",
-    "MPI_ERR_LOCKTYPE","MPI_ERR_ASSERT","MPI_RMA_CONFLICT","MPI_RMA_SYNC",
-    "MPI_ERR_FILE","MPI_ERR_NOT_SAME","MPI_ERR_AMODE","MPI_ERR_UNSUPPORTED_DATAREP",
-    "MPI_ERR_UNSUPPORTED_OPERATION","MPI_ERR_NO_SUCH_FILE","MPI_ERR_FILE_EXISTS",
-    "MPI_ERR_BAD_FILE","MPI_ERR_ACCESS","MPI_ERR_NO_SPACE","MPI_ERR_QUOTA",
-    "MPI_ERR_READ_ONLY","MPI_ERR_FILE_IN_USE","MPI_ERR_DUP_DATAREP",
-    "MPI_ERR_CONVERSION","MPI_ERR_IO","MPI_ERR_RMA_ATTACH","MPI_ERR_RMA_CONFLICT",
-    "MPI_ERR_RMA_RANGE","MPI_ERR_RMA_SHARED","MPI_ERR_RMA_SYNC",
-    "MPI_ERR_RMA_FLAVOR","MPI_T_ERR_CANNOT_INIT","MPI_T_ERR_NOT_INITIALIZED",
-    "MPI_T_ERR_MEMORY","MPI_T_ERR_INVALID_INDEX","MPI_T_ERR_INVALID_ITEM",
-    "MPI_T_ERR_INVALID_SESSION","MPI_T_ERR_INVALID_HANDLE",
-    "MPI_T_ERR_OUT_OF_HANDLES","MPI_T_ERR_OUT_OF_SESSIONS",
-    "MPI_T_ERR_CVAR_SET_NOT_NOW","MPI_T_ERR_CVAR_SET_NEVER",
-    "MPI_T_ERR_PVAR_NO_WRITE","MPI_T_ERR_PVAR_NO_STARTSTOP",
-    "MPI_T_ERR_PVAR_NO_ATOMIC"
-  };
-
-  *resultlen = strlen(smpi_error_strings[errorcode]);
-  strncpy(string, smpi_error_strings[errorcode], *resultlen);
-  return MPI_SUCCESS;  
+  if (errorcode<0 || string ==nullptr){
+    return MPI_ERR_ARG;
+  } else {
+    static const char *smpi_error_string[] = {
+      FOREACH_ERROR(GENERATE_STRING)
+    };
+    *resultlen = strlen(smpi_error_string[errorcode]);
+    strncpy(string, smpi_error_string[errorcode], *resultlen);
+    return MPI_SUCCESS;  
+  }
 }
 
 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
-  smpi_copy_fn _copy_fn={copy_fn,nullptr,nullptr};
-  smpi_delete_fn _delete_fn={delete_fn,nullptr,nullptr};
+  smpi_copy_fn _copy_fn={copy_fn,nullptr,nullptr,nullptr,nullptr,nullptr};
+  smpi_delete_fn _delete_fn={delete_fn,nullptr,nullptr,nullptr,nullptr,nullptr};
   return simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
 }