Advertisement
Guest User

Untitled

a guest
Jan 5th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         begin = omp_get_wtime();
  2.  
  3.         #pragma omp parallel for reduction(+:sum_distribution)
  4.         for (int i = 0; i < x.n; ++i) {
  5.             int example = dist2[i].second;
  6.             float d2 = 0.0, diff;
  7.             for (int j = 0; j < x.d; ++j) {
  8.                 diff = x(example,j) - x(chosen_pts[ndx - 1],j);
  9.                 d2 += diff * diff;
  10.             }
  11.             if (d2 < dist2[i].first) {
  12.                 dist2[i].first = d2;
  13.             }
  14.            
  15.             sum_distribution += dist2[i].first;
  16.         }
  17.         end = omp_get_wtime() - begin;
  18.  
  19.         std::cout << "center assigning -- "
  20.                 << ndx << " of " << k << " = "
  21.                 << (float)ndx / k * 100
  22.                 << "% is done. Elasped time: "<< (float)end <<"\n";
  23. /*
  24. without pragma
  25. center assigning -- 1 of 5000 = 0.02% is done. Elasped time: 1.9931
  26. center assigning -- 2 of 5000 = 0.04% is done. Elasped time: 2.35191
  27. center assigning -- 3 of 5000 = 0.06% is done. Elasped time: 2.24706
  28. center assigning -- 4 of 5000 = 0.08% is done. Elasped time: 2.24564
  29. center assigning -- 5 of 5000 = 0.1% is done. Elasped time: 2.38944
  30. center assigning -- 6 of 5000 = 0.12% is done. Elasped time: 2.10984
  31. center assigning -- 7 of 5000 = 0.14% is done. Elasped time: 2.14609
  32. center assigning -- 8 of 5000 = 0.16% is done. Elasped time: 2.13032
  33. center assigning -- 9 of 5000 = 0.18% is done. Elasped time: 2.09305
  34. center assigning -- 10 of 5000 = 0.2% is done. Elasped time: 2.66016
  35. center assigning -- 11 of 5000 = 0.22% is done. Elasped time: 2.08289
  36. center assigning -- 12 of 5000 = 0.24% is done. Elasped time: 2.09065
  37. center assigning -- 13 of 5000 = 0.26% is done. Elasped time: 2.08595
  38. center assigning -- 14 of 5000 = 0.28% is done. Elasped time: 2.10572
  39. center assigning -- 15 of 5000 = 0.3% is done. Elasped time: 2.05595
  40. center assigning -- 16 of 5000 = 0.32% is done. Elasped time: 2.06249
  41. ...keeps running...
  42.  
  43. with pragma
  44. center assigning -- 1 of 5000 = 0.02% is done. Elasped time: 0.707227
  45. center assigning -- 2 of 5000 = 0.04% is done. Elasped time: 0.721848
  46. center assigning -- 3 of 5000 = 0.06% is done. Elasped time: 0.755143
  47. center assigning -- 4 of 5000 = 0.08% is done. Elasped time: 0.708477
  48. center assigning -- 5 of 5000 = 0.1% is done. Elasped time: 0.659136
  49. center assigning -- 6 of 5000 = 0.12% is done. Elasped time: 0.678935
  50. center assigning -- 7 of 5000 = 0.14% is done. Elasped time: 0.662681
  51. center assigning -- 8 of 5000 = 0.16% is done. Elasped time: 0.65667
  52. --- stops here ---
  53.  
  54. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement