LinuxInstall

From KratosWiki
(Difference between revisions)
Jump to: navigation, search
(Cannot found KratosMultiphysics)
(Replaced content with "The information in this page was moved to GitHub: https://github.com/KratosMultiphysics/Kratos/wiki/Linux-Build")
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
== How to compile Kratos: Linux ==
+
The information in this page was moved to GitHub: https://github.com/KratosMultiphysics/Kratos/wiki/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 Ubuntu 14.04 LTS, with the latest checked libraries. A basic knowledge of Linux is assumed ( execute commands, create directories, etc...)
+
 
+
=== Subversion ===
+
 
+
* Objectives:
+
** Install subversion
+
** 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 subversion manager. You can install the default subversion by using this command:
+
 
+
    sudo apt-get install subversion
+
 
+
Once subversion is installed you can fetch the code by using this command:
+
 
+
    svn co https://svn.cimne.upc.edu/p/kratos/kratos .
+
 
+
=== Dev Packages ===
+
 
+
* Objectives:
+
** Get Python3-dev
+
** Get G++
+
** Get Fortran compiler
+
** Get LIBBLAS and LIBLAPACK
+
 
+
You will need python dev files in order to compile kratos and some of its dependent libraries. Whether you wish to use python 3 ( recommended ) or python 2, you will need to install its dev files. This guide will show the process to install python 3.4 dev files, as is its recommended version. Additionally you will need a G++ and fortran compiler, which are not present in ubuntu 14.04 by default. Finally it will be also need an implementation of blas and lapack. You can obtain all these dependencies by running this command:
+
 
+
    sudo apt-get install python-dev python3-dev gcc g++ gfortran libblas-dev liblapack-dev
+
 
+
=== Boost ===
+
 
+
* Objectives:
+
** Compile boost libraries
+
 
+
<span style="color:red">Important: Version 1.60 is not compatible with Kratos</span>
+
 
+
The next step will consist in compile Boost. Kratos Multiphysics needs Boost libraries to support some of its functions. You can use any version from version 1.54 onward, except version 1.60, which is not supported due to a bug with python wrappers. This bug has been fixed in version 1.61.
+
 
+
It's very important to add the correct path to the boost library in the configure.sh, see more below. You can download boost from its official website:
+
 
+
    http://www.boost.org/users/download/
+
 
+
Navigate to the directory where you have extracted boost and execute this command:
+
 
+
    sh bootstrap.sh
+
 
+
Some additional files will be generated.
+
 
+
By default, boost will try to link with python 2.7. '''It is important to manually specify that we want to use python 3 by adding “using python : 3.4 : /usr ;”''' to the file project-config.jam. It will look like this:
+
 
+
    # Boost.Build Configuration
+
    # Automatically generated by bootstrap.sh
+
   
+
    import option ;
+
    import feature ;
+
   
+
    # Compiler configuration. This definition will be used unless
+
    # you already have defined some toolsets in your user-config.jam
+
    # file.
+
    if ! gcc in [ feature.values <toolset> ]
+
    {
+
        using gcc ;
+
    }
+
   
+
    project : default-build <toolset>gcc ;
+
   
+
    <span style="color:red">'''# Python configuration'''</span>
+
    <span style="color:red">'''using python : 3.4 : /usr ;'''</span>
+
   
+
    # List of --with-<library> and --without-<library>
+
    # options. If left empty, all libraries will be built.
+
    # Options specified on the command line completely
+
    # override this variable.
+
    libraries =  ;
+
   
+
    # These settings are equivalent to corresponding command-line
+
    # options.
+
    option.set prefix : /usr/local ;
+
    option.set exec-prefix : /usr/local ;
+
    option.set libdir : /usr/local/lib ;
+
    option.set includedir : /usr/local/include ;
+
   
+
    # Stop on first error
+
    option.set keep-going : false ;
+
 
+
After modifying it you will have to compile the required boost libraries using this command. Notice that this will only compile “serialization” and “python” libraries. If you need further libraries, you will need to explicitly tell boost to compile them.
+
 
+
    ./b2 stage --with-python --with-serialization cxxflags="-std=c++11" link=shared,static
+
 
+
If you don't intend to debug your code you may want to compile with the 'variant=release' option which will reduce approximately 20% the compilation time:
+
 
+
    ./b2 stage --with-python --with-serialization cxxflags="-std=c++11" variant=release link=shared,static
+
 
+
=== CMake ===
+
 
