450 likes | 470 Views
Parallaxis. Parallaxis is a machine-independent language for data-parallel computing Modula-2 extended by data-parallel concepts Programming is done using virtual processors and virtual connections The programming environment for Parallaxis is available as public domain software
E N D
Parallaxis • Parallaxis is a machine-independent language for data-parallel computing • Modula-2 extended by data-parallel concepts • Programming is done using virtual processors and virtual connections • The programming environment for Parallaxis is available as public domain software • These slides are based on the paper Parallaxis-III by Thomas Bräunl ICSS531 - Parallaxis
Design Goals • Two major goals in developing the language • Structured programming has a number of advantages in developing sequential and parallel software • Almost all commercial SIMD programming languages are machine dependent, since they have been specifically designed for a single hardware platform to achieve maximum performance • The central point of Parallaxis is programming on a level of abstraction with virtual PEs and virtual connections ICSS531 - Parallaxis
Parallaxis Machine Model • Parallaxis makes the following assumptions about its abstract parallel machine • SIMD structure with • central control unit (Host) • variable number of processing elements (PEs) • flexible communication network • Operations occur synchronously • PEs are identical in processor and memory structure • Each PE has the same number of bi-directional ports for sending and receiving data • one process per PE ICSS531 - Parallaxis
Primitive Types Integer Cardinal (positive integers) Subrange Enumerated Char Boolean Real Pointer types Structured Types Arrays Records Sets Parallaxis and Modula-2 ICSS531 - Parallaxis
Operators (unary) NOT + - - ** (right associative) * / DIV MOD {AND &} + - OR = {<> #} < <= > >= IN Constants TRUE FALSE EOL PI NIL Parallaxis and Modula-2 ICSS531 - Parallaxis
New Features • Multiple Comparisons • Boolean expressions may consist of any number of comparisons • All have to be true in order to make the entire expression true • If 1 < x < 100 • Power Operator • Constant arrays and records ICSS531 - Parallaxis
Virtual Processors • Every Parallaxis program uses one or several virtual machines consisting of • Processors • Connection network • The machine is defined in two steps • CONFIGURATION • CONNECTION ICSS531 - Parallaxis
Specifying a Virtual Network • CONFIGURATION • Specifies the number of PEs and their arrangement • CONNECTION • May be omitted if no connections are required • Every connection has a symbolic name and defines a mapping from a PE to the corresponding neighbor PE ICSS531 - Parallaxis
TwoD Grid ICSS531 - Parallaxis
Torus CONFIGURATION torus [0..h-1],[0..w-1]; CONNECTION north: torus[i,j]->torus[(i-1) mod h,j]; south: torus[i,j]->torus[(i+1) mod h,j]; east: torus[i,j]->torus[i,(j+1) mod w]; west: torus[i,j]->torus[i,(j-1) mod w]; ICSS531 - Parallaxis
Binary Tree Note the bi-directional connections require a second connection name on The right hand side of the connecion ICSS531 - Parallaxis
Hypercube Note the parameterized connections. This makes it possible to perform A data exchange in a computed direction ICSS531 - Parallaxis
One to Many/Many to One CONFIGURATION grid [1..100],[1..100]; CONNECTION one2many: grid[i,1]->grid[i,1..100]; CONFIGURATION grid [1..100],[1..100]; CONNECTION one2many: grid[i,1]->grid[i,*]; CONFIGURATION grid [1..100],[1..100]; CONNECTION many2one: grid[i,j]->grid[i1]; ICSS531 - Parallaxis
Scalar and Vector Data • In Parallaxis variables can live in the host memory or in the memory of the Pes • Scalar variables live in the memory of the host • Vector values live in the virtual processing elements, one copy per processor ICSS531 - Parallaxis
Example ICSS531 - Parallaxis
Processor Positions • ID • Processor position as a single number in a row-major ordering (starting with 1) • DIM • Takes a configuration name and the number or a dimension • Returns the position of the PE within the dimension (note dimensions are numbered from right to left) ICSS531 - Parallaxis
Examples ICSS531 - Parallaxis
Other Configuration Functions • LEN( grid ) • Total number of PEs in a configuration • LEN( grid, i ) • The size of a dimension • RANK( grid ) • The number of dimensions • LOWER/UPPER( grid, i ) • The lower/upper bound of a dimension ICSS531 - Parallaxis
Assignment Rules • Scalar values may be assigned to vector variables • Vector values cannot be assigned to a scalar variable, unless the scalar variable is an array of the appropriate size • Binary operations with at least one vector value will produce a vector result • Vector indexes cannot be used in scalar arrays ICSS531 - Parallaxis
Parallel Execution • A statement with a vector component is executed in parallel on the PEs. • Control statements execute differently when done in parallel ICSS531 - Parallaxis
Example MODULE variables; CONFIGURATION list [2..200]; CONNECTION ; CONFIGURATION grid [1..3][1..3]; CONNECTION north: grid[i,j]->grid[i-1,j]; south: grid[i,j]->grid[i+1,j]; east: grid[i,j]->grid[i,j+1]; west: grid[i,j]->grid[i,j-1]; VAR next_prime: INTEGER; (* scalar variable *) x, y, z : list OF BOOLEAN; (* vector variable *) a, b, c : grid OF INTEGER; (* vector variable *) BEGIN x := y AND z; a := b + c; END prime. ICSS531 - Parallaxis
Parallel IF ICSS531 - Parallaxis
Parallel IF ICSS531 - Parallaxis
Parallel WHILE ICSS531 - Parallaxis
Structured Data Exchange • Data exchanges between processors are possible • MOVE • SEND (a procedure) • RECEIVE • Only active processors participate in a data exchange operation • So an inactive processor might get some data ICSS531 - Parallaxis
Executing an Exchange • An exchange is executed as follows: • The “exchange expression” is initialized with the values being sent • For SEND(x,y), y gets the x values in all active processors • For MOVE(x) and RECEIVE(x) (functions) the temporary variable gets the x values • Active and non-border processors exchange data ICSS531 - Parallaxis
Example CONFIGURATION grid [1..3][1..3]; CONNECTION north: grid[i,j]->grid[i-1,j]; south: grid[i,j]->grid[i+1,j]; east: grid[i,j]->grid[i,j+1]; west: grid[i,j]->grid[i,j-1]; All data exchange operations shift data in the direction indicated By the connection, so it does not have the semantics receive from A direction ICSS531 - Parallaxis
SEND ICSS531 - Parallaxis
RECEIVE ICSS531 - Parallaxis
MOVE ICSS531 - Parallaxis
Scalar/Vector Exchanges • Transferring a scalar field into a parallel vector is done using LOAD • Transferring data back into a scalar field form a vector is done using STORE ICSS531 - Parallaxis
LOAD and STORE ICSS531 - Parallaxis
Random.pm (* Create a small processor pipeline, generate some *) (* random values, and print them out. *) CONST n = 8; CONFIGURATION pipe[ 1..n ]; CONNECTION right : pipe[ i ] <-> pipe[ i + 1 ] : left; VAR value : pipe OF INTEGER; BEGIN value := RandomInt( pipe ) MOD 100; WriteInt( value, 5 ); END random. ICSS531 - Parallaxis
max.pm MODULE max; (* Find the maximum value in a group of processors connected in a *) (* pipeline in a not so parallel way *) CONST n = 8; CONFIGURATION pipe[ 1..n ]; CONNECTION right : pipe[ i ] <-> pipe[ i + 1 ] : left; VAR i : INTEGER; value, temp : pipe OF INTEGER; ICSS531 - Parallaxis
max.pm (continued) BEGIN value := RandomInt( pipe ) MOD 100; WriteInt( value, 5 ); FOR i := 1 TO n - 1 DO temp := RECEIVE.left( value ); IF temp > value THEN value := temp; END; END; IF ID( pipe ) = 1 THEN WriteInt( value, 5 ); END; END max. ICSS531 - Parallaxis
Unstructured Data Exchange ICSS531 - Parallaxis
Max2.pm MODULE max2; (* Find the maximum value in a group of processors connected in a *) (* pipeline in a not so parallel way *) CONST n = 8; CONFIGURATION pipe[ 1..n ]; VAR i : INTEGER; value, temp, index : pipe OF INTEGER; ICSS531 - Parallaxis
Max2.pm (continued) BEGIN index := ID( pipe ) + 1; IF ID( pipe ) = n THEN index := n; END; value := RandomInt( pipe ) MOD 100; FOR i := 1 TO n - 1 DO temp := RECEIVE.<<index>>( value ); IF temp > value THEN value := temp; END; END; IF ID( pipe ) = 1 THEN WriteInt( value, 5 ); END; END max2. ICSS531 - Parallaxis
Reduce.pm MODULE reduce; (* Find the maximum value in a group of processors connected in a *) (* pipeline in log n time (parallel reduction) *) CONST lgn = 3; n = 2 ** lgn; CONFIGURATION pipe[ 1..n ]; VAR i : INTEGER; value, temp, index : pipe OF INTEGER; ICSS531 - Parallaxis
Reduce.pm (continued) BEGIN value := RandomInt( pipe ) MOD 100; FOR i := 1 TO lgn DO index := ID( pipe ) - 2 ** ( i - 1 ); IF ID( pipe ) MOD ( 2 ** i ) = 0 THEN temp := RECEIVE.<<index>>( value ); IF temp > value THEN value := temp; END; END; END; IF ID( pipe ) = n THEN WriteInt( value, 5 ); END; END reduce. ICSS531 - Parallaxis
Reduction in Parallaxis • The REDUCE operation performs parallel reduction in Parallaxis using system-defined or user-defined operators • SUM, PRODUCT, MAX, MIN, AND, OR, FIRST, LAST • General syntax: • x := REDUCE.MAX( value ); ICSS531 - Parallaxis
montepi.pm MODULE montepi; CONST guesses = 20000; CONFIGURATION list[ 1..guesses ]; VAR guess : REAL; num : INTEGER; x, y, yup : list OF REAL; BEGIN WriteString("Guesses Guess Actual Error"); WriteLn; WriteString("------- ---------- ---------- ----------"); WriteLn; ICSS531 - Parallaxis
montepi.pm (continued) FOR num:=1000 TO 20000 BY 1000 DO yup:=0.0; IF ID( list ) < num THEN x := RandomReal( list ); y := RandomReal( list ); IF ( x ** 2 + y ** 2 <= 1.0 ) THEN yup:=1.0 END END; guess := ( REDUCE.SUM( yup ) / FLOAT( num ) ) * 4.0; WriteInt( num, 7 ); WriteString( " " ); WriteFixPt( guess, 10, 8 ); WriteString( " " ); WriteFixPt( pi, 10, 8 ); WriteString( " " ); WriteFixPt( ABS( pi - guess ), 10, 8 ); WriteLn; END; END montepi. ICSS531 - Parallaxis
It Really Works!! Guesses Guess Actual Error ------- ---------- ---------- ---------- 1000 3.13200000 3.14159265 0.00959265 2000 3.09400000 3.14159265 0.04759265 3000 3.21600000 3.14159265 0.07440735 4000 3.13900000 3.14159265 0.00259265 5000 3.15280000 3.14159265 0.01120735 6000 3.13933333 3.14159265 0.00225932 7000 3.13257143 3.14159265 0.00902123 8000 3.14350000 3.14159265 0.00190735 9000 3.15422222 3.14159265 0.01262957 10000 3.14200000 3.14159265 0.00040735 11000 3.13927273 3.14159265 0.00231993 12000 3.13600000 3.14159265 0.00559265 13000 3.16523077 3.14159265 0.02363812 14000 3.14657143 3.14159265 0.00497877 15000 3.13413333 3.14159265 0.00745932 16000 3.14700000 3.14159265 0.00540735 17000 3.14305882 3.14159265 0.00146617 18000 3.16733333 3.14159265 0.02574068 19000 3.14336842 3.14159265 0.00177577 20000 3.14120000 3.14159265 0.00039265 ICSS531 - Parallaxis
The Sieve MODULE prime; CONFIGURATION list [ 2..200 ]; VAR next_prime: INTEGER; (* scalar variable *) is_prime : list OF BOOLEAN; (* vector variable *) BEGIN is_prime := TRUE; WHILE is_prime DO next_prime := REDUCE.FIRST( DIM( list, 1 ) ); (* next value *) WriteInt( next_prime, 10 ); WriteLn; (* print it *) is_prime := DIM( list, 1 ) MOD next_prime <> 0; (* remove multiples *) END; END prime. ICSS531 - Parallaxis