From 0b86d2dae6ca1d3b4beed12f4dfc08611f7f1c4b Mon Sep 17 00:00:00 2001 From: degomme Date: Tue, 3 Apr 2018 14:53:11 +0200 Subject: [PATCH 1/1] try to handle getopt internal global variable add a wrapper that will set the value at each call to get the one from the correct process This will probably not work for BSD implementations (they have optreset as well that might be needed). --- include/smpi/smpi.h | 6 ++++++ include/smpi/smpi_helpers.h | 16 ++++++++++++++++ src/smpi/include/smpi_process.hpp | 3 +++ src/smpi/internals/smpi_bench.cpp | 18 ++++++++++++++++++ src/smpi/internals/smpi_process.cpp | 7 +++++++ src/smpi/smpicc.in | 2 ++ tools/cmake/DefinePackages.cmake | 1 + 7 files changed, 53 insertions(+) create mode 100644 include/smpi/smpi_helpers.h diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 34b5e547eb..2bad6bd56d 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -994,6 +994,10 @@ XBT_PUBLIC void SMPI_finalize(); XBT_PUBLIC void smpi_register_static(void* arg, void_f_pvoid_t free_fn); XBT_PUBLIC void smpi_free_static(); + +struct option; +XBT_PUBLIC int smpi_getopt_long (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index); +XBT_PUBLIC int smpi_getopt (int argc, char *const *argv, const char *options); #define SMPI_VARINIT_GLOBAL(name,type) \ type *name = NULL; \ static void __attribute__((constructor)) __preinit_##name(void) { \ @@ -1064,6 +1068,8 @@ std::vector> shift_and_frame_private_blocks(const std: size_t offset, size_t buff_size); std::vector> merge_private_blocks(std::vector> src, std::vector> dst); + + #endif #endif diff --git a/include/smpi/smpi_helpers.h b/include/smpi/smpi_helpers.h new file mode 100644 index 0000000000..6f279ceee4 --- /dev/null +++ b/include/smpi/smpi_helpers.h @@ -0,0 +1,16 @@ +#include /* Load it before the define next line to not mess with the system headers */ + +#define sleep(x) smpi_sleep(x) +#define usleep(x) smpi_usleep(x) +#define gettimeofday(x, y) smpi_gettimeofday(x, NULL) +#if _POSIX_TIMERS > 0 +#define nanosleep(x, y) smpi_nanosleep(x, y) +#define clock_gettime(x, y) smpi_clock_gettime(x, y) +#endif +#if SIMGRID_HAVE_MC +#undef assert +#define assert(x) MC_assert(x) +#endif + +#define getopt(x,y,z) smpi_getopt(x,y,z) +#define getopt_long(x,y,z,a,b) smpi_getopt_long(x,y,z,a,b) diff --git a/src/smpi/include/smpi_process.hpp b/src/smpi/include/smpi_process.hpp index c6c07a74a3..af8fa3d158 100644 --- a/src/smpi/include/smpi_process.hpp +++ b/src/smpi/include/smpi_process.hpp @@ -36,6 +36,7 @@ class Process { smpi_trace_call_location_t trace_call_loc_; simgrid::s4u::ActorPtr process_ = nullptr; smpi_privatization_region_t privatized_region_; + int optind=0; /*for getopt replacement */ #if HAVE_PAPI /** Contains hardware data as read by PAPI **/ int papi_event_set_; @@ -75,6 +76,8 @@ class Process { msg_bar_t finalization_barrier(); static void init(int *argc, char ***argv); simgrid::s4u::ActorPtr process(); + int get_optind(); + void set_optind(int optind); }; diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index 423fe6e11f..7f1ae4a6cc 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -12,6 +12,7 @@ #include "src/mc/mc_replay.hpp" #include "src/simix/ActorImpl.hpp" #include "xbt/config.hpp" +#include "getopt.h" #include @@ -430,3 +431,20 @@ void smpi_bench_destroy() { samples.clear(); } + +int smpi_getopt_long (int argc, char *const *argv, const char *options, + const struct option * long_options, int *opt_index) +{ + optind = smpi_process()->get_optind(); + int ret = getopt_long (argc, argv, options, long_options, opt_index); + smpi_process()->set_optind(optind); + return ret; +} + +int smpi_getopt (int argc, char *const *argv, const char *options) +{ + optind = smpi_process()->get_optind(); + int ret = getopt (argc, argv, options); + smpi_process()->set_optind(optind); + return ret; +} diff --git a/src/smpi/internals/smpi_process.cpp b/src/smpi/internals/smpi_process.cpp index b4f2dd887d..31fd2b93ba 100644 --- a/src/smpi/internals/smpi_process.cpp +++ b/src/smpi/internals/smpi_process.cpp @@ -276,5 +276,12 @@ void Process::init(int *argc, char ***argv){ "Please use MPI_Init(&argc, &argv) as usual instead."); } +int Process::get_optind(){ + return optind; +} +void Process::set_optind(int new_optind){ + optind=new_optind; +} + } } diff --git a/src/smpi/smpicc.in b/src/smpi/smpicc.in index fcafe88eee..abcd52f6a2 100755 --- a/src/smpi/smpicc.in +++ b/src/smpi/smpicc.in @@ -22,6 +22,7 @@ if [ "x@WIN32@" = "x1" ]; then list_add CFLAGS "-include" "@includedir@/smpi/smpi_main.h" list_add LINKARGS "@libdir@\libsimgrid.dll" elif [ "x@APPLE@" = "x1" ]; then + list_add CFLAGS "-include" "@includedir@/smpi/smpi_helpers.h" list_add CFLAGS "-fpic" if [ "x${SMPI_PRETEND_CC}" = "x" ]; then list_add LINKARGS "-shared" @@ -30,6 +31,7 @@ elif [ "x@APPLE@" = "x1" ]; then fi list_add LINKARGS "-lsimgrid" "-Wl,-undefined,error" else + list_add CFLAGS "-include" "@includedir@/smpi/smpi_helpers.h" list_add CFLAGS "-fpic" if [ "x${SMPI_PRETEND_CC}" = "x" ]; then list_add LINKARGS "-shared" diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index c5928885db..bbceacb482 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -716,6 +716,7 @@ set(headers_to_install include/smpi/mpi.h include/smpi/smpi.h include/smpi/smpi_main.h + include/smpi/smpi_helpers.h include/smpi/smpi_extended_traces.h include/smpi/smpi_extended_traces_fortran.h include/smpi/forward.hpp -- 2.20.1