Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Further code simplifications now that the Thread context backend is always available
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 4 Jan 2019 23:45:27 +0000 (00:45 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 4 Jan 2019 23:45:27 +0000 (00:45 +0100)
13 files changed:
CMakeLists.txt
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextBoost.hpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextRaw.hpp
src/kernel/context/ContextUnix.cpp
src/kernel/context/ContextUnix.hpp
src/simix/smx_context.cpp
tools/cmake/DefinePackages.cmake
tools/cmake/MakeLib.cmake
tools/cmake/MakeLibWin.cmake
tools/cmake/Tests.cmake
tools/cmake/src/internal_config.h.in

index 27cca00..8abfa35 100644 (file)
@@ -404,10 +404,7 @@ else()
 endif()
 
 #--------------------------------------------------------------------------------------------------
-### Initialize of CONTEXT THREADS
-
-set(HAVE_THREAD_CONTEXTS 1)
-message(STATUS "Support for thread context factory ok.")
+### Check what context backends are available
 
 set(HAVE_UCONTEXT_CONTEXTS 0)
 if(NOT HAVE_UCONTEXT_H)
index ea98813..e1fff93 100644 (file)
@@ -20,41 +20,29 @@ BoostContextFactory::BoostContextFactory()
     : ContextFactory("BoostContextFactory"), parallel_(SIMIX_context_is_parallel())
 {
   BoostContext::set_maestro(nullptr);
-  if (parallel_) {
-#if HAVE_THREAD_CONTEXTS
+  if (parallel_)
     ParallelBoostContext::initialize();
-#else
-    xbt_die("No thread support for parallel context execution");
-#endif
-  }
 }
 
 BoostContextFactory::~BoostContextFactory()
 {
-#if HAVE_THREAD_CONTEXTS
   if (parallel_)
     ParallelBoostContext::finalize();
-#endif
 }
 
 smx_context_t BoostContextFactory::create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup_func,
                                                   smx_actor_t process)
 {
-#if HAVE_THREAD_CONTEXTS
   if (parallel_)
     return this->new_context<ParallelBoostContext>(std::move(code), cleanup_func, process);
-#endif
-
   return this->new_context<SerialBoostContext>(std::move(code), cleanup_func, process);
 }
 
 void BoostContextFactory::run_all()
 {
-#if HAVE_THREAD_CONTEXTS
   if (parallel_)
     ParallelBoostContext::run_all();
   else
-#endif
     SerialBoostContext::run_all();
 }
 
@@ -191,8 +179,6 @@ void SerialBoostContext::run_all()
 
 // ParallelBoostContext
 
-#if HAVE_THREAD_CONTEXTS
-
 simgrid::xbt::Parmap<smx_actor_t>* ParallelBoostContext::parmap_;
 std::atomic<uintptr_t> ParallelBoostContext::threads_working_;
 thread_local uintptr_t ParallelBoostContext::worker_id_;
@@ -252,7 +238,6 @@ void ParallelBoostContext::resume()
   BoostContext::swap(worker_context, this);
 }
 
-#endif
 
 XBT_PRIVATE ContextFactory* boost_factory()
 {
index 7b3a58e..fb60021 100644 (file)
@@ -80,7 +80,6 @@ private:
   static unsigned long process_index_;
 };
 
-#if HAVE_THREAD_CONTEXTS
 class ParallelBoostContext : public BoostContext {
 public:
   ParallelBoostContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
@@ -100,7 +99,6 @@ private:
   static std::atomic<uintptr_t> threads_working_;
   static thread_local uintptr_t worker_id_;
 };
