esa / pagmo2

A C++ platform to perform parallel computations of optimisation tasks (global and local) via the asynchronous generalized island model.
https://esa.github.io/pagmo2/
GNU General Public License v3.0
808 stars 160 forks source link

Documentation how to build Pagmo2 using local installed TBB, BOOST, Eigen (not system-wide) #464

Closed erwincoumans closed 3 years ago

erwincoumans commented 3 years ago

Nice project, thanks!

Instead of system-wide installation, some projects have local installed versions of Eigen, BOOST and TBB etc.

ROOT=$(pwd)
cd third_party/eigen
#Build Eigen locally
mkdir build_cmake
cd build_cmake
cmake -DCMAKE_CXX_FLAGS="/MP" -DCMAKE_DEBUG_POSTFIX="" -DINSTALL_LIBS=ON -DCMAKE_BUILD_TYPE=Release  -DCMAKE_INSTALL_PREFIX:PATH=local_install   ..
cmake  --build .  --target INSTALL  --config Release
#now Eigen install is in the local_install folder

cd $ROOT/third_party/oneTBB
#Build TBB locally
cmake -DCMAKE_INSTALL_PREFIX:PATH=local_install -DTBB_TEST=OFF ..
cmake  --build .  --target INSTALL  --config Release
#now TBB install (include/lib) is in the local_install directory

#Build BOOST locally
cd $ROOT/third_party/boost_1_69_0
bootstrap.bat
b2 install --prefix=local_install --toolset=msvc --build-type=complete --address-model=64 link=static  --with-thread   --with-serialization --with-test
#now BOOST installation (include, libs) are in the local directory.

Then you can tell cmake where to find the local installed versions:

git clone https://github.com/esa/pagmo2
cd pagmo2
mkdir build
cd build
cmake -DEigen3_DIR=$ROOT/third_party/eigen3/build_cmake/local_install   -DTBB_DIR=$ROOT/third_party/oneTBB/build_cmake/local_install -DBOOST_DIR=$ROOT/third_party/boost_1_69_0/local_install ..

Is your feature request related to a problem? Please describe. Can't build Pagmo2, it doesn't find Eigen, BOOST or (one)TBB

Describe the solution you'd like A clear and concise description how to tell cmake where to find local Eigen, TBB and Boost installations preferably using the common -D_DIR=location method (-DEigen_DIR=...), BOOST (-DBOOST_DIR=...), TBB (-DTBB_DIR=...)

