Embarrassingly Parallel Computations processes …….. Input data results Each process requires...

Post on 04-Jan-2016

215 views 0 download

Transcript of Embarrassingly Parallel Computations processes …….. Input data results Each process requires...

Embarrassingly Parallel Computations

processes ……..

Input data

results

Each process requires different data and produces results from its input without any results from other processes

Embarrassingly Parallel Computations

……..

Collect results

send initial dataslaves

recv()

send()

spawn()send()

recv()

Master

Geometrical Transformations of images

(a) Shift

yyy

xxx

'

'

(b) Scaling

y

x

ySy

xSx

'

'

© Rotation

sincos

sincos'

'

yxy

yxx

(d) Clipping

hl

hl

yyy

xxx

'

'

Geometrical Transformations of images

640

480

80

80

process

map

Geometrical Transformations of images

640

480

process

10

Geometrical Transformations of images

Master for(i=0, row; i<48 ; i++, row = row +10) send(row, Pi);

for(i=0 ; i<480 ; i++) for(j=0 ; j<640 ; j++) temp_map[i][j] = 0;

for(i=0 ; I<(640*480) ; i++){ recv(oldrow, oldcol, newcol, Pany); if(!((newrow<0)||(newrow>=480)||(new<0)||(new>=640))) temp_map[newrow][newcol]=map[oldrow][oldcol];}

for(i=0 ; i<480 ; i++) for(j=0 ; j<640 ; j++) map[i][j] = temp_map[i][j];

Geometrical Transformations of images

Slave recv(row, Pmaster);

for(oldrow = row ; oldrow<(row+10) ; oldrow++) for(oldcol=0 ; oldcol<640 ; oldcol++){ newrow = oldrow + delta_x; newcol = newcol + delta_y; send(oldrow, oldcol, newrow, newcol, Pmaster);}

Geometrical Transformations of images

Analysis

)()(4)2( 22 npOttnttpt datastartupdatastartupcomm

communication

computation )/()(2 2

2

pnOp

ntcomp

Mandelbrot Set

czz kk 2

1

22 bazlength

imagimagrealimag

realimagrealreal

czzz

czzz

abibaz

2

222

222

Mandelbrot Set

int cal_pixel(complex c){ int count, max; complex z; float temp, lengthsq; max = 256; z.real = 0; z.imag = 0; count = 0; do{ temp = z.real *z.real - z.imag * z.imag; z.real = temp; lengthsq = z.real * z.real + z.imag * z.imag; count++; }while((length<4.0)&&(count<max)); return count; }

struct complex{ float real; float imag;};

Sequential code

Mandelbrot Set

Sequential codec.real = real_min + x * (real_max - real_min) / disp_height;c.imag = imag_min + y * (imag_max - imag_min) / disp_width;

scale_real = (real_max - real_min) / disp_height;scale_imag = (imag_max - imag_min) / disp_width;

for(x=0 ; x < disp_width ; x++) for(y=0 ; y < disp_height ; y++){ c.real = real_min + ((float) x * scale_real); c.imag = imag_min + ((float) y * scale_imag); color = cal_pixel(c); display(x, y, color);}

Mandelbrot Set

Static Task Assignment

Master :for(i=0, row=0 ; i<48 ; i++, row = row + 10) sned(&row, Pi)for(i=0 ; i < (480*640) ; i++){ recv(&c, &color, Pany); display(c, color);}

Slaverecv(&row, Pmaster);for( x=0 ; x< disp_width ; x++) for(y=0 ; y < (row+10) ; y++){ c.real = min_real + ((float)x*scale_real); c.imag = min_imag + ((float)y*scale_imag); color = cal_pixel(c); send(&c, &color, Pmaster);}

Mandelbrot Set

Dynamic Task Assignment

Work pool.(xa, ya)

.(xb, yb) .(xc, yc)

.(xd, yd)

.(xe, ye)

………….

Mandelbrot Set

Dynamic Task Assignment

Master:

recv(&slave, &r, color, Pany, result_tag)count--;if( row<disp_height ){ sned(&row, Pslave, data_tag); row++; count++; }else send(&row, Pslave, terminator_tag);row_recv++;disply(r, color);}while(count>0);

Slave:

recv(y, Pmaster, ANYTAG, source_tag);while( source_tag == data_tag){ c.imag = imag_min + ((float)y*scale_imag); for(x=0 ; x<width ; x++){ c.real = real_min + ((float)x*scale_real); color[x] = cal_pixel(c); } send(&i, &y, color, Pmaster, result_tag); recv(y, Pmaster, source_tag);};

Mandelbrot Set

Dynamic Task Assignment

terminate Row returneddecrement

Row sentincrement disp_height

Mandelbrot Set

nts max

)(1 datastartupcomm ttst

s

ntcomp

max

)(2 datastartupcomm tts

nt

))((max

datastartupp ttss

n

s

nt

Phase I

Phase II

Phase III

Monte Carlo Methods

2

2

422

)1( 2

squareofArea

circleofArea

Monte Carlo Methods

1

1

x

21 xy 21 rr xy

41

1

0

2 dxx

Monte Carlo Methods

2

1 1

21 )()( limx

x

N

ir

N

xfN

xxdxxfArea

2

1

)3( 2x

xdxxxI

sum=0;for(i=0; i<N ; i++) xr = rand_v(x1, x2); sum = sum + xr * xr – 3 * xr;}Area = sum / N;

Sequential Code

Monte Carlo Methods

Parallel Code

Master

Slaves Slaves

Partial sumPartial sum

random number process

Masterfor(i=0 ; i<N/n ; i++){ for(j=0 ; j< n ; j++) xr[j] = rand(); recv(Pany, reg_tag, Psource); send(xr, &n, Psource, compute_tag);}

for(i=0 ; i<slave_no ; i++){ recv(Pi, reg_tag); send(Pi, stop_tag);}

sum=0;reduce_add(&sum, Pgroup);

Monte Carlo Methods

Parallel CodeMaster

Slaves Slaves

Partial sumPartial sum

random number process

Slave

sum=0;send(Pmaster, reg_tag);recv(xr, &n, Pmaster, source_tag);while(source_tag == compute_tag){ for(i=0 ; i<n ; i++) sum = sum + xr[i] * xr[i] - 3 * xr[i]; send(Pmaster, reg_tag); recv(xr, &n, Pmaster, source_tag);};

reduce_add(&sum, Pgroup);