Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to handle getopt internal global variable
authordegomme <augustin.degomme@unibas.ch>
Tue, 3 Apr 2018 12:53:11 +0000 (14:53 +0200)
committerdegomme <augustin.degomme@unibas.ch>
Tue, 3 Apr 2018 12:55:51 +0000 (14:55 +0200)
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
include/smpi/smpi_helpers.h [new file with mode: 0644]
src/smpi/include/smpi_process.hpp
src/smpi/internals/smpi_bench.cpp
src/smpi/internals/smpi_process.cpp
src/smpi/smpicc.in
tools/cmake/DefinePackages.cmake

index 34b5e54..2bad6bd 100644 (file)
@@ -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<std::pair<size_t, size_t>> shift_and_frame_private_blocks(const std:
                                                                       size_t offset, size_t buff_size);
 std::vector<std::pair<size_t, size_t>> merge_private_blocks(std::vector<std::pair<size_t, size_t>> src,
                                                             std::vector<std::pair<size_t, size_t>> dst);
+                                                            
+                                                            
 #endif
 
 #endif
diff --git a/include/smpi/smpi_helpers.h b/include/smpi/smpi_helpers.h
new file mode 100644 (file)
index 0000000..6f279ce
--- /dev/null
@@ -0,0 +1,16 @@
+#include <sys/time.h> /* 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)
index c6c07a7..af8fa3d 100644 (file)
@@ -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);
 };
 
 
index 423fe6e..7f1ae4a 100644 (file)
@@ -12,6 +12,7 @@
 #include "src/mc/mc_replay.hpp"
 #include "src/simix/ActorImpl.hpp"
 #include "xbt/config.hpp"
+#include "getopt.h"
 
 #include <unordered_map>
 
@@ -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;
+}
index b4f2dd8..31fd2b9 100644 (file)
@@ -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;
+}
+
 }
 }
index fcafe88..abcd52f 100755 (executable)
@@ -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"
index c592888..bbceacb 100644 (file)
@@ -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