From 41846d24bea977a7c671c77cab7c3a2105f65a6c Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 22 Apr 2017 09:32:32 +0200 Subject: [PATCH] try to avoid that others fall into the trap where I was yesterday not quite sucessfull: the failure occures before main :( --- include/simgrid/s4u/engine.hpp | 3 +++ src/s4u/s4u_engine.cpp | 5 +++++ src/smpi/smpi_mpi.cpp | 12 ++++++------ src/smpi/smpi_pmpi.cpp | 5 ++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/simgrid/s4u/engine.hpp b/include/simgrid/s4u/engine.hpp index 2a9d3053bd..ea09d3e690 100644 --- a/include/simgrid/s4u/engine.hpp +++ b/include/simgrid/s4u/engine.hpp @@ -102,6 +102,9 @@ public: }); } + /** Returns whether SimGrid was initialized yet -- mostly for internal use */ + static bool isInitialized(); + simgrid::kernel::EngineImpl* pimpl; private: diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index 5734a1f680..3d98c545a2 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -153,5 +153,10 @@ void Engine::netpointUnregister(simgrid::kernel::routing::NetPoint* point) delete point; }); } + +bool Engine::isInitialized() +{ + return Engine::instance_ != nullptr; } } +} // namespace diff --git a/src/smpi/smpi_mpi.cpp b/src/smpi/smpi_mpi.cpp index 35ae81d2b1..aa987f6979 100644 --- a/src/smpi/smpi_mpi.cpp +++ b/src/smpi/smpi_mpi.cpp @@ -1,5 +1,4 @@ -/* Copyright ,(c) 2007-2017. The SimGrid Team. - * All rights reserved.*/ +/* Copyright ,(c) 2007-2017. 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. */ @@ -9,10 +8,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi, smpi, "Logging specific to SMPI ,(mpi)"); -#define NOT_YET_IMPLEMENTED { \ -XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__); \ -return MPI_SUCCESS; \ -} +#define NOT_YET_IMPLEMENTED \ + { \ + XBT_WARN("Not yet implemented : %s. Please contact the SimGrid team if support is needed", __FUNCTION__); \ + return MPI_SUCCESS; \ + } #define WRAPPED_PMPI_CALL(type,name,args,args2) \ type name args { \ diff --git a/src/smpi/smpi_pmpi.cpp b/src/smpi/smpi_pmpi.cpp index 25b581fde0..7a11da6fe8 100644 --- a/src/smpi/smpi_pmpi.cpp +++ b/src/smpi/smpi_pmpi.cpp @@ -3,6 +3,7 @@ /* 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 #include #include "private.h" @@ -24,7 +25,9 @@ extern "C" { // Obviously, the C MPI interface should use the C linkage int PMPI_Init(int *argc, char ***argv) { - // PMPI_Init is call only one time by only by SMPI process + xbt_assert(simgrid::s4u::Engine::isInitialized(), + "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){ -- 2.20.1