Download ASC Programming - Computer Science

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

C Sharp syntax wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Join-pattern wikipedia , lookup

Structured programming wikipedia , lookup

Multi-core processor wikipedia , lookup

Corecursion wikipedia , lookup

MapReduce wikipedia , lookup

C syntax wikipedia , lookup

Stream processing wikipedia , lookup

General-purpose computing on graphics processing units wikipedia , lookup

Computer cluster wikipedia , lookup

Algorithmic skeleton wikipedia , lookup

ILLIAC IV wikipedia , lookup

Data-intensive computing wikipedia , lookup

Supercomputer wikipedia , lookup

Supercomputer architecture wikipedia , lookup

Distributed computing wikipedia , lookup

Parallel computing wikipedia , lookup

Transcript
Data Parallel
Languages
(Chapter 4)
ASC Language
multiC
Fortran 90 and HPF
Contents
ASC Programming Language
 Multi-C Language
 Fortran 90 and High Performance Fortran

Parallel & Distributed Computing
2
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.
Parallel & Distributed Computing
3
The ASC Language
Michael C. Scherger & Johnnie Baker
Department of Computer Science
Kent State University
October 2003
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
5
Software






Anyprog.asc
Compiler and Emulator
DOS/Windows, UNIX
(Linux)
WaveTracer
Connection Machine
http://zserver.cs.kent.edu/
PACL/downloads.htm
Use any text editor.

-e
-wt
-cm
ASC Compiler
Anyprog.iob
-e
-wt
-cm
Careful on moving files
between DOS and UNIX!
Parallel & Distributed Computing
ASC Emulator
Standard I/O
File I/O
6
Software

Example:
 To
compile your program…

 To
% asc1.exe –e shapes.asc
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
7
Basic Program Structure

Main program_name
 Constants;
 Variables;
 Associations;
 Body;

End;
Parallel & Distributed Computing
8
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
9
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
10
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
11
Array Dimensions


A parallel variable can have up to 3 dimensions
 First 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
12
Mixed Mode Operations


Mixed mode operations are supported and their result
has the “natural” mode. For example, given declarations
int scalar a, b, c;
int parallel p[$], q[$], r[$], t[$,4];
index parallel x[$], y[$];
then
c=a+b
is a scalar integer
q[$] = a + p[$]
is a parallel integer variable
a + p[x]
is a integer value
r[$] = t[x,2]+3*p[$] is a parallel integer variable
x[$] = p[$] .eq. r[$] is an index parallel variable
More examples are given on page 9-10 of ASC Primer
Parallel & Distributed Computing
13
Operator Notation

Relational Operators




Logical Operators




“not” is denoted by .not. or !
“or” is denoted by .or. OR ||
“and” is denoted by .and. or &&
Arithmetic Operators




“less than” is denoted by .lt. or <
“equal” is denoted .eq. or =
“not equal” is denoted by .ne. or !=
Addition is denoted by +
Multiplication is denoted by *
Division is denoted by /
For more information, see page 40 of ASC Primer
Parallel & Distributed Computing
14
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
15
Parallel IF-THEN-ELSE Example
if A[$] .eq. 2
then 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
16
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
EXAMPLE
IF 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
17
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. 10
B[$] =11;
elsenany
B[$] = 100;
endany;
For more information, see pages 17-19 of ASC Primer.



Parallel & Distributed Computing
18
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
19
Parallel For Loop

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 & Distributed Computing
20
For Loop Example


Example:
sum = 0;
for x in A[$] .eq. 2
sum = sum + B[$];
endfor x;
Trace for example:
A[$]
B[$]
x
1
1
0
2
2
1
1st
2
2
3
1
2nd
5
1
4
0
2
5
1
3rd
10
Parallel & Distributed Computing
loop
sum
0
21
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
22
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. 1
val[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
23
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
24
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
25
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
26
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
27
Input / Output

Parallel read statement
 See
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
28
Input / Output

Parallel print statement
 See
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
29
Input / Output

The msg command
 Page
13-14 of ASC Primer
 Used to display user text messages.
 Used to display values of scalar variables.
 Used to display a dump of the parallel
variables.
Parallel & Distributed Computing
30
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
31
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:
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.
from tree[$].
32
Parallel‘A’
& Distributed
Computing
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
33
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.
Parallel & Distributed Computing
34