Skip to content

7. Compiling DualSPHysics

alexbexe edited this page Apr 29, 2019 · 11 revisions

The code can be compiled for either CPU or CPU&GPU. Please note that both the C++ and CUDA version of the code contain the same features and options. Most of the source code is common to CPU and GPU, which allows the code to be run on workstations without a CUDA-enabled GPU, using only the CPU implementation.

To run DualSPHysics on a GPU using an executable, only an Nvidia CUDA-enabled GPU card is needed and the latest version of the GPU driver must be installed. However, to compile the source code, the GPU programming language CUDA and nvcc compiler must be installed on your computer. CUDA Toolkit X.X can be downloaded from Nvidia website http://developer.nvidia.com/cuda-toolkit-XX. CUDA versions from 4.0 till 9.2 have been tested.

Once the C++ compiler (for example gcc) and the CUDA compiler (nvcc) have been installed in your machine, you can download the relevant files from the directory DualSPHysics_v4.4/src.

Windows compilation

In DualSPHysics_v4.4/src there are also several folders:

  • source: contains all the source files;
  • lib/vs2013 & lib/vs2015: precompiled libraries for x64 (debug and release);
  • VS: includes the project file DualSPHysics4Re_vs2015.sln is provided to be opened with Visual Studio Community 2015.

Different configurations can be chosen for compilation: a) Release: for CPU and GPU b) ReleaseCPU: only for CPU

The result of the compilation is the executable DualSPHysics4.4_win64.exe or DualSPHysics4.4CPU_win64.exe created in DualSPHysics_v4.4/bin/windows. The GPU codes were compiled for compute capabilities sm30, sm35, sm50, sm52 sm61, sm70 and with CUDA v9.2.

The Visual Studio project is created including the libraries for OpenMP in the executable. To not include them, user can modify Props config -> C/C++ -> Language -> OpenMp and compile again. The use of OpenMP can be also deactivated by commenting the code line #define OMP_USE in **OmpDefs.h. **

In order to simulate more than 2000 and up to 65000 floating or solid objects, the user should activate or comment the code line #define CODE_SIZE4 in Types.h.

Linux compilation

As mentioned before, in DualSPHysics_v4.4/src there are also several folders:

  • source: contains all the source files and makefiles;
  • lib/linux_gcc: precompiled libraries for GCC;

Makefiles can be used to compile the code in linux:

  • make –f Makefile: full compilation just using make command
  • make –f Makefile_cpu: only for CPU

The result of the compilation is the executable DualSPHysics4.4_linux64 or DualSPHysics4.4CPU_linux64 created in DualSPHysics_v4.4/bin/linux.

To exclude the use of OpenMP you have to remove the flags –fopenmp and -lgomp in the Makefile and comment line #define OMP_USE in OmpDefs.h. In order to simulate more than 2000 and up to 65000 floating or solid objects, the user should activate or comment the code line #define CODE_SIZE4 in Types.h.

You can see the content of the makefile here

The user can modify the compilation options, the path of the CUDA toolkit directory, the GPU architecture. The GPU code is already compiled (bin) for compute capabilities sm30, sm35, sm50, sm52 sm61, sm70 and with CUDA v9.2.

Note that if you are using a GCC version greater than v4.9 you should set the "USE_GCC5" option to "YES" to avoid compatibility issues during the compilation.

Alternative building method via CMAKE

A new building method is supported since the version 4.0 of DualSPHysics using CMAKE (https://cmake.org/). CMAKE is a cross-platform and an independent building system for compilation. This software generates native building files (like makefiles or Visual Studio projects) for any platform. The location of dependencies and the needed flags are automatically determined.

Compile instructions for Microsoft Windows with Cmake: The building system needs the following dependencies:

  • Cmake version 2.8.10 or greater (https://cmake.org/download/)
  • Nvidia CUDA Toolkit version 4.0 or higher.
  • Visual Studio 2013 or 2015 version.
  • File “CMakeLists.txt” in src/source.

The folder build will be created in src/source. This folder will contain the building files so it can be safely removed in case of rebuilding, it can actually be placed anywhere where the user has writing permissions. Afterwards, open the Cmake application, a new window will appear:

Paste the Source folder path in the textbox labelled as Where is the source code, and paste the build folder path into the Where to build the binaries textbox. Once the paths are introduced, the Configure button should be pressed. A new dialog will appear asking for the compiler to be used in the project. Please, remember that only Visual Studio 2013 and Visual Studio 2015 for 64 bit are supported.

If the configuration succeeds, now press the Generate button. This will generate a Visual Studio project file into the build directory. In order to compile both CPU and GPU versions, just change configuration to Release and compile. If the user only wants to compile one version, one can choose one of the solutions DualSPHysics4.4CPU or DualSPHysics4.4 for CPU or GPU versions respectively, and compile it.

The user can freely customize the src/source/CMakeLists.txt file to add new source files or any other modifications. For more information about how to edit this file, please, refer to official Cmake documentation (https://cmake.org/documentation/).

Compile instructions for Linux with Cmake

The building system needs the following dependencies:

  • Cmake version 2.8.10 or higher.
  • Nvidia CUDA Toolkit version 4.0 or higher.
  • GNU G++ compiler 4.4 version or higher.
  • File “CMakeLists.txt” in src/source.

The folder build will be created in src/source. This folder will contain the building files so it can be safely removed in case of rebuilding; it can actually be placed anywhere where the user has writing permissions. To create this folder and run Cmake just type the commands in bold shown below:

> cd src/source
> mkdir build
> cd build
> cmake ..
-- The C compiler identification is GNU 6.4.1
-- The CXX compiler identification is GNU 6.4.1
-- Check for working C compiler: /usr/bin/gcc-6
-- Check for working C compiler: /usr/bin/gcc-6 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++-6
-- Check for working CXX compiler: /usr/bin/g++-6 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
Using cuda version >=9.1
Using libraries for gcc
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/DualSPHysics/src/source/build

The command cmake .. will search for a Cmake file (CMakeLists.txt) in the specified folder. As mentioned before, the user can freely customize this file to add new source files or any other modifications. For more information about how to edit this file, please, refer to Cmake official documentation (https://cmake.org/documentation/).

Once the cmake command runs without error, a Makefile can be found in the build folder. To build both CPU and GPU versions of DualSPHysics just type make. If the user only needs to build one of the executable files he can use the commands make DualSPHysics4.4CPU or make DualSPHysics4.4 for CPU and GPU versions respectively. In order to install the compiled binaries into the bin folder, the user can either copy the executable files or type the command make install.