Next: Sequential program
Up: Short example application programs
Previous: Archetype file mesh_uparms.h
In this example, the goal is to solve the 1D heat diffusion equation:
using the approximation:
A sequential program for this computation is straightforward.
It maintains two copies of variable U, one for the current time
step (uk) and one for the next time step (ukp1).
At each time step, it computes the values of ukp1 based on
the values of uk.
Observe that the two boundary points are handled differently -- they
maintain a constant value.
An equivalent parallel program using the mesh archetype is not
much more complicated:
-
The declaration of the size of the grid (NX)
is 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.
Parameter XPROCS is chosen by the user.
-
Grid-based variables uk and ukp1
are distributed among grid processes.
Observe the use of archetype-supplied constants IXLO
and IXHI to declare the size of the local sections --
these constants give the proper dimensions of the local section,
including ghost boundaries, while allowing the indices of the
local section proper (exclusive of ghost boundaries) to range
from 1 to NXlsize.
-
The whole array 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 time step,
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 routine xintersect to determine
which points in the local section are in the interior of the global
array (global indices 2 through NX - 1).
The grid values are then 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 time-step
loop, for example. This ensures that proper synchronization is
maintained.
Next: Sequential program
Up: Short example application programs
Previous: Archetype file mesh_uparms.h
Berna L Massingill
Mon Jun 8 19:35:58 PDT 1998