PR target/35485
[official-gcc.git] / libgomp / testsuite / libgomp.c / lib-1.c
blob4839cf936f20d20a90a5fa4e4b6764fa0d6bcb3d
1 #include <stdlib.h>
2 #include <omp.h>
4 int
5 main (void)
7 double d, e;
8 int l;
9 omp_lock_t lck;
10 omp_nest_lock_t nlck;
12 d = omp_get_wtime ();
14 omp_init_lock (&lck);
15 omp_set_lock (&lck);
16 if (omp_test_lock (&lck))
17 abort ();
18 omp_unset_lock (&lck);
19 if (! omp_test_lock (&lck))
20 abort ();
21 if (omp_test_lock (&lck))
22 abort ();
23 omp_unset_lock (&lck);
24 omp_destroy_lock (&lck);
26 omp_init_nest_lock (&nlck);
27 if (omp_test_nest_lock (&nlck) != 1)
28 abort ();
29 omp_set_nest_lock (&nlck);
30 if (omp_test_nest_lock (&nlck) != 3)
31 abort ();
32 omp_unset_nest_lock (&nlck);
33 omp_unset_nest_lock (&nlck);
34 if (omp_test_nest_lock (&nlck) != 2)
35 abort ();
36 omp_unset_nest_lock (&nlck);
37 omp_unset_nest_lock (&nlck);
38 omp_destroy_nest_lock (&nlck);
40 omp_set_dynamic (1);
41 if (! omp_get_dynamic ())
42 abort ();
43 omp_set_dynamic (0);
44 if (omp_get_dynamic ())
45 abort ();
47 omp_set_nested (1);
48 if (! omp_get_nested ())
49 abort ();
50 omp_set_nested (0);
51 if (omp_get_nested ())
52 abort ();
54 omp_set_num_threads (5);
55 if (omp_get_num_threads () != 1)
56 abort ();
57 if (omp_get_max_threads () != 5)
58 abort ();
59 if (omp_get_thread_num () != 0)
60 abort ();
61 omp_set_num_threads (3);
62 if (omp_get_num_threads () != 1)
63 abort ();
64 if (omp_get_max_threads () != 3)
65 abort ();
66 if (omp_get_thread_num () != 0)
67 abort ();
68 l = 0;
69 #pragma omp parallel reduction (|:l)
71 l = omp_get_num_threads () != 3;
72 l |= omp_get_thread_num () < 0;
73 l |= omp_get_thread_num () >= 3;
74 #pragma omp master
75 l |= omp_get_thread_num () != 0;
77 if (l)
78 abort ();
80 if (omp_get_num_procs () <= 0)
81 abort ();
82 if (omp_in_parallel ())
83 abort ();
84 #pragma omp parallel reduction (|:l)
85 l = ! omp_in_parallel ();
86 #pragma omp parallel reduction (|:l) if (1)
87 l = ! omp_in_parallel ();
89 e = omp_get_wtime ();
90 if (d > e)
91 abort ();
92 d = omp_get_wtick ();
93 /* Negative precision is definitely wrong,
94 bigger than 1s clock resolution is also strange. */
95 if (d <= 0 || d > 1)
96 abort ();
98 return 0;