-#endif
 
 class BoostContextFactory : public ContextFactory {
 public:
index a4b8db5..3029274 100644 (file)
@@ -190,41 +190,30 @@ RawContextFactory::RawContextFactory() : ContextFactory("RawContextFactory"), pa
 {
   RawContext::set_maestro(nullptr);
   if (parallel_) {
-#if HAVE_THREAD_CONTEXTS
     // TODO: choose dynamically when SIMIX_context_get_parallel_threshold() > 1
     ParallelRawContext::initialize();
-#else
-    xbt_die("You asked for a parallel execution, but you don't have any threads.");
-#endif
   }
 }
 
 RawContextFactory::~RawContextFactory()
 {
-#if HAVE_THREAD_CONTEXTS
   if (parallel_)
     ParallelRawContext::finalize();
-#endif
 }
 
 Context* RawContextFactory::create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup_func,
                                            smx_actor_t process)
 {
-#if HAVE_THREAD_CONTEXTS
   if (parallel_)
     return this->new_context<ParallelRawContext>(std::move(code), cleanup_func, process);
-#endif
-
   return this->new_context<SerialRawContext>(std::move(code), cleanup_func, process);
 }
 
 void RawContextFactory::run_all()
 {
-#if HAVE_THREAD_CONTEXTS
   if (parallel_)
     ParallelRawContext::run_all();
   else
-#endif
     SerialRawContext::run_all();
 }
 
@@ -329,8 +318,6 @@ void SerialRawContext::run_all()
 
 // ParallelRawContext
 
-#if HAVE_THREAD_CONTEXTS
-
 simgrid::xbt::Parmap<smx_actor_t>* ParallelRawContext::parmap_;
 std::atomic<uintptr_t> ParallelRawContext::threads_working_; /* number of threads that have started their work */
 uintptr_t thread_local ParallelRawContext::worker_id_;       /* thread-specific storage for the thread id */
@@ -394,8 +381,6 @@ void ParallelRawContext::resume()
   RawContext::swap(worker_context, this);
 }
 
-#endif
-
 ContextFactory* raw_factory()
 {
   XBT_VERB("Using raw contexts. Because the glibc is just not good enough for us.");
index 6d79a94..e1ececd 100644 (file)
@@ -65,7 +65,6 @@ private:
   static unsigned long process_index_;
 };
 
-#if HAVE_THREAD_CONTEXTS
 class ParallelRawContext : public RawContext {
 public:
   ParallelRawContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
@@ -85,7 +84,6 @@ private:
   static std::atomic<uintptr_t> threads_working_;
   static uintptr_t thread_local worker_id_;
 };
-#endif
 
 class RawContextFactory : public ContextFactory {
 public:
index e412895..e31ba6a 100644 (file)
@@ -33,30 +33,21 @@ namespace context {
 UContextFactory::UContextFactory() : ContextFactory("UContextFactory"), parallel_(SIMIX_context_is_parallel())
 {
   UContext::set_maestro(nullptr);
-  if (parallel_) {
-#if HAVE_THREAD_CONTEXTS
+  if (parallel_)
     ParallelUContext::initialize();
-#else
-    xbt_die("No thread support for parallel context execution");
-#endif
-  }
 }
 
 UContextFactory::~UContextFactory()
 {
-#if HAVE_THREAD_CONTEXTS
   if (parallel_)
     ParallelUContext::finalize();
-#endif
 }
 
 Context* UContextFactory::create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup, smx_actor_t process)
 {
-#if HAVE_THREAD_CONTEXTS
   if (parallel_)
     return new_context<ParallelUContext>(std::move(code), cleanup, process);
   else
-#endif
     return new_context<SerialUContext>(std::move(code), cleanup, process);
 }
 
@@ -66,11 +57,9 @@ Context* UContextFactory::create_context(std::function<void()> code, void_pfn_sm
  */
 void UContextFactory::run_all()
 {
-#if HAVE_THREAD_CONTEXTS
   if (parallel_)
     ParallelUContext::run_all();
   else
-#endif
     SerialUContext::run_all();
 }
 
@@ -202,8 +191,6 @@ void SerialUContext::run_all()
 
 // ParallelUContext
 
-#if HAVE_THREAD_CONTEXTS
-
 simgrid::xbt::Parmap<smx_actor_t>* ParallelUContext::parmap_;
 std::atomic<uintptr_t> ParallelUContext::threads_working_;         /* number of threads that have started their work */
 thread_local uintptr_t ParallelUContext::worker_id_;               /* thread-specific storage for the thread id */
@@ -295,8 +282,6 @@ void ParallelUContext::resume()
   // initial soul of the current working thread
 }
 
-#endif
-
 XBT_PRIVATE ContextFactory* sysv_factory()
 {
   XBT_VERB("Activating SYSV context factory");
index 60775df..71f8999 100644 (file)
@@ -67,7 +67,6 @@ private:
   static unsigned long process_index_;
 };
 
-#if HAVE_THREAD_CONTEXTS
 class ParallelUContext : public UContext {
 public:
   ParallelUContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
@@ -87,7 +86,6 @@ private:
   static std::atomic<uintptr_t> threads_working_;
   static thread_local uintptr_t worker_id_;
 };
-#endif
 
 class UContextFactory : public ContextFactory {
 public:
index 6f32bb1..8326069 100644 (file)
@@ -40,9 +40,7 @@ static std::pair<const char*, simgrid::kernel::context::ContextFactoryInitialize
 #if HAVE_BOOST_CONTEXTS
   { "boost", &simgrid::kernel::context::boost_factory },
 #endif
-#if HAVE_THREAD_CONTEXTS
   { "thread", &simgrid::kernel::context::thread_factory },
-#endif
 };
 
 static_assert(sizeof(context_factories) != 0, "No context factories are enabled for this build");
@@ -251,9 +249,6 @@ void SIMIX_context_set_nthreads(int nb_threads) {
     nb_threads = std::thread::hardware_concurrency();
     XBT_INFO("Auto-setting contexts/nthreads to %d", nb_threads);
   }
-#if !HAVE_THREAD_CONTEXTS
-  xbt_assert(nb_threads == 1, "Parallel runs are impossible when the pthreads are missing.");
-#endif
   smx_parallel_contexts = nb_threads;
 }
 
