diff --git a/compiler/CMakeLists.txt b/compiler/CMakeLists.txt index 46cd15469..3d5202090 100644 --- a/compiler/CMakeLists.txt +++ b/compiler/CMakeLists.txt @@ -83,7 +83,10 @@ if(CONCRETELANG_PARALLEL_EXECUTION_ENABLED) find_package(HPX REQUIRED CONFIG) include_directories(SYSTEM ${HPX_INCLUDE_DIRS}) list(APPEND CMAKE_MODULE_PATH "${HPX_CMAKE_DIR}") - add_compile_options(-DCONCRETELANG_PARALLEL_EXECUTION_ENABLED) + add_compile_options( + -DCONCRETELANG_PARALLEL_EXECUTION_ENABLED + -DHPX_DEFAULT_CONFIG_FILE="${PROJECT_SOURCE_DIR}/hpx.ini" + ) else() message(STATUS "ConcreteLang parallel execution disabled.") diff --git a/compiler/hpx.ini b/compiler/hpx.ini new file mode 100644 index 000000000..5427fe985 --- /dev/null +++ b/compiler/hpx.ini @@ -0,0 +1,27 @@ +[hpx] +location = ${HPX_LOCATION:$[system.prefix]} +component_path = $[hpx.location]/lib/hpx:$[system.executable_prefix]/lib/hpx:$[system.executable_prefix]/../lib/hpx +master_ini_path = $[hpx.location]/share/hpx-:$[system.executable_prefix]/share/hpx-:$[system.executable_prefix]/../share/hpx- +ini_path = $[hpx.master_ini_path]/ini +os_threads = 1 +localities = 1 +program_name = +cmd_line = +lock_detection = ${HPX_LOCK_DETECTION:0} +throw_on_held_lock = ${HPX_THROW_ON_HELD_LOCK:1} +minimal_deadlock_detection = +spinlock_deadlock_detection = +spinlock_deadlock_detection_limit = ${HPX_SPINLOCK_DEADLOCK_DETECTION_LIMIT:1000000} +max_background_threads = ${HPX_MAX_BACKGROUND_THREADS:$[hpx.os_threads]} +max_idle_loop_count = ${HPX_MAX_IDLE_LOOP_COUNT:} +max_busy_loop_count = ${HPX_MAX_BUSY_LOOP_COUNT:} +max_idle_backoff_time = ${HPX_MAX_IDLE_BACKOFF_TIME:} +exception_verbosity = ${HPX_EXCEPTION_VERBOSITY:1} +default_stack_size = 0x20000000 + +[hpx.stacks] +small_size = 0x8000000 +medium_size = 0x10000000 +large_size = 0x20000000 +huge_size = 0x40000000 +use_guard_pages = ${HPX_THREAD_GUARD_PAGE:3} diff --git a/compiler/lib/Runtime/DFRuntime.cpp b/compiler/lib/Runtime/DFRuntime.cpp index 4de2aa769..ccba5368c 100644 --- a/compiler/lib/Runtime/DFRuntime.cpp +++ b/compiler/lib/Runtime/DFRuntime.cpp @@ -791,12 +791,21 @@ static inline void _dfr_start_impl(int argc, char *argv[]) { if (nCores < 1) nCores = 1; + // We do not directly handle this, but we should take into account + // the choices made by the OpenMP runtime if we would be mixing + // loop & dataflow parallelism. char *env = getenv("OMP_NUM_THREADS"); if (env != nullptr) nOMPThreads = strtoul(env, NULL, 10); else nOMPThreads = nCores; + // Unless specified, we will consider that within each node loop + // parallelism is the priority, so we would allocate either + // ncores/OMP_NUM_THREADS or ncores-OMP_NUM_THREADS+1. Both make + // sense depending on whether we have very regular computation or + // not - the latter being more conservative in that we will + // exploit all cores, but we may oversubscribe. env = getenv("DFR_NUM_THREADS"); if (env != nullptr) nHPXThreads = strtoul(env, NULL, 10); @@ -805,7 +814,16 @@ static inline void _dfr_start_impl(int argc, char *argv[]) { if (nHPXThreads < 1) nHPXThreads = 1; + // If the user does not provide their own config file, one is by + // default located at the root of the concrete-compiler directory. env = getenv("HPX_CONFIG_FILE"); + // If no file is provided, try and check that the default is + // available - otherwise use a basic default configuration. +#ifdef HPX_DEFAULT_CONFIG_FILE + if (env == nullptr) + if (access(HPX_DEFAULT_CONFIG_FILE, F_OK) == 0) + env = const_cast(HPX_DEFAULT_CONFIG_FILE); +#endif if (env != nullptr) { int _argc = 3; char *_argv[3] = {const_cast("__dummy_dfr_HPX_program_name__"), @@ -813,6 +831,11 @@ static inline void _dfr_start_impl(int argc, char *argv[]) { const_cast(env)}; hpx::start(nullptr, _argc, _argv); } else { + // Last resort configuration in case no config file could be + // identified, provide some default values that make (some) + // sense for homomorphic computations (stacks need to reflect + // the size of ciphertexts rather than simple cleartext + // scalars). std::string numHPXThreads = std::to_string(nHPXThreads); int _argc = 7; char *_argv[7] = {