DA2022 – Computer Architecture
Introduction to ZPL
Marcus Edvinsson Morgan Ericsson
with slides originally made by
Today
!!
Introduction to the assignments
”The deal” !! The assignment
!!
!!
Introduction to ZPL
What is ZPL !! Getting started !! ZPL and lots of examples
!!
”The deal”
!!
Everything you need is on the course page or linked to from the course page, except
!!
/stud/kurser/da2022
!!
I introduce the assignment and the different techniques and environments and I also answer your questions and correct/grade your (practical) work/assignments
The assignments
!!
Parallel programming
ZPL (today) !! MPI (later)
!!
!!
Image manipulation
Grey-scale conversion !! Histogram !! Smoothing
!!
PPM and PGM
!!
Format used for images in this course
!! !!
You should be able to load/save these formats Very simple formats
!!
ASCII readable (mostly)
!!
Raw and ASCII (we like it raw!)
!!
Uncompressed NetPBM (/usr/local/netpbm) XV (/usr/local/bin) Etc (google!)
!!
Lots of available tools
!! !! !!
PPM and PGM
!!
Format
[MAGIC] # Optional comment [WIDTH] [HEIGHT] [MAXIMUM COLOR COMPONENT VALUE] Image data (RGB) * HEIGHT * WIDTH
!!
!!
Height, width, etc, ”ASCII formatted” integers, e.g., 640 Magic identifies the format, P5 PGM RAW, P6 PPM RAW
Example
P6 # CREATOR: XV Version 3.10a Rev: 12/29/94 720 480 255 ^O^M^N^P^N^O^Q^Q^Q^Q^S^R^M^O^N ^M^L^N^T ^R^X^^ ^\ ^^$" &$#''&%%%%%%&$%&&&%%'$%'$%'#$$&"#%”#%"#% #$&$%'$%'%&(%&($%'$%'#$&"$##%$#%$$&%$&%#%$#%$"$#! #"!#""$##%$#%$"$#!#"!#""#%"#%"#%"#%"#%"#%"#%"#%#$ &$%'$%'$%'$%'#$&"#%!"$#%$#%$#%$$&%$&%%'&%'&%'%$ #%$#%$$&%$&%%'&%'&%'& …
ZPL
High-level, platform independent !! Implicitly parallel
!!
!!
Can be run in parallel or sequentially Operations can be applied to arrays (of any dimension)
!!
Array programming language
!!
Getting started
!!
ZPL is installed in the Unix lab rooms
!!
Set the following environment variables:
!! !! !! !!
Set ZPLHOME to /opt/zplhome Set ZPLCOMMLAYER to seq Set ZPLTARGET to sparc-solaris (Syntax depending on shell, use setenv if csh) Run /stud/kurser/da2022/instMPI Compiler is zc Executables are named like the source, but without .z
!!
Or
!!
!!
Then what?
!! !!
ZPL
Syntax very similar to Pascal (and Ada) !! Please note
!!
/* */ comments !! := assignment, = comparison
!!
Example 1
program Ex1; procedure Ex1(); begin writeln("Hello, world!"); end;
Example 2
program Ex2; var a,b:integer; procedure Ex2(); begin b:=10; a:=a+b; a+=b;; writeln("a=",a,"."); write("a=%0d.\n":a); write("a=%0d":a, ", b=%0d.\n":b); end;
Example 3
program Ex3; var a,b,i:integer; procedure Ex3(); begin a:=0; for i:=1 to 5 do a+=i; end; writeln(a); end;
Example 4
program Ex4; var a,b:integer; procedure Ex4(); begin read(a); read(b); if a
b then writeln("a>b"); else writeln("a=b"); end; end;
(Parallel) Arrays and Regions
Regions = indices !! Used to declare arrays or specify ”regions” that operations should operate on !! Example:
!!
!! !! !!
region R = [1..10]; a: [R] integer; [R] a:=1;
!!
Not first-class objects!
Example 5
program Ex5; region R = [1..10]; var a: [R] integer; procedure Ex5(); begin [R] a:=1; [R] write(a); end;
Example 6
program Ex6; region R = [1..10]; R2 = [3..6]; var a,b: [R] integer; procedure Ex6(); begin [R] a:=1; [R] b:=Index1; [R2] a+=b; [R] write(a); end;
Directions
!!
”Position-independent” way of indexing arrays
Directions
!!
Defined by giving rules for transforming an index
direction north = [-1, 0];
!!
Parallel arrays can not be indexed in other ways
Region Operators
!!
Used to index/create new regions based on regions and/or directions
Of, creates a new region relative to a region and a direction !! At (@), ”indexing” (displacement) by direction (can be used with variables as well) !! In, creates a new region inside another region
!!
Example 7
program Ex7; region R = [1..10]; R2 = [3..6]; direction above = [+1]; below = [-1]; var a,b: [R] integer; procedure Ex7(); begin [R] a:=1; [R] b:=Index1; [R2] a+=b; [above of R2] a:=99; [below of R2] a:=-100; [R] write(a); end;
Scans and Reductions
!!
Operations that calculates ”something” based on the whole array
Reductions reduces the array to a single value !! Scans propagate the values through the array
!!
!!
A = [ 1, 3, 2 ]
max<