Skip to content
Snippets Groups Projects
Commit 8deb53cb authored by Carlos Mastalli's avatar Carlos Mastalli
Browse files

[cmake] Added option in cmake for setting the number of threads

parent bf33b1e9
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,7 @@ ENDIF() ...@@ -37,7 +37,7 @@ ENDIF()
SET(CXX_DISABLE_WERROR True) SET(CXX_DISABLE_WERROR True)
# Create different building options # Create different building options
OPTION(ENABLE_VECTORIZATION "Enable vectorization and futhers processor-related optimizations" ON) OPTION(ENABLE_VECTORIZATION "Enable vectorization and futhers processor-related optimizations" OFF)
OPTION(BUILD_PYTHON_INTERFACE "Build the python binding" ON) OPTION(BUILD_PYTHON_INTERFACE "Build the python binding" ON)
OPTION(BUILD_UNIT_TESTS "Build the unitary tests" ON) OPTION(BUILD_UNIT_TESTS "Build the unitary tests" ON)
OPTION(BUILD_BENCHMARK "Build the benchmark" ON) OPTION(BUILD_BENCHMARK "Build the benchmark" ON)
...@@ -58,16 +58,25 @@ ADD_OPTIONAL_DEPENDENCY("quadprog") ...@@ -58,16 +58,25 @@ ADD_OPTIONAL_DEPENDENCY("quadprog")
ADD_OPTIONAL_DEPENDENCY("scipy") ADD_OPTIONAL_DEPENDENCY("scipy")
OPTION(BUILD_WITH_MULTITHREADING "Build the library with the OpenMP support (required OpenMP)" ON) OPTION(BUILD_WITH_MULTITHREADS "Build the library with the OpenMP support (required OpenMP)" OFF)
IF(BUILD_WITH_MULTITHREADS)
SET(BUILD_WITH_NTHREADS "4" CACHE STRING "Number of threads")
string(REGEX MATCH "^[0-9]+$" BUILD_WITH_NTHREADS ${BUILD_WITH_NTHREADS})
IF(NOT BUILD_WITH_NTHREADS MATCHES "^[0-9]+$")
SET(BUILD_WITH_NTHREADS 4)
MESSAGE("Warning: the number of threads have to be an interger value, set to ${BUILD_WITH_NTHREADS}")
ENDIF()
ENDIF()
#OpenMP # Add OpenMP
if(BUILD_WITH_MULTITHREADING) if(BUILD_WITH_MULTITHREADS)
find_package(OpenMP) find_package(OpenMP)
ENDIF() ENDIF()
if(OPENMP_FOUND) if(OPENMP_FOUND)
SET(CMAKE_CXX_FLAGS "-fopenmp") SET(CMAKE_CXX_FLAGS "-fopenmp")
ADD_DEFINITIONS(-DWITH_MULTITHREADING) ADD_DEFINITIONS(-DWITH_MULTITHREADING)
LIST(APPEND CFLAGS_DEPENDENCIES "-DWITH_MULTITHREADING") ADD_DEFINITIONS(-DNTHREADS=${BUILD_WITH_NTHREADS})
LIST(APPEND CFLAGS_DEPENDENCIES "-DWITH_MULTITHREADING", "DNTHREADS")
ENDIF() ENDIF()
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
int main() { int main() {
bool CALLBACKS = false; bool CALLBACKS = false;
unsigned int N = 200; // number of nodes unsigned int N = 200; // number of nodes
unsigned int T = 10; // number of trials unsigned int T = 5e3; // number of trials
unsigned int MAXITER = 1; unsigned int MAXITER = 1;
using namespace crocoddyl; using namespace crocoddyl;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <iostream> #include <iostream>
#ifdef WITH_MULTITHREADING #ifdef WITH_MULTITHREADING
#include <omp.h> #include <omp.h>
#define NUM_THREADS 4 #define NUM_THREADS NTHREADS
#endif // WITH_MULTITHREADING #endif // WITH_MULTITHREADING
namespace crocoddyl { namespace crocoddyl {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment