Overview: What is Linda?
Overview: The Linda Model
Overview: Master/Worker Model using Virtual Shared Memory
Linda Basics: Definitions
('arraydata', dim1, 13, 2)
(var1, var2)
('common block', /datacom/)
('array sections', a_array(2:10, 4:8))
Linda Basics: Operations
There are four basic operations
out ('array data', dim1, dim2)
eval ("test", i, f(i));
in ("arraydata", ?dim1, ?dim2);
rd("arraydata", ?dim1, ?dim2);
Linda Basics: Templates
in("arraydata", ?dim1, ?dim2, ?dim3);
in ("arraydata", 4, ?dim2, ?dim3);
out("arraydata", 4, 6, 8);
Linda Basics: Template Matching Rules
Can't predict whether i will be incremented before or after it is evaluated for the third field.
Can't predict whether j (in third field) will have value set by ?j (second field) or value before statement was executed.
In this Fortran example, if the function f() modifies the value of x, we can't predict whether the second field will have the original or the modified value of x.
out ('testdata', i, 3, 4+6)
integer cnt, var, sum
character*8 string
.
.
in ('testdata', ?cnt, ?var, ?sum)
or
in ('testdata', ?cnt, ?var, 10)
or
in (?string, ?cnt, ?var, ?sum)
Example Code
Below is a simple example in the use of C and Fortran Linda. In this example, a master process creates a number of parallel "hello_world" processes, each of which prints the message:
"Hello world from process i"where
i
is a different number for each process.
While both the C and Fortran versions exhibit the same behavior, they demonstrate two different termination strategies.
Example Code: Fortran-Linda - Hello World
C ******************************************************************
C File: hello_world.fl
C
C Simple Fortran Linda Example
C*******************************************************************
C
subroutine real_main
integer i, NPROC
parameter (NPROC=8)
C
out('count', 0)
do 100 i=1, NPROC
eval('worker', hello(i))
100 continue
C
in ('count', NPROC)
print *, ' Hello world is finished'
end
C
subroutine hello(id)
integer id, j
C
print *, ' Hello world from process ',id
in ('count', ?j)
out ('count', j+1)
C
return
end
Example Code: C-Linda - Hello World
/***********************************************************************
* File: hello_world.cl
*
* Simple C Linda example
***********************************************************************/
real_main(argc,argv)
int argc;
char *argv[];
{
int nworker, j, hello();
nworker=atoi (argv[1]);
for (j=0; j < nworker; j++)
eval ("worker", hello(j));
for(j=0; j < nworker; j++)
in("done");
printf("Hello_world is finished.\n");
}
/** subroutine hello **/
int hello (i)
int i;
{
printf("Hello world from number %d.\n",i);
out("done");
return(0);
}
Example Code: Features Illustrated in Fortran Code
This example illustrates a number of features of Fortran-Linda:
Example Code: Features Illustrated in C Code
This examples illustrates the following features of C-Linda:
Linda Programming Environment
There are two execution models on the SP2:
Linda Programming Environment: Code Development System (CDS)
Linda Programming Environment: Environment Setup
using c shell
setenv LINDA_PATH /source/vendorcode/linda/poe/
setenv PATH ${PATH}:${LINDA_PATH}bin
using korn shell
export LINDA_PATH=/source/vendorcode/linda/poe/
export PATH= ${PATH}:${LINDA_PATH}bin
using cshell
setenv LINDA_FLC cds
using korn shell
export LINDA_FLC=cds
using c shell
setenv LINDA_FLC network
using korn shell
export LINDA_FLC=network
using c shell
setenv LINDA_CLC cds
using korn shell
export LINDA_CLC=cds
using c shell
setenv LINDA_CLC network
using korn shell
export LINDA_CLC=network
NOTE: When running Network Linda, the value of the environment variable MP_PROCS will be used to determine how many processors are used. It will use the host.list file which should contain switch node addresses. (See Parallel Operating Environment Overview section for details).
Linda Programming Environment: Compilers
flc -g -o hello -linda tuple_scope hello_world.fl clc -g -o hello -linda tuple_scope hello_world.cl
Using Linda Code Development System (CDS)
% setenv LINDA_FLC cds % flc -o hello hello.fl FLC (V2.5.2 CDS version) hello.fl: Undeclared subprogram hello is treated as a subroutine ** real_main === End of Compilation 1 === ** hello === End of Compilation 2 === 1501-510 Compilation successful for file hello_.f. hello.fl:13: warning --- no matching Linda op. % % hello Linda initializing (2000 blocks). Linda initialization complete. Hello world from process 4 Hello world from process 7 Hello world from process 6 Hello world from process 1 Hello world from process 8 Hello world from process 3 Hello world from process 2 Hello world from process 5 Hello world is finished all tasks are completed (9 tasks). linda: cloning proc has been told to exit, waiting for 8 clones. linda: cleanup releasing semaphores and shared region.
Using Linda Code Development System: The TupleScope Visual Debugger
To use TupleScope, you must compile with the
-linda tuple_scopeoption and be using cds:
using c shell
%setenv LINDA_CLC cds %clc -o array.out -linda tuple_scope array.cl
using korn shell
%export LINDA_CLC=cds %clc -o array.out -linda tuple_scope array.cl
Press this image to see a larger version.
The TupleScope display consists of two parts: the control panel window and a separate window for each tuple class.
Using Linda Code Development System: Tuple Class Windows
The TupleScope run modes are controlled by buttons in the control panel:Using Linda Code Development System: TupleScope Run Modes
Using Linda Code Development System: Using the Debugger
flc -g -o hello -linda tuple_scope hello_world.fl
Exercise 1
Arrays in C-Linda: Array Specification
In C-Linda operations arrays have the attribute of having a fixed or varying length.
int a [20], b[20];
.
.
out ("fixed array", a);
in ("fixed array", ?b);
a:10
a:
in ("array", ?a:length);
will have the number of elements retrieved put into the variable length.
int *p, a[20], b[20], c[10], len; p=a;
out("varying array", a:);
out("varying array", a:20);
out("varying array", p:20);
The length is required in the third case because pointers must always specify
an explicit length.
out("ten elements", a:10);
out("ten elements", p:10);
in("ten elements", ?a:len);
in("ten elements", ?p:len);
in("ten elements", ?b:);
in("ten elements", ?c:);
However,
in ("ten elements", ?c) would not work, because it is
a fixed type and fixed arrays never match variable arrays.
Arrays in C-Linda: Multidimensional Arrays
int a[3][5][2], b[4][6][2], c[7][2][5];the following would match:
out("multi", a[0][0]);
in ("multi", ?b[0][0]);
out("multi", a[0]);
in ("multi", ?b[0]);
int a[3][5][2], b[5][2], c[2], i;
out("fixed", a[0]);
in("fixed", ?b);
out("varying", a[0][0]:);
in ("varying", ?c:);
out("not an array", a[0][0][0]);
in ("not an array", ?i);
int x[2][16][512], y[2][16][512], len
out("fixed", x);
in ("fixed", ?y);
out("varying", x:);
in ("varying, ?y:len);
out("section", x:200);
in ("section", ?y:len);
Arrays in C-Linda: Template Matching and Arrays
In Fortran-Linda operations arrays have the attribute of having a fixed or varying length.Arrays in Fortran-Linda: Array Specification
integer a(50,10)
out ('fixed-size array', a)
in ('fixed-size array, ?a)
double precision b(n)
The array may be referenced either by using the array name by itself or by appending a colon.
out ('computed-size array', b)
or
out ('computed-size array', b:)
To refer to only part of the array, for example to m entries beginning with b(i) use:
out ('specified-size array', b(i):m).
double precision c(*)
It must be put into tuple space using a statement similar to:
out('assumed-size array', c(i):length)
where i is the index of the first array entry to be included, and length is an integer constant or variable.
If the portion of the array starts with the first element then the following can be used:
out('assumed-size array', c:length)
This syntax has to be used even if the whole array is being passed.
Retrieval of the array, using the out statement in the last two examples would be:
in('assumed-size array', ?b(i):m)
where m would be set to the number of array elements retrieved, and would be placed in array b, starting at ith element of b.
Arrays in Fortran-Linda: Fortran 90 Array Sections
ifirst:ilast:istride
where:
double precision a (10,10,10)
a(1:5,1:2,1:5) a(1:10:2,2:10:2,1:10:5) a(1:5,:,2)
a(1:5,1:10,2)
out('first half', a(:,:,1:5)
out('second half', a(:,:,6:10)
in('first half', ?a:length))
in('first half', ?a(1:10, 1:10:2, :))
rd('second half', ?a(:, :, 6:10))
in('second half', ?a(1, 1, 6):)
Arrays in Fortran-Linda: Template Matching and Arrays
Hints and Miscellaneous
In Fortran this refers to:
In C this refers to:
Fortran Routines:
C Routines:
For C-Linda:
in ("data", ?int);
For Fortran-Linda:
in ('data', ?typeof(integer))
out of tb's
-linda ts nwhere n is the size of tuple space in 200-byte blocks.
Exercise 2,3,4...
Acknowledgements and References
C-Linda User's Guide & Reference Manual, Version 2.5.2, Scientific Computing Associates, Inc.
Fortran Linda User's Guide, Version 2.5.2, Scientific Computing Associates, Inc.
Presentation materials, David Turner, Scientific Computing Associates, Inc., New Haven, CT
We gratefully acknowledge David Turner of Scientific Computing Associates, for the use of his presentation materials and assistance in reviewing this documentation, and Scientific Computing Associates, New Haven, CT, for the use of portions of the C-Linda User's Guide & Reference Manual and Fortran Linda User's Guide materials.
Documents located on the Maui High Performance Computing Center's WWW server are copyrighted by the MHPCC. Educational institutions are encouraged to reproduce and distribute these materials for educational use as long as credit and notification are provided. Please retain this copyright notice and include this statement with any copies that you make. Also, the MHPCC requests that you send notification of their use to help@mail.mhpcc.edu.
Commercial use of these materials is prohibited without prior written permission.
Last revised: 3/20/95 Blaise Barney