LLVM OpenMP 20.0.0git
kmp_set_dispatch_buf.c
Go to the documentation of this file.
1// RUN: %libomp-compile && %libomp-run 7
2// RUN: %libomp-run 0 && %libomp-run -1
3// RUN: %libomp-run 1 && %libomp-run 2 && %libomp-run 5
4// RUN: %libomp-compile -DMY_SCHEDULE=guided && %libomp-run 7
5// RUN: %libomp-run 1 && %libomp-run 2 && %libomp-run 5
6// UNSUPPORTED: clang-11, clang-12
7#include <stdio.h>
8#include <omp.h>
9#include <stdlib.h>
10#include <limits.h>
11#include "omp_testsuite.h"
12
13#define INCR 7
14#define MY_MAX 200
15#define MY_MIN -200
16#ifndef MY_SCHEDULE
17# define MY_SCHEDULE dynamic
18#endif
19
22
24{
25 int success = 1;
26 a = 0;
27 b = 0;
28 // run many small dynamic loops to stress the dispatch buffer system
29 #pragma omp parallel
30 {
31 int i,j;
32 for (j = 0; j < num_loops; j++) {
33 #pragma omp for schedule(MY_SCHEDULE) nowait
34 for (i = MY_MIN; i < MY_MAX; i+=INCR) {
35 #pragma omp atomic
36 a++;
37 }
38 #pragma omp for schedule(MY_SCHEDULE) nowait
39 for (i = MY_MAX; i >= MY_MIN; i-=INCR) {
40 #pragma omp atomic
41 b++;
42 }
43 }
44 }
45 // detect failure
46 if (a != a_known_value || b != b_known_value) {
47 success = 0;
48 printf("a = %d (should be %d), b = %d (should be %d)\n", a, a_known_value,
50 }
51 return success;
52}
53
54int main(int argc, char** argv)
55{
56 int i,j;
57 int num_failed=0;
58
59 if (argc != 2) {
60 fprintf(stderr, "usage: %s num_disp_buffers\n", argv[0]);
61 exit(1);
62 }
63
64 // set the number of dispatch buffers
65 num_disp_buffers = atoi(argv[1]);
67
68 // figure out the known values to compare with calculated result
69 a_known_value = 0;
70 b_known_value = 0;
71
72 // if specified to use bad num_disp_buffers set num_loops
73 // to something reasonable
74 if (num_disp_buffers <= 0)
75 num_loops = 10;
76 else
78
79 for (j = 0; j < num_loops; j++) {
80 for (i = MY_MIN; i < MY_MAX; i+=INCR)
82 for (i = MY_MAX; i >= MY_MIN; i-=INCR)
84 }
85
86 for(i = 0; i < REPETITIONS; i++) {
88 num_failed++;
89 }
90 }
91 if (num_failed == 0)
92 printf("passed\n");
93 else
94 printf("failed %d\n", num_failed);
95 return num_failed;
96}
#define MY_MAX
int test_kmp_set_disp_num_buffers()
#define MY_MIN
int a_known_value
#define INCR
int b_known_value
#define kmp_set_disp_num_buffers
Definition: kmp_stub.cpp:46
#define i
Definition: kmp_stub.cpp:87
#define REPETITIONS
Definition: omp_testsuite.h:13
int main()
Definition: test-touch.c:21
int num_disp_buffers
int num_loops