-
Notifications
You must be signed in to change notification settings - Fork 0
/
openmp_max_threads.c
37 lines (31 loc) · 941 Bytes
/
openmp_max_threads.c
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
29
30
31
32
33
34
35
36
37
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
int np, t_id, num_threads, max_threads;
if (argc != 2) {
printf(" %s Number_of_threads \n", argv[0]);
return -1;
} else {
np = atoi(argv[1]);
if (np < 1) {
printf("Error: Number_of_threads (%i) < 1 \n", np);
return -1;
}
}
omp_set_num_threads(np);
max_threads = omp_get_max_threads();
omp_set_num_threads(max_threads/2);
num_threads = omp_get_num_threads();
printf("Before Parallel: num_threads=%i max_threads %i\n", num_threads,
max_threads);
#pragma omp parallel default(none) private(num_threads, t_id)
{
num_threads = omp_get_num_threads();
t_id = omp_get_thread_num();
printf("In Parallel: num_threads=%i t_id=%i \n", num_threads, t_id);
}
num_threads = omp_get_num_threads();
printf("After Parallel: num_threads=%i \n", num_threads);
return 0;
} // main()