Download presentation
Presentation is loading. Please wait.
Published byKellen Feather Modified over 9 years ago
1
Partitioning and Divide-and-Conquer Strategies Data partitioning (or Domain decomposition) Functional decomposition
2
+ x 0 …….x (n/m)-1 + x n/m …….x (2n/m)-1 ……. + x (m-1)n/m …….x n-1 + sum Partitioning and Divide-and-Conquer Strategies
3
Addition of a sequence of numbers Master s = n / m; for(i=0, x=0 ; i<m ; i++, x=x+s) send(&number[x], s, Pi); result = 0; for(i=0 ; i<m ; i++){ recv(&part_sum, Pany); sum = sum + part_sum; } Slave recv(numbers, s, Pmaster); sum = 0; for(i=0 ; i<s ; i++) part_sum = part_sum + numbers[i]; send(&part_sum, Pmaster);
4
Addition of a sequence of numbers Master s = n / m; bcast(numbers, s, Pslave_group); result = 0; for(i=0 ; i<m ; i++){ recv(&part_sum, Pany); sum = sum + part_sum; } Slave bcast(numbers, s, Pmaster); start = slave_number * s; end = start + s; sum = 0; for(i=start ; i<end ; i++) part_sum = part_sum + numbers[i]; send(&part_sum, Pmaster);
5
Addition of a sequence of numbers Analysis. Phase I. communication Phase II. computation
6
Addition of a sequence of numbers Analysis. Phase III. communication Phase VI. computation
7
Addition of a sequence of numbers Analysis.
8
Divide-and-Conquer int add(int* s) { if(number(s)=<2) return (n1+n2); else{ divide(s, s1, s2); part_sum1 = add(s1); part_sum2 = add(s2); retunr(part_sum1 + part_sum2); }
9
Divide-and-Conquer Divide problem
10
Divide-and-Conquer P0 P4 P0P2 P0P1P2P3 P6P4 P7P6P5P4
11
Divide-and-Conquer P0 P4 P0P2 P0P1P2P3 P6P4 P7P6P5P4
12
Process P0 divide(s1, s1, s2); send(s2, P4); divide(s1, s1, s2); send(s2, P2); divide(s1, s1, s2); send(s2, P0); part_sum = *s1; recv(&part_sum1, P0); part_sum = part_sum + part_sum1; recv(&part_sum1, P2); part_sum = part_sum + part_sum1; recv(&part_sum1, P4); part_sum = part_sum + part_sum1; Process P4 recv(s1, P0) divide(s1, s1, s2); send(s2, P6); divide(s1, s1, s2); send(s2, P5); part_sum = *s1; recv(&part_sum1, P5); part_sum = part_sum + part_sum1; recv(&part_sum1, P6); part_sum = part_sum + part_sum1; send(&part_sum, P0); Divide-and-Conquer
13
analysis communication
14
Divide-and-Conquer analysis computation
15
M-way Divide-and-Conquer int add(int* s) { if(number(s) =<4) return(n1+n2+n3+n4); esle{ divide(s, s1, s2, s3, s4); part_sum1 = add(s1); part_sum2 = add(s2); part_sum3 = add(s3); part_sum4 = add(s4); return(part_sum1 + part_sum2 + part_sum3 + part_sum4); }
16
M-way Divide-and-Conquer
18
Numerical Integration a p q b f(p) f(q) f(x)
19
Numerical Integration a p q b f(p) f(q) f(x)
20
a p q b f(p) f(q) Numerical Integration f(x)
21
Numerical Integration AB
22
Process Pi if( i== master ){ printf("Enter number of intervals"); scanf("%d", &n); } bcast(&n, Pgroup); region = (b-a) / p; start = a + region * i; end = start + region; d = (b-a) / n; area = 0.0; for(x=start ; x<end ; x = x+d) area = area + 0.5 * (f(x)+f(x+d)) * d; reduce_add(&integral, &area, Pgroup); area = 0.0; for(x=start ; x<end ; x=x+d) area = area + f(x) + f(x+d); area = 0.5 * area * d; area = 0.5 * (f(start) + f(end)); for(x=start+d ; x<end ; x=x+d) area = area + f(x); area = area * d;
23
N-body problem
24
Three dimension space
25
N-body problem Sequential Code for(t=0 ; t<tmax ; t++) for(i=0 ; i<N ; i++) { F=FORCE_ROUTINE(i); v[i]new = v[i] + F * dt; x[i]new = x[i] + v[i]new * dt; } for(i=0 ; i<nmax ; i++){ x[i] = x[i]new; v[i] = v[i]new; }
26
N-body problem Center of mass distance cluster of bodies
27
N-body problem Barnes-Hut algorithm
28
N-body problem
29
for( t=0 ; t<tmax ; t++) { Build_OCTTREE(); Tot_Mass_center(); comp_Force(); Update(); }
30
N-body problem
31
Buckets Sort
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.