index b3bab2d..85040bb 100644 (file)
@@ -292,6 +292,7 @@ set(XBT_SRC
   src/xbt/xbt_main.cpp
   src/xbt/xbt_os_file.cpp
   src/xbt/xbt_os_synchro.cpp
+  src/xbt/xbt_os_thread.c
   src/xbt/xbt_os_time.c
   src/xbt/xbt_replay.cpp
   src/xbt/xbt_str.cpp
@@ -382,6 +383,8 @@ set(SIMIX_SRC
   src/kernel/context/Context.hpp
   src/kernel/context/ContextRaw.cpp
   src/kernel/context/ContextRaw.hpp
+  src/kernel/context/ContextThread.cpp
+  src/kernel/context/ContextThread.hpp
   src/simix/smx_deployment.cpp
   src/simix/smx_environment.cpp
   src/simix/smx_global.cpp
@@ -783,22 +786,6 @@ set(source_of_generated_headers
   include/smpi/mpif.h.in)
 
 ### depend of some variables setted upper
-# -->HAVE_THREAD_CONTEXTS HAVE_UCONTEXT_CONTEXTS
-if(${HAVE_THREAD_CONTEXTS}) #pthread
-  set(SURF_SRC   ${SURF_SRC}   src/kernel/context/ContextThread.cpp
-                               src/kernel/context/ContextThread.hpp )
-else() # NOT pthread
-  set(EXTRA_DIST ${EXTRA_DIST} src/kernel/context/ContextThread.cpp
-                               src/kernel/context/ContextThread.hpp )
-endif()
-
-if(${HAVE_THREAD_CONTEXTS}) #pthread
-  set(SURF_SRC    ${SURF_SRC}   src/xbt/xbt_os_thread.c)
-else() # NOT pthread
-  set(EXTRA_DIST  ${EXTRA_DIST} src/xbt/xbt_os_thread.c
-    )
-endif()
-
 if(${HAVE_UCONTEXT_CONTEXTS}) #ucontext
   set(SURF_SRC    ${SURF_SRC}   src/kernel/context/ContextUnix.hpp
                                 src/kernel/context/ContextUnix.cpp)
@@ -840,16 +827,6 @@ if(SIMGRID_HAVE_NS3)
   set(simgrid_sources  ${simgrid_sources}  ${NS3_SRC})
 endif()
 
-# WINDOWS
-if(WIN32)
-  set(simgrid_sources
-    ${simgrid_sources}
-    src/kernel/context/ContextThread.cpp
-    src/kernel/context/ContextThread.hpp
-    src/xbt/xbt_os_thread.c
-    )
-endif()
-
 if(SIMGRID_HAVE_LUA)
   set(simgrid_sources  ${simgrid_sources}  ${LUA_SRC})
 else()
index 7a81ade..b1ea27d 100644 (file)
@@ -50,7 +50,7 @@ if (HAVE_BOOST_CONTEXTS)
   set(SIMGRID_DEP "${SIMGRID_DEP} ${Boost_CONTEXT_LIBRARY}")
 endif()
 
-if(CMAKE_USE_PTHREADS_INIT AND ${HAVE_THREAD_CONTEXTS})
+if(CMAKE_USE_PTHREADS_INIT)
   set(SIMGRID_DEP "${SIMGRID_DEP} ${CMAKE_THREAD_LIBS_INIT}")
 endif()
 
index 596f09c..e7c5783 100644 (file)
@@ -16,9 +16,6 @@ else()
 
   set(SIMGRID_DEP "-lm")
 
-  if (HAVE_PTHREAD)
-    set(SIMGRID_DEP "${SIMGRID_DEP} -lpthread")
-  endif()
   if (HAVE_BOOST_CONTEXTS)
     set(SIMGRID_DEP "${SIMGRID_DEP} ${Boost_CONTEXT_LIBRARY}")
   endif()
index 0f2c6a0..aac23e8 100644 (file)
@@ -57,7 +57,7 @@ MACRO(ADD_TESH_FACTORIES NAME FACTORIES)
     LIST(REMOVE_AT ARGR 0)
   ENDFOREACH()
   FOREACH(FACTORY ${FACTORIES})
-    if ((${FACTORY} STREQUAL "thread" AND HAVE_THREAD_CONTEXTS) OR
+    if ((${FACTORY} STREQUAL "thread" ) OR # Always available, thanks to C++11 threads
         (${FACTORY} STREQUAL "boost" AND HAVE_BOOST_CONTEXTS) OR
         (${FACTORY} STREQUAL "raw" AND HAVE_RAW_CONTEXTS) OR
         (${FACTORY} STREQUAL "ucontext" AND HAVE_UCONTEXT_CONTEXTS))
@@ -90,7 +90,7 @@ IF(SIMGRID_HAVE_MC)
   ENDIF()
 ENDIF()
 
-IF(enable_smpi_MPICH3_testsuite AND SMPI_FORTRAN AND HAVE_THREAD_CONTEXTS)
+IF(enable_smpi_MPICH3_testsuite AND SMPI_FORTRAN)
   ADD_TEST(test-smpi-mpich3-thread-f77     ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/teshsuite/smpi/mpich3-test/f77/ ${PERL_EXECUTABLE} ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/runtests "-wrapper=${TESH_WRAPPER}" -mpiexec=${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun -srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/f77/ -tests=testlist -privatization=${HAVE_PRIVATIZATION} -execarg=--cfg=contexts/stack-size:8000 -execarg=--cfg=contexts/factory:thread -execarg=--cfg=smpi/privatization:${HAVE_PRIVATIZATION})
   SET_TESTS_PROPERTIES(test-smpi-mpich3-thread-f77 PROPERTIES PASS_REGULAR_EXPRESSION "tests passed!")
   ADD_TEST(test-smpi-mpich3-thread-f90     ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/teshsuite/smpi/mpich3-test/f90/ ${PERL_EXECUTABLE} ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/runtests "-wrapper=${TESH_WRAPPER}" -mpiexec=${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun -srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/f90/ -tests=testlist -privatization=${HAVE_PRIVATIZATION} -execarg=--cfg=smpi/privatization:${HAVE_PRIVATIZATION} -execarg=--cfg=contexts/factory:thread)
index 97c598b..15c3db5 100644 (file)
 /* The usable context factories */
 #cmakedefine01 HAVE_BOOST_CONTEXTS
 #cmakedefine01 HAVE_RAW_CONTEXTS
-#cmakedefine01 HAVE_THREAD_CONTEXTS
 #cmakedefine01 HAVE_UCONTEXT_CONTEXTS
 
 /* Variables for the thread contexts (and parallel mode of raw contexts) */
-/* Define to 1 if threads are usable . */
-#cmakedefine01 HAVE_PTHREAD
 /* Does not seems defined on Mac nor Windows */
 #cmakedefine01 HAVE_PTHREAD_SETAFFINITY