-
Notifications
You must be signed in to change notification settings - Fork 247
Linux Build
In this section we are going to go through the process of compiling a basic version of Kratos Multiphysics under linux environments. Specifically, we explain how to compile in the current Ubuntu LTS (16.04 at this moment), with the latest checked libraries. A basic knowledge of Linux is assumed ( execute commands, create directories, etc...).
Please notice that this guide is introductory and many of the steps and software used here can be customized. The only hard restriction is to use a C++11 compatible compiler.
- Objectives:
- Install git
- Get Kratos Multiphysics source code
The first thing you will need is the Kratos Multiphysics source code. To download the code you will have to use a git. You can install the default git by using this command:
sudo apt-get install git
Once git is installed you can fetch the code by using these commands:
git clone https://github.com/KratosMultiphysics/Kratos Kratos
- Objectives:
- Get Python3-dev
- Get G++
- Get Fortran compiler
- Get LIBBLAS and LIBLAPACK
You will need a series of packages with some kratos dependencies. The command below will install all the packages needed. It will allow you to compile with python2 or python3 so you will be able to chose later ( we recommend python3 )
sudo apt-get install python-dev python3-dev gcc g++ gfortran libblas-dev liblapack-dev
- Objectives:
- Download Boost
The next step will consist in downloading Boost. Kratos Multiphysics needs Boost libraries to support some of its functions ans you can found them here: http://www.boost.org/users/download/.
We recommend you to use boost 1.65 or newer but any version from 1.59 or greater should work.
It's very important to add the correct path to the boost library in the configure.sh by setting the variable -DBOOST_ROOT. You will see an example in the configure section.
- Objectives:
- Install CMake
CMake is the tool used to compile kratos. To install it, the first option is to execute the following command. Please ensure that you '''use CMake 3.4 or higher''':
sudo apt-get install cmake
- Objectives:
- Configure Kratos for the first time compilation
In order to compile kratos for the first time you will need to configure the project. First, navigate to your kratos/cmake_build folder and make a copy of the template file:
cp example_configure.sh.do_not_touch configure.sh
Then, open configure.sh with any text editor and modify the lines that tell cmake where some components are located. You will need to provide at least '''BOOST_ROOT''', '''PYTHON_LIBRARY''' and '''PYTHON_INCLUDE_DIR'''.
Kratos has moved to C++11 recently, Please mind to add the "-std=c++11" to your compiler of choice. If you follow the example below, it is already present ( notice the flag in CMAKE_CXX_FLAGS, highlighted in bold)
For example, in ubuntu it will look something like:
cmake .. \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DCMAKE_INSTALL_RPATH="/home/example/kratos/libs" \
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -msse3" \
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -msse3 -std=c++11" \
-DBOOST_ROOT="~/compiled_libraries/boost_1_59_0" \
-DPYTHON_LIBRARY="/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5m.so" \
-DPYTHON_INCLUDE_DIR="/usr/include/python3.5" \
-DMESHING_APPLICATION=ON \
-DEXTERNAL_SOLVERS_APPLICATION=ON \
// More options ( do not include this line )
Note that the \
must be the last character in the line. Even an space after it will cause an error! (and the returned message is completely misleading, so be careful with this!!)
Notice that you can also turn ON/OFF parts of the code according to your necessities:
-DSTRUCTURAL_APPLICATION=ON/OFF
\
therefore MUST NOT be followed by any whitespace in the same line as this would prevent the cmake from running the lines below
- Objectives:
- Compile kratos.
If you followed all the steps correctly, compiling kratos should be as easy as executing the configure script:
sh configure.sh
Please, notice that kratos is big and the compilation process can easily take 1 or 2 hours, depending on which applications are being compiled. A typical compilation process with the default configuration takes approximately 45 minutes with a i7 / 8GB Ram computer.
- Objectives:
- Tell Linux how to execute kratos
Once Kratos is compiled, you will have to tell the OS where to find the libraries. You can do that by executing these commands. Notice that '''you have to put the same path as in the section "Configure"'''
echo "export PYTHONPATH=$PYTHONPATH:/path/to/my/kratos/installation" >> $HOME/.bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/my/kratos/installation/libs" >> $HOME/.bashrc
If you have enabled the embedded python option -DINSTALL_EMBEDDED_PYTHON=ON, you can also add
echo "export PATH=$PATH:/path/to/my/kratos/installation" >> $HOME/.bashrc
In order to have the "runkratos" available as a regular command.
Now each time you open a terminal these commands will be executed and the paths set automatically. If you don't want to reset your terminal the first time, just execute:
source ~/.bashrc
- Objectives:
- Tests kratos
To to tests the compilation, you can execute a simple python script containing this line:
from KratosMultiphysics import *
We strongly recommend you to run kratos scripts with the "runkratos" binary that will be generated inside your Kratos installation folder. You can also run them by using python (if you have compiled with python version 2.x.x), or python3 (if you have compiled with python version 3.x.x)
- runkratos test.py
- python test.py
- python3 test.py
If everething was ok you will see this message:
| / |
' / __| _` | __| _ \ __|
. \ | ( | | ( |\__ \
_|\_\_| \__,_|\__|\___/ ____/
Multi-Physics 3.3.11016
In this section we provide will try to provide solutions to the most common problems and issues that may appear during the compilation process
Make sure that LD_LIBRARY_PATH
and PYTHONPATH
are pointing to your kratos folder.
To make sure that the variables are set correctly, you can always print their value from the terminal by typing:
echo $LD_LIBRARY_PATH
echo $PYTHONPATH
echo $PATH
Some shell interpreters have issues with the separator token. If environment variables above listed are correctly set, try to remove the ":" if kratos is the only path there.
# This may cause problem
echo $PYTHONPATH
:path/to/kratos
# Should be
export PYTHONPATH=path/to/kratos
echo $PYTHONPATH
path/to/kratos
This errors appear if the version of python used to compile boost is not the same as the one used by Kratos.
There are several causes that may be causing this. Pleas try the following:
The most provable reason for this error to happend is a missmatch between the python versions used by Kratos and Boost. Please, double check you have the same version of python in the projet-config.jam (boost) and configure.sh (Kratos) files.
If the error remains, please check that CMake version is 3.0.2 or newer. If it is not, it will be unable to load python 3.4. To solve the error please upgrade to CMake 3.0.2.
It has been observed that compiling with IDE's ( QTCreator, Netbeans, ...) sometimes causes this error as well. If you are experiencing this problem, try to modify the configure.sh script and replace '''cmake''' by the absolute path of CMake 3.0.2:
/path/to/correct/cmake .. \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
...
If for some reason you have to use an older version of CMake you can manually add support for python 3.4 by adding the version to these files:
/usr/share/cmake-2.8/Modules/FindPythonLibs.cmake (line 41)
/usr/share/cmake-2.8/Modules/FindPythonInterp.cmake (line 36)
Please add the version at the begining of the list:
SET(_PYTHON1_VERSIONS 1.6 1.5)
SET(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
SET(_PYTHON3_VERSIONS 3.4 3.3 3.2 3.1 3.0)
It is known that in some cases warnings appear while including boost files due to the fact that the flag "-Wunused-local-typedefs" is set by default in gcc.
This does not have any impact on the final code, but if you want a cleaner output you can add the flag "-Wno-unused-local-typedefs" to the configuration files:
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -msse3 -Wno-unused-local-typedefs" \
-DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -msse3 -Wno-unused-local-typedefs" \
If you want to compile the MPI-version of Kratos, you need to
- Have a MPI installation (e.g. OpenMPI or Intel MPI)
- compile boost with MPI-support
- Install ParMETIS
- Install Trilinos
The latest version tested is 2.1.1
For general information about the usable version, see the beginning of this page. Use the following three commands to compile boost with MPI-support. You might have to adjust the version of python that you are using
./bootstrap.sh --with-python-version=3.5 --with-libraries=python,mpi,serialization
Add "using mpi ;" at the end of "project-configure.jam" (Source and more Info)
./b2 stage --with-python --with-serialization --with-mpi variant=release cxxflags="-std=c++11" link=shared
./b2 install
The latest version working with Kratos is 3.2.0. Edit the makefile Makefile.in
to look like this:
# Which compiler to use
CC = mpicc
# What optimization level to use
#OPTFLAGS = -g
OPTFLAGS = -O3
# Include directories for the compiler
INCDIR =
# What options to be used by the compiler
#COPTIONS = -g
COPTIONS = -fPIC
# Which loader to use
LD = mpicc
# In which directories to look for any additional libraries
LIBDIR =
# What additional libraries to link the programs with (eg., -lmpi)
#XTRALIBS = -lefence
#XTRALIBS = -ldmalloc
# What archiving to use
AR = ar rv
# What to use for indexing the archive
#RANLIB = ranlib
RANLIB = ar -ts
VERNUM = 3.2.0
Build ParMETIS with:
make lib
The latest version tested with Kratos is 12.10.1.
It is recommended to create a build directory in the root folder of Trilinos. Inside this folder, create a do-configure.sh
to compile Trilinos.
If you use LAPACK 3.6 or newer, then you have to apply the following fixes: (sources: 1, 2):
In trilinos-12.10.1-Source/packages/epetra/src/Epetra_LAPACK_wrappers.h
Change
#define DGGSVD_F77 F77_BLAS_MANGLE(dggsvd,DGGSVD)
#define SGGSVD_F77 F77_BLAS_MANGLE(sggsvd,SGGSVD)
to
#define DGGSVD_F77 F77_BLAS_MANGLE(dggsvd3,DGGSVD3)
#define SGGSVD_F77 F77_BLAS_MANGLE(sggsvd3,SGGSVD3)
This is an example for a do-configure.sh
. Of course, the paths have to be adjusted
TRILINOS_ROOT="${HOME}/software/kratos/trilinos"
EXTRA_LINK_FLAGS=""
EXTRA_ARGS=$@
MPI_ROOT="${HOME}/software/ompi"
METIS_ROOT="{HOME}/software/kratos/parmetis/ParMetis-3.2.0"
LAPACK_ROOT="${HOME}/software/kratos/lapack/lapack-3.7.0"
rm CMakeCache.txt
rm -rf CMakeFiles
rm *.cmake
cmake \
-D CMAKE_INSTALL_PREFIX:FILEPATH="${TRILINOS_ROOT}" \
-D CMAKE_BUILD_TYPE:STRING=RELEASE \
-D Trilinos_SOURCE_DIR="${TRILINOS_SOURCE}" \
-D CMAKE_CXX_COMPILER=mpicxx \
-D CMAKE_C_COMPILER=mpicc \
-D CMAKE_Fortran_COMPILER=mpif90 \
-D TPL_ENABLE_MPI:BOOL=ON \
-D Trilinos_ENABLE_CXX11=ON\
-D MPI_BASE_DIR="${MPI_ROOT}" \
-D MPI_INCLUDE_DIRS:PATH="${MPI_ROOT}/include" \
-D BUILD_SHARED_LIBS:BOOL=ON \
-D BLAS_LIBRARY_DIRS:FILEPATH="${LAPACK_ROOT}" \
-D BLAS_LIBRARY_NAMES:STRING="librefblas.a" \
-D LAPACK_LIBRARY_DIRS:FILEPATH="${LAPACK_ROOT}" \
-D LAPACK_LIBRARY_NAMES:STRING="liblapack.a" \
-D TPL_ENABLE_ParMETIS:BOOL=ON \
-D ParMETIS_INCLUDE_DIRS:PATH="${METIS_ROOT}" \
-D ParMETIS_LIBRARY_NAMES:STRING="parmetis" \
-D ParMETIS_LIBRARY_DIRS:PATH="${METIS_ROOT}" \
-D TPL_ENABLE_METIS:BOOL=ON \
-D METIS_INCLUDE_DIRS:PATH="${METIS_ROOT}/METISLib" \
-D METIS_LIBRARY_NAMES:STRING="metis" \
-D METIS_LIBRARY_DIRS:PATH="${METIS_ROOT}" \
-D Trilinos_EXTRA_LINK_FLAGS:STRING="$EXTRA_LINK_FLAGS" \
-D Trilinos_ENABLE_Amesos:BOOL=ON \
-D Amesos_ENABLE_SuperLUDist:BOOL=ON \
-D Trilinos_ENABLE_Anasazi:BOOL=ON \
-D Trilinos_ENABLE_AztecOO:BOOL=ON \
-D AztecOO_ENABLE_Teuchos:BOOL=ON \
-D Trilinos_ENABLE_Didasko:BOOL=ON \
-D Trilinos_ENABLE_Epetra:BOOL=ON \
-D Trilinos_ENABLE_EpetraExt:BOOL=ON \
-D Trilinos_ENABLE_Galeri:BOOL=ON \
-D Trilinos_ENABLE_Ifpack:BOOL=ON \
-D Trilinos_ENABLE_ML:BOOL=ON \
-D Trilinos_ENABLE_PyTrilinos:BOOL=OFF \
-D Trilinos_ENABLE_Teuchos:BOOL=ON \
-D Trilinos_ENABLE_Triutils:BOOL=ON \
-D DART_TESTING_TIMEOUT:STRING=600 \
-D CMAKE_Fortran_FLAGS:STRING="-O5 -funroll-all-loops -fPIC" \
-D CMAKE_C_FLAGS:STRING="-O3 -fPIC -funroll-loops -march=native" \
-D CMAKE_CXX_FLAGS:STRING="-O3 -fPIC -funroll-loops -ffast-math -march=native -DMPICH_IGNORE_CXX_SEEK" \
$EXTRA_ARGS \
${TRILINOS_SOURCE}
Build Trilinos with:
sh do-configure.sh
make
make install
Add the following lines to your configure.sh
:
-DPARMETIS_ROOT_DIR="/path/to/parmetis/ParMetis-3.2.0" \
-DMETIS_APPLICATION=ON \
-DTRILINOS_ROOT="/path/to/trilinos/trilinos-12.10.1-Source" \
-DTRILINOS_APPLICATION=ON \
Now Kratos will be compiled with MPI-support.
To to tests the compilation, you can execute a simple python script containing these lines:
from KratosMultiphysics import *
from KratosMultiphysics.mpi import *
from KratosMultiphysics.MetisApplication import *
from KratosMultiphysics.TrilinosApplication import *
To execute Kratos in parallel, you can for example use the mpiexec
command (running with 4 processes):
mpiexec -np 4 python3 MainKratos.py
Additional information regarding the compilation can be found here
- Getting Kratos (Last compiled Release)
- Compiling Kratos
- Running an example from GiD
- Kratos input files and I/O
- Data management
- Solving strategies
- Manipulating solution values
- Multiphysics
- Video tutorials
- Style Guide
- Authorship of Kratos files
- Configure .gitignore
- How to configure clang-format
- How to use smart pointer in Kratos
- How to define adjoint elements and response functions
- Visibility and Exposure
- Namespaces and Static Classes
Kratos structure
Conventions
Solvers
Debugging, profiling and testing
- Compiling Kratos in debug mode
- Debugging Kratos using GDB
- Cross-debugging Kratos under Windows
- Debugging Kratos C++ under Windows
- Checking memory usage with Valgind
- Profiling Kratos with MAQAO
- Creating unitary tests
- Using ThreadSanitizer to detect OMP data race bugs
- Debugging Memory with ASAN
HOW TOs
- How to create applications
- Python Tutorials
- Kratos For Dummies (I)
- List of classes and variables accessible via python
- How to use Logger
- How to Create a New Application using cmake
- How to write a JSON configuration file
- How to Access DataBase
- How to use quaternions in Kratos
- How to do Mapping between nonmatching meshes
- How to use Clang-Tidy to automatically correct code
- How to use the Constitutive Law class
- How to use Serialization
- How to use GlobalPointerCommunicator
- How to use PointerMapCommunicator
- How to use the Geometry
- How to use processes for BCs
- How to use Parallel Utilities in futureproofing the code
- Porting to Pybind11 (LEGACY CODE)
- Porting to AMatrix
- How to use Cotire
- Applications: Python-modules
- How to run multiple cases using PyCOMPSs
- How to apply a function to a list of variables
- How to use Kratos Native sparse linear algebra
Utilities
Kratos API
Kratos Structural Mechanics API