matheus__serpa

dependencies

Oct 3rd, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. /*Removal of dependencies*/
  2. // Serial version containing anti-dependency
  3. for(int i = 0; i < n; i++){
  4.    x = (b[i] + c[i]) / 2;
  5.    a[i] = a[i + 1] + x;
  6. }
  7.  
  8. // Parallel version with dependencies removed
  9. #pragma omp parallel for shared(a, a_copy)
  10. for(int i = 0; i < n; i++)
  11.    a_copy[i] + a[i + 1];
  12. #pragma omp parallel for shared(a, a_copy) private(x)
  13. for(int i = 0; i < n; i++){
  14.    x = (b[i] + c[i]) / 2;
  15.    a[i] = a_copy[i] + x;
  16. }
  17.  
  18.  
  19. // Serial version containing flow dependency
  20. for(int i = 1; i < n; i++){
  21.    b[i] = b[i] + a[i - 1];
  22.    a[i] = a[i] + c[i];
  23. }
  24.  
  25. // Parallel version with dependencies removed by loop skewing http://en.wikipedia.org/wiki/Loop_optimization
  26. b[1] = b[1] - a[0];
  27. #pragma omp parallel for shared(a, b, c)
  28. for(int i = 1; i < n; i++){
  29.    a[i] = a[i] + c[i];
  30.    b[i + 1] = b[i + 1] + a[i];
  31. }
  32. a[n - 1] = a[n - 1] + c[n - 1];
Advertisement
Add Comment
Please, Sign In to add comment