(let's ignore about oneTBB versus TBB for now, it has its own issue)

erwincoumans commented 3 years ago

The cmake/pagmo2 'find' doesn't manage to find things. Deleting all the logic and replacing those hardcoded values works for me, including oneTBB

target_include_directories (pagmo  PUBLIC  ${CMAKE_CURRENT_LIST_DIR}/../boost_1_69_0)
target_include_directories (pagmo  PUBLIC  ${CMAKE_CURRENT_LIST_DIR}/../oneTBB/include)
target_link_directories (pagmo  PUBLIC  ${CMAKE_CURRENT_LIST_DIR}/../boost_1_69_0/lib)
target_link_directories (pagmo  PUBLIC  ${CMAKE_CURRENT_LIST_DIR}/../oneTBB/build/msvc_19.28_cxx_64_md_debug)
add_library (eigen INTERFACE)
add_library (Eigen3::Eigen ALIAS eigen)
#target_compile_definitions (eigen INTERFACE ${EIGEN_DEFINITIONS})
target_include_directories (eigen INTERFACE
   ${CMAKE_CURRENT_LIST_DIR}/../eigen3
)
set(Eigen3_FOUND TRUE)

Not a general solution of course.

bluescarni commented 3 years ago

Hi @erwincoumans

the general pattern that we adopt when dealing with local installations is to pass the -DCMAKE_PREFIX_PATH=... and -DCMAKE_INSTALL_PREFIX=... options when invoking CMake, and this usually works relatively well.

We are trying to eliminate custom-written CMake find scripts as much as possible in favour of proper config-file package support, but of course this requires that the libraries we depend on use CMake as a build system and that they adopt good practices:

https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html

I think that in pagmo 2.16.1 we are shipping custom find scripts only for TBB and IPOPT. We have some custom logic for Boost as well, but this is just a thin wrapper around CMake's own FindBoost.cmake. Once we move to oneTBB, I believe the only remaining custom find script will be IPOPT's, and that should use fairly standard CMake patterns (e.g., you should be able to pass in -DPAGMO_IPOPT_INCLUDE_DIR=... for a custom location of IPOPT's headers).

Of course, there could be bugs in our CMake scripts, so please feel free to open issues here if you find any.

erwincoumans commented 3 years ago

pagmo did find the Boost includes, but it didn't find the libraries in the libs folder. How can you point to the Boost library folder? (all possible versions of the libs are in there)

I can create a simple reproduction case with a script file that clones pagmo2, boost, eigen and oneTBB, see if we can make that work in a local folder?

bluescarni commented 3 years ago

pagmo did find the Boost includes, but it didn't find the libraries in the libs folder. How can you point to the Boost library folder? (all possible versions of the libs are in there)

My best guess is that CMake is trying to use Boost's own CMake scripts, which are known to cause issues at this time. Can you try passing the option -DBoost_NO_BOOST_CMAKE=ON when you invoke CMake and see if it makes a difference?

I can create a simple reproduction case with a script file that clones pagmo2, boost, eigen and oneTBB, see if we can make that work in a local folder?

This sounds similar to what we are already doing in the CI, where (in some builds) we install the dependencies via conda. In such a setup, CMake has to locate the dependencies in a non-standard prefix (i.e., not /usr nor /use/local). See here for an example:

https://github.com/esa/pagmo2/blob/master/tools/circleci_bionic_gcc7_coverage.sh

It's not 100% clear to me however what the acitvation of the conda environment means exactly in terms of environment variables and how this helps CMake.

in any case, feel free to share the script here, so we can try to understand what is going on.

erwincoumans commented 3 years ago

Yes, I had a quick look at conda, but there is too much complexity/magic happening in that system. Better to simply build Boost, oneTBB, Eigen and pagmo2 from source, explicitly, using cmake, and get that to work. I'll try to find time to share a script and hopefully we can sort it out. I will try using your suggestion, -DBoost_NO_BOOST_CMAKE=ON. Thanks!

It is kind of amazing, how much time is lost trying to tell the build systems where the include folder and .lib/.a file is...

erwincoumans commented 3 years ago

Finally got pagmo2 to compile with local installed versions, including the latest oneTBB

cmake -DPAGMO_WITH_EIGEN3=ON -DBoost_DIR:PATH=D:/dev/tds/pagmo2_example/third_party/boost/local/lib/cmake/Boost-1.76.0 -DEigen3_DIR:PATH=D:/dev/tds/pagmo2_example/third_party/eigen/build_cmake -DTBB_VERSION=2021.1.0 -DPAGMO_BUILD_STATIC_LIBRARY=ON ..

-DBoost_DIR:PATH=<...> and -DEigen3_DIR:PATH=<...> seems to work, pointing to the install cmake directory Explicitly providing the TBB_VERSION will skip the error on file on oneTBB -DPAGMO_BUILD_STATIC_LIBRARY=ON will prevent pagmo2 DLL and failing to find the tbb library. Leave it up to the user application to find the right onTBB library.

There are some padding warnings that are treated as errors. Disabling warnings as errors make it work (Removing /WX).

Severity    Code    Description Project File    Line    Suppression State
Error   C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Warning C4324   'tbb::detail::d1::task': structure was padded due to alignment specifier    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Error   C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\pagmo2\src\problems\cec2014.cpp   522 
Warning C4701   potentially uninitialized local variable 'sum2' used    pagmo   D:\dev\tds\pagmo2_example\third_party\pagmo2\src\problems\cec2014.cpp   522 
Warning C4701   potentially uninitialized local variable 'xx' used  pagmo   D:\dev\tds\pagmo2_example\third_party\pagmo2\src\problems\cec2014.cpp   1324    
Error   C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Warning C4324   'tbb::detail::d1::task': structure was padded due to alignment specifier    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Error   C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Warning C4324   'tbb::detail::d1::task': structure was padded due to alignment specifier    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Error   C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Warning C4324   'tbb::detail::d1::task': structure was padded due to alignment specifier    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
bluescarni commented 3 years ago
Severity  Code    Description Project File    Line    Suppression State
Error C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Warning   C4324   'tbb::detail::d1::task': structure was padded due to alignment specifier    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Error C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\pagmo2\src\problems\cec2014.cpp   522 
Warning   C4701   potentially uninitialized local variable 'sum2' used    pagmo   D:\dev\tds\pagmo2_example\third_party\pagmo2\src\problems\cec2014.cpp   522 
Warning   C4701   potentially uninitialized local variable 'xx' used  pagmo   D:\dev\tds\pagmo2_example\third_party\pagmo2\src\problems\cec2014.cpp   1324    
Error C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Warning   C4324   'tbb::detail::d1::task': structure was padded due to alignment specifier    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Error C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Warning   C4324   'tbb::detail::d1::task': structure was padded due to alignment specifier    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Error C2220   the following warning is treated as an error    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 
Warning   C4324   'tbb::detail::d1::task': structure was padded due to alignment specifier    pagmo   D:\dev\tds\pagmo2_example\third_party\oneTBB\build_cmake\local_install\include\oneapi\tbb\detail\_task.h    233 

Thanks for reporting these, I'll make sure to add pragmas to ignore these warnings in the TBB headers.

Unfortunately it's hard for us to test debug builds on Windows because of the incompatibilities on that platform between debug and release runtimes.