In a multiprocess Sun MPI program, a parallel array is an array whose elements may be distributed among the processes of the program (every process holds only part of the global array). Prism can extract the global dimensionality and distribution information from these arrays and manipulate them as single entities. For the purpose of this discussion, arrays that are not distributed (arrays that belong in their entirety to a single process) are referred to as regular arrays.
Sun S3L's parallel array syntax is based on array handles, which define the properties of the parallel array. Using Prism's type command to identify a Sun S3L array handle and specify its basic data type, you can use Prism to display and visualize the Sun S3L parallel array.
Basic data types are int, float, double, complex8, and complex16. Before using the type command, Prism recognizes the array handle as a simple variable. In Fortran 77 and Fortran 90, the array handle is a variable of type integer*8. In C, the array handle is type S3L_array_t.
Table 5-4 S3L Array Demonstration Program
c c Copyright (c) 1998, by Sun Microsystems, Inc. c All rights reserved c |
program test_prism_s3l |
c |
include 's3l/s3l-f.h' |
c c In f77 programs, s3l arrays are integer*8 c |
integer*8 a |
c |
integer*4 ext(2),local(2),ier |
c |
c Initialize the S3L library and the prism/s3l interface. |
c |
call s3l_init(ier) |
|
c c Declare a parallel S3L array of size 2 x 3, c with the second dimension distributed. |
c |
ext(1) = 2 |
ext(2) = 3 |
|
local(1) = 1 |
local(2) = 0 |
|
call s3l_declare(a,2,ext,S3L_float,local, |
.S3L_USE_MALLOC,ier) |
|
c c Initialize the array randomly by using S3L_rand_lcg c |
|
call s3l_rand_lcg(a,123456,ier) |
w = 1.0 |
c c free the resources associated with the parallel S3L array
|
call s3l_free(a,ier) |
|
c finalize the S3L library. |
|
call s3l_exit(ier) |
c |
stop end |
For example, before using the type command, the whatis command reports that the Sun S3L array handle, a, has been declared an integer*8 in the Fortran program in Table 5-4.
Before applying the Prism type command, Prism identifies the array handle, a, as a variable of type integer*8:
(prism all) whatis a integer*8 a
Issue the type command, associating the Sun S3L handle, a, with the basic data type float, the same type used to declare the element type of the Sun S3L array in your program:
(prism all) type float a "a" defined as "float a"
Now Prism recognizes a as a Sun S3L handle and can call the appropriate Sun S3L routines to get the array's data and extents.
(prism all) type float a "a" defined as "float a"
Prism now recognizes a as a Sun S3L array. You can now use Prism to display the values of a using the print command:
(prism all) print a a = (0:1,0) 0.000000 1.000000 (0:1,1) 0.1000000 1.100000 (0:1,2) 0.2000000 1.200000
In all respects, you can use a as you would use any array in Prism. For example:
You can use a as an array variable:
(prism all) assign a=9 (prism all) print a a = (0:1,0) 9.000000 9.000000 (0:1,1) 9.000000 9.000000 (0:1,2) 9.000000 9.000000
You can use a to gather information on where the elements of a are distributed:
(prism all) print layout a layout (a) = a = (0:1,0) 0 0 (0:1,1) 0 0 (0:1,2) 1 1
You can launch Prism's visualizers to display a graphically. For example, to launch a visualizer window:
(prism all) print layout(a) on dedicated
Sun S3L arrays are distributed across multiple processes. Since each process has an identical view of a, Prism prints the values of the array only once.
However, when Prism prints a regular array, larr,Prism prints the values of larr separately for each process. For regular arrays such as larr, the values of the array can be different on different processes, since every process has its own copy. For example:
(prism all) print larr larr = Pset 0 (1:2,1,1) 0.000000 1.000000 (1:2,2,1) 0.1000000 1.100000 (1:2,3,1) 0.2000000 1.200000 Pset 1 (1:2,1,2) 0.000000 1.000000 (1:2,2,2) 0.1000000 1.100000 (1:2,3,2) 0.2000000 1.200000 (prism all) assign larr=larr*5 pset 0 (prism all) print larr larr = Pset 0 (1:2,1,1) 0.000000 5.000000 (1:2,2,1) 0.5000000 5.500000 (1:2,3,1) 1.000000 6.000000 Pset 1 (1:2,1,2) 0.000000 1.000000 (1:2,2,2) 0.1000000 1.100000 (1:2,3,2) 0.2000000 1.200000
Expressions involving Sun S3L arrays (after having issued the type command), unless they include a variable in the user program, are printed only once. Their values are the same for all processes:
(prism all) print 10* a - 1 10* a - 1 = (0:1,0) -1.000000000000000 9.000000000000000 (0:1,1) 0.00000000000000000 10.00000023841858 (0:1,2) 1.000000029802322 11.00000047683716 (prism all) print a a = (0:1,0) 0.000000 1.000000 (0:1,1) 0.1000000 1.100000 (0:1,2) 0.2000000 1.200000
However, if you use a Sun S3L array in an expression that includes a variable, then Prism replicates the array on each process and then evaluates the array separately on each process. This example adds a variable, w, to a. Prism prints the results for both processes.
(prism all) print w w = (1:2) 0 0 (prism all) print a+w a+w = Pset 0 (0:1,0,1) 0.000000000000000 1.000000000000000 (0:1,1,1) 0.1000000014901161 1.100000023841858 (0:1,2,1) 0.2000000029802322 1.200000047683716 Pset 1 (0:1,0,2) 0.000000000000000 1.000000000000000 (0:1,1,2) 0.1000000014901161 1.100000023841858 (0:1,2,2) 0.2000000029802322 1.200000047683716