1 / 33

Partitioning and Divide-and-Conquer Strategies

Partitioning and Divide-and-Conquer Strategies. Data partitioning (or Domain decomposition) Functional decomposition. 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. Addition of a sequence of numbers.

tex
Download Presentation

Partitioning and Divide-and-Conquer Strategies

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Partitioning and Divide-and-Conquer Strategies Data partitioning (or Domain decomposition) Functional decomposition

  2. x0…….x(n/m)-1 xn/m…….x(2n/m)-1 x(m-1)n/m…….xn-1 + + + ……. + sum Partitioning and Divide-and-Conquer Strategies

  3. Addition of a sequence of numbers Slave recv(numbers, s, Pmaster); sum = 0; for(i=0 ; i<s ; i++) part_sum = part_sum + numbers[i]; send(&part_sum, Pmaster); 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; }

  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. P0 P0 P4 P0 P2 P4 P6 P0 P1 P2 P3 P4 P5 P6 P7 Divide-and-Conquer

  11. P0 P0 P4 P0 P2 P4 P6 P0 P1 P2 P3 P4 P5 P6 P7 Divide-and-Conquer

  12. Divide-and-Conquer 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);

  13. Divide-and-Conquer 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

  17. M-way Divide-and-Conquer

  18. Numerical Integration f(x) f(q) f(p) a p q b

  19. Numerical Integration f(x) f(q) f(p) a p q b

  20. Numerical Integration f(x) f(q) f(p) a p q b

  21. Numerical Integration A B

  22. Numerical Integration 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. N-body problem 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. N-body problem for( t=0 ; t<tmax ; t++) { Build_OCTTREE(); Tot_Mass_center(); comp_Force(); Update(); }

  30. N-body problem

  31. Buckets Sort

  32. Buckets Sort

  33. Buckets Sort

More Related