From: Martin Quinson Date: Fri, 4 Jan 2019 23:45:27 +0000 (+0100) Subject: Further code simplifications now that the Thread context backend is always available X-Git-Tag: v3_22~688 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f482ec0290d8271beaea0e2657b33c29a66ad420?hp=e68fd495117dc356fc39a080335eb5f0328dc038 Further code simplifications now that the Thread context backend is always available --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 27cca00c15..8abfa35fb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/kernel/context/ContextBoost.cpp b/src/kernel/context/ContextBoost.cpp index ea98813fd4..e1fff9327a 100644 --- a/src/kernel/context/ContextBoost.cpp +++ b/src/kernel/context/ContextBoost.cpp @@ -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 code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process) { -#if HAVE_THREAD_CONTEXTS if (parallel_) return this->new_context(std::move(code), cleanup_func, process); -#endif - return this->new_context(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* ParallelBoostContext::parmap_; std::atomic 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() { diff --git a/src/kernel/context/ContextBoost.hpp b/src/kernel/context/ContextBoost.hpp index 7b3a58e8e2..fb60021fd9 100644 --- a/src/kernel/context/ContextBoost.hpp +++ b/src/kernel/context/ContextBoost.hpp @@ -80,7 +80,6 @@ private: static unsigned long process_index_; }; -#if HAVE_THREAD_CONTEXTS class ParallelBoostContext : public BoostContext { public: ParallelBoostContext(std::function code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process) @@ -100,7 +99,6 @@ private: static std::atomic threads_working_; static thread_local uintptr_t worker_id_; }; -#endif class BoostContextFactory : public ContextFactory { public: diff --git a/src/kernel/context/ContextRaw.cpp b/src/kernel/context/ContextRaw.cpp index a4b8db5846..302927489b 100644 --- a/src/kernel/context/ContextRaw.cpp +++ b/src/kernel/context/ContextRaw.cpp @@ -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 code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process) { -#if HAVE_THREAD_CONTEXTS if (parallel_) return this->new_context(std::move(code), cleanup_func, process); -#endif - return this->new_context(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* ParallelRawContext::parmap_; std::atomic 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."); diff --git a/src/kernel/context/ContextRaw.hpp b/src/kernel/context/ContextRaw.hpp index 6d79a94e6f..e1ececd741 100644 --- a/src/kernel/context/ContextRaw.hpp +++ b/src/kernel/context/ContextRaw.hpp @@ -65,7 +65,6 @@ private: static unsigned long process_index_; }; -#if HAVE_THREAD_CONTEXTS class ParallelRawContext : public RawContext { public: ParallelRawContext(std::function code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process) @@ -85,7 +84,6 @@ private: static std::atomic threads_working_; static uintptr_t thread_local worker_id_; }; -#endif class RawContextFactory : public ContextFactory { public: diff --git a/src/kernel/context/ContextUnix.cpp b/src/kernel/context/ContextUnix.cpp index e41289507d..e31ba6aedf 100644 --- a/src/kernel/context/ContextUnix.cpp +++ b/src/kernel/context/ContextUnix.cpp @@ -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 code, void_pfn_smxprocess_t cleanup, smx_actor_t process) { -#if HAVE_THREAD_CONTEXTS if (parallel_) return new_context(std::move(code), cleanup, process); else -#endif return new_context(std::move(code), cleanup, process); } @@ -66,11 +57,9 @@ Context* UContextFactory::create_context(std::function 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* ParallelUContext::parmap_; std::atomic 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"); diff --git a/src/kernel/context/ContextUnix.hpp b/src/kernel/context/ContextUnix.hpp index 60775dfde9..71f8999249 100644 --- a/src/kernel/context/ContextUnix.hpp +++ b/src/kernel/context/ContextUnix.hpp @@ -67,7 +67,6 @@ private: static unsigned long process_index_; }; -#if HAVE_THREAD_CONTEXTS class ParallelUContext : public UContext { public: ParallelUContext(std::function code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process) @@ -87,7 +86,6 @@ private: static std::atomic threads_working_; static thread_local uintptr_t worker_id_; }; -#endif class UContextFactory : public ContextFactory { public: diff --git a/src/simix/smx_context.cpp b/src/simix/smx_context.cpp index 6f32bb18b6..8326069dee 100644 --- a/src/simix/smx_context.cpp +++ b/src/simix/smx_context.cpp @@ -40,9 +40,7 @@ static std::pairHAVE_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() diff --git a/tools/cmake/MakeLib.cmake b/tools/cmake/MakeLib.cmake index 7a81adec2f..b1ea27d06b 100644 --- a/tools/cmake/MakeLib.cmake +++ b/tools/cmake/MakeLib.cmake @@ -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() diff --git a/tools/cmake/MakeLibWin.cmake b/tools/cmake/MakeLibWin.cmake index 596f09c28f..e7c5783059 100644 --- a/tools/cmake/MakeLibWin.cmake +++ b/tools/cmake/MakeLibWin.cmake @@ -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() diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index 0f2c6a0051..aac23e812c 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -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) diff --git a/tools/cmake/src/internal_config.h.in b/tools/cmake/src/internal_config.h.in index 97c598b090..15c3db5c0e 100644 --- a/tools/cmake/src/internal_config.h.in +++ b/tools/cmake/src/internal_config.h.in @@ -38,12 +38,9 @@ /* 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