130 likes | 367 Views
Building and Linking against Trilinos. November 2nd /4pm Brent Perschbacher SAND2010-7620 P.
E N D
Building and Linking against Trilinos November 2nd /4pm Brent Perschbacher SAND2010-7620 P Sandia National Laboratories is a multi-program laboratory operated by Sandia Corporation, a wholly owned subsidiary of Lockheed Martin company, for the U.S. Department of Energy’s National Nuclear Security Administration under contract DE-AC04-94AL85000.
How to configure with Cmake • Intro to linking against Trilinos with Cmake • Intro to linking against Trilinos with Make
Simple Configure and Build cmake \ -D Trilinos_ENABLE_Epetra:BOOL=ON \ -D Trilinos_ENABLE_EpetraExt:BOOL=ON \ -D Trilinos_ENABLE_Teuchos:BOOL=ON \ -D CMAKE_CXX_COMPILER:FILEPATH=<path to compiler> \ -D CMAKE_C_COMPILER:FILEPATH=<path to compiler> \ -D CMAKE_Fortran_COMPILER:FILEPATH=<path to compiler> \ ../Trilinos make
Configure with MPI cmake \ -D Trilinos_ENABLE_Epetra:BOOL=ON \ -D Trilinos_ENABLE_EpetraExt:BOOL=ON \ -D Trilinos_ENABLE_Teuchos:BOOL=ON \ -D TPL_ENABLE_MPI:BOOL=ON \ -D MPI_BASE_DIR:PATH=<path to mpi installation> \ ../Trilinos
Specifying MPI Compilers cmake \ -D Trilinos_ENABLE_Epetra:BOOL=ON \ -D Trilinos_ENABLE_EpetraExt:BOOL=ON \ -D Trilinos_ENABLE_Teuchos:BOOL=ON \ -D TPL_ENABLE_MPI:BOOL=ON \ -D MPI_BASE_DIR:PATH=<path to mpi installation> \ -D MPI_CXX_COMPILER:FILEPATH=<path to compiler> \ -D MPI_C_COMPILER:FILEPATH=<path to compiler> \ -D MPI_Fortran_COMPILER:FILEPATH=<path to compiler> \ ../Trilinos
Benefits of the Find Trilinos and Makefile Export Systems • Makes it easy to build against Trilinos • Solves consistency issues with compiler versions and options • Makes getting the correct ordering on the link line easy • If dependencies of packages change they will be automatically updated • Protects against internal changes to the number and names of libraries
Linking Against Trilinos With CMake • Trilinos can be found like any other package • find_package(Trilinos PATHS <path to Trilinos installation>) • find_package(Epetra PATHS <path to Trilinos installation>) • Compiler variables • Trilinos_CXX_COMPILER, Trilinos_CXX_COMPILER_FLAGS • Trilinos_C_COMPILER, Trilinos_C_COMPILER_FLAGS • Trilinos_Fortran_COMPILER, Trilinos_Fortran_COMPILER_FLAGS • Include and library variables • Trilinos_INCLUDE_DIRS, Trilinos_TPL_INCLUDE_DIRS • Trilinos_LIBRARY_DIRS, Trilinos_TPL_LIBRARY_DIRS • Trilinos_LIBRARIES, Trilinos_TPL_LIBRARIES
cmake_minimum_required(VERSION 2.7) FIND_PACKAGE(Trilinos PATHS ${MYAPP_TRILINOS_DIR}/include) IF(NOT Trilinos_FOUND) MESSAGE(FATAL_ERROR "Could not find Trilinos!") ENDIF() # Make sure to use same compilers and flags as Trilinos SET(CMAKE_CXX_COMPILER ${Trilinos_CXX_COMPILER} ) SET(CMAKE_C_COMPILER ${Trilinos_C_COMPILER} ) SET(CMAKE_Fortran_COMPILER ${Trilinos_Fortran_COMPILER} ) SET(CMAKE_CXX_FLAGS "${Trilinos_CXX_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}") SET(CMAKE_C_FLAGS "${Trilinos_C_COMPILER_FLAGS} ${CMAKE_C_FLAGS}") SET(CMAKE_Fortran_FLAGS "${Trilinos_Fortran_COMPILER_FLAGS} ${CMAKE_Fortran_FLAGS}")
PROJECT(MyApp) ADD_DEFINITIONS(-DMYAPP_EPETRA) INCLUDE_DIRECTORIES(${Trilinos_INCLUDE_DIRS} ${Trilinos_TPL_INCLUDE_DIRS}) LINK_DIRECTORIES(${Trilinos_LIBRARY_DIRS} ${Trilinos_TPL_LIBRARY_DIRS}) ADD_LIBRARY(myappLib src_file.cpp src_file.hpp) ADD_EXECUTABLE(MyApp.exe main_file.cpp) TARGET_LINK_LIBRARIES(MyApp.exe myappLib ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES}) ENABLE_TESTING() ADD_TEST(NAME MyTest COMMAND MyApp.exe)
Linking Against Trilinos With Make • Trilinos Makefiles can be included in other Makefiles • include <path to Trilinos installation>/Makefile.export.Trilnos • include <path to Trilinos installation>/Makefile.export.Epetra • Compiler variables (the same as the cmake version) • Trilinos_CXX_COMPILER, Trilinos_CXX_COMPILER_FLAGS • Trilinos_C_COMPILER, Trilinos_C_COMPILER_FLAGS • Trilinos_Fortran_COMPILER, Trilinos_Fortran_COMPILER_FLAGS • Include and Library variables • Trilinos_INCLUDE_DIRS, Trilinos_TPL_INCLUDE_DIRS • Trilinos_LIBRARY_DIRS, Trilinos_TPL_LIBRARY_DIRS • Trilinos_LIBRARIES, Trilinos_TPL_LIBRARIES
include $(MYAPP_TRILINOS_DIR)/include/Makefile.export.Trilinos CXX=$(Trilinos_CXX_COMPILER) CC=$(Trilinos_C_COMPILER) FORT=$(Trilinos_Fortran_COMPILER) CXX_FLAGS=$(Trilinos_CXX_COMPILER_FLAGS) $(USER_CXX_FLAGS) C_FLAGS=$(Trilinos_C_COMPILER_FLAGS) $(USER_C_FLAGS) FORT_FLAGS=$(Trilinos_Fortran_COMPILER_FLAGS) $(USER_FORT_FLAGS) 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)
DEFINES=-DMYAPP_EPETRA default: MyApp.exe test: MyApp.exe input.xml ./MyApp.exe MyApp.exe: libmyappLib.a $(CXX) $(CXX_FLAGS) $(LINK_FLAGS) $(INCLUDE_DIRS) $(DEFINES) $(LIBRARY_DIRS) $(LIBRARIES) libMyappLib.a main_file.cpp -o MyApp.exe 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
Additional Resources • Getting Started with Trilinos • trilinos.sandia.gov/getting_started.html • trilinos.sandia.gov/documentation.html • Cmake • www.cmake.org/cmake/resources/software.html • trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt • Find Trilinos • trilinos.sandia.gov/Finding_Trilinos.txt • Makefile export • trilinos.sandia.gov/Export_Makefile.txt