[OpenACC] Implement 'collapse' for combined constructs.
[llvm-project.git] / openmp / runtime / test / affinity / kmp-affinity-reset.c
blobdac75f70a65e31ccce670396b19eff70d386cf17
1 // RUN: %libomp-compile -D_GNU_SOURCE
2 // RUN: env OMP_NUM_THREADS=2,2 KMP_AFFINITY=reset,granularity=thread,compact %libomp-run
3 // REQUIRES: linux
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <omp.h>
9 #include "libomp_test_affinity.h"
11 #define CHECK_EQUAL 0
12 #define CHECK_NOT_EQUAL 1
14 void check_primary_thread_affinity(int line, affinity_mask_t *other_aff,
15 int type) {
16 #pragma omp master
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);
22 exit(EXIT_FAILURE);
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);
26 exit(EXIT_FAILURE);
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)
37 int main() {
38 int i;
39 affinity_mask_t *initial_mask = affinity_mask_alloc();
40 get_thread_affinity(initial_mask);
42 for (i = 0; i < 10; ++i) {
43 #pragma omp parallel
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) {
52 #pragma omp parallel
54 CHECK_PRIMARY_THREAD_AFFINITY_NOT_EQUAL(initial_mask);
56 #pragma omp parallel
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);
65 return EXIT_SUCCESS;