From a3f765ce3cffa1174d7122e16221f645bb574975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Thu, 3 Jul 2025 10:41:16 +0200 Subject: [PATCH] Fix compilation errors and enhance Makefile --- Makefile | 14 ++++++++++++-- src/CMakeLists.txt | 8 ++++---- src/common/Utils.h | 6 +++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 045f767..67e2d88 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,13 @@ f_release = build_Release f_debug = build_Debug app_targets = b_best b_list b_main b_manage b_grid b_results test_targets = unit_tests_platform +# Set the number of parallel jobs to the number of available processors minus 7 +CPUS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null \ + || nproc --all 2>/dev/null \ + || sysctl -n hw.ncpu) + +# --- Your desired job count: CPUs – 7, but never less than 1 -------------- +JOBS := $(shell n=$(CPUS); [ $${n} -gt 7 ] && echo $$((n-7)) || echo 1) define ClearTests @for t in $(test_targets); do \ @@ -25,6 +32,8 @@ define build_target @if [ -d $(2) ]; then rm -fr $(2); fi @conan install . --build=missing -of $(2) -s build_type=$(1) @cmake -S . -B $(2) -DCMAKE_TOOLCHAIN_FILE=$(2)/build/$(1)/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$(1) -D$(3) + @echo ">>> Will build using $(JOBS) parallel jobs" + echo ">>> Done" endef define compile_target @@ -34,14 +43,15 @@ define compile_target else \ target=""; \ fi - @cmake --build $(2) --config $(1) --parallel $(target) + @cmake --build $(2) --config $(1) --parallel $(JOBS) $(target) + @echo ">>> Done" endef init: ## Initialize the project installing dependencies @echo ">>> Installing dependencies with Conan" @conan install . --output-folder=build --build=missing -s build_type=Release @conan install . --output-folder=build_debug --build=missing -s build_type=Debug - @echo ">>> Done"; + @echo ">>> Done" clean: ## Clean the project @echo ">>> Cleaning the project..." diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4941624..c631371 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,7 @@ add_executable( experimental_clfs/DecisionTree.cpp experimental_clfs/AdaBoost.cpp ) -target_link_libraries(b_best Boost::boost "${PyClassifiers}" bayesnet::bayesnet argparse::argparse fimdlp::fimdlp ${Python3_LIBRARIES} torch::torch Boost::python Boost::numpy "${XLSXWRITER_LIB}") +target_link_libraries(b_best Boost::boost "${PyClassifiers}" bayesnet::bayesnet argparse::argparse fimdlp::fimdlp ${Python3_LIBRARIES} torch::torch Boost::python Boost::numpy libxlsxwriter::libxlsxwriter) # b_grid set(grid_sources GridSearch.cpp GridData.cpp GridExperiment.cpp GridBase.cpp ) @@ -49,7 +49,7 @@ add_executable(b_list commands/b_list.cpp experimental_clfs/DecisionTree.cpp experimental_clfs/AdaBoost.cpp ) -target_link_libraries(b_list "${PyClassifiers}" bayesnet::bayesnet argparse::argparse fimdlp::fimdlp ${Python3_LIBRARIES} torch::torch Boost::python Boost::numpy "${XLSXWRITER_LIB}") +target_link_libraries(b_list "${PyClassifiers}" bayesnet::bayesnet argparse::argparse fimdlp::fimdlp ${Python3_LIBRARIES} torch::torch Boost::python Boost::numpy libxlsxwriter::libxlsxwriter) # b_main set(main_sources Experiment.cpp Models.cpp HyperParameters.cpp Scores.cpp ArgumentsExperiment.cpp) @@ -76,8 +76,8 @@ add_executable( results/Result.cpp results/ResultsDataset.cpp results/ResultsDatasetConsole.cpp main/Scores.cpp ) -target_link_libraries(b_manage torch::torch "${XLSXWRITER_LIB}" fimdlp::fimdlp bayesnet::bayesnet argparse::argparse) +target_link_libraries(b_manage torch::torch libxlsxwriter::libxlsxwriter fimdlp::fimdlp bayesnet::bayesnet argparse::argparse) # b_results add_executable(b_results commands/b_results.cpp) -target_link_libraries(b_results torch::torch "${XLSXWRITER_LIB}" fimdlp::fimdlp bayesnet::bayesnet argparse::argparse) +target_link_libraries(b_results torch::torch libxlsxwriter::libxlsxwriter fimdlp::fimdlp bayesnet::bayesnet argparse::argparse) diff --git a/src/common/Utils.h b/src/common/Utils.h index e20541e..70e5c5d 100644 --- a/src/common/Utils.h +++ b/src/common/Utils.h @@ -7,8 +7,12 @@ #include #include #include +#include +#include +#include +#include -extern char **environ; +extern char** environ; namespace platform { static std::string trim(const std::string& str)