1 // RUN: %libomp-compile -D_GNU_SOURCE
2 // RUN: env OMP_NUM_THREADS=2,2 KMP_AFFINITY=reset,granularity=thread,compact %libomp-run
9 #include "libomp_test_affinity.h"
12 #define CHECK_NOT_EQUAL 1
14 void check_primary_thread_affinity(int line
, affinity_mask_t
*other_aff
,
18 affinity_mask_t
*primary_aff
= affinity_mask_alloc();
19 get_thread_affinity(primary_aff
);
20 if (type
== CHECK_EQUAL
&& !affinity_mask_equal(primary_aff
, other_aff
)) {
21 fprintf(stderr
, "error: line %d: primary affinity was not equal\n", line
);
23 } else if (type
== CHECK_NOT_EQUAL
&&
24 affinity_mask_equal(primary_aff
, other_aff
)) {
25 fprintf(stderr
, "error: line %d: primary affinity was equal\n", line
);
28 affinity_mask_free(primary_aff
);
32 #define CHECK_PRIMARY_THREAD_AFFINITY_EQUAL(other_aff) \
33 check_primary_thread_affinity(__LINE__, other_aff, CHECK_EQUAL)
34 #define CHECK_PRIMARY_THREAD_AFFINITY_NOT_EQUAL(other_aff) \
35 check_primary_thread_affinity(__LINE__, other_aff, CHECK_NOT_EQUAL)
39 affinity_mask_t
*initial_mask
= affinity_mask_alloc();
40 get_thread_affinity(initial_mask
);
42 for (i
= 0; i
< 10; ++i
) {
45 CHECK_PRIMARY_THREAD_AFFINITY_NOT_EQUAL(initial_mask
);
47 CHECK_PRIMARY_THREAD_AFFINITY_EQUAL(initial_mask
);
50 omp_set_max_active_levels(2);
51 for (i
= 0; i
< 10; ++i
) {
54 CHECK_PRIMARY_THREAD_AFFINITY_NOT_EQUAL(initial_mask
);
57 CHECK_PRIMARY_THREAD_AFFINITY_NOT_EQUAL(initial_mask
);
59 CHECK_PRIMARY_THREAD_AFFINITY_NOT_EQUAL(initial_mask
);
61 CHECK_PRIMARY_THREAD_AFFINITY_EQUAL(initial_mask
);
64 affinity_mask_free(initial_mask
);