diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a10760fb25858afa4fbbc412c6b31dac04a2a4a..d059c0aa3cbb6a0a20b753b9f023cc07722a736e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ include(ProjectSetup) include(Functions) include(ConanSetup) include(CompilerSetup) +include(JobPools) include(Find) include(CLCacheSetup) include(Dependencies) diff --git a/ProcessLib/CMakeLists.txt b/ProcessLib/CMakeLists.txt index e9d496842f9affba359948c2197ea0c85176721c..d2d2924e3a142f72688627ed57a2befbad0e194d 100644 --- a/ProcessLib/CMakeLists.txt +++ b/ProcessLib/CMakeLists.txt @@ -5,6 +5,9 @@ foreach(process ${_processes_list}) if(OGS_BUILD_PROCESS_${process}) add_subdirectory(${process}) target_link_libraries(Processes INTERFACE ${process}) + set_target_properties( + ${process} PROPERTIES JOB_POOL_COMPILE heavy_tasks + ) endif() endforeach() diff --git a/scripts/cmake/JobPools.cmake b/scripts/cmake/JobPools.cmake new file mode 100644 index 0000000000000000000000000000000000000000..e2d25e4d80e7c1fc4d7ef260b4ec8ba534d5a360 --- /dev/null +++ b/scripts/cmake/JobPools.cmake @@ -0,0 +1,27 @@ +# From https://www.youtube.com/watch?v=8y7UuAG3Z0g (minute 52) +cmake_host_system_information(RESULT _memfree QUERY AVAILABLE_PHYSICAL_MEMORY) +cmake_host_system_information(RESULT _cores QUERY NUMBER_OF_LOGICAL_CORES) +message( + STATUS "Number of (logical) cores: ${_cores}, Free memory: ${_memfree} MB" +) + +# Sets number of jobs between 1 and number of logical cores depending on the +# available memory. +function(setup_job_pool name mem_per_task) + math(EXPR res "${_memfree} / ${mem_per_task}") + if(res LESS 1) + set(res 1) + endif() + if(res GREATER ${_cores}) + set(res ${_cores}) + endif() + message(STATUS " Job pool ${name} using ${res} cores.") + set_property(GLOBAL APPEND PROPERTY JOB_POOLS ${name}=${res}) +endfunction() + +# Default job pool +setup_job_pool(light_tasks 800) # MB per task +set(CMAKE_JOB_POOL_COMPILE light_tasks) +set(CMAKE_JOB_POOL_LINK light_tasks) + +setup_job_pool(heavy_tasks 4000)