LAPACK

From PHASTA Wiki
Jump to: navigation, search

Download and Build LAPACK

First download LAPACK tarball from http://netlib.org/lapack/ and extract the files with tar -xf <name_of_tarball> , which produced folder 'lapack-3.9.1' for this example. Note that for the current method, the location of the unpacked folder does not need to be within the PHASTA source directory.

Create a copy of the provided make include file with cp lapack-3.9.1/make.inc.example lapack-3.9.1/make.inc and modify make.inc with any platform specific changes that are needed (for viz002 no changes were needed).

At the same level as the lapack-3.9.1 folder, create and change to a build directory, <build_lapack_dir> and execute the following from within the build directory, followed by make -j .

#!/bin/bash
cmake \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_Fortran_COMPILER=gfortran \
-DCMAKE_BUILD_TYPE=Release \
../lapack-3.9.1 

The directory <build_lapack_dir>/lib/ should now contain libblas.a and liblapack.a library files. These are the files that will be linked to when compiling PHASTA.

Modify CMakeLists.txt File

Add the following flags to the build script that you would normally execute when compiling PHASTA.

-DPHASTA_USE_LAPACK=ON \
-DLAPACKBLAS_DIR=</path/to/build_lapack_dir>/lib/ \ 

Note that the forward slash after 'lib' is required for the next section of code to work.

Within the desired PHASTA source directory, edit the <phasta_dir>/phSolver/compressible/CMakeLists.txt file and add the following section of code.

OPTION(PHASTA_USE_LAPACK "Link LAPACK libraries" OFF)
if(PHASTA_USE_LAPACK)
        target_link_libraries(phastaC.exe "${LAPACKBLAS_DIR}liblapack.a"
                                          "${LAPACKBLAS_DIR}libblas.a")
endif(PHASTA_USE_LAPACK)  

This chunk of code should be placed near the end of the CMakeLists.txt file just above where the configure_file() command is called. Note that the order in which the liblapack.a and libblas.a files are listed in the target_link_libraries() command must be preserved since the LAPACK library has dependencies on BLAS.

PHASTA is now ready to be built in your preferred directory. When calling LAPACK subroutines, be sure to use the version of the routine that corresponds to the datatype object being considered. For example, if you are trying to perform an eigen-decomposition of a real-valued double precision matrix, you would call the DGEEV routine (D for double) as opposed to the SGEEV routine (S for single precision).