Next: Sequential program
Up: Short example application programs
Previous: Parallel program (user-supplied code)
In this example, the goal is to solve the 2D Poisson problem:
with Dirichlet boundary condition
using Jacobi iteration; i.e., by discretizing the problem domain
and applying the following operation to all interior points
until convergence is reached:
(This example is based on the discussion of the Poisson problem in
[3]).
A sequential program for this computation is straightforward.
It maintains two copies of variable u, one for the current
iteration (uk) and one for the next iteration (ukp1).
At each iteration, it computes the values of ukp1 based on
the values of uk.
Observe that the boundary points are handled differently -- they
maintain a constant value.
Every NCHECK steps, the maximum of
is computed to check
for convergence.
An equivalent parallel program using the mesh archetype is not
much more complicated:
-
The declarations of the dimensions of the grid
(NX and NY) are moved to INCLUDE
file mesh_uparms.h.
Parameter NGHOST is 1 for this application, since ukp1
depends on values of uk at most one step away.
Parameters XPROCS and YPROCS are chosen by the user.
-
Grid-based variables uk and ukp1
are distributed among grid processes.
Observe the use of archetype-supplied constants to declare
their dimensions.
-
The whole grid is initialized in the host process and then copied
to the grid processes
(routines mesh_HtoG_host and mesh_HtoG_grid).
(It could also be initialized directly in
the grid processes; this approach was chosen for simplicity.)
-
At each iteration,
mesh_update_bdry is called to update the ghost boundaries
before they are used in the grid computation.
The special handling for the (global) boundary points is provided
by using archetype library routines xintersect and
yintersect to determine
which points in the local section are in the interior of the global
grid.
Computing a global maximum for the convergence test is accomplished
by computing a local maximum in each grid process and then
calling archetype library routine mesh_merge_real_maxabs
to find the global maximum. (After calling
mesh_merge_real_maxabs, every process, including the
host process, has the value of the global maximum.)
-
When convergence is reached (or MAXSTEPS iterations have
been performed),
grid values are copied back to the host process for printing
(routines mesh_GtoH_host and mesh_GtoH_grid).
Observe that the code executed by the host and grid processes
has the same high-level structure -- both execute the main
loop, for example, including the convergence test.
This ensures that proper synchronization is maintained.
Next: Sequential program
Up: Short example application programs
Previous: Parallel program (user-supplied code)
Berna L Massingill
Mon Jun 8 19:35:58 PDT 1998