[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / openmp / libomptarget / deviceRTLs / nvptx / test / parallel / thread_limit.c
blob5e40bb564aa0f3931f8417e0f2546c3e9c35f493
1 // RUN: %compile-run-and-check
3 #include <stdio.h>
4 #include <omp.h>
6 const int WarpSize = 32;
7 const int ThreadLimit = 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 for (int i = 0; i < MaxThreads; i++) {
17 check1[i] = check2[i] = check3[i] = 0;
20 int threadLimit = -1;
22 #pragma omp target teams num_teams(1) thread_limit(ThreadLimit) \
23 map(check1[:], check2[:], check3[:], threadLimit)
25 threadLimit = omp_get_thread_limit();
27 // All parallel regions should get as many threads as specified by the
28 // thread_limit() clause.
29 #pragma omp parallel
31 check1[omp_get_thread_num()] += omp_get_num_threads();
34 omp_set_num_threads(NumThreads2);
35 #pragma omp parallel
37 check2[omp_get_thread_num()] += omp_get_num_threads();
40 #pragma omp parallel num_threads(NumThreads3)
42 check3[omp_get_thread_num()] += omp_get_num_threads();
46 // CHECK: threadLimit = 32
47 printf("threadLimit = %d\n", threadLimit);
49 // CHECK-NOT: invalid
50 for (int i = 0; i < MaxThreads; i++) {
51 if (i < ThreadLimit) {
52 if (check1[i] != ThreadLimit) {
53 printf("invalid: check1[%d] should be %d, is %d\n", i, ThreadLimit, check1[i]);
55 } else if (check1[i] != 0) {
56 printf("invalid: check1[%d] should be 0, is %d\n", i, check1[i]);
59 if (i < ThreadLimit) {
60 if (check2[i] != ThreadLimit) {
61 printf("invalid: check2[%d] should be %d, is %d\n", i, ThreadLimit, check2[i]);
63 } else if (check2[i] != 0) {
64 printf("invalid: check2[%d] should be 0, is %d\n", i, check2[i]);
67 if (i < ThreadLimit) {
68 if (check3[i] != ThreadLimit) {
69 printf("invalid: check3[%d] should be %d, is %d\n", i, ThreadLimit, check3[i]);
71 } else if (check3[i] != 0) {
72 printf("invalid: check3[%d] should be 0, is %d\n", i, check3[i]);
76 return 0;