Thursday, March 29, 2012

Install & start using Trilinos Libraries and Tools

After one whole day hacking in the total mess, finally got everything about Trilinos setup in my ubuntu linux. This blog is about how to install trilinos and its package from scratch, hoping others won't be staying up as late as me when taking this work...

1. The reason I reluctantly install Trilinos is all about using its OO framework in building our own large-scale computational software. Though it's so painful to kick off, I was told everything will get better after that. God bless so...
The introduction, download page, examples, almost everything of Trilinos can be found:
Trilinos Website

The install processes can also be reached from:
Trilinos Installation

2. Follow the processes  in Trilinos Installation, first and second steps are trivial. If you also running ubuntu, just
             > sudo apt-get install cmake
    to update cmake to newest version.
 
    After download the Clapack, try to follow section 5 in lawn81.pdf in clapack-3.2.1-CMAKE/INSTALL (clapack-3.2.1-CMAKE is the dir I extracted Clapack to). Don't care about section 6, it only makes ur life tough...

    The only changes i did to make.inc are
                  uncomment      #TIMER = EXT_ETIME.
                  change             BLASLIB= ../../blas$(PLAT).a   to  BLASLIB = -lgoto -lpthread
                  change             CC=gcc                                      to  CC= gcc -DNO_BLAS_WRAP
