7 #include <cilk/cilk_api.h>
12 double xmin
, xmax
, ymin
, ymax
;
16 static void compute(void *_g
, int i
, int tid
)
18 global_t
*g
= (global_t
*)_g
;
19 double x
, x0
= g
->xmin
+ (g
->xmax
- g
->xmin
) * (i
%g
->w
) / g
->w
;
20 double y
, y0
= g
->ymin
+ (g
->ymax
- g
->ymin
) * (i
/g
->w
) / g
->h
;
25 for (k
= 0; k
< g
->max_iter
; ++k
) {
28 if (x
+ y
>= 4) break;
35 void kt_for(int n_threads
, int n_items
, void (*func
)(void*,int,int), void *data
);
37 int main(int argc
, char *argv
[])
39 int i
, tmp
, tot
, type
= 0, n_threads
= 2;
40 global_t global
= { 10240*100, 800, 600, -2., -1.2, -1.2, 1.2, 0 };
41 // global_t global = { 10240*1, 8, 6, -2., -1.2, -1.2, 1.2, 0 };
44 type
= argv
[1][0] == 'o'? 2 : argv
[1][0] == 'c'? 3 : argv
[1][0] == 'n'? 1 : 0;
45 if (argv
[1][0] >= '0' && argv
[1][0] <= '9')
46 n_threads
= atoi(argv
[1]);
48 fprintf(stderr
, "Usage: ./a.out [openmp | cilk | #threads]\n");
50 tot
= global
.w
* global
.h
;
51 global
.k
= calloc(tot
, sizeof(int));
52 for (i
= 0; i
< tot
; ++i
) global
.k
[i
] = -1;
54 kt_for(n_threads
, tot
, compute
, &global
);
55 } else if (type
== 2) {
56 #pragma omp parallel for
57 for (i
= 0; i
< tot
; ++i
)
58 compute(&global
, i
, 0);
59 } else if (type
== 3) {
61 cilk_for (i
= 0; i
< tot
; ++i
)
62 compute(&global
, i
, 0);
65 for (i
= tmp
= 0; i
< tot
; ++i
) tmp
+= (global
.k
[i
] < 0);