DA2022 – Computer Architecture Introduction to ZPL Marcus Edvinsson with slides originally made by...

Preview:

Citation preview

DA2022 – Computer Architecture

Introduction to ZPLMarcus Edvinsson

with slides originally made by

Morgan Ericsson

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

Lots of available tools NetPBM (/usr/local/netpbm) XV (/usr/local/bin) Etc (google!)

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

ExampleP6# CREATOR: XV Version 3.10a Rev: 12/29/94720 480255^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 Array programming language

Operations can be applied to arrays (of any dimension)

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)

Or Run /stud/kurser/da2022/instMPI

Then what? Compiler is zc Executables are named like the source, but without

.z

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 2program 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 3program Ex3;var a,b,i:integer;procedure Ex3();begin a:=0; for i:=1 to 5 do a+=i; end; writeln(a);end;

Example 4program Ex4;var a,b:integer;procedure Ex4();begin read(a); read(b); if a<b then writeln("a<b"); elsif 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 5program Ex5;

region R = [1..10];

var a: [R] integer;

procedure Ex5();begin[R] a:=1;[R] write(a);end;

Example 6program 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 7program 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<<A = 3 (R) max||A = [ 1, 3, 3 ] (S)

Reductions

Available reductions (scans similar)+<<

*<<

max<<

min<<

&<< (and)

|<< (or)

Example 8program Ex8;region R = [1..10];var a,b: [R] integer; m,s: integer;procedure Ex8();begin[R] a:=1;[R] b:=Index1;[R] m:=max<<b;[R] s:=+<<b;[R] a:=+||a;end;

Config variables

Can be used to set constants at runtime Array sizes or regions, for example

executable –svariable=value ./ex9 –sn=5

Example 9program Ex9;config var n:integer = 10;region R = [1..n,1..n];var a: [R] integer; m,s: integer;procedure Ex9();begin[R] a:=Index1*Index2;[R] m:=max<<a;[R] s:=+<<a;end;

Records Composite types, like records are

availabletype Name = record

Definitions … ;

end;

’.’ is used to access values in a record (like Ada, C)

myRecord.myInteger := 5;

(See example 11 for more information)

Now what?

Use the reference manual Try to understand the examples

Not all available examples were used in this presentation

File I/O (ex11)

Experiment!

Recommended