The last changes following the README.install, which is quite helpful if u have time reading it!

    Then, just >make under clapack-3.2.1-CMAKE/.

    Now we have blas_LINUX.a, lapack_LINUX.a, tmglib_LINUX.a in root dir and libf2c.a under F2CLIBS/. They will be used in cmake, make, and install of Trilinos.

    At this time, > sudo apt-get install libblas-dev, liblapack-dev under command line, which should be necessary according to my experience. (I tried tens times to solve a link problem, finally get done by installing ubuntu's libblas and including it in do-configure file)

    The most tricky part in installation is adapting do-configure file, here is my version (I just tried, tried and tried again, uncountable times... and got it work. I'm not even sure why the order should be like this...)

do-configure:
********************************************************************************


#!/bin/sh

EXTRA_ARGS=$@

rm -f CMakeCache.txt


cmake \
-D CMAKE_INSTALL_PREFIX:PATH=/home/rex/Trilinos \
-D CMAKE_BUILD_TYPE:STRING=DEBUG \
-D CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ \
-D CMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc \
-D CMAKE_Fortran_COMPILER:FILEPATH=/usr/bin/gfortran \
-D HAVE_GCC_ABI_DEMANGLE:BOOL=ON \
-D Trilinos_WARNINGS_AS_ERRORS_FLAGS:STRING="" \
-D CMAKE_VERBOSE_MAKEFILE:BOOL=TRUE \
-D Trilinos_ENABLE_ALL_PACKAGES:BOOL=FALSE \
-D Trilinos_ENABLE_Belos:BOOL=ON \
-D Trilinos_ENABLE_Teuchos:BOOL=ON \
-D Trilinos_ENABLE_Epetra:BOOL=ON \
-D Trilinos_ENABLE_TESTS:BOOL=ON \
-D Trilinos_ENABLE_ALL_FORWARD_DEP_PACAKGES:BOOL=ON \
-D Trilinos_ENABLE_BLAS:BOOL=ON \
-D Trilinos_ENABLE_LAPACK:BOOL=ON \
-D Trilinos_ENABLE_Komplex:BOOL=ON \
-D BLAS_LIBRARY_DIRS:FILEPATH="/home/rex/Downloads/clapack-3.2.1-CMAKE" \
-D BLAS_LIBRARY_NAMES:STRING="blas_LINUX.a;libf2c.a;libblas.so" \
-D TPL_BLAS_LIBRARIES:FILEPATH="/home/rex/Downloads/clapack-3.2.1-CMAKE/blas_LINUX.a;/home/rex/Downloads/clapack-3.2.1-CMAKE/libf2c.a;/usr/lib/libblas.so" \
-D BLAS_INCLUDE_DIRS:PATH="/home/rex/Downloads/clapack-3.2.1-CMAKE/INCLUDE" \
-D LAPACK_LIBRARY_DIRS:FILEPATH="/home/rex/Downloads/clapack-3.2.1-CMAKE" \
-D LAPACK_LIBRARY_NAMES:STRING="lapack_LINUX.a;tmglib_LINUX.a" \
-D TPL_LAPACK_LIBRARIES:FILEPATH="/home/rex/Downloads/clapack-3.2.1-CMAKE/lapack_LINUX.a;/home/rex/Downloads/clapack-3.2.1-CMAKE/tmglib_LINUX.a" \
-D LAPACK_INCLUDE_DIRS:PATH="/home/rex/Downloads/clapack-3.2.1-CMAKE/INCLUDE" \
$EXTRA_ARGS \
../trilinos-10.10.1-Source
********************************************************************************


OK, now just type > make install  and wait, wait, wait, maybe enjoy several cups of coffee... Now we finish first four steps. As mentioned in step 5 in Trilinos Installation, we'll find two dir's INCLUDE and LIB under /home/rex/Trilinos (which is the value of CMAKE_INSTALL_PREFIX:PATH in do-configure. set it as u wish before make install).

Now, we're done with the installation. To start using it, we must follow step 5 in Trilinos Installation to keep hacking tens mins or longer in Makefiles... Below is mine (enabled EPETRA, EPETRAEXT, TEUCHO, BELOS packages. If u wanna change it or add more, browse the two files: Export_Makefile_example.txt and Export_Makefile.txt. U'll know how to change it very quickly if following the format in my Makefile below:)

Makefile:
********************************************************************************

# CMAKE File for "MyApp" application building against an installed Trilinos

#This file is an adaptation of the CMakeLists.txt file that was converted from
#the buildAgainstTrilinos example. This Makefile was designed to be used in a
#flat directory structure. If you would like to run this example you will need
#put this file and src_file.cpp, src_file.hpp, main_file.cpp from
#buildAgainstTrilinos into a new directory. You will then need to set the
#environment variable MYAPP_TRILINOS_DIR to point to your base installation of
#Trilinos. Note that this example assumes that the installation of Trilinos that
#you point to has Epetra enabled.

# Get Trilinos as one entity
MYAPP_TRILINOS_DIR=/home/rex/Trilinos

include $(MYAPP_TRILINOS_DIR)/include/Makefile.export.Belos
include $(MYAPP_TRILINOS_DIR)/include/Makefile.export.Epetra
include $(MYAPP_TRILINOS_DIR)/include/Makefile.export.EpetraExt
include $(MYAPP_TRILINOS_DIR)/include/Makefile.export.Teuchos


# Make sure to use same compilers and flags as Trilinos
CXX=/usr/bin/g++
CC=/usr/bin/gcc
FORT=/usr/bin/gfortran

CXX_FLAGS= -g -O0
C_FLAGS= -g -O0
FORT_FLAGS= -g

Trilinos_SHARED_LIB_RPATH_COMMAND=
Trilinos_BUILD_SHARED_LIBS=OFF

Trilinos_LINKER=/usr/bin/ld
Trilinos_AR=/usr/bin/ar

Trilinos_VERSION=10.10.1


Trilinos_TPL_INCLUDE_DIRS= -I/home/rex/Downloads/clapack-3.2.1-CMAKE/INCLUDE -I/home/rex/Downloads/clapack-3.2.1-CMAKE/INCLUDE -I/usr/include
Trilinos_TPL_LIBRARY_DIRS= -L/home/rex/Downloads/clapack-3.2.1-CMAKE/
Trilinos_TPL_LIBRARIES= /home/rex/Downloads/clapack-3.2.1-CMAKE/lapack_LINUX.a /home/rex/Downloads/clapack-3.2.1-CMAKE/tmglib_LINUX.a /home/rex/Downloads/clapack-3.2.1-CMAKE/blas_LINUX.a /home/rex/Downloads/clapack-3.2.1-CMAKE/libf2c.a /usr/lib/libblas.so /usr/lib/libpthread.so

Trilinos_PACKAGE_LIST= Belos EpetraExt Epetra Teuchos
Trilinos_TPL_LIST= LAPACK BLAS Pthread

Trilinos_INCLUDE_DIRS= -I/home/rex/Trilinos/include
Trilinos_LIBRARY_DIRS= -L/home/rex/Trilinos/lib
Trilinos_LIBRARIES= -lbelostpetra -lbelosepetra -lbelos -ltpetraext -ltpetrainout -ltpetra -lepetra -lkokkoslinalg -lkokkosnodeapi -lkokkos -ltpi -lteuchos -lepetraext -ltriutils -lzoltan -lsimpi
#Trilinos_LIBRARIES= -lbelostpetra -lbelosepetra -lbelos -ltpetraext -ltpetrainout -ltpetra -lepetra -lkokkoslinalg -lkokkosnodeapi -lkokkos -ltpi -lteuchos -lepetraext -ltriutils -lzoltan -lsimpi

#Trilions_TPL_INCLUDE_DIRS= -I/home/rex/Downloads/clapack-3.2.1-CMAKE/INCLUDE -I/home/rex/Downloads/clapack-3.2.1-CMAKE/INCLUDE -I/usr/include
#Trilinos_TPL_LIBRARY_DIRS=
#Trilinos_TPL_LIBRARIES= /home/rex/Downloads/clapack-3.2.1-CMAKE/lapack_LINUX.a /home/rex/Downloads/clapack-3.2.1-CMAKE/tmglib_LINUX.a /home/rex/Downloads/clapack-3.2.1-CMAKE/blas_LINUX.a /home/rex/Downloads/clapack-3.2.1-CMAKE/libf2c.a /usr/lib/libpthread.so


INCLUDE_DIRS=$(Trilinos_INCLUDE_DIRS) $(Trilinos_TPL_INCLUDE_DIRS)
LIBRARY_DIRS=$(Trilinos_LIBRARY_DIRS) $(Trilinos_TPL_LIBRARY_DIRS)
LIBRARIES=$(Trilinos_LIBRARIES) $(Trilinos_TPL_LIBRARIES)

LINK_FLAGS=$(Trilinos_EXTRA_LD_FLAGS)

#just assuming that epetra is turned on.
DEFINES=-DMYAPP_EPETRA
DEFINES=-DMYAPP_EPETRAEXT
DEFINES=-DMYAPP_TEUCHO
DEFINES=-DMYAPP_BELOS


default: print_info MyApp.out

# Echo trilinos build info just for fun
print_info:
@echo "\nFound Trilinos!  Here are the details: "
@echo "   Trilinos_VERSION = $(Trilinos_VERSION)"
@echo "   Trilinos_PACKAGE_LIST = $(Trilinos_PACKAGE_LIST)"
@echo "   Trilinos_LIBRARIES = $(Trilinos_LIBRARIES)"
@echo "   Trilinos_INCLUDE_DIRS = $(Trilinos_INCLUDE_DIRS)"
@echo "   Trilinos_LIBRARY_DIRS = $(Trilinos_LIBRARY_DIRS)"
@echo "   Trilinos_TPL_LIST = $(Trilinos_TPL_LIST)"
@echo "   Trilinos_TPL_INCLUDE_DIRS = $(Trilinos_TPL_INCLUDE_DIRS)"
@echo "   Trilinos_TPL_LIBRARIES = $(Trilinos_TPL_LIBRARIES)"
@echo "   Trilinos_TPL_LIBRARY_DIRS = $(Trilinos_TPL_LIBRARY_DIRS)"
@echo "   Trilinos_BUILD_SHARED_LIBS = $(Trilinos_BUILD_SHARED_LIBS)"
@echo "End of Trilinos details\n"

# run the given test
#test: MyApp.exe input.xml
# ./MyApp.exe

# build the
#: libmyappLib.a
# libMyappLib.a
MyApp.out:
$(CXX) $(CXX_FLAGS) main.cpp -o MyApp.out $(LINK_FLAGS) $(INCLUDE_DIRS) $(DEFINES) $(LIBRARY_DIRS) $(LIBRARIES)

#libmyappLib.a: src_file.o
# $(Trilinos_AR) cr libmyappLib.a src_file.o

#src_file.o:
# $(CXX) -c $(CXX_FLAGS) $(INCLUDE_DIRS) $(DEFINES) src_file.cpp

.PHONY: clean
clean:
rm -f *.o *.a *.exe

********************************************************************************

Now ctrl-C your cpp codes into main.cpp if just a small exmaple and > make , we'll get the executable MyApp.out and ./MyApp.out. Bingo! With small changes in Makefile above, we're ready to start using Trilinos and its powerful libs and OO frameworks!



No comments:

Post a Comment