Download Using PyTrilinos

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
PyTrilinos: A Python Interface to Parallel,
Object-Oriented Solver Packages for
Scientific Computing
Bill Spotz
DOE/Office of Science/ASCR
(Sandia National Laboratories)
SIAM Annual Meeting 2008
July 10, 2008
Computational Sciences at Sandia
•
•
•
•
•
•
•
•
Chemically reacting flows
Climate modeling
Combustion
Compressible flows
Computational biology
Electrical modeling
Heat transfer
Load balancing
•
•
•
•
Materials modeling
MEMS modeling
Mesh generation
Optimization and
uncertainty quantification
• Seismic imaging
• Shock and multiphysics
• Structural dynamics
The Trilinos Project
•
•
•
•
•
•
•
•
•
•
•
Provide a central repository for Sandia’s solver technology
Increase code-reuse
Organized on concept of “packages”
Minimize package interdependence
Maximize package interoperability
Provide a framework for SQE and SQA
– Compliance with requirements
– Nightly test harness
High degree of developer autonomy
Open source: GNU Lesser General Public License
Web site: http://trilinos.sandia.gov
Next release: Version 9.0, September, 2008
Trilinos Users Group Meeting every November
The Trilinos Project
Linear Algebra
Services
Communicators, maps, vectors, matrices,
graphs…
Direct,
sparse
Complex interface
Java
Sparse kernels
Iterative, sparse to AztecOO
Tools &
Templated Reduction, transformation
operators
Direct, dense
Iterative,
sparse,
Extensions
Utilities
next generation
Generic interface
Epetra
Jpetra
Tpetra
EpetraExt
Kokkos
RTOp
Linear Solvers
Nonlinear Solvers
Amesos
AztecOO
Belos
Komplex
Pliris
Stratimikos
Preconditioners
IFPACK
ML
Claps
Meros
Incomplete factorization
Multi-level
Domain decomposition
Segregated, block
NOX
Anasazi
Rythmos
LOCA
MOOCHO
Meta-Solvers
Primary tools package
Python Interface
Common testing tools
Web interface
Matrix gallery
Eigensolvers
Common interface
Time-stepping algorithms
Partitioning & load balance
Continuation algorithms
Mortar elements
Package template
Constrained optimization
Trilinos examples
Teuchos
TriUtils
Galeri
Thyra
Isorropia
Moertel
Didasko
PyTrilinos
WebTrilinos
New_Package
The Trilinos Project
• Recently, the scope of Trilinos has been
expanded to include:
– Meshing
– Numerical methods
– Finite element interface
– Dynamic load balancing
– Automatic differentiation
– Probably others…
PyTrilinos
• Linear Algebra Services
– Epetra (with extensive NumPy compatibility and integration)
– EpetraExt (coloring algorithms and some I/O)
• Linear Solvers
– Amesos (LAPACK, KLU, UMFPACK, ScaLAPACK, SuperLU, SuperLUDist,
DSCPACK, MUMPS)
– AztecOO
• Preconditioners
– IFPACK
– ML
• Nonlinear Solvers
– NOX
• Meta-Solvers
– LOCA (python wrappers not yet caught up to recent redesigns)
– Anasazi
• Tools and Utilities
–
–
–
–
Teuchos (ParameterLists, communicators, traits and refcount pointers)
TriUtils
Galeri
Thyra (early development stage)
PyTrilinos Design
• PyTrilinos is a “python package,” meaning a
python module with sub-modules
– Each “Trilinos package” translates into a PyTrilinos
sub-module
– Trilinos package namespaces also become submodules
• PyTrilinos python interfaces match Trilinos C++
interfaces (within reason)
– Generated by SWIG (simple wrapper interface
generator)
– Some classes made more “pythonic”
PyTrilinos Documentation
• Trilinos documentation is handled by doxygen:
special comments within code
– Web pages updated twice daily
• C++ doxygen comments are now automatically
converted to python doc strings:
>>> from PyTrilinos import Epetra
>>> help(Epetra.Vector)
Returns standard Epetra_Vector documentation
PyTrilinos.Epetra
• Communicators
– Comm
– SerialComm
– MpiComm
– PyComm
• Maps
– BlockMap
– Map
– LocalMap
• Vectors
– MultiVector
– Vector
– IntVector
• SerialDense objects
– SerialDenseOperator
– SerialDenseMatrix
– SerialDenseVector
– SerialDenseSolver
– IntSerialDenseMatrix
– IntSerialDenseVector
• Graphs
– CrsGraph
• Operators
– Operator
– RowMatrix
– CrsMatrix
A Quick Detour…
• Python lists are not suitable for scientific
computing
– Flexible but inefficient
– Heterogeneous data, noncontiguous memory
• NumPy module provides needed functionality
– Contiguous, homogeneous n-dimensional arrays
– High-level interface
– Part of SciPy
• SciPy is a large, open source package for a wide
variety of python interfaces to scientific software:
– NetLib’s “greatest hits”
PyTrilinos.Epetra and NumPy
• Array-like classes inherit from numpy.UserArray
– MultiVector
– Vector
– IntVector
– SerialDenseMatrix
– SerialDenseVector
– IntSerialDenseMatrix
– IntSerialDenseVector
• Methods throughout Epetra have arguments that
accept or produce pointers to C arrays
– Python input arguments accept python sequences
– Python output arguments produce ndarrays
PyTrilinos.Teuchos
• Teuchos::ParameterList
• Used by several Trilinos packages to set problem parameters
• Maps string names to arbitrary-type values
• Python implementation allows dictionary substitutions
• The following conversions are supported:
Python
Dir
C / C++
bool

bool
int

int
float

double
string

std::string
string

char *
dict

ParameterList
wrapped ParameterList

ParameterList
PyTrilinos Demonstration
• Governing equation:
d 2u
du
 2  c  0, x  [0,1]
dx
dx
• Boundary conditions:
u(0)  0, u(1)  1
• Exact solution:

ecx 1
u(x)  c
e 1
ui1  2ui 
ui1
ui1  ui1
c
0
• CDS: 
2
h
2h

c
2
• Oscillations: ch 
n 1

Parallelism
• Configure Trilinos with –enable-mpi, and PyTrilinos will
also be mpi-enabled
• Scripts are run in parallel in the standard way:
$ mpirun -np 4 python script.py …
• When Epetra is imported, MPI_Init() is called
automatically and MPI_Finialize() is registered with the
atexit module.
• Use the PyComm() function to obtain a communicator, and
use a parallel programming paradigm:
– Global and local IDs
– Ghost nodes if necessary
– Epetra Import and Export objects if needed
Conclusions
• Python lets developers focus on the problem
– Memory management, garbage collection
– Powerful, flexible containers
– Clean, readable syntax
• PyTrilinos provides access to powerful solver
technologies
– Rapid prototyping
– Application development
– Serial, parallel