[Trilinos-Users] Using find_package to compile Trilinos?
Nico Schlömer
nico.schloemer at ua.ac.be
Mon Aug 23 17:07:10 MDT 2010
Hi Mike,
CMake functionality has been added to Trilinos a while ago; you could
use FIND_PACKAGE( Trilinos REQUIRED ).
I'll attach a CMakeLists.txt along with a simple executable that does
something around Tpetra; maybe you can use this as a template for
whatever you do.
Generally you may want to create the folder structure like
./source/CMakeLists.txt
./source/main.cpp
./build
then cd into ./build/, and call
cmake -D Trilinos_DIR:PATH=/path/to/your/trilinos/installation/
./source
This should generate all the files necessary for building the
executable.
Cheers,
Nico
On Mon, 23 Aug 2010 16:10:12 -0600, "Michael Buksas"
<mwbuksas at lanl.gov> wrote:
> Hi everyone,
>
> Can I use CMake's find_package command in my own project to find
> Trilinos? Is there a FindTrilinos.cmake file somewhere? Or, do I need to
> point CMake to TrilinosConfig.cmake in the install directory?
>
> Thanks,
> Mike Buksas
-------------- next part --------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
FIND_PACKAGE( Trilinos REQUIRED )
SET( CMAKE_C_COMPILER ${Trilinos_C_COMPILER} )
SET( CMAKE_CXX_COMPILER ${Trilinos_CXX_COMPILER} )
SET( CMAKE_Fortran_COMPILER ${Trilinos_Fortran_COMPILER} )
PROJECT( extract CXX Fortran )
INCLUDE_DIRECTORIES ( ${Trilinos_INCLUDE_DIRS}
${Trilinos_TPL_INCLUDE_DIRS} )
LINK_DIRECTORIES( ${Trilinos_LIBRARY_DIRS}
${Trilinos_TPL_LIBRARY_DIRS} )
SET( MY_EXECUTABLE
"crsgraph.exe" )
SET ( extract_SRCS
main.cpp )
ADD_EXECUTABLE( ${MY_EXECUTABLE}
${extract_SRCS} )
SET_TARGET_PROPERTIES( ${MY_EXECUTABLE}
PROPERTIES LINKER_LANGUAGE Fortran )
TARGET_LINK_LIBRARIES( ${MY_EXECUTABLE}
${Trilinos_LIBRARIES}
${Trilinos_TPL_LIBRARIES} )
-------------- next part --------------
#include <Teuchos_DefaultComm.hpp>
#include <Tpetra_CrsMatrix.hpp>
typedef int ORD;
int
main (int argc, char** argv)
{
#ifdef HAVE_MPI
MPI_Init( &argc, &argv );
#endif
// Create a communicator for Tpetra objects
const Teuchos::RCP<const Teuchos::Comm<ORD> > comm =
Teuchos::DefaultComm<int>::getComm();
// allocate map
int NumGlobalElements = 4;
Teuchos::RCP<Tpetra::Map<ORD> > map =
Teuchos::rcp( new Tpetra::Map<ORD>( NumGlobalElements, 0, comm ) );
// allocate matrix
// TODO try ( map, map, maxNumEntriesPerRow ) in the intializer
int maxNumEntriesPerRow = NumGlobalElements;
Teuchos::RCP<Tpetra::CrsMatrix<double,ORD> > matrix =
Teuchos::rcp( new Tpetra::CrsMatrix<double,ORD>( map, maxNumEntriesPerRow ) );
// insert the first set of indices
Teuchos::Tuple<ORD,4> indices = Teuchos::tuple( 0, 1, 2, 3 );
Teuchos::Tuple<double,4> values = Teuchos::tuple( 1.0, -2.0, 3.0, -4.0 );
for ( ORD i=0; i<matrix->getNodeNumRows(); i++ )
matrix->insertGlobalValues( matrix->getRowMap()->getGlobalElement(i),
indices,
values
);
matrix->globalAssemble();
matrix->fillComplete();
// show matrix
Teuchos::RCP<Teuchos::FancyOStream> out =
Teuchos::fancyOStream( Teuchos::rcpFromRef(std::cout) );
matrix->describe( *out, Teuchos::VERB_EXTREME );
// allocate vectors and perform mm
Tpetra::MultiVector<double> tmpIn( matrix->getDomainMap(), 1 );
tmpIn.putScalar( 1.0 );
Tpetra::MultiVector<double> tmpOut( matrix->getRangeMap(), 1 );
tmpOut.putScalar( 0.0 );
matrix->multiply( tmpIn,
tmpOut,
Teuchos::NO_TRANS,
1.0,
0.0
);
std::cout << "Here's the result vector:" << std::endl;
tmpOut.describe( *out, Teuchos::VERB_EXTREME );
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return( EXIT_SUCCESS );
}
More information about the Trilinos-Users
mailing list