Example 1
This is a two processor example. Each processor owns one box in the grid. For reference, the two grid boxes are those in the example diagram in the struct interface chapter of the User's Manual. Note that in this example code, we have used the two boxes shown in the diagram as belonging to processor 0 (and given one box to each processor). The solver is PCG with no preconditioner.
We recommend viewing examples 1-4 sequentially for a nice overview/tutorial of the struct interface.
Example 2
This is a two processor example and is similar to the previous structured interface example (Example 1). However, in this case the grid boxes are exactly those in the example diagram in the struct interface chapter of the User's Manual. (Processor 0 owns two boxes and processor 1 owns one box.) The solver is PCG with SMG preconditioner.
We recommend viewing example 1 before viewing this example.
Example 3
This code solves a system corresponding to a discretization of the Laplace equation with zero boundary conditions on the unit square. The domain is split into an N x N processor grid. Thus, the given number of processors should be a perfect square. Each processor's piece of the grid has n x n cells with n x n nodes connected by the standard 5-point stencil. Note that the struct interface assumes a cell-centered grid, and, therefore, the nodes are not shared. This example demonstrates more features than the previous two struct examples (Example 1 and Example 2). Two solvers are available.
To incorporate the boundary conditions, we do the following: Let x_i and x_b be the interior and boundary parts of the solution vector x. We can split the matrix A as
A = [A_ii A_ib; A_bi A_bb]. Let u_0 be the Dirichlet B.C. We can simply say that x_b = u_0. If b_i is the right-hand side, then we just need to solve in the interior:
A_ii x_i = b_i - A_ib u_0. For this partitcular example, u_0 = 0, so we are just solving A_ii x_i = b_i.
We recommend viewing examples 1 and 2 before viewing this example.
Example 4
This example differs from the previous structured example (Example 3) in that a more sophisticated stencil and boundary conditions are implemented. The method illustrated here to implement the boundary conditions is much more general than that in the previous example. Also symmetric storage is utilized when applicable.
This code solves the convection-reaction-diffusion problem div (-K grad u + B u) + C u = F in the unit square with boundary condition u = U0. The domain is split into N x N processor grid. Thus, the given number of processors should be a perfect square. Each processor has a n x n grid, with nodes connected by a 5-point stencil. Note that the struct interface assumes a cell-centered grid, and, therefore, the nodes are not shared.
To incorporate the boundary conditions, we do the following: Let x_i and x_b be the interior and boundary parts of the solution vector x. If we split the matrix A as
A = [A_ii A_ib; A_bi A_bb], then we solve
[A_ii 0; 0 I] [x_i ; x_b] = [b_i - A_ib u_0; u_0]. Note that this differs from the previous example in that we are actually solving for the boundary conditions (so they may not be exact as in ex3, where we only solved for the interior). This approach is useful for more general types of b.c.
A number of solvers are available. More information can be found in the Solvers and Preconditioners chapter of the User's Manual.
We recommend viewing examples 1, 2, and 3 before viewing this example.
Example 5
This example solves the 2-D Laplacian problem with zero boundary conditions on an nxn grid. The number of unknowns is N=n^2. The standard 5-point stencil is used, and we solve for the interior nodes only.
This example solves the same problem as Example 3. Available solvers are AMG, PCG, and PCG with AMG or Parasails preconditioners.
Example 5 (Babel-based C version)
This example solves the 2-D Laplacian problem with zero boundary conditions on an nxn grid. The number of unknowns is N=n^2. The standard 5-point stencil is used, and we solve for the interior nodes only.
This example solves the same problem as Example 3. Available solvers are AMG, PCG, and PCG with AMG or Parasails preconditioners.
Example 6
This is a two processor example and is the same problem as is solved with the structured interface in Example 2. (The grid boxes are exactly those in the example diagram in the struct interface chapter of the User's Manual. Processor 0 owns two boxes and processor 1 owns one box.) This is the simplest sstruct example. There is one part and one variable. The solver is PCG with SMG preconditioner. We use a structured solver for this example.
We recommend comparing this example with Example 2.
Example 7
This example uses the sstruct interface to solve the same problem as was solved in Example 4 with the struct interface. Therefore, there is only one part and one variable.
This code solves the convection-reaction-diffusion problem div (-K grad u + B u) + C u = F in the unit square with boundary condition u = U0. The domain is split into N x N processor grid. Thus, the given number of processors should be a perfect square. Each processor has a n x n grid, with nodes connected by a 5-point stencil. We use cell-centered variables, and, therefore, the nodes are not shared.
To incorporate the boundary conditions, we do the following: Let x_i and x_b be the interior and boundary parts of the solution vector x. If we split the matrix A as
A = [A_ii A_ib; A_bi A_bb], then we solve
[A_ii 0; 0 I] [x_i ; x_b] = [b_i - A_ib u_0; u_0]. Note that this differs from the previous example in that we are actually solving for the boundary conditions (so they may not be exact as in ex3, where we only solved for the interior). This approach is useful for more general types of b.c.
As in the previous example (Example 6), we use a structured solver. A number of structured solvers are available. More information can be found in the Solvers and Preconditioners chapter of the User's Manual.
We recommend viewing Examples 6 before viewing this example.
Example 8
This is a two processor example which solves a similar problem to the one in Example 2, and Example 6 (The grid boxes are exactly those in the example diagram in the struct interface chapter of the User's Manual.)
The difference with the previous examples is that we use three parts, two with a 5-point and one with a 9-point discretization stencil. The solver is PCG with split-SMG preconditioner.
We recommend comparing this example with Example 2 and Example 6.
Example 9
This code solves a system corresponding to a discretization of the biharmonic problem treated as a system of equations on the unit square. Specifically, instead of solving Delta^2(u) = f with zero boundary conditions for u and Delta(u), we solve the system A x = b, where
A = [ Delta -I ; 0 Delta], x = [ u ; v] and b = [ 0 ; f] The corresponding boundary conditions are u = 0 and v = 0.
The domain is split into an N x N processor grid. Thus, the given number of processors should be a perfect square. Each processor's piece of the grid has n x n cells with n x n nodes. We use cell-centered variables, and, therefore, the nodes are not shared. Note that we have two variables, u and v, and need only one part to describe the domain. We use the standard 5-point stencil to discretize the Laplace operators. The boundary conditions are incorporated as in Example 3.
We recommend viewing Examples 3, 6 and 7 before this example.