Commit | Line | Data |
---|---|---|
80f575fc DM |
1 | #ifdef USE_OMP |
2 | int openmptest(){ | |
3 | int start = timeOfDayinMS(); | |
4 | long int sum=0; | |
5 | int i,j; | |
6 | ||
7 | #pragma omp parallel for shared(sum) | |
8 | for (i=0; i<10;i++){ | |
9 | printf("num theads: %i\n",omp_get_thread_num()); | |
10 | long int k=0; | |
11 | for (j=0; j<40000;j++){ | |
12 | k+=sqrt(j); | |
13 | } | |
14 | #pragma omp atomic | |
15 | sum+=k; | |
16 | } | |
17 | int end = timeOfDayinMS(); | |
18 | fprintf(stderr, "Sum: %li\n",sum); | |
19 | return end-start; | |
20 | } | |
21 | int openmp(){ | |
22 | fprintf(stderr, "Processors: %i, Max # theads: %i\n", omp_get_num_procs(), omp_get_max_threads()); | |
23 | ||
24 | int time, timeref; | |
25 | omp_set_dynamic( 0 ); | |
26 | omp_set_num_threads( 1 ); | |
27 | fprintf(stderr,"********** omp speedtest:\n"); | |
28 | time = openmptest(); | |
29 | fprintf(stderr,"***C time: %i ms\n", time); | |
30 | timeref=time; | |
31 | omp_set_dynamic( 0 ); | |
32 | omp_set_num_threads( 2 ); | |
33 | time = openmptest(); | |
34 | fprintf(stderr,"***C (2)time: %i ms, Speedup %f\n", time, | |
35 | (double)timeref/time); | |
36 | omp_set_dynamic( 1 ); | |
37 | return 1; | |
38 | } | |
39 | #endif |