Download presentation
Presentation is loading. Please wait.
Published byDeirdre Irma Briggs Modified over 9 years ago
1
Embarrassingly Parallel Computations processes …….. Input data results Each process requires different data and produces results from its input without any results from other processes
2
Embarrassingly Parallel Computations …….. Collect results send initial data slaves recv() send() spawn() send() recv() Master
3
Geometrical Transformations of images (a)Shift (b) Scaling © Rotation (d) Clipping
4
Geometrical Transformations of images 640 480 80 process map
5
Geometrical Transformations of images 640 480 process 10
6
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 =480)||(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];
7
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); }
8
Geometrical Transformations of images Analysis communication computation
9
Mandelbrot Set
10
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
11
Mandelbrot Set Sequential code c.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); }
12
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); } Slave recv(&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); }
13
Mandelbrot Set Dynamic Task Assignment Work pool.(x a, y a ).(x b, y b ).(x c, y c ).(x d, y d ).(x e, y e ) ………….
14
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); };
15
Mandelbrot Set Dynamic Task Assignment terminate Row returned decrement Row sent increment disp_height
16
Mandelbrot Set Phase I Phase II Phase III
17
Monte Carlo Methods 2 2
18
1 1 x
19
sum=0; for(i=0; i<N ; i++) xr = rand_v(x1, x2); sum = sum + xr * xr – 3 * xr; } Area = sum / N; Sequential Code
20
Monte Carlo Methods Parallel Code Master Slaves Partial sum random number process Master for(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);
21
Monte Carlo Methods Parallel Code Master Slaves Partial 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);
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.