+
* Objectives:
+
** Install CMake
+
 
+
Cmake is the tool used to compile kratos. To install it, the first option is to execute the following command (but '''check the version that will be installed''', not all versions work, so see the warnings after these lines):
+
 
+
    sudo apt-get install cmake
+
 
+
{{Warning|
+
* If you use CMake 2.8 or earlier please refer to http://kratos-wiki.cimne.upc.edu/index.php/LinuxInstall#Old_version_of_CMake
+
}}
+
 
+
=== Configure ===
+
 
+
* 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'''.
+
 
+
<!-- It is also recommended to change '''KRATOS_INSTALL_PREFIX''' -->
+
Option:
+
* BOOST_ROOT: Directory where you have compiled boost
+
* PYTHON_LIBRARY: Location of the python librarie used to compile boost
+
* PYTHON_INCLUDE_DIR: Location of the python headers
+
<!-- ** KRATOS_INSTALL_PREFIX: Sets the install directory -->
+
 
+
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'''"               \
+
    <span style="color:red">-DBOOST_ROOT="~/compiled_libraries/boost_1_57_0"                                    \</span>
+
    <span style="color:red">-DPYTHON_LIBRARY="/usr/lib/python3.4/config-3.4m-x86_64-linux-gnu/libpython3.4m.so" \</span>
+
    <span style="color:red">-DPYTHON_INCLUDE_DIR="/usr/include/python3.4"                                      \</span>
+
    -DMESHING_APPLICATION=ON                                                            \
+
    -DEXTERNAL_SOLVERS_APPLICATION=ON                                                  \
+
   
+
    // More options ( do not include this line )
+
 
+
<!-- It is also recomended that you specify the directory where kratos is goin to be installed. You can do that by changing
+
the path in '''-DKRATOS_INSTALL_PREFIX'''. If the variable is not set, the installation will be done in the source directory.
+
 
+
    -DKRATOS_INSTALL_PREFIX="/path/to/my/kratos/installation"                          \
+
-->
+
Note that the "\" must be the last character in the line. Even an space 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=<span style="color:green">'''ON'''</span>/<span style="color:red">'''OFF'''</span>                               
+
 
+
{{Warning|
+
* Cmake requires all definitions in a single line! The line concatenation character '\' therefore MUST NOT be followed by any whitespace in the same line as this would prevent the cmake from running the lines below
+
}}
+
 
+
=== Compile ===
+
 
+
* Objectives:
+
** Compile kratos.
+
 
+
If you followed all the steps correctly, compile 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.
+
 
+
=== Setting up your enviroment ===
+
 
+
* Objectives:
+
** Tell Linux how to execute kratos
+
 
+
Once Kratos ins 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=<span style="color: red">/path/to/my/kratos/installation</span>:$PYTHONPATH" >> $HOME/.bashrc
+
  echo "export LD_LIBRARY_PATH=<span style="color: red">/path/to/my/kratos/installation/libs</span>:$LD_LIBRARY_PATH" >> $HOME/.bashrc
+
 
+
If you have enabled the embedded python option, you can also add
+
 
+
  echo "export PATH=<span style="color: red">/path/to/my/kratos/installation</span>:$PATH" >> $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
+
 
+
=== Test ===
+
 
+
* 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
+
 
+
== Troubleshooting ==
+
 
+
In this section we provide will try to provide solutions to the most common problems and issues that may appear during the compilation process
+
 
+
=== Cannot find KratosMultiphysics ===
+
 
+
=== I am getting Python link errors ===
+
 
+
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:
+
 
+
==== Python version mismatch ====
+
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.
+
 
+
==== Old version of CMake ====
+
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:
+
 
+
    <span style="color:red">'''/path/to/correct/cmake ..'''</span>                                              \
+
    -DCMAKE_C_COMPILER=/usr/bin/gcc   \
+
    ...
+
 
+
<!-- -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE                                \ -->
+
<!-- -DCMAKE_INSTALL_RPATH="/home/youruser/kratos/kratos/libs" -->
+
 
+
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 <span style="color:red">'''3.4'''</span> 3.3 3.2 3.1 3.0)
+
 
+
=== I am getting lots of warnings when I compile Kratos ===
+
 
+
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" \
+

Latest revision as of 08:38, 2 July 2018

The information in this page was moved to GitHub: https://github.com/KratosMultiphysics/Kratos/wiki/Linux-Build

Personal tools
Categories