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)
: 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();
}
// 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_;
BoostContext::swap(worker_context, this);
}
-#endif
XBT_PRIVATE ContextFactory* boost_factory()
{
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)
static std::atomic<uintptr_t> threads_working_;
static thread_local uintptr_t worker_id_;
};
-#endif
class BoostContextFactory : public ContextFactory {
public:
{
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();
}
// 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 */
RawContext::swap(worker_context, this);
}
-#endif
-
ContextFactory* raw_factory()
{
XBT_VERB("Using raw contexts. Because the glibc is just not good enough for us.");
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)
static std::atomic<uintptr_t> threads_working_;
static uintptr_t thread_local worker_id_;
};
-#endif
class RawContextFactory : public ContextFactory {
public:
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);
}
*/
void UContextFactory::run_all()
{
-#if HAVE_THREAD_CONTEXTS
if (parallel_)
ParallelUContext::run_all();
else
-#endif
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 */
// initial soul of the current working thread
}
-#endif
-
XBT_PRIVATE ContextFactory* sysv_factory()
{
XBT_VERB("Activating SYSV context factory");
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)
static std::atomic<uintptr_t> threads_working_;
static thread_local uintptr_t worker_id_;
};
-#endif
class UContextFactory : public ContextFactory {
public:
#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");
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;
}
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
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
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)
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()
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()
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()
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))
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)
/* 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