Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- begin = omp_get_wtime();
- #pragma omp parallel for reduction(+:sum_distribution)
- for (int i = 0; i < x.n; ++i) {
- int example = dist2[i].second;
- float d2 = 0.0, diff;
- for (int j = 0; j < x.d; ++j) {
- diff = x(example,j) - x(chosen_pts[ndx - 1],j);
- d2 += diff * diff;
- }
- if (d2 < dist2[i].first) {
- dist2[i].first = d2;
- }
- sum_distribution += dist2[i].first;
- }
- end = omp_get_wtime() - begin;
- std::cout << "center assigning -- "
- << ndx << " of " << k << " = "
- << (float)ndx / k * 100
- << "% is done. Elasped time: "<< (float)end <<"\n";
- /*
- without pragma
- center assigning -- 1 of 5000 = 0.02% is done. Elasped time: 1.9931
- center assigning -- 2 of 5000 = 0.04% is done. Elasped time: 2.35191
- center assigning -- 3 of 5000 = 0.06% is done. Elasped time: 2.24706
- center assigning -- 4 of 5000 = 0.08% is done. Elasped time: 2.24564
- center assigning -- 5 of 5000 = 0.1% is done. Elasped time: 2.38944
- center assigning -- 6 of 5000 = 0.12% is done. Elasped time: 2.10984
- center assigning -- 7 of 5000 = 0.14% is done. Elasped time: 2.14609
- center assigning -- 8 of 5000 = 0.16% is done. Elasped time: 2.13032
- center assigning -- 9 of 5000 = 0.18% is done. Elasped time: 2.09305
- center assigning -- 10 of 5000 = 0.2% is done. Elasped time: 2.66016
- center assigning -- 11 of 5000 = 0.22% is done. Elasped time: 2.08289
- center assigning -- 12 of 5000 = 0.24% is done. Elasped time: 2.09065
- center assigning -- 13 of 5000 = 0.26% is done. Elasped time: 2.08595
- center assigning -- 14 of 5000 = 0.28% is done. Elasped time: 2.10572
- center assigning -- 15 of 5000 = 0.3% is done. Elasped time: 2.05595
- center assigning -- 16 of 5000 = 0.32% is done. Elasped time: 2.06249
- ...keeps running...
- with pragma
- center assigning -- 1 of 5000 = 0.02% is done. Elasped time: 0.707227
- center assigning -- 2 of 5000 = 0.04% is done. Elasped time: 0.721848
- center assigning -- 3 of 5000 = 0.06% is done. Elasped time: 0.755143
- center assigning -- 4 of 5000 = 0.08% is done. Elasped time: 0.708477
- center assigning -- 5 of 5000 = 0.1% is done. Elasped time: 0.659136
- center assigning -- 6 of 5000 = 0.12% is done. Elasped time: 0.678935
- center assigning -- 7 of 5000 = 0.14% is done. Elasped time: 0.662681
- center assigning -- 8 of 5000 = 0.16% is done. Elasped time: 0.65667
- --- stops here ---
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement