diff --git a/compiler/lib/Runtime/CMakeLists.txt b/compiler/lib/Runtime/CMakeLists.txt index 74b173b12..4ad011298 100644 --- a/compiler/lib/Runtime/CMakeLists.txt +++ b/compiler/lib/Runtime/CMakeLists.txt @@ -10,6 +10,10 @@ if(CONCRETELANG_PARALLEL_EXECUTION_ENABLED) PRIVATE HPX::hpx HPX::iostreams_component ) + set_source_files_properties( + DFRuntime.cpp + PROPERTIES COMPILE_FLAGS "-fopenmp" + ) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") diff --git a/compiler/lib/Runtime/DFRuntime.cpp b/compiler/lib/Runtime/DFRuntime.cpp index f3287525d..56c6035c3 100644 --- a/compiler/lib/Runtime/DFRuntime.cpp +++ b/compiler/lib/Runtime/DFRuntime.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "concretelang/Runtime/DFRuntime.hpp" #include "concretelang/Runtime/distributed_generic_task_server.hpp" @@ -788,12 +789,25 @@ static inline void _dfr_stop_impl() { static inline void _dfr_start_impl(int argc, char *argv[]) { mlir::concretelang::dfr::dl_handle = dlopen(nullptr, RTLD_NOW); + + // If OpenMP is to be used, we need to force its initialization + // before thread binding occurs. Otherwise OMP threads will be bound + // to the core of the thread initializing the OMP runtime. + if (mlir::concretelang::dfr::_dfr_use_omp()) { +#pragma omp parallel shared(mlir::concretelang::dfr::use_omp_p) + { +#pragma omp critical + mlir::concretelang::dfr::use_omp_p = true; + } + } + if (argc == 0) { int nCores, nOMPThreads, nHPXThreads; std::string hpxThreadNum; std::vector parameters; parameters.push_back(const_cast("__dummy_dfr_HPX_program_name__")); + parameters.push_back(const_cast("--hpx:print-bind")); hwloc_topology_t topology; hwloc_topology_init(&topology);