data parallel languages (chapter 4) asc language multic fortran 90 and hpf
Post on 22-Dec-2015
229 views
TRANSCRIPT
Data Parallel Languages
(Chapter 4)
ASC LanguagemultiCFortran 90 and HPF
Parallel & Distributed Computing 2
Contents
ASC Programming Language Multi-C Language Fortran 90 and High Performance Fortran
Parallel & Distributed Computing 3
References for Chapter 4
11. Jerry Potter, Associative Computing - A Programming Paradigm for Massively Parallel Computers, Plenum Publishing Company, 1992
18. Jerry Potter, ASC Primer, 42 pages, posted at parallel website under downloads at http://zserver.cs.kent.edu/PACL/downloads.
19. Ian Foster, Designing and Building Parallel Programs: Concepts and Tools for Parallel Software Engineering, Addison Wesley, 1995, Online at http://www-unix.mcs.anl.gov/dbpp/text/book.html
20. “The multiC Programming Language”, Preliminary Documentation, WaveTracer, PUB-00001-001-00.80, Jan. 1991.
21. “The multiC Programming Language”, User Documentation, WaveTracer, PUB-00001-001-1.02, June 1992.
The ASC Language
Michael C. Scherger & Johnnie BakerDepartment of Computer ScienceKent State UniversityOctober 2003
Parallel & Distributed Computing 5
Contents Software Location and Installation Basic Program Structure Data Types and Variables Operator Notation Control Structures Looping Accessing Values in Parallel Variables Associations and Setscope Input and Output Performance Monitor Subroutines and other topics
Parallel & Distributed Computing 6
Software
Compiler and Emulator DOS/Windows, UNIX
(Linux) WaveTracer Connection Machine
http://zserver.cs.kent.edu/PACL/downloads.htm
Use any text editor. Careful on moving files
between DOS and UNIX!
ASC Compiler
ASC Emulator
Anyprog.asc
Anyprog.iob
Standard I/O File I/O
-e-wt-cm
-e-wt-cm
Parallel & Distributed Computing 7
Software
Example:To compile your program…
% asc1.exe –e shapes.asc
To execute your program… % asc2.exe –e shapes.iob % asc2.exe –e shapes.iob < shapes.dat % asc2.exe –e shapes.iob < shapes.dat > shapes.out
Parallel & Distributed Computing 8
Basic Program Structure
Main program_nameConstants;Variables;Associations;Body;
End;
Parallel & Distributed Computing 9
Basic Program Structure
Example:Consider an ASC Program that computes the
area of various simple shapes (circle, rectangle, triangle).
Here is an example shapes.asc Here is the data shapes.dat Here is the shapes.out
NOTE: Above links are only active during the “slide show”.
Parallel & Distributed Computing 10
Data Types and Variables
ASC has eight data types… int (i.e., integer), real, hex (i.e., base 16), oct (i.e.,
base 8), bin (i.e., binary), card (i.e., cardinal), char (i.e., character), logical, index.
Card is used for unsigned integer data. Variables can either be scalar or parallel.
Scalar variables are in the IS. Parallel variables are in the cells.
Parallel variables have the suffix “[$]” at the end of the identifier.
Can specify the length (in bits) of parallel variables. Default word length works fine for most programs.
Parallel & Distributed Computing 11
Comparison of Logical Parallel and Index Parallel
A index parallel variable selects a single scalar value from a parallel variable.
A logical parallel variable L is normally used to store a logical value resulting from a search such as
L[$] = A[$] .eq. B[$] ASC implementation simplifies usage by not formally
distinguishing between the two. The correct type, based on usage, should be selected
to improve readability.
Parallel & Distributed Computing 12
Array Dimensions
A parallel variable can have up to 3 dimensionsFirst dimension is “$”, the parallel dimension
The array numbering is zero-based, so the declaration
int parallel A[$,2]creates the following 1dimensional variables:
A[$,0], A[$,1], A[$,2]
Parallel & Distributed Computing 13
Mixed Mode Operations Mixed mode operations are supported and their result
has the “natural” mode. For example, given declarationsint scalar a, b, c;int parallel p[$], q[$], r[$], t[$,4];index parallel x[$], y[$];
then c = a + b is a scalar integerq[$] = a + p[$] is a parallel integer variablea + p[x] is a integer valuer[$] = t[x,2]+3*p[$] is a parallel integer variablex[$] = p[$] .eq. r[$] is an index parallel variable
More examples are given on page 9-10 of ASC Primer
Parallel & Distributed Computing 14
Operator Notation
Relational Operators “less than” is denoted by .lt. or < “equal” is denoted .eq. or = “not equal” is denoted by .ne. or !=
Logical Operators “not” is denoted by .not. or ! “or” is denoted by .or. OR || “and” is denoted by .and. or &&
Arithmetic Operators Addition is denoted by + Multiplication is denoted by * Division is denoted by /
For more information, see page 40 of ASC Primer
Parallel & Distributed Computing 15
The IF-THEN-ELSE Control Structure
Scalar version similar to sequential programming languages. Either executes either the body of the IF or the body
of the ELSE. Parallel version normally executes both “bodies”.
First finds the responders for the conditional If there are any responders, the responding PEs
execute the body of the IF. Next identifies the non-responders for the conditional
If there are non-responders, those PEs executes the body of the ELSE.
This control structure is also a masking operation.
Parallel & Distributed Computing 16
Parallel IF-THEN-ELSE Example
if A[$] .eq. 2then A[$] = 5;else A[$] = 0;
endif;
A[$]
BEFORE
MASK
BEFORE
A[$]
AFTER
THEN
MASK
ELSE
MASK
2 1 5 1 0
5 1 0 0 1
3 0 3 0 0
2 1 5 1 0
1 1 0 0 1
Parallel & Distributed Computing 17
IF-THEN-ELSENANY Control Statement Similar to the IF-THEN-ELSE, except that only one of the two bodies
of code is executed. First the logical expression following the “IF’ is evaluated If there is at least one responder, then the responding processors
execute the body of the IF. However, if there were no responders to the logical expression, then
all processors that were initially active at the start of this command execute the body of the ELSENANY
EXAMPLEIF A[$] .GE. 2 and A[$] .LT. 4 THEN
C[$] = 1;
ELSENANY
C[$] = 9;
ENDIF; See page 16-17 of ASC Primer for more information
Parallel & Distributed Computing 18
ANY-ELSENANY Control Statement
If there is at least one responder, then all active processors (i.e., ones active at the start of this command) execute the statements inside the any-block.
If there are no responders, then all active processors execute the statements inside the elsenany block
any can be used alone (without the elsenany) Example
any A[$] .eq. 10B[$] =11;
elsenanyB[$] = 100;
endany; For more information, see pages 17-19 of ASC Primer.
Parallel & Distributed Computing 19
Looping
Sequential looping Loop-Until
See example on page 20 of ASC Primer Sequential looping is an infrequently used operation in ASC
Two types of parallel looping constructs: Parallel For-Loop
Conditional is evaluated only once. Example on page 21.
Parallel While-Loop Conditional is evaluated every iteration. Example on page 21-22.
Parallel & Distributed Computing 20
For construct Often used when a process must be repeated for
each cell that satisfies a certain condition. The index variable is available throughout the
body of the for statement The index value of for is only evalulated initially
Parallel For Loop
Parallel & Distributed Computing 21
For Loop Example Example:
sum = 0;
for x in A[$] .eq. 2
sum = sum + B[$];
endfor x; Trace for example:
A[$] B[$] x loop sum
1 1 0 0
2 2 1 1st 2
2 3 1 2nd 5
1 4 0
2 5 1 3rd 10
Parallel & Distributed Computing 22
While Loop
Unlike the for statement, this construct re-evaluates the logical conditional statement prior to each execution of the body of the while.
The bit array resulting from the evaluation of the conditional statement is assigned to the index parallel variable on each pass.
The index parallel array is available for use within the body each loop.
The body of the while construct will continue to be executed until there are no responders (i.e., all zeros) in the index parallel variable.
Study example and trace in the ASC Primer carefully to make sure you understand the while construct.
Parallel & Distributed Computing 23
Get Statement
Used to retrieve a value from a specific field in a parallel variable satisfying a specific conditional statement.
Example:
get x in tail[$] .eq. 1val[x] = 0;
endget x; Study the trace of this example in on page 24 of ASC
Primer to make sure its action is clear.
Parallel & Distributed Computing 24
Next Statement
Similar to get statement, except next updates the set of responders each time it is called.
Unlike get, two successive calls to next is expected to select two distinct processors (and two distinct association records).
Can be used inside a loop to sequentially process each responder.
See page 22-23 of ASC Primer for more details.
Parallel & Distributed Computing 25
Maximum and Minimum Values
The maxval and minval functions maxval returns the maximum value of the specified
items among the active responders. Similarly, minval returns the minimum value. Example:
if (tail[$] .neq. 1) then k = maxval( weight[$]);
endif; See trace of example on pg 27 of ASC Primer.
The maxdex and mindex functions Returns the index of one processor where a
maximum or minimum occurs. If maximum/minimum value occurs at more than one
location, an arbitrary selection is made as to which index is returned.
Parallel & Distributed Computing 26
The associate statement
Creates an association between parallel variables and a parallel logical variables.There are no “structs” or “classes” in ASC.
See earlier example in sample program. See page 8 of ASC primer for more
information.
Parallel & Distributed Computing 27
Setscope – Endsetscope Commands
Resets the parallel mask register setscope jumps out of current mask setting to another
mask setting. One use is to reactivate currently inactive processors. Also allow an immediate return to a previously
calculated mask, such as an association. Is an unstructured command such as go-to and
jumps from current environment to a new environment.
Use sparingly
endsetscope resets mask to preceding setting. See example on page 15 of ASC Primer.
Parallel & Distributed Computing 28
Input / Output
Parallel read statementSee page 12-13 of ASC Primer Illustrated in earlier example program.Must have an ASSOCIATE statement. Input file must have blank line at end of data
set. Input is from “interactive user input” or from a
data file identified in the command line.
Parallel & Distributed Computing 29
Input / Output
Parallel print statementSee page 13 in the ASC primer Illustrated in earlier example program.Must have an ASSOCIATE statement.Does not output user specified strings.
I.e. User text messages. Only outputs the values of parallel variables.
Parallel & Distributed Computing 30
Input / Output
The msg commandPage 13-14 of ASC PrimerUsed to display user text messages.Used to display values of scalar variables.Used to display a dump of the parallel
variables.
Parallel & Distributed Computing 31
Scalar variable input
Static input can be handled in the code. Also, define or deflog statements can be used to handle static input. Dynamic input is currently not supported directly, but can be
accomplished as follows: Reserve a parallel variable dummy (of desired type) for input. Reserve a parallel index variable used. Values to be stored in scalar variables are first read into dummy
using a parallel-read and then transferred using get or next to the appropriate scalar variable.
Example:
read dummy[$] in used[x];
get x in used[$]
scalar-variable = dummy[x];
endget x; NOTE: Don’t need to use associate statement to associate dummy
with used. Omission causes no problems as no check is currently made.
Parallel & Distributed Computing 32
Dynamic Storage Allocation allocate is used to identify a processor whose association record is
currently unused. Will be used to store a new association record Creates a parallel index that points to the processor selected
release is used to de-allocate storage of specified records in an association Can release multiple records simultaneously.
Example:Example:char parallel node[$], parent[$];logical parallel tree[$];index parallel x[$];associate node[$], level[$], parent[$] with tree[$];......allocate x in tree[$]
node[x] = ‘B’endallocate x;release parent[$] .eq. ‘A’ from tree[$].
Parallel & Distributed Computing 33
Performance Monitor Keeps track of number of scalar and parallel operations. It is turned on and off using the perform statement
PERFORM = 1; PERFORM = 0;
The number of scalar and parallel operations can be printed using the msg command MSG “Number of scalar and parallel operations are”
PA_PERFORM SC_PERFORM; The ASC Monitor is important for evaluation and
comparison of various ASC algorithms and software. See Pg 30-31 of ASC Primer for more information
Parallel & Distributed Computing 34
Additional Features
Restricted subroutine capability is currently available See call and include on pg 25-6 of ASC Primer.
Use of personal pronouns and articles in ASC make code easier to read and shorter. See page 29 of ASC Primer.