Docsity

UPC - Parallel Computing - Lecture Slides, Slides of Parallel Computing and Programming

Partial preview of the text

Download UPC - Parallel Computing - Lecture Slides and more Slides Parallel Computing and Programming in PDF only on Docsity!

Unified Parallel C (UPC)

Which System Would You Want?

Blacklight, the SGI

® Altix

® UV

  • 4096 cores

  • 32 TB of memory

  • NUMAlink

® 5 interconnect

Vs

Titan, HPC Cluster, Oak Ridge National Lab.

  • 299,008 cores

  • 710 TB of memory

  • Gemini Interconnect

Attribution: 1) Blacklight presentation by Sanielevici, SG-WG Update, March 18, 2011. 2) Titan homepage

docsity.com

Process/Thread

Memory

Parallel Architectures

4

Programming Models

Shared Memory

Cilk

OpenMP

Pthreads

MPI
UPC
CAF

Distributed Memory

interconnect

docsity.com

What are the most expensive operations when

programming distributed memory systems?

5

Distributed Memory

interconnect

Data movement and synchronization

docsity.com

7

UPC

shared int v1[N],v2[N], sum[N];

upc_forall (i=0; i<100; i++; i)

sum[i] = v1[i]+v2[i];

C

int v1[N], v2[N];

void main() {

for(i=0; i<N; i++)

sum[i]=v1[i]+v2[i];

}

MPI

int v1[N], v2[N], sum[N];

if(i_am_process0)

send_to_everyone_chunks_v12();

else

receive_from_process0_v12();

for(i=0; i<N/p; i++)

sum[i]=v1[i]+v2[i];

MPI_Gather(sum, ...,process_0, ...);

PGAS

Addition of two vectors

docsity.com

8

  • Global address space

—one-sided communication (GET/PUT)

  • Programmer has control over performance-critical factors

—data distribution and locality control

—computation partitioning

—communication placement

  • Data movement and synchronization as language primitives

—amenable to compiler-based communication optimization

HPF & OpenMP compilers

& runtimes must get this right

simpler than msg passing

lacking in OpenMP

Partitioned Global Address Space Languages

docsity.com

Unified Parallel C (UPC)

  • An explicit parallel extension of ISO C

—a few extra keywords

  • shared , MYTHREAD , THREADS , upc_forall

Language features

—partitioned global address space for shared data

  • part of shared data co-located with each thread

—threads created at application launch

  • each bound to a CPU
  • each has some private data

—a memory model

  • defines semantics of interleaved accesses to shared data

—synchronization primitives

  • barriers
  • locks
  • load/store

UPC Execution Model

  • Multiple threads working independently in a SPMD fashion

—MYTHREAD specifies thread index (0..THREADS-1)

—# threads specified at compile-time or program launch

  • Address Space
  • Threads synchronize as necessary using using

—synchronization primitives

—shared variables

Shared and Private Data

  • Static and dynamic memory allocation of each type of data
  • Shared objects placed in memory based on affinity

—shared scalars have affinity to thread 0

  • here, a scalar means a singleton instance of any type

—elements of shared arrays are allocated round robin among

memory modules co-located with each thread

Consider the following data layout directive

shared int y[ 2 * THREADS + 1 ];

For THREADS = 3,

A One-dimensional Shared Array

Thread 0

y[3]

y[0]

y[4]

y[1]

Thread 1

z y[5]

y[2]

Thread 2

y[6]

Consider the following data layout directives

shared int x; // x has affinity to thread 0

shared int y[THREADS];

int z; // private

For THREADS = 3, we get the following layout

Shared and Private Data

Thread 0

x

z

y[0]

z

y[1]

Thread 1

z z

y[2]

Thread 2

Controlling the Layout of Shared Arrays

  • Can specify a blocking factor for shared arrays

—default block size is 1 element

  • Shared arrays are distributed on a block per thread basis,

round robin allocation of block size chunks

  • Example layout using block size specifications

— e.g., shared [2] int a[16]

a[0]

a[1]

a[6]

a[7]

a[2]

a[3]

a[8]

a[9]

a[4]

a[5]

a[10]

a[11]

a[12]

a[13]

a[14]

a[15]

Thread 0 Thread 1 Thread 2

block size

Blocking Multi-dimensional Data I

  • Manage the interaction between

—contiguous memory layout of C multi-dimensional arrays

—blocking factor for shared layout

  • Consider layouts for different block sizes for

—shared [BLOCKSIZE] double grids[N][N];

N

N

Default

BLOCKSIZE=

Column Blocks

BLOCKSIZE=N/THREADS

Distribution by Row

BLOCKSIZE=N

  • Consider the data declaration

— shared [3] int A[4][THREADS];

  • When THREADS = 4, this results in the following data layout

Blocking Multi-dimensional Data II

A[0][0]
A[0][1]
A[0][2]
A[3][0]
A[3][1]
A[3][2]
A[0][3]
A[1][0]
A[1][1]
A[3][3]
A[1][2]
A[1][3]
A[2][0]
A[2][1]
A[2][2]
A[2][3]

Thread 0 Thread 1 Thread 2 Thread 3

The mapping is not pretty for most blocking factors