forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omp.cpp
28 lines (24 loc) · 792 Bytes
/
omp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "mandel.hpp"
#include <omp.h>
void mandelbrot_omp(unsigned num_threads, int d = D) {
omp_set_num_threads(num_threads);
int i,j ;
# pragma omp parallel shared (d) private (i, j)
{
# pragma omp for schedule(dynamic, 1)
for(i=0; i<H ;i ++) {
for(j=0; j<W; j++) {
auto xy = scale_xy(i, j);
auto value = escape_time(xy.first, xy.second, d);
auto k = 3*(j*W + i);
std::tie(RGB[k], RGB[k+1], RGB[k+2]) = get_color(value);
}
}
}
}
std::chrono::microseconds measure_time_omp(unsigned num_threads) {
auto beg = std::chrono::high_resolution_clock::now();
mandelbrot_omp(num_threads);
auto end = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
}