[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / openmp / libomptarget / deviceRTLs / nvptx / test / parallel / num_threads.c
blob4a2f73fee827a95baa675797710724feca08d869
1 // RUN: %compile-run-and-check
3 #include <stdio.h>
4 #include <omp.h>
6 const int WarpSize = 32;
7 const int NumThreads1 = 1 * WarpSize;
8 const int NumThreads2 = 2 * WarpSize;
9 const int NumThreads3 = 3 * WarpSize;
10 const int MaxThreads = 1024;
12 int main(int argc, char *argv[]) {
13 int check1[MaxThreads];
14 int check2[MaxThreads];
15 int check3[MaxThreads];
16 int check4[MaxThreads];
17 for (int i = 0; i < MaxThreads; i++) {
18 check1[i] = check2[i] = check3[i] = check4[i] = 0;
21 int maxThreads1 = -1;
22 int maxThreads2 = -1;
23 int maxThreads3 = -1;
25 #pragma omp target map(check1[:], check2[:], check3[:], check4[:]) \
26 map(maxThreads1, maxThreads2, maxThreads3)
28 #pragma omp parallel num_threads(NumThreads1)
30 check1[omp_get_thread_num()] += omp_get_num_threads();
33 // API method to set number of threads in parallel regions without
34 // num_threads() clause.
35 omp_set_num_threads(NumThreads2);
36 maxThreads1 = omp_get_max_threads();
37 #pragma omp parallel
39 check2[omp_get_thread_num()] += omp_get_num_threads();
42 maxThreads2 = omp_get_max_threads();
44 // num_threads() clause should override nthreads-var ICV.
45 #pragma omp parallel num_threads(NumThreads3)
47 check3[omp_get_thread_num()] += omp_get_num_threads();
50 maxThreads3 = omp_get_max_threads();
52 // Effect from omp_set_num_threads() should still be visible.
53 #pragma omp parallel
55 check4[omp_get_thread_num()] += omp_get_num_threads();
59 // CHECK: maxThreads1 = 64
60 printf("maxThreads1 = %d\n", maxThreads1);
61 // CHECK: maxThreads2 = 64
62 printf("maxThreads2 = %d\n", maxThreads2);
63 // CHECK: maxThreads3 = 64
64 printf("maxThreads3 = %d\n", maxThreads3);
66 // CHECK-NOT: invalid
67 for (int i = 0; i < MaxThreads; i++) {
68 if (i < NumThreads1) {
69 if (check1[i] != NumThreads1) {
70 printf("invalid: check1[%d] should be %d, is %d\n", i, NumThreads1, check1[i]);
72 } else if (check1[i] != 0) {
73 printf("invalid: check1[%d] should be 0, is %d\n", i, check1[i]);
76 if (i < NumThreads2) {
77 if (check2[i] != NumThreads2) {
78 printf("invalid: check2[%d] should be %d, is %d\n", i, NumThreads2, check2[i]);
80 } else if (check2[i] != 0) {
81 printf("invalid: check2[%d] should be 0, is %d\n", i, check2[i]);
84 if (i < NumThreads3) {
85 if (check3[i] != NumThreads3) {
86 printf("invalid: check3[%d] should be %d, is %d\n", i, NumThreads3, check3[i]);
88 } else if (check3[i] != 0) {
89 printf("invalid: check3[%d] should be 0, is %d\n", i, check3[i]);
92 if (i < NumThreads2) {
93 if (check4[i] != NumThreads2) {
94 printf("invalid: check4[%d] should be %d, is %d\n", i, NumThreads2, check4[i]);
96 } else if (check4[i] != 0) {
97 printf("invalid: check4[%d] should be 0, is %d\n", i, check4[i]);
101 return 0;