forked from OpenMP/Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample_affinity.6.c
More file actions
38 lines (32 loc) · 860 Bytes
/
Example_affinity.6.c
File metadata and controls
38 lines (32 loc) · 860 Bytes
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
38
/*
* @@name: affinity.6c
* @@type: C
* @@compilable: yes
* @@linkable: no
* @@expect: success
*/
#include <stdio.h>
#include <omp.h>
void socket_init(int socket_num)
{
int n_procs;
n_procs = omp_get_place_num_procs(socket_num);
#pragma omp parallel num_threads(n_procs) proc_bind(close)
{
printf("Reporting in from socket num, thread num: %d %d\n",
socket_num,omp_get_thread_num() );
}
}
int main()
{
int n_sockets, socket_num;
omp_set_nested(1); // or export OMP_NESTED=true
omp_set_max_active_levels(2); // or export OMP_MAX_ACTIVE_LEVELS=2
n_sockets = omp_get_num_places();
#pragma omp parallel num_threads(n_sockets) private(socket_num) \
proc_bind(spread)
{
socket_num = omp_get_place_num();
socket_init(socket_num);
}
}