Petsc Tutorials
Petsc Tutorials
Tutorial Objectives
Introduce the Portable, Extensible Toolkit for
Scientific Computation (PETSc)
Demonstrate how to write a complete parallel
implicit PDE solver using PETSc
Introduce PETSc interfaces to other software
packages
Explain how to learn more about PETSc
What is PETSc?
PETSc history
Begun in September 1991
Now: over 8,500 downloads since 1995 (versions 2.0 and 2.1)
Matt
Knepley
Kris
Buschelman
Lois
Curfman
McInnes
Bill
Gropp
Barry
Smith
Dinesh
Kaushik
Hong
Zhang
PETSc Concepts
How to specify the mathematics of the problem
Data objects
vectors, matrices
Solvers (cont.)
Data objects
motivating examples
programming paradigm
vectors (e.g., field
variables)
matrices (e.g., sparse
Jacobians)
Viewers
object information
visualization
Solvers
Linear
Profiling and
performance tuning
nonlinear
timestepping (and ODEs)
structured and
unstructured mesh
problems
Tutorial Topics:
Using PETSc with Other
Packages
Linear solvers
AMG http://www.mgnet.org/mgnet-codes-gmd.html
BlockSolve95 http://www.mcs.anl.gov/BlockSolve95
ILUTP http://www.cs.umn.edu/~saad/
LUSOL http://www.sbsi-sol-optimize.com
SPAI http://www.sam.math.ethz.ch/~grote/spai
SuperLU http://www.nersc.gov/~xiaoye/SuperLU
Optimization software
TAO http://www.mcs.anl.gov/tao
Veltisto http://www.cs.nyu.edu/~biros/veltisto
ODE solvers
PVODE
http://www.llnl.gov/CASC/PVODE
Others
Matlab http://www.mathworks.com
ParMETIS http://www.cs.umn.edu/~karypis/
metis/parmetis
10
3D incompressible Euler
Tetrahedral grid
Up to 11 million unknowns
Based on a legacy NASA
code, FUN3d, developed
by W. K. Anderson
Fully implicit steady-state
Primary PETSc tools:
nonlinear solvers (SNES)
and vector scatters
(VecScatter)
11
12
13
14
Multiphase Flow
15
PC and SP Comparison
179,000 unknowns (22,375 cell blocks)
1200
Solution time
1000
800
600
PC
SP
400
200
0
16
Number Processors
16
Speedup
Speedup Comparison
18
16
14
12
10
8
6
4
2
0
PC
SP
ideal
Number Processors
17
Structures Simulations
ALE3D (LLNL structures code) test problems
Simulation with over 16 million degrees of freedom
Run on NERSC 512 processor T3E and LLNL ASCI Blue
Pacific
Primary PETSc tools: multigrid linear solvers (SLES)
18
100
200
300
400
Processors
500
19
Tutorial Approach
From the perspective of an application programmer:
Beginner
Advanced
user-defined customization of
algorithms and data structures
beginner
beginner
advanced
advanced
Intermediate
selecting options, performance
evaluation and tuning
2
intermediate
intermediate
Developer
advanced customizations,
intended primarily for use by
library developers
4
developer
developer
20
Incremental Application
Improvement
Beginner
Get the application up and walking
Intermediate
Experiment with options
Determine opportunities for improvement
Advanced
Extend algorithms and/or data structures as needed
Developer
Consider interface and efficiency issues for integration and
interoperability of multiple toolkits
http://www.mcs.anl.gov/petsc/docs/tutorials
21
Structure of PETSc
PETSc PDE Application Codes
ODE Integrators
Visualization
Nonlinear Solvers,
Interface
Unconstrained Minimization
Linear Solvers
Preconditioners + Krylov Methods
Object-Oriented
Grid
Matrices, Vectors, Indices
Management
Profiling Interface
Computation and Communication Kernels
MPI, MPI-IO, BLAS, LAPACK
22
Time Steppers
Other
Euler
Other
Additive
Schwartz
CG
Block
Jacobi
Compressed
Sparse Row
(AIJ)
CGS
Bi-CG-STAB
TFQMR
Preconditioners
Jacobi
Blocked Compressed
Sparse Row
(BAIJ)
ILU
ICC
Other
LU
(Sequential only)
Others
Matrix-free
Other
Matrices
Block
Diagonal
(BDIAG)
Distributed Arrays
Vectors
Richardson Chebychev
Dense
Index Sets
Indices
Block Indices
Stride
Other
23
Discretizations
Unstructured mesh generation and refinement tools
Load balancing tools
Sophisticated visualization capabilities
24
PETSc
KSP
Function
Evaluation
User code
Jacobian
Evaluation
PETSc code
PostProcessing
25
SAMRAI
Timestepping Solvers (TS)
Nonlinear Solvers (SNES)
SPAI
PETSc
KSP
ILUDTP
PETSc code
Function
Evaluation
Other Tools
Jacobian
Evaluation
PostProcessing
PVODE
26
Levels of Abstraction
in Mathematical Software
Application-specific interface
PETSc
emphasis
27
28
29
30
Performance Debugging
Integrated profiling using -log_summary
Profiling by stages of an application
User-defined events
31
Approach
Distributed memory, shared-nothing
Requires only a compiler (single node or processor)
Access to data on remote machines through MPI
32
Collectivity
MPI communicators (MPI_Comm) specify collectivity
(processes involved in a computation)
All PETSc routines for creating solver and data objects are
collective with respect to a communicator, e.g.,
VecCreate(MPI_Comm comm, int m, int M, Vec *x)
Use PETSC_COMM_WORLD for all processes (like
MPI_COMM_WORLD, but allows the same code to work when
PETSc is started with a smaller set of processes)
33
Hello World
#include petsc.h
int main( int argc, char *argv[] )
{
PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
PetscPrintf(PETSC_COMM_WORLD,Hello World\n);
PetscFinalize();
return 0;
}
34
35
36
Data Objects
Vectors (Vec)
focus: field data arising in nonlinear PDEs
Matrices (Mat)
focus: linear operators arising in nonlinear PDEs (i.e., Jacobians)
beginner
beginner
Object creation
beginner
beginner
Object assembly
intermediate
intermediate
Setting options
intermediate
intermediate
Viewing
advanced
advanced
User-defined customizations
tutorial
tutorialoutline:
outline:
data
dataobjects
objects
37
Vectors
What are PETSc vectors?
Fundamental objects for storing field solutions, right-hand
sides, etc.
Each process locally owns a subvector of contiguously
numbered global indices
proc 0
proc 1
proc 2
VecSetType(Vec,VecType)
Where VecType is
proc 3
proc 4
beginner
beginner
data
dataobjects:
objects:
vectors
vectors
38
Creating a vector
Use PETSc to get value
from command line
Vec x;
int n;
PetscInitialize(&argc,&argv,(char*)0,help);
PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
VecCreate(PETSC_COMM_WORLD,&x);
VecSetSizes(x,PETSC_DECIDE,n);
VecSetType(x,VEC_MPI);
VecSetFromOptions(x);
Global size
PETSc determines
local size
39
40
SMP
CPUs
CPUs
Cache
Cache
Main Memory
Main Memory
Interconnect
...
42
Address
Space
Process 1
A(10)
A(10)
Different Variables!
Integer A(10)
print *, A
Integer A(10)
do i=1,10
A(i) = i
enddo
...
43
Vector Assembly
A three step process
Each process tells PETSc what values to set or add to a vector component.
Once all values provided,
Begin communication between processes to ensure that values end up where
needed
(allow other operations, such as some computation, to proceed)
Complete the communication
VecSetValues(Vec,)
VecAssemblyBegin(Vec)
VecAssemblyEnd(Vec)
beginner
beginner
data
dataobjects:
objects:
vectors
vectors
44
beginner
beginner
data
dataobjects:
objects:
vectors
vectorsand
and
matrices
matrices
45
46
47
Operation
y = y + a*x
y = x + a*y
w = a*x + y
x = a*x
y=x
w_i = x_i *y_i
r = max x_i
x_i = s+x_i
x_i = |x_i |
r = ||x||
beginner
beginner
data
dataobjects:
objects:
vectors
vectors
48
ex2.c
- synchronized printing
Location: petsc/src/vec/examples/tutorials/
E
1
beginner
beginner
1
- basic vector routines
- parallel vector
data
dataobjects:
objects:
vectors
vectors
49
PetscInitialize(&argc,&argv,0,0);
PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
VecCreate(PETSC_COMM_WORLD,&x);
VecSetSizes(x,PETSC_DECIDE,n);
VecSetFromOptions(x);
VecSet(&one,x);
VecDot(x,x,&dot);
PetscPrintf(PETSC_COMM_WORLD,"Vector length %dn",(int)dot);
VecDestroy(x);
PetscFinalize();
return 0;
50
You must return the array to PETSc when you are done with it
VecRestoreArray( Vec, double *[] )
51
Example of VecGetArray
Vec
vec;
Double *avec;
VecCreate(PETSC_COMM_SELF,&vec);
VecSetSizes(vec,PETSC_DECIDE,n);
VecSetFromOptions(vec);
VecGetArray(vec,&avec);
/* compute with avec directly, e.g., */
PetscPrintf(PETSC_COMM_WORLD,
First element of local array of vec in each process is %f\n,
avec[0] );
VecRestoreArray(vec,&avec);
52
Matrices
What are PETSc matrices?
Fundamental objects for storing linear operators (e.g., Jacobians)
MatSetType(Mat,MatType)
where MatType is one of
default sparse AIJ: MPIAIJ, SEQAIJ
block sparse AIJ (for multi-component PDEs): MPIAIJ, SEQAIJ
symmetric block sparse AIJ: MPISBAIJ, SAEQSBAIJ
block diagonal: MPIBDIAG, SEQBDIAG
dense: MPIDENSE, SEQDENSE
matrix-free
etc.
MatSetFromOptions(Mat) lets you set the MatType at runtime.
beginner
beginner
data
dataobjects:
objects:
matrices
matrices
53
Matrix-vector multiplication
MatMult()
Matrix viewing
MatView()
data
dataobjects:
objects:
matrices
matrices
54
Matrix Assembly
Same form as for PETSc Vectors:
MatSetValues(Mat,)
MatAssemblyBegin(Mat)
MatAssemblyEnd(Mat)
beginner
beginner
data
dataobjects:
objects:
matrices
matrices
55
MatCreate(PETSC_COMM_WORLD,
PETSC_DECIDE,PETSC_DECIDE,n,n,&A);
MatSetFromOptions(A);
/* mesh interior */
Let PETSc decide
value[0] = -1.0; value[1] = 2.0; value[2] = -1.0;
to allocate matrix
if (rank == 0) { /* Only one process creates matrix */
for (i=1; i<n-2; i++) {
across processes
column[0] = i-1; column[1] = i; column[2] = i+1;
MatSetValues(A,1,&i,3,column,value,INSERT_VALUES);
}
}
/* also must set boundary points (code for global row 0 and n-1 omitted) */
MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
beginner
beginner
how
data
dataobjects:
objects:
matrices
matrices
56
data
dataobjects:
objects:
matrices
matrices
57
MatCreate(PETSC_COMM_WORLD,
PETSC_DECIDE,PETSC_DECIDE,n,n,&A);
MatSetFromOptions(A);
MatGetOwnershipRange(A,&start,&end);
Let PETSc decide how
/* mesh interior */
to allocate matrix
istart = start; if (start == 0) istart = 1;
iend = end; if (iend == n-1) iend = n-2;
across processes
value[0] = -1.0; value[1] = 2.0; value[2] = -1.0;
for (i=istart; i<iend; i++) {
column[0] = i-1; column[1] = i; column[2] = i+1;
MatSetValues(A,1,&i,3,column,value,INSERT_VALUES);
}
/* also must set boundary points (code for global row 0 and n-1 omitted) */
MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
data
MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
dataobjects:
objects:
beginner
beginner
matrices
matrices
58
59
3D compressible
Euler code
Block size 5
IBM Power2
80
MFlop
/sec
60
40
20
0
Basic
Matrix-vector products
Triangular solves
beginner
beginner
data
dataobjects:
objects:
matrices
matrices
60
Viewers
beginner
beginner
beginner
beginner
intermediate
intermediate
tutorial
tutorialoutline:
outline:
viewers
viewers
61
Viewer Concepts
Information about PETSc objects
runtime choices for solvers, nonzero info for matrices, etc.
Visualization
simple x-window graphics
vector fields
matrix sparsity structure
beginner
beginner
viewers
viewers
62
Default viewers
ASCII (sequential):
PETSC_VIEWER_STDOUT_SELF
ASCII (parallel):
PETSC_VIEWER_STDOUT_WORLD
X-windows:
PETSC_VIEWER_DRAW_WORLD
PETSC_VIEWER_ASCII_DEFAULT
PETSC_VIEWER_ASCII_MATLAB
PETSC_VIEWER_ASCII_COMMON
PETSC_VIEWER_ASCII_INFO
etc.
velocity: u
velocity: v
vorticity: temperature: T
beginner
beginner
viewers
viewers
63
-mat_view_draw
sparsity structure
-mat_view
data in ASCII
etc.
beginner
beginner
viewers
viewers
64
intermediate
intermediate
viewers
viewers
65
The easiest approach is to use the PETSc Makefile provided with the examples
Make sure that you have your PETSc environment setup correctly:
Copy an example file and the makefile from the directory to your local
directory:
cp ${PETSC_DIR}/src/vec/examples/tutorials/ex1.c .
cp ${PETSC_DIR}/src/vec/examples/tutorials/makefile .
Ensures that all of the correct libraries are used and that the correct compilation
options are used.
66
End of Day 1
67
important
importantconcepts
concepts
Usage Concepts
Context variables
Solver options
Callback routines
Customization
tutorial
tutorialoutline:
outline:
solvers
solvers
68
PETSc
Solve
Ax = b
Application
Initialization
PC
Evaluation of A and b
User code
beginner
beginner
KSP
PostProcessing
PETSc code
solvers:
solvers:
linear
linear
69
Linear Solvers
Goal: Support the solution of linear systems,
Ax=b,
particularly for sparse, parallel problems arising
within PDE-based models
User provides:
Code to evaluate A, b
beginner
beginner
solvers:
solvers:
linear
linear
70
2u k 2u 0
lim r
1/ 2
beginner
beginner
Real
iku 0
Imaginary
solvers:
solvers:
linear
linear
71
Natural ordering
beginner
beginner
Close-up
72
beginner
beginner
beginner
beginner
beginner
beginner
intermediate
intermediate
intermediate
intermediate
advanced
advanced
Matrix-free solvers
advanced
advanced
User-defined customizations
tutorial
tutorialoutline:
outline:
solvers:
solvers:
linear
linear
73
Objects In PETSc
How should a matrix be described in a program?
Old way:
Dense matrix:
double precision A(10,10)
Sparse matrix:
integer ia(11), ja(max_nz)
double precision a(max_nx)
New way:
Mat M
Benefit
Programs become independent of particular choices of data structure, making it
easier to modify and adapt
74
Operations In PETSc
How should operations like solve linear system be described in a
program?
Old way:
mpiaijgmres( ia, ja, a, comm, x, b, nlocal, nglobal, ndir, orthmethod, convtol,
&its )
New way:
SLESSolve( sles, b, x, &its )
Benefit
Programs become independent of particular choices of algorithm, making
it easier to explore algorithmic choices and to adapt to new methods.
75
Context Variables
Are the key to solver organization
Contain the complete state of an algorithm,
including
parameters (e.g., convergence tolerance)
functions that run the algorithm (e.g.,
convergence monitoring routine)
information about the current state (e.g., iteration
number)
beginner
beginner
solvers:
solvers:
linear
linear
76
Fortran version
call SLESCreate(PETSC_COMM_WORLD,sles,ierr)
beginner
beginner
solvers:
solvers:
linear
linear
77
SLES Structure
Each SLES object actually contains two other
objects:
KSP Krylov Space Method
The iterative method
The context contains information on method parameters (e.g.,
GMRES search directions), work spaces, etc
PC Preconditioners
Knows how to apply a preconditioner
The context contains information on the preconditioner, such
as what routine to call to apply it
78
Conjugate Gradient
GMRES
CG-Squared
Bi-CG-stab
Transpose-free QMR
etc.
beginner
beginner
Preconditioners (PC)
Block Jacobi
Overlapping Additive
Schwarz
ICC, ILU via BlockSolve95
ILU(k), LU (direct solve,
sequential only)
Arbitrary matrix
etc.
solvers:
solvers:
linear
linear
79
MatCreate(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE ,n,n,&A);
MatSetFromOptions(A);
/* (code to assemble matrix not shown) */
Indicate whether the preconditioner
VecCreate(PETSC_COMM_WORLD,&x);
has the same nonzero pattern as the
VecSetSizes(x,PETSC_DECIDE, n);
matrix each time a system is
VecSetFromOptions(x);
solved. This default works with all
VecDuplicate(x,&b);
preconditioners. Other values
/* (code to assemble RHS vector not shown)*/
(e.g.,
SAME_NONZERO_PATTERN)
can be used for particular
SLESCreate(PETSC_COMM_WORLD,&sles);
SLESSetOperators(sles,A,A,DIFFERENT_NONZERO_PATTERN); preconditioners. Ignored when
solving only one system
SLESSetFromOptions(sles);
SLESSolve(sles,b,x,&its);
SLESDestroy(sles);
beginner
beginner
solvers:
solvers:
linear
linear
80
sles
A
x, b
n, its, ierr
MatCreate( PETSC_COMM_WORLD,PETSC_DECIDE,n,n,A,ierr )
MatSetFromOptions( A, ierr )
VecCreate( PETSC_COMM_WORLD,x,ierr )
VecSetSizes( x, PETSC_DECIDE, n, ierr )
VecSetFromOptions( x, ierr )
VecDuplicate( x,b,ierr )
beginner
beginner
SLESCreate(PETSC_COMM_WORLD,sles,ierr)
SLESSetOperators(sles,A,A,DIFFERENT_NONZERO_PATTERN,ierr)
SLESSetFromOptions(sles,ierr)
SLESSolve(sles,b,x,its,ierr)
solvers:
SLESDestroy(sles,ierr)
solvers:
linear
linear
81
Customization Options
Command Line Interface
Applies same rule to all queries via a database
Enables the user to have complete control at runtime,
with no extra coding
Procedural Interface
Provides a great deal of control on a usage-by-usage
basis inside a single code
Gives full flexibility inside an application
beginner
beginner
solvers:
solvers:
linear
linear
82
-ksp_max_it <max_iters>
-ksp_gmres_restart <restart>
-pc_asm_overlap <overlap>
-pc_asm_type
[basic,restrict,interpolate,none]
etc ...
1
beginner
beginner intermediate
intermediate
solvers:
solvers:
linear
linear
83
-ksp_truemonitor
-ksp_xtruemonitor
beginner
beginner intermediate
intermediate advanced
advanced
solvers:
solvers:
linear
linear
84
solvers:
solvers:
linear
linear
85
beginner
beginner
solvers:
solvers:linear:
linear:
preconditioners
preconditioners
86
Helmholtz: Scalability
128x512 grid, wave number = 13, IBM SP
GMRES(30)/Restricted Additive Schwarz
1 block per proc, 1-cell overlap, ILU(1) subdomain solver
Procs
1
2
4
8
16
32
beginner
beginner
Iterations
221
222
224
228
229
230
Time (Sec)
163.01
81.06
37.36
19.49
10.85
6.37
Speedup
-
2.0
4.4
8.4
15.0
25.6
solvers:
solvers:
linear
linear
87
beginner
beginner
solvers:
solvers:
linear
linear
88
Procedural Interface
Runtime Option
-pc_type [lu,ilu,jacobi,
sor,asm,]
PCILUSetLevels( )
PCSORSetIterations( )
PCSORSetOmega( )
PCASMSetType( )
-pc_ilu_levels <levels>
2
-pc_sor_its <its>
-pc_sor_omega <omega>
-pc_asm_type [basic,
restrict,interpolate,none]
PCGetSubSLES( )
-sub_pc_type <pctype>
-sub_ksp_type
<ksptype>
-sub_ksp_rtol <rtol>
beginner
beginner intermediate
intermediate
solvers:
solvers:linear:
linear:
preconditioners
preconditioners
89
Procedural Interface
Runtime Option
KSPSetType( )
-ksp_type [cg,gmres,bcgs,
tfqmr,cgs,]
Set monitoring
routine
KSPSetMonitor( )
-ksp_monitor, ksp_xmonitor,
-ksp_truemonitor, ksp_xtruemonitor
KSPSetTolerances( )
-ksp_rtol <rt> -ksp_atol <at>
Set convergence
-ksp_max_its <its>
tolerances
KSPGMRESSetRestart( ) -ksp_gmres_restart <restart>
Set GMRES restart
parameter
-ksp_unmodifiedgramschmidt
Set orthogonalization KSPGMRESSet
Orthogonalization( )
-ksp_irorthog
routine for GMRES
beginner
beginner intermediate
intermediate
90
Why Polymorphism?
Programs become independent of the choice of
algorithm
Consider the question:
What is the best combination of iterative method and
preconditioner for my problem?
New way:
91
intermediate
intermediate
solvers:
solvers:
linear
linear
92
intermediate
intermediate
solvers:
solvers:
linear
linear
93
SLESSetOperators(SLES sles,
advanced
advanced
Mat A,
Mat P,
MatStructure flag)
solvers:
solvers:
linear
linear
94
Matrix-Free Solvers
Use shell matrix data structure
MatCreateShell(, Mat *mfctx)
solvers:
solvers:
linear
linear
95
User-defined Customizations
Restricting the available solvers
Customize PCRegisterAll( ), KSPRegisterAll( )
advanced
advanced developer
developer
solvers:
solvers:
linear
linear
96
ex4.c
ex9.c
E systems
ex22.c
ex15.c
1
beginner
beginner intermediate
intermediate advanced
advanced
E - on-line exercise
solvers:
solvers:
linear
linear
97
Now What?
If you have a running program, are you done?
Yes, if your program answers your question.
No, if you now need to run much larger problems or many more
problems.
98
Performance Tuning:
intermediate
intermediate
Matrix optimizations
intermediate
intermediate
Application optimizations
advanced
advanced
Algorithmic tuning
tutorial
tutorialoutline:
outline:
profiling
profilingand
and
performance
performancetuning
tuning
99
Profiling
Integrated monitoring of
time
floating-point performance
memory usage
communication
profiling
profilingand
and
performance
performancetuning
tuning
100
User-defined Events
int USER_EVENT;
int user_event_flops
PetscLogEventRegister(&USER_EVENT,User
event name, eventColor);
PetscLogEventBegin(USER_EVENT,0,0,0,0);
[ code to monitor]
PetscLogFlops(user_evnet_flops);
PetscLogEvent End(USER_EVENT,0,0,0,0);
intermediate
intermediate
profiling
profilingand
and
performance
performancetuning
tuning
101
beginner
beginner
beginner
beginner
beginner
beginner
intermediate
intermediate
advanced
advanced
Matrix-free solvers
advanced
advanced
User-defined customizations
tutorial
tutorialoutline:
outline:
solvers:
solvers:
nonlinear
nonlinear
102
PC
Application
Initialization
PETSc
KSP
Function
Evaluation
User code
beginner
beginner
Jacobian
Evaluation
PETSc code
PostProcessing
solvers:
solvers:
nonlinear
nonlinear
103
Nonlinear Solvers
Goal: For problems arising from PDEs,
support the general solution of F(u) = 0
User provides:
Code to evaluate F(u)
Code to evaluate Jacobian of F(u) (optional)
or use sparse finite difference approximation
or use automatic differentiation
AD support via collaboration with P. Hovland and B. Norris
Coming in next PETSc release via automated interface to
ADIFOR and ADIC (see http://www.mcs.anl.gov/autodiff)
beginner
beginner
solvers:
solvers:
nonlinear
nonlinear
104
beginner
beginner
solvers:
solvers:
nonlinear
nonlinear
105
beginner
beginner
Solution Components
velocity: u
vorticity:
velocity: v
temperature: T
solvers:
solvers:
nonlinear
nonlinear
106
snes;
J;
x, F;
n, its;
cationCtx usercontext;
eate(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE ,n,n,&J);
etFromOptions(J);
eate(PETSC_COMM_WORLD,&x);
tSizes(x,PETSC_DECIDE,n);
tFromOptions(x);
uplicate(x,&F);
Create(PETSC_COMM_WORLD,&snes);
SetFunction(snes,F,EvaluateFunction,usercontext);
SetJacobian(snes,J,J,EvaluateJacobian,usercontext);
SetFromOptions(snes);
Solve(snes,x,&its);
Destroy(snes);
beginner
beginner
solvers:
solvers:
nonlinear
nonlinear
107
call MatCreate(PETSC_COMM_WORLD,PETSC_DECIDE,
PETSC_DECIDE,n,n,J,ierr)
call MatSetFromOptions( J, ierr )
call VecCreate(PETSC_COMM_WORLD,x,ierr)
call VecSetSizes(x,PETSC_DECIDE,n,ierr)
call VecSetFromOptions(x,ierr)
call VecDuplicate(x,F,ierr)
call
call
call
call
call
call
beginner
beginner
SNESCreate(PETSC_COMM_WORLD, snes,ierr)
SNESSetFunction(snes,F,EvaluateFunction,PETSC_NULL,ierr)
SNESSetJacobian(snes,J,J,EvaluateJacobian,PETSC_NULL,ierr)
SNESSetFromOptions(snes,ierr)
SNESSolve(snes,x,its,ierr)
SNESDestroy(snes,ierr)
solvers:
solvers:
nonlinear
nonlinear
108
important
importantconcept
concept
uservector - vector to store function values
userfunction - name of the users function
usercontext - pointer to private data for the users function
solvers:
solvers:
nonlinear
nonlinear
109
110
beginner
beginner
solvers:
solvers:
nonlinear
nonlinear
111
solvers:
solvers:
nonlinear
nonlinear
112
solvers:
solvers:
nonlinear
nonlinear
113
beginner
beginner intermediate
intermediate
solvers:
solvers:
nonlinear
nonlinear
114
2
SNESCubicLineSearch( ) - cubic line search
SNESQuadraticLineSearch( ) - quadratic line search
SNESNoLineSearch( ) - full Newton step
SNESNoLineSearchNoNorms( ) - full Newton step but calculates
no norms (faster in parallel, useful when using a fixed number of
Newton iterations instead of usual convergence testing)
YourOwnFavoriteLineSearchRoutine( )
2
intermediate
intermediate advanced
advanced
solvers:
solvers:
nonlinear
nonlinear
115
solvers:
solvers:
nonlinear
nonlinear
116
Procedural Interface
Runtime Option
SNESSetType( )
SNESSetMonitor( )
-snes_type [ls,tr,umls,umtr,]
-snes_monitor
1
snes_xmonitor,
Set convergence
tolerances
Set line search routine
View solver options
Set linear solver options
SNESSetTolerances( )
beginner
beginner intermediate
intermediate
SNESSetLineSearch( )
SNESView( )
SNESGetSLES( )
SLESGetKSP( )
SLESGetPC( )
solvers:
solvers:
nonlinear
nonlinear
117
Location: petsc/src/snes/examples/tutorials/
ex1.c, ex1f.F
ex2.c
E
1
- basic uniprocess codes
- uniprocess nonlinear PDE
(1 DoF per node)
- parallel nonlinear PDE (1 DoF
ex18.c
ex19.c
with
beginner
beginner intermediate
intermediate
E - on-line exercise
solvers:
solvers:
nonlinear
nonlinear
118
beginner
beginner
beginner
beginner
beginner
beginner
intermediate
intermediate
advanced
advanced
119
PETSc
Solve
U t = F(U,Ux,Uxx)
KSP
Function
Evaluation
User code
beginner
beginner
Jacobian
Evaluation
PETSc code
PostProcessing
solvers:
solvers:
timestepping
timestepping
120
Timestepping Solvers
Goal: Support the (real and pseudo) time
evolution of PDE systems
Ut = F(U,Ux,Uxx,t)
User provides:
Code to evaluate F(U,Ux,Uxx,t)
Code to evaluate Jacobian of F(U,Ux,Uxx,t)
or use sparse finite difference approximation
or use automatic differentiation (coming soon!)
beginner
beginner
solvers:
solvers:
timestepping
timestepping
Ut= U Ux + Uxx
U(0,x) = sin(2x)
U(t,0) = U(t,1)
beginner
beginner
solvers:
solvers:
timestepping
timestepping
122
solvers:
solvers:
timestepping
timestepping
123
Timestepping Solvers
Euler
Backward Euler
Pseudo-transient continuation
Interface to PVODE, a sophisticated parallel ODE
solver package by Hindmarsh et al. of LLNL
Adams
BDF
beginner
beginner
solvers:
solvers:
timestepping
timestepping
124
Timestepping Solvers
Allow full access to all of the PETSc
nonlinear solvers
linear solvers
distributed arrays, matrix assembly tools, etc.
beginner
beginner
solvers:
solvers:
timestepping
timestepping
125
TSCreate( )
TSSetRHSFunction( )
TSSetRHSJacobian( )
TSSetFromOptions( )
TSSolve( )
TSView( )
TSDestroy( )
beginner
beginner
- Create TS context
- Set function eval. routine
- Set Jacobian eval. routine
- Set runtime solver options
for [TS,SNES,SLES,KSP,PC]
- Run timestepping solver
- View solver options
actually used at runtime
(alternative: -ts_view)
- Destroy solver
solvers:
solvers:
timestepping
timestepping
126
Procedural
Interface
TSSetDuration ( )
TSView( )
View solver options
Set timestepping solver TSGetSNES( )
SNESGetSLES( )
options
SLESGetKSP( )
SLESGetPC( )
beginner
beginner intermediate
intermediate
Runtime Option
-ts_ type [euler,beuler,pseudo,]
1
-ts_monitor
-ts_xmonitor,
-ts_max_steps <maxsteps>
-ts_max_time <maxtime>
-ts_view
-snes_monitor -snes_rtol <rt>
-ksp_type <ksptype>
2
-ksp_rtol <rt>
-pc_type <pctype>
solvers:
solvers:
timestepping
timestepping
127
ex2.c, ex2f.F
ex3.c
ex4.c
beginner
beginner intermediate
intermediate
E - on-line exercise
solvers:
solvers:
timestepping
timestepping
128
Mesh Definitions:
beginner
beginner
data
datalayout
layout
129
Structured Meshes
beginner
beginner
data
datalayout
layout
130
Unstructured Meshes
One is always free to
manage the mesh data as
if unstructured
PETSc does not currently
have high-level tools for
managing such meshes
PETSc can manage
unstructured meshes
though lower-level
VecScatter utilities
beginner
beginner
data
datalayout
layout
131
Semi-Structured Meshes
beginner
beginner
data
datalayout
layout
132
Mesh Types
Structured
DA objects
Unstructured
VecScatter objects
important
importantconcepts
concepts
Usage Concepts
Geometric data
Data structure creation
Ghost point updates
Local numerical computation
tutorial
tutorialoutline:
outline:
data
layout
data layout
133
Ghost Values
Local node
Ghost
node
data
datalayout
layout
stencil
[implicit]
DACreate( )
DA
AO
Ghost Point
Updates
DAGlobalToLocal( )
structured meshes
elements
edges
vertices
VecScatter
VecScatterCreate( ) AO
Loops over
I,J,K
indices
VecScatter( )
unstructured meshes
Local
Numerical
Computation
Loops over
entities
beginner
beginner intermediate
intermediate
data
datalayout
layout
135
beginner
beginner
beginner
beginner
DA creation
intermediate
intermediate
intermediate
intermediate
Viewing
tutorial
tutorialoutline:
outline:
data
layout:
data layout:
distributed
distributedarrays
arrays
136
DA
AO
Ghost Point
Updates
DAGlobalToLocal( )
structured meshes
beginner
beginner
Local
Numerical
Computation
Loops over
I,J,K
indices
data
datalayout:
layout:
distributed
distributedarrays
arrays
137
9
0
138
9 10 11
6 7 8
Global Representation:
Proc 0
3 4 5
0 1 2
0 1 2 34 5
Proc 1
Proc 0
6 7 8
3 4 5
0 1 2
6 7 8
3 4 5
0 1 2
Proc 0
Proc 1
Local Representations:
Proc 1
3 4 5 6 7 8 9 1 11
0
0 1 2 3 4 5 6 7 8
0 1 23 4 5 6 7 8
0 1 2 3 4
beginner
beginner
6 7 8 9 10 11
Proc 0
5 6 7 8
data
datalayout:
layout:
distributed
distributedarrays
arrays
139
data
datalayout:
layout:
distributed
distributedarrays
arrays
140
Distributed Arrays
Data layout and ghost values
Proc 10
Proc 0
Proc 1
Box-type
stencil
beginner
beginner
Proc 10
Proc 0
Proc 1
Star-type
stencil
data
datalayout:
layout:
distributed
distributedarrays
arrays
141
data
datalayout:
layout:
distributed
distributedarrays
arrays
142
DACreate1d(,*DA)
DACreate1d(MPI_Comm
comm,DAPeriodicType wrap,int M,int dof,int
s,int *lc,DA *inra)
MPI_Comm processes containing array
DA_[NONPERIODIC,XPERIODIC]
beginner
beginner
143
DACreate2d(,*DA)
DACreate2d(MPI_Comm comm,DAPeriodicType
wrap,DAStencilType stencil_type, int M,int N,int
m,int n,int dof,int s,int *lx,int *ly,DA *inra)
DA_[NON,X,Y,XY]PERIODIC
DA_STENCIL_[STAR,BOX]
data
datalayout:
layout:
distributed
distributedarrays
arrays
144
DAGlobalToLocal End(DA,)
Takes same arguments
beginner
beginner
data
datalayout:
layout:
distributed
distributedarrays
arrays
145
146
Proc 3
Proc 2
Proc 3
26 27 28
21 22 23
16 17 18
29 30
24 25
19 20
22 23 24
19 20 21
16 17 18
29 30
27 28
25 26
11 12 13
6 7 8
1 2 3
14 15
9 10
4 5
Proc 0
Proc1
7
4
8
5
9
6
14 15
12 13
10 11
Proc 0
Proc1
147
data
datalayout:
layout:
distributed
distributedarrays
arrays
148
149
End of Day 2
150
Unstructured Meshes
Setting up communication patterns is much more
complicated than the structured case due to
mesh dependence
discretization dependence
cell-centered
vertex-centered
cell and vertex centered (e.g., staggered grids)
mixed triangles and quadrilaterals
data
datalayout:
layout:
vector
vectorscatters
scatters
stencil
[implicit]
DACreate( )
DA
AO
Ghost Point
Updates
DAGlobalToLocal( )
structured mesh
elements
edges
vertices
VecScatter
VecScatterCreate( ) AO
Loops over
I,J,K
indices
VecScatter( )
unstructured mesh
Local
Numerical
Computation
Loops over
entities
beginner
beginner intermediate
intermediate
data
datalayout
layout
152
VecScatter:
update ghost points using vector scatters/gathers
ISLocalToGlobalMapping
map from a local (calling process) numbering of indices
to a global (across-processes) numbering
intermediate
intermediate
data
datalayout:
layout:
vector
vectorscatters
scatters
153
intermediate
intermediate
data
datalayout:
layout:
vector
vectorscatters
scatters
154
Proc1
11
10
6
9
7
8
data
datalayout:
layout:
vector
vectorscatters
scatters
155
Proc 1
10
11
data
datalayout:
layout:
vector
vectorscatters
scatters
156
Process 1
application
numbers
n_local: 6
app_numbers: {3,4,6,7,9,8}
petsc_numbers: {6,7,8,9,10,11}
intermediate
intermediate
Proc 0
0
Proc 1
10
11
11 10
3
6
9
4
7
8
data
datalayout:
layout:
vector
vectorscatters
scatters
157
intermediate
intermediate
int nlocal,
int app_numbers[ ],
int petsc_numbers[ ],
AO *ao );
data
datalayout:
layout:
vector
vectorscatters
scatters
158
intermediate
intermediate
data
datalayout:
layout:
vector
vectorscatters
scatters
159
Neighbors
using global PETSc numbers (ordering
of the global PETSc vector)
Process 0
Process1
10
10
11
intermediate
intermediate
ghost cells
data
datalayout:
layout:
vector
vectorscatters
scatters
160
Local Numbering
Proc 0
Proc1
ghost cells
data
datalayout:
layout:
vector
vectorscatters
scatters
161
PETSc Ordering
13
14
15
16
15
16
10
11
12
13
14
11
12
10
12
12
11
11
10
10
Local points
at the end
162
Local representation
sequential vectors with room for ghost points
used to evaluate functions, Jacobians, etc.
intermediate
intermediate
data
datalayout:
layout:
vector
vectorscatters
scatters
163
6 7 8 9 10 11
Proc 0
Proc1
Local Representations:
0 1 2 3 4 5 6 8 10
0 1 2 3 4 5 6 7 8
Proc1
intermediate
intermediate
Proc 0
6 7 8 9 10 11 1 3 5
0 1 2 3 4 5 6 7 8
data
datalayout:
layout:
vector
vectorscatters
scatters
164
Creating Vectors
Sequential
VecCreateSeq(PETSC_COMM_SELF, 9, Vec
*lvec);
Parallel
VecCreateMPI(PETSC_COMM_WORLD,
6,PETSC_DETERMINE,Vec
*gvec)
intermediate
intermediate
data
datalayout:
layout:
vector
vectorscatters
scatters
165
Process 1
ISCreateStride
int indices = {6,7,8,9,10,11,1,3,5};
() - Specify local
ISCreateGeneral(PETSC_COMM_WORLD,
numbers of
9, indices, IS *isg);
locally owned
ISCreateStride(PETSC_COMM_SELF, 9,0,1,IS*
isl);including
cells,
ghost cells
intermediate
intermediate
data
datalayout:
layout:
vector
vectorscatters
scatters
166
IS gis,
Vec lvec,
IS lis
VecScatter gtol);
data
datalayout:
layout:
vector
vectorscatters
scatters
167
Vec gvec,
Vec lvec,
INSERT_VALUES
SCATTER_FORWARD);
VecScatterEnd(...);
intermediate
intermediate
data
datalayout:
layout:
vector
vectorscatters
scatters
168
Vec lvec,
Vec gvec,
ADD_VALUES,
SCATTER_REVERSE);
VecScatterEnd(...);
intermediate
intermediate
data
datalayout:
layout:
vector
vectorscatters
scatters
169
Set mapping
VecSetLocalToGlobalMapping(Vec gvec,
ISLocalToGlobalMapping lgmap);
MatSetLocalToGlobalMapping(Mat gmat,
ISLocalToGlobalMapping lgmap);
data
datalayout:
layout:
vector
vectorscatters
scatters
170
intermediate
intermediate
data
datalayout:
layout:
vector
vectorscatters
scatters
stencil
[implicit]
DACreate( )
DA
AO
Ghost Point
Updates
DAGlobalToLocal( )
structured mesh
elements
edges
vertices
VecScatter
VecScatterCreate( ) AO
Loops over
I,J,K
indices
VecScatter( )
unstructured mesh
Local
Numerical
Computation
Loops over
entities
beginner
beginner intermediate
intermediate
data
datalayout
layout
172
173
tutorial outline:
data objects:
matrix partitioning
and coloring
174
intermediate
intermediate
data
dataobjects:
objects:
matrices:
matrices:
partitioning
partitioning
175
intermediate
intermediate
data
dataobjects:
objects:
matrices:
matrices:
partitioning
partitioning
176
MatPartitioningSetVertexWeights(
MatPartitioning matpart,
int *weights);
MatPartitioningSetFromOptions(
MatPartitioning matpart);
intermediate
intermediate
data
dataobjects:
objects:
matrices:
matrices:
partitioning
partitioning
177
Partitioning
MatPartitioningApply(
MatPartitioning matpart,
IS* processforeachlocalnode);
MatPartitioningDestroy(
MatPartitioning matpart);
intermediate
intermediate
data
dataobjects:
objects:
matrices:
matrices:
partitioning
partitioning
178
MPI_Comm comm,
int numberlocalrows,
int numbercolums,
int rowindices[ ],
int columnindices[ ],
int values[ ],
Mat *adj)
intermediate
intermediate
data
dataobjects:
objects:
matrices:
matrices:
partitioning
partitioning
179
intermediate
intermediate
data
dataobjects:
objects:
matrices:
matrices:
coloring
coloring
180
DAGetMatrix(
DA da,
MatType mtype,
Mat *sparsematrix );
intermediate
intermediate
data
dataobjects:
objects:
matrices:
matrices:
coloring
coloring
181
MATCOLORING_NATURAL
MATCOLORING_SL
MATCOLORING_LF
MATCOLORING_ID
ISColoring *coloringinfo)
matrices:
matrices:
coloring
coloring
182
MatFDColoringSetFunction(
MatFDColoring matfd,
int (*f)(void),void *fctx)
MatFDColoringSetFromOptions(
MatFDColoring)
intermediate
intermediate
data
dataobjects:
objects:
matrices:
matrices:
coloring
coloring
183
SNES snes,
Mat A ,
Mat J,
SNESDefaultComputeJacobianColor( ),
fdcoloring);
Mat J,
MatFDColoring coloring,
Vec x1,
MatStructure *flag,
void *sctx)
data
dataobjects:
objects:
matrices:
matrices:
coloring
coloring
184
velocity: u
velocity: v
[u,v,,T]
vorticity: temperature: T
1
beginner
beginner intermediate
intermediate
solvers:
solvers:
nonlinear
nonlinear
185
Experimentation
1
beginner
beginner intermediate
intermediate
solvers:
solvers:
nonlinear
nonlinear
186
Main Routine
PC
Application
Initialization
PETSc
KSP
Function
Evaluation
C
User code
Jacobian
Evaluation
PostProcessing
D
PETSc code
solvers:
solvers:
nonlinear
nonlinear
187
Driven Cavity:
Running the program (1)
Matrix-free Jacobian approximation with no preconditioning
(via -snes_mf) does not use explicit Jacobian
evaluation
1 process: (thermally-driven flow)
mpirun -np 1 ex19 -snes_mf -snes_monitor -grashof
1000.0 -lidvelocity 0.0
solvers:
solvers:
nonlinear
nonlinear
188
Driven Cavity:
Running the program (2)
Use MatFDColoring for sparse finite difference Jacobian
approximation; view SNES options used at runtime
mpirun ex8 -snes_view -mat_view_info
intermediate
intermediate
solvers:
solvers:
nonlinear
nonlinear
189
beginner
beginner
developer
developer
tutorial
tutorialoutline:
outline:
debugging
debuggingand
anderrors
errors
190
Debugging
Support for parallel debugging
-start_in_debugger [gdb,dbx,noxterm]
-on_error_attach_debugger
[gb,dbx,noxterm]
-on_error_abort
-debugger_nodes 0,1
-display machinename:0.0
debugging
debuggingand
anderrors
errors
191
beginner
beginner
debugging
debuggingand
anderrors
errors
192
beginner
beginner
debugging
debuggingand
anderrors
errors
193
beginner
beginner
debugging
debuggingand
anderrors
errors
194
beginner
beginner
debugging
debuggingand
anderrors
errors
195
Performance Requires
Managing Memory
Real systems have many levels of memory
Programming models try to hide memory hierarchy
Except Cregister
intermediate
intermediate
profiling
profilingand
and
performance
performancetuning
tuning
196
profiling
profilingand
and
performance
performancetuning
tuning
197
Computation
nnz multiply-add (MA)
intermediate
intermediate
profiling
profilingand
and
performance
performancetuning
tuning
198
profiling
profilingand
and
performance
performancetuning
tuning
199
Number
of Vectors
1
4
1
4
Mflops
Ideal
Achieved
49
45
182
120
64
55
236
175
profiling
profilingand
and
performance
performancetuning
tuning
200
profiling
profilingand
and
performance
performancetuning
tuning
201
intermediate
intermediate
another sample
nonzero pattern
profiling
profilingand
and
performance
performancetuning
tuning
202
intermediate
intermediate
profiling
profilingand
and
performance
performancetuning
tuning
203
diagonal portions
off-diagonal portions
204
profiling
profilingand
and
performance
performancetuning
tuning
205
Verifying Predictions
Use runtime option: -log_info
Output:
[proc #] Matrix size: % d X % d; storage space: % d
unneeded, % d used
[proc #] Number of mallocs during MatSetValues( ) is
%d
intermediate
intermediate
profiling
profilingand
and
performance
performancetuning
tuning
206
intermediate
intermediate
profiling
profilingand
and
performance
performancetuning
tuning
207
Cache-based CPUs
memory
slow
intermediate
intermediate
cache
floating
registers point
units
fast
profiling
profilingand
and
performance
performancetuning
tuning
208
Variable Interleaving
real u(maxn), v(maxn)
V V V
U V
U V
UV
UV
U
VU
U
VU
V
UV
V
UV
V
UV
V
UV
U
UU U
Doubles number of cache misses
Halves performance
profiling
profilingand
and
performance
performancetuning
tuning
209
Techniques:
Interleaving Field Variables
Not
Not
Instead
double precision fields(nc,largesize)
intermediate
intermediate
profiling
profilingand
and
performance
performancetuning
tuning
210
Techniques:
Reordering to Reuse Cache Data
Sort objects so that repeated use occurs together
e.g., sort edges by the first vertex they contain
intermediate
intermediate
profiling
profilingand
and
performance
performancetuning
tuning
211
intermediate
intermediate
profiling
profilingand
and
performance
performancetuning
tuning
212
Effects on Performance:
Sample Results on IBM SP
120
100
80
Time (seconds)
60
40
intermediate
intermediate
All
I nterlaced
reordered
I nterlaced
blocking
I nterlaced
Basic
20
profiling
profilingand
and
performance
performancetuning
tuning
213
Summary
New features
Interfacing with other packages
Extensibility issues
References
tutorial
tutorialoutline:
outline:
conclusion
conclusion
214
Summary
Creating data objects
Setting algorithmic options for linear, nonlinear
and ODE solvers
Using callbacks to set up the problems for
nonlinear and ODE solvers
Managing data layout and ghost point
communication
Evaluating parallel functions and Jacobians
Consistent profiling and error handling
216
Multigrid Structured Mesh Support:
Proc 10
Proc 0 Proc 1
217
Multigrid Structured Mesh Support:
lambda = user->param;
hx
= 1.0/(info->mx-1);
hy
= 1.0/(info->my-1);
for (j=info->ys; j<info->ys+info->ym; j++) {
for (i=info->xs; i<info->xs+info->xm; i++) {
f[j][i] = u[j][i] u[j-1][i] .
}
}
218
Multigrid Structured Mesh Support:
219
Nonlinear Example
2-dim nonlinear problem with 4 degrees of freedom per mesh point
Function() and Jacobian() are user-provided functions
DMMG dmmg;
DMMGCreate(comm,nlevels,user,&dmmg)
DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_STAR,4,
4,PETSC_DECIDE,PETSC_DECIDE,4,1,0,0,&da)
DMMGSetDM(dmmg,da)
DMMGSetSNESLocal(dmmg,Function,Jacobian,0,0)
DMMGSolve(dmmg)
solution = DMMGGetx(damg)
220
221
Optimization software
AMG
TAO
BlockSolve95
Veltisto
DSCPACK
hypre
Overture
ILUTP
SAMRAI
LUSOL
SPAI
SPOOLES
SuperLU, SuperLU_Dist
SUMAA3d
ODE solvers
PVODE
Others
Matlab
ParMETIS
222
Using PETSc with Other Packages:
Linear Solvers
Interface Approach
Based on interfacing at the matrix level, where external linear solvers typically use
a variant of compressed sparse row matrix storage
Usage
Install PETSc indicating presence of any optional external packages in the file
petsc/bmake/$PETSC_ARCH/base.site, e.g.,
PETSC_HAVE_SPAI = -DPETSC_HAVE_SPAI
SPAI_INCLUDE = -I/home/username/software/spai_3.0/include
SPAI_LIB = /home/username/software/spai_3.0/lib/$
{PETSC_ARCH}/libspai.a
223
Using PETSc with Other Packages:
Linear Solvers
AMG
Algebraic multigrid code by J. Ruge, K. Steuben, and R. Hempel
(GMD)
http://www.mgnet.org/mgnet-codes-gmd.html
PETSc interface by D. Lahaye (K.U.Leuven), uses MatSeqAIJ
BlockSolve95
ILUTP
Drop tolerance ILU by Y. Saad (Univ. of Minnesota), in SPARSKIT
http://www.cs.umn.edu/~saad/
PETSc interface uses MatSeqAIJ
224
Using PETSc with Other Packages:
SPAI
Sparse approximate inverse code by S. Barnhard (NASA Ames) and M. Grote (ETH Zurich)
http://www.sam.math.ethz.ch/~grote/spai
PETSc interface converts from any matrix format to SPAI matrix
SuperLU
Parallel, sparse LU
J. Demmel, J. Gilbert, (U.C. Berkeley) and X. Li (NERSC)
http://www.nersc.gov/~xiaoye/SuperLU
PETSc interface uses MatSeqAIJ
Currently only sequential interface supported; parallel interface under development
225
Using PETSc with Other Packages:
226
TAO Interface
TAO_SOLVER
Vec
vectors */
ApplicationCtx
tao;
x, g;
usercontext;
/* optimization solver */
/* solution and gradient
/* user-defined context */
TaoInitialize();
/* Initialize Application -- Create variable and gradient vectors
x and g */ ...
TaoCreate(MPI_COMM_WORLD,tao_lmvm,&tao);
TaoSetFunctionGradient(tao,x,g, FctGrad,
(void*)&usercontext);
TaoSolve(tao);
/* Finalize application -- Destroy vectors x and g */ ...
TaoDestroy(tao);
TaoFinalize();
software
software
interfacing:
interfacing:
TAO
TAO
227
Using PETSc with Other Packages:
PVODE
http://www.llnl.gov/CASC/PVODE
Interface Approach
PVODE
PETSc
Usage
TSCreate(MPI_Comm,TS_NONLINEAR,&ts)
TSSetType(ts,TS_PVODE)
.. regular TS functions
TSPVODESetType(ts,PVODE_ADAMS)
http://www.mcs.anl.gov/sumaa3d
SAMRAI
Structured adaptive mesh refinement
R. Hornung, S. Kohn (LLNL)
http://www.llnl.gov/CASC/SAMRAI
Overture
Structured composite meshes and discretizations
D. Brown, W. Henshaw, D. Quinlan (LLNL)
http://www.llnl.gov/CASC/Overture
229
Using PETSc with Other Packages:
Matlab
Matlab
http://www.mathworks.com
Interface Approach
Usage
PetscMatlabEngineCreate(MPI_Comm,machinename,
PetscMatlabEngine eng)
PetscMatlabEnginePut(eng,PetscObject obj)
Vector
Matrix
PetscMatlabEngineEvaluate(eng,R = QR(A);)
PetscMatlabEngineGet(eng,PetscObject obj)
230
Using PETSc with Other Packages:
Interface Approach
Use PETSc MatPartitioning() interface and MPIAIJ or MPIAdj matrix
formats
Usage
MatPartitioningCreate(MPI_Comm,MatPartitioning ctx)
MatPartitioningSetAdjacency(ctx,matrix)
Optional MatPartitioningSetVertexWeights(ctx,weights)
MatPartitioningSetFromOptions(ctx)
MatPartitioningApply(ctx,IS *partitioning)
231
Recent Additions
Hypre (www.llnl.gov/casc/hypre) via PCHYPRE, includes
EUCLID (parallel ILU(k) by David Hysom)
BoomerAMG
PILUT
232
Extensibility Issues
Most PETSc objects are designed to allow one to
drop in a new implementation with a new set of
data structures (similar to implementing a new
class in C++).
Heavily commented example codes include
Krylov methods: petsc/src/sles/ksp/impls/cg
preconditioners: petsc/src/sles/pc/impls/jacobi
233
Caveats Revisited
Developing parallel, non-trivial PDE solvers that
deliver high performance is still difficult, and
requires months (or even years) of concentrated
effort.
PETSc is a toolkit that can ease these difficulties
and reduce the development time, but it is not a
black-box PDE solver nor a silver bullet.
Users are invited to interact directly with us
regarding correctness and performance issues by
writing to [email protected].
234
References
Documentation: http://www.mcs.anl.gov/petsc/docs
Publications: http://www.mcs.anl.gov/petsc/publications
Research and publications that make use PETSc