1 / 13

Building and Linking against Trilinos

Building and Linking against Trilinos. November 2nd /4pm Brent Perschbacher SAND2010-7620 P.

emery
Download Presentation

Building and Linking against Trilinos

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. How to configure with Cmake • Intro to linking against Trilinos with Cmake • Intro to linking against Trilinos with Make

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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}")

  9. 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)

  10. 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

  11. 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)

  12. 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

  13. 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

More Related