CCCC
C bytecode compiler + VM interpreter
Loading...
Searching...
No Matches
omp.h
Go to the documentation of this file.
1
11#ifndef __OMP_H
12#define __OMP_H
13
14#include <stdio.h>
15#include <time.h>
16#include <unistd.h>
17
25
28#define omp_sched_monotonic ((omp_sched_t)0x80000000u)
29
39
41#define omp_lock_hint_none omp_sync_hint_none
42#define omp_lock_hint_uncontended omp_sync_hint_uncontended
43#define omp_lock_hint_contended omp_sync_hint_contended
44#define omp_lock_hint_nonspeculative omp_sync_hint_nonspeculative
45#define omp_lock_hint_speculative omp_sync_hint_speculative
46
47#ifdef __CCCC_OMP_THREADED__
48
49/* -c=native, -m and -c=generated run parallel regions on real threads; the
50 runtime is emitted into the output. */
51
52typedef struct {
53 void *__impl;
55
56typedef struct {
57 void *__impl;
58 int __reserved; /* keeps it a distinct type from omp_lock_t */
60
61int omp_get_num_threads(void);
62int omp_get_max_threads(void);
63int omp_get_thread_num(void);
64int omp_get_thread_limit(void);
65int omp_in_parallel(void);
66int omp_in_final(void);
67int omp_get_num_procs(void);
68void omp_set_num_threads(int n);
69void omp_set_dynamic(int on);
70int omp_get_dynamic(void);
71double omp_get_wtime(void);
72double omp_get_wtick(void);
73void omp_set_schedule(omp_sched_t kind, int chunk);
74void omp_get_schedule(omp_sched_t *kind, int *chunk);
75
76void omp_init_lock(omp_lock_t *lock);
77void omp_destroy_lock(omp_lock_t *lock);
78void omp_set_lock(omp_lock_t *lock);
79void omp_unset_lock(omp_lock_t *lock);
80int omp_test_lock(omp_lock_t *lock);
81
82void omp_init_nest_lock(omp_nest_lock_t *lock);
83void omp_destroy_nest_lock(omp_nest_lock_t *lock);
84void omp_set_nest_lock(omp_nest_lock_t *lock);
85void omp_unset_nest_lock(omp_nest_lock_t *lock);
86int omp_test_nest_lock(omp_nest_lock_t *lock);
87
88#else
89
91typedef struct {
92 int held;
94
96typedef struct {
97 int depth;
99
101static inline int omp_get_num_threads(void) { return 1; }
103static inline int omp_get_max_threads(void) { return 1; }
105static inline int omp_get_thread_num(void) { return 0; }
107static inline int omp_get_thread_limit(void) { return 1; }
109static inline int omp_in_parallel(void) { return 0; }
111static inline int omp_in_final(void) {
112 return 0;
113}
115static inline int omp_get_num_procs(void) {
116 long n = sysconf(_SC_NPROCESSORS_ONLN);
117 return n > 0 ? (int)n : 1;
118}
120static inline void omp_set_num_threads(int n) { (void)n; }
122static inline void omp_set_dynamic(int on) { (void)on; }
124static inline int omp_get_dynamic(void) { return 0; }
125
126static inline int *__omp_schedule_icv(void) {
127 static int icv[2] = {omp_sched_static, 0};
128 return icv;
129}
132static inline void omp_set_schedule(omp_sched_t kind, int chunk) {
133 int k = (int)kind & 0x7fffffff;
134 if (k >= omp_sched_static && k <= omp_sched_auto) {
135 __omp_schedule_icv()[0] = k;
136 __omp_schedule_icv()[1] = chunk;
137 }
138}
140static inline void omp_get_schedule(omp_sched_t *kind, int *chunk) {
141 *kind = (omp_sched_t)__omp_schedule_icv()[0];
142 *chunk = __omp_schedule_icv()[1];
143}
144
146static inline double omp_get_wtime(void) {
147 struct timespec ts;
148 clock_gettime(CLOCK_MONOTONIC, &ts);
149 return (double)ts.tv_sec + (double)ts.tv_nsec * 1e-9;
150}
152static inline double omp_get_wtick(void) { return 1e-9; }
153
155static inline void omp_init_lock(omp_lock_t *lock) { lock->held = 0; }
157static inline void omp_destroy_lock(omp_lock_t *lock) { lock->held = 0; }
159static inline void omp_set_lock(omp_lock_t *lock) {
160 if (lock->held) {
161 fputs("omp_set_lock: lock is already held (deadlock)\n", stderr);
162 __builtin_trap();
163 }
164 lock->held = 1;
165}
167static inline void omp_unset_lock(omp_lock_t *lock) { lock->held = 0; }
169static inline int omp_test_lock(omp_lock_t *lock) {
170 if (lock->held)
171 return 0;
172 lock->held = 1;
173 return 1;
174}
175
177static inline void omp_init_nest_lock(omp_nest_lock_t *lock) {
178 lock->depth = 0;
179}
181static inline void omp_destroy_nest_lock(omp_nest_lock_t *lock) {
182 lock->depth = 0;
183}
185static inline void omp_set_nest_lock(omp_nest_lock_t *lock) { lock->depth++; }
187static inline void omp_unset_nest_lock(omp_nest_lock_t *lock) {
188 if (lock->depth > 0)
189 lock->depth--;
190}
192static inline int omp_test_nest_lock(omp_nest_lock_t *lock) {
193 return ++lock->depth;
194}
195
196#endif /* __CCCC_OMP_THREADED__ */
197
198#endif
omp_sync_hint_t omp_lock_hint_t
Definition omp.h:40
omp_sync_hint_t
Hints for #pragma omp atomic hint(...); or them together, but not contended with uncontended or specu...
Definition omp.h:32
@ omp_sync_hint_uncontended
Definition omp.h:34
@ omp_sync_hint_contended
Definition omp.h:35
@ omp_sync_hint_none
Definition omp.h:33
@ omp_sync_hint_nonspeculative
Definition omp.h:36
@ omp_sync_hint_speculative
Definition omp.h:37
omp_sched_t
Loop schedule kinds for omp_set_schedule() and omp_get_schedule().
Definition omp.h:19
@ omp_sched_dynamic
Definition omp.h:21
@ omp_sched_auto
Definition omp.h:23
@ omp_sched_guided
Definition omp.h:22
@ omp_sched_static
Definition omp.h:20
Simple lock.
Definition omp.h:91
int held
Definition omp.h:92
Nestable lock.
Definition omp.h:96
int depth
Definition omp.h:97