1 /* Copyright (C) 2005-2021 Free Software Foundation, Inc.
2    Contributed by Jakub Jelinek <jakub@redhat.com>.
3 
4    This file is part of the GNU Offloading and Multi Processing Library
5    (libgomp).
6 
7    Libgomp is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3, or (at your option)
10    any later version.
11 
12    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15    more details.
16 
17    Under Section 7 of GPL version 3, you are granted additional
18    permissions described in the GCC Runtime Library Exception, version
19    3.1, as published by the Free Software Foundation.
20 
21    You should have received a copy of the GNU General Public License and
22    a copy of the GCC Runtime Library Exception along with this program;
23    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24    <http://www.gnu.org/licenses/>.  */
25 
26 /* This file contains Fortran wrapper routines.  */
27 
28 #include "libgomp.h"
29 #include "libgomp_f.h"
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <limits.h>
34 
35 #ifdef HAVE_ATTRIBUTE_ALIAS
36 /* Use internal aliases if possible.  */
37 # ifndef LIBGOMP_GNU_SYMBOL_VERSIONING
38 ialias_redirect (omp_init_lock)
ialias_redirect(omp_init_nest_lock)39 ialias_redirect (omp_init_nest_lock)
40 ialias_redirect (omp_destroy_lock)
41 ialias_redirect (omp_destroy_nest_lock)
42 ialias_redirect (omp_set_lock)
43 ialias_redirect (omp_set_nest_lock)
44 ialias_redirect (omp_unset_lock)
45 ialias_redirect (omp_unset_nest_lock)
46 ialias_redirect (omp_test_lock)
47 ialias_redirect (omp_test_nest_lock)
48 # endif
49 ialias_redirect (omp_set_dynamic)
50 ialias_redirect (omp_get_dynamic)
51 #pragma GCC diagnostic push
52 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
53 ialias_redirect (omp_set_nested)
54 ialias_redirect (omp_get_nested)
55 #pragma GCC diagnostic pop
56 ialias_redirect (omp_set_num_threads)
57 ialias_redirect (omp_in_parallel)
58 ialias_redirect (omp_get_max_threads)
59 ialias_redirect (omp_get_num_procs)
60 ialias_redirect (omp_get_num_threads)
61 ialias_redirect (omp_get_thread_num)
62 ialias_redirect (omp_get_wtick)
63 ialias_redirect (omp_get_wtime)
64 ialias_redirect (omp_set_schedule)
65 ialias_redirect (omp_get_schedule)
66 ialias_redirect (omp_get_thread_limit)
67 ialias_redirect (omp_set_max_active_levels)
68 ialias_redirect (omp_get_max_active_levels)
69 ialias_redirect (omp_get_supported_active_levels)
70 ialias_redirect (omp_set_num_teams)
71 ialias_redirect (omp_get_max_teams)
72 ialias_redirect (omp_set_teams_thread_limit)
73 ialias_redirect (omp_get_teams_thread_limit)
74 ialias_redirect (omp_get_level)
75 ialias_redirect (omp_get_ancestor_thread_num)
76 ialias_redirect (omp_get_team_size)
77 ialias_redirect (omp_get_active_level)
78 ialias_redirect (omp_in_final)
79 ialias_redirect (omp_get_cancellation)
80 ialias_redirect (omp_get_proc_bind)
81 ialias_redirect (omp_get_num_places)
82 ialias_redirect (omp_get_place_num_procs)
83 ialias_redirect (omp_get_place_proc_ids)
84 ialias_redirect (omp_get_place_num)
85 ialias_redirect (omp_get_partition_num_places)
86 ialias_redirect (omp_get_partition_place_nums)
87 ialias_redirect (omp_set_default_device)
88 ialias_redirect (omp_get_default_device)
89 ialias_redirect (omp_get_num_devices)
90 ialias_redirect (omp_get_device_num)
91 ialias_redirect (omp_get_num_teams)
92 ialias_redirect (omp_get_team_num)
93 ialias_redirect (omp_is_initial_device)
94 ialias_redirect (omp_get_initial_device)
95 ialias_redirect (omp_get_max_task_priority)
96 ialias_redirect (omp_pause_resource)
97 ialias_redirect (omp_pause_resource_all)
98 ialias_redirect (omp_init_allocator)
99 ialias_redirect (omp_destroy_allocator)
100 ialias_redirect (omp_set_default_allocator)
101 ialias_redirect (omp_get_default_allocator)
102 ialias_redirect (omp_display_env)
103 ialias_redirect (omp_fulfill_event)
104 #endif
105 
106 #ifndef LIBGOMP_GNU_SYMBOL_VERSIONING
107 # define gomp_init_lock__30 omp_init_lock_
108 # define gomp_destroy_lock__30 omp_destroy_lock_
109 # define gomp_set_lock__30 omp_set_lock_
110 # define gomp_unset_lock__30 omp_unset_lock_
111 # define gomp_test_lock__30 omp_test_lock_
112 # define gomp_init_nest_lock__30 omp_init_nest_lock_
113 # define gomp_destroy_nest_lock__30 omp_destroy_nest_lock_
114 # define gomp_set_nest_lock__30 omp_set_nest_lock_
115 # define gomp_unset_nest_lock__30 omp_unset_nest_lock_
116 # define gomp_test_nest_lock__30 omp_test_nest_lock_
117 #endif
118 
119 void
120 gomp_init_lock__30 (omp_lock_arg_t lock)
121 {
122 #ifndef OMP_LOCK_DIRECT
123   omp_lock_arg (lock) = malloc (sizeof (omp_lock_t));
124 #endif
125   gomp_init_lock_30 (omp_lock_arg (lock));
126 }
127 
128 void
gomp_init_nest_lock__30(omp_nest_lock_arg_t lock)129 gomp_init_nest_lock__30 (omp_nest_lock_arg_t lock)
130 {
131 #ifndef OMP_NEST_LOCK_DIRECT
132   omp_nest_lock_arg (lock) = malloc (sizeof (omp_nest_lock_t));
133 #endif
134   gomp_init_nest_lock_30 (omp_nest_lock_arg (lock));
135 }
136 
137 void
gomp_destroy_lock__30(omp_lock_arg_t lock)138 gomp_destroy_lock__30 (omp_lock_arg_t lock)
139 {
140   gomp_destroy_lock_30 (omp_lock_arg (lock));
141 #ifndef OMP_LOCK_DIRECT
142   free (omp_lock_arg (lock));
143   omp_lock_arg (lock) = NULL;
144 #endif
145 }
146 
147 void
gomp_destroy_nest_lock__30(omp_nest_lock_arg_t lock)148 gomp_destroy_nest_lock__30 (omp_nest_lock_arg_t lock)
149 {
150   gomp_destroy_nest_lock_30 (omp_nest_lock_arg (lock));
151 #ifndef OMP_NEST_LOCK_DIRECT
152   free (omp_nest_lock_arg (lock));
153   omp_nest_lock_arg (lock) = NULL;
154 #endif
155 }
156 
157 void
gomp_set_lock__30(omp_lock_arg_t lock)158 gomp_set_lock__30 (omp_lock_arg_t lock)
159 {
160   gomp_set_lock_30 (omp_lock_arg (lock));
161 }
162 
163 void
gomp_set_nest_lock__30(omp_nest_lock_arg_t lock)164 gomp_set_nest_lock__30 (omp_nest_lock_arg_t lock)
165 {
166   gomp_set_nest_lock_30 (omp_nest_lock_arg (lock));
167 }
168 
169 void
gomp_unset_lock__30(omp_lock_arg_t lock)170 gomp_unset_lock__30 (omp_lock_arg_t lock)
171 {
172   gomp_unset_lock_30 (omp_lock_arg (lock));
173 }
174 
175 void
gomp_unset_nest_lock__30(omp_nest_lock_arg_t lock)176 gomp_unset_nest_lock__30 (omp_nest_lock_arg_t lock)
177 {
178   gomp_unset_nest_lock_30 (omp_nest_lock_arg (lock));
179 }
180 
181 int32_t
gomp_test_lock__30(omp_lock_arg_t lock)182 gomp_test_lock__30 (omp_lock_arg_t lock)
183 {
184   return gomp_test_lock_30 (omp_lock_arg (lock));
185 }
186 
187 int32_t
gomp_test_nest_lock__30(omp_nest_lock_arg_t lock)188 gomp_test_nest_lock__30 (omp_nest_lock_arg_t lock)
189 {
190   return gomp_test_nest_lock_30 (omp_nest_lock_arg (lock));
191 }
192 
193 #ifdef LIBGOMP_GNU_SYMBOL_VERSIONING
194 void
gomp_init_lock__25(omp_lock_25_arg_t lock)195 gomp_init_lock__25 (omp_lock_25_arg_t lock)
196 {
197 #ifndef OMP_LOCK_25_DIRECT
198   omp_lock_25_arg (lock) = malloc (sizeof (omp_lock_25_t));
199 #endif
200   gomp_init_lock_25 (omp_lock_25_arg (lock));
201 }
202 
203 void
gomp_init_nest_lock__25(omp_nest_lock_25_arg_t lock)204 gomp_init_nest_lock__25 (omp_nest_lock_25_arg_t lock)
205 {
206 #ifndef OMP_NEST_LOCK_25_DIRECT
207   omp_nest_lock_25_arg (lock) = malloc (sizeof (omp_nest_lock_25_t));
208 #endif
209   gomp_init_nest_lock_25 (omp_nest_lock_25_arg (lock));
210 }
211 
212 void
gomp_destroy_lock__25(omp_lock_25_arg_t lock)213 gomp_destroy_lock__25 (omp_lock_25_arg_t lock)
214 {
215   gomp_destroy_lock_25 (omp_lock_25_arg (lock));
216 #ifndef OMP_LOCK_25_DIRECT
217   free (omp_lock_25_arg (lock));
218   omp_lock_25_arg (lock) = NULL;
219 #endif
220 }
221 
222 void
gomp_destroy_nest_lock__25(omp_nest_lock_25_arg_t lock)223 gomp_destroy_nest_lock__25 (omp_nest_lock_25_arg_t lock)
224 {
225   gomp_destroy_nest_lock_25 (omp_nest_lock_25_arg (lock));
226 #ifndef OMP_NEST_LOCK_25_DIRECT
227   free (omp_nest_lock_25_arg (lock));
228   omp_nest_lock_25_arg (lock) = NULL;
229 #endif
230 }
231 
232 void
gomp_set_lock__25(omp_lock_25_arg_t lock)233 gomp_set_lock__25 (omp_lock_25_arg_t lock)
234 {
235   gomp_set_lock_25 (omp_lock_25_arg (lock));
236 }
237 
238 void
gomp_set_nest_lock__25(omp_nest_lock_25_arg_t lock)239 gomp_set_nest_lock__25 (omp_nest_lock_25_arg_t lock)
240 {
241   gomp_set_nest_lock_25 (omp_nest_lock_25_arg (lock));
242 }
243 
244 void
gomp_unset_lock__25(omp_lock_25_arg_t lock)245 gomp_unset_lock__25 (omp_lock_25_arg_t lock)
246 {
247   gomp_unset_lock_25 (omp_lock_25_arg (lock));
248 }
249 
250 void
gomp_unset_nest_lock__25(omp_nest_lock_25_arg_t lock)251 gomp_unset_nest_lock__25 (omp_nest_lock_25_arg_t lock)
252 {
253   gomp_unset_nest_lock_25 (omp_nest_lock_25_arg (lock));
254 }
255 
256 int32_t
gomp_test_lock__25(omp_lock_25_arg_t lock)257 gomp_test_lock__25 (omp_lock_25_arg_t lock)
258 {
259   return gomp_test_lock_25 (omp_lock_25_arg (lock));
260 }
261 
262 int32_t
gomp_test_nest_lock__25(omp_nest_lock_25_arg_t lock)263 gomp_test_nest_lock__25 (omp_nest_lock_25_arg_t lock)
264 {
265   return gomp_test_nest_lock_25 (omp_nest_lock_25_arg (lock));
266 }
267 
268 omp_lock_symver (omp_init_lock_)
omp_lock_symver(omp_destroy_lock_)269 omp_lock_symver (omp_destroy_lock_)
270 omp_lock_symver (omp_set_lock_)
271 omp_lock_symver (omp_unset_lock_)
272 omp_lock_symver (omp_test_lock_)
273 omp_lock_symver (omp_init_nest_lock_)
274 omp_lock_symver (omp_destroy_nest_lock_)
275 omp_lock_symver (omp_set_nest_lock_)
276 omp_lock_symver (omp_unset_nest_lock_)
277 omp_lock_symver (omp_test_nest_lock_)
278 #endif
279 
280 #define TO_INT(x) ((x) > INT_MIN ? (x) < INT_MAX ? (x) : INT_MAX : INT_MIN)
281 
282 void
283 omp_set_dynamic_ (const int32_t *set)
284 {
285   omp_set_dynamic (*set);
286 }
287 
288 void
omp_set_dynamic_8_(const int64_t * set)289 omp_set_dynamic_8_ (const int64_t *set)
290 {
291   omp_set_dynamic (!!*set);
292 }
293 
294 #pragma GCC diagnostic push
295 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
296 void
omp_set_nested_(const int32_t * set)297 omp_set_nested_ (const int32_t *set)
298 {
299   omp_set_nested (*set);
300 }
301 
302 void
omp_set_nested_8_(const int64_t * set)303 omp_set_nested_8_ (const int64_t *set)
304 {
305   omp_set_nested (!!*set);
306 }
307 #pragma GCC diagnostic pop
308 
309 void
omp_set_num_threads_(const int32_t * set)310 omp_set_num_threads_ (const int32_t *set)
311 {
312   omp_set_num_threads (*set);
313 }
314 
315 void
omp_set_num_threads_8_(const int64_t * set)316 omp_set_num_threads_8_ (const int64_t *set)
317 {
318   omp_set_num_threads (TO_INT (*set));
319 }
320 
321 int32_t
omp_get_dynamic_(void)322 omp_get_dynamic_ (void)
323 {
324   return omp_get_dynamic ();
325 }
326 
327 #pragma GCC diagnostic push
328 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
329 int32_t
omp_get_nested_(void)330 omp_get_nested_ (void)
331 {
332   return omp_get_nested ();
333 }
334 #pragma GCC diagnostic pop
335 
336 int32_t
omp_in_parallel_(void)337 omp_in_parallel_ (void)
338 {
339   return omp_in_parallel ();
340 }
341 
342 int32_t
omp_get_max_threads_(void)343 omp_get_max_threads_ (void)
344 {
345   return omp_get_max_threads ();
346 }
347 
348 int32_t
omp_get_num_procs_(void)349 omp_get_num_procs_ (void)
350 {
351   return omp_get_num_procs ();
352 }
353 
354 int32_t
omp_get_num_threads_(void)355 omp_get_num_threads_ (void)
356 {
357   return omp_get_num_threads ();
358 }
359 
360 int32_t
omp_get_thread_num_(void)361 omp_get_thread_num_ (void)
362 {
363   return omp_get_thread_num ();
364 }
365 
366 double
omp_get_wtick_(void)367 omp_get_wtick_ (void)
368 {
369   return omp_get_wtick ();
370 }
371 
372 double
omp_get_wtime_(void)373 omp_get_wtime_ (void)
374 {
375   return omp_get_wtime ();
376 }
377 
378 void
omp_set_schedule_(const int32_t * kind,const int32_t * chunk_size)379 omp_set_schedule_ (const int32_t *kind, const int32_t *chunk_size)
380 {
381   omp_set_schedule (*kind, *chunk_size);
382 }
383 
384 void
omp_set_schedule_8_(const int32_t * kind,const int64_t * chunk_size)385 omp_set_schedule_8_ (const int32_t *kind, const int64_t *chunk_size)
386 {
387   omp_set_schedule (*kind, TO_INT (*chunk_size));
388 }
389 
390 void
omp_get_schedule_(int32_t * kind,int32_t * chunk_size)391 omp_get_schedule_ (int32_t *kind, int32_t *chunk_size)
392 {
393   omp_sched_t k;
394   int cs;
395   omp_get_schedule (&k, &cs);
396   /* For now mask off GFS_MONOTONIC, because OpenMP 4.5 code will not
397      expect to see it.  */
398   *kind = k & ~GFS_MONOTONIC;
399   *chunk_size = cs;
400 }
401 
402 void
omp_get_schedule_8_(int32_t * kind,int64_t * chunk_size)403 omp_get_schedule_8_ (int32_t *kind, int64_t *chunk_size)
404 {
405   omp_sched_t k;
406   int cs;
407   omp_get_schedule (&k, &cs);
408   /* See above.  */
409   *kind = k & ~GFS_MONOTONIC;
410   *chunk_size = cs;
411 }
412 
413 int32_t
omp_get_thread_limit_(void)414 omp_get_thread_limit_ (void)
415 {
416   return omp_get_thread_limit ();
417 }
418 
419 void
omp_set_max_active_levels_(const int32_t * levels)420 omp_set_max_active_levels_ (const int32_t *levels)
421 {
422   omp_set_max_active_levels (*levels);
423 }
424 
425 void
omp_set_max_active_levels_8_(const int64_t * levels)426 omp_set_max_active_levels_8_ (const int64_t *levels)
427 {
428   omp_set_max_active_levels (TO_INT (*levels));
429 }
430 
431 int32_t
omp_get_max_active_levels_(void)432 omp_get_max_active_levels_ (void)
433 {
434   return omp_get_max_active_levels ();
435 }
436 
437 int32_t
omp_get_supported_active_levels_(void)438 omp_get_supported_active_levels_ (void)
439 {
440   return omp_get_supported_active_levels ();
441 }
442 
443 int32_t
omp_get_level_(void)444 omp_get_level_ (void)
445 {
446   return omp_get_level ();
447 }
448 
449 int32_t
omp_get_ancestor_thread_num_(const int32_t * level)450 omp_get_ancestor_thread_num_ (const int32_t *level)
451 {
452   return omp_get_ancestor_thread_num (*level);
453 }
454 
455 int32_t
omp_get_ancestor_thread_num_8_(const int64_t * level)456 omp_get_ancestor_thread_num_8_ (const int64_t *level)
457 {
458   return omp_get_ancestor_thread_num (TO_INT (*level));
459 }
460 
461 int32_t
omp_get_team_size_(const int32_t * level)462 omp_get_team_size_ (const int32_t *level)
463 {
464   return omp_get_team_size (*level);
465 }
466 
467 int32_t
omp_get_team_size_8_(const int64_t * level)468 omp_get_team_size_8_ (const int64_t *level)
469 {
470   return omp_get_team_size (TO_INT (*level));
471 }
472 
473 int32_t
omp_get_active_level_(void)474 omp_get_active_level_ (void)
475 {
476   return omp_get_active_level ();
477 }
478 
479 int32_t
omp_in_final_(void)480 omp_in_final_ (void)
481 {
482   return omp_in_final ();
483 }
484 
485 void
omp_set_num_teams_(const int32_t * num_teams)486 omp_set_num_teams_ (const int32_t *num_teams)
487 {
488   omp_set_num_teams (*num_teams);
489 }
490 
491 void
omp_set_num_teams_8_(const int64_t * num_teams)492 omp_set_num_teams_8_ (const int64_t *num_teams)
493 {
494   omp_set_max_active_levels (TO_INT (*num_teams));
495 }
496 
497 int32_t
omp_get_max_teams_(void)498 omp_get_max_teams_ (void)
499 {
500   return omp_get_max_teams ();
501 }
502 
503 void
omp_set_teams_thread_limit_(const int32_t * thread_limit)504 omp_set_teams_thread_limit_ (const int32_t *thread_limit)
505 {
506   omp_set_teams_thread_limit (*thread_limit);
507 }
508 
509 void
omp_set_teams_thread_limit_8_(const int64_t * thread_limit)510 omp_set_teams_thread_limit_8_ (const int64_t *thread_limit)
511 {
512   omp_set_teams_thread_limit (TO_INT (*thread_limit));
513 }
514 
515 int32_t
omp_get_teams_thread_limit_(void)516 omp_get_teams_thread_limit_ (void)
517 {
518   return omp_get_teams_thread_limit ();
519 }
520 
521 int32_t
omp_get_cancellation_(void)522 omp_get_cancellation_ (void)
523 {
524   return omp_get_cancellation ();
525 }
526 
527 int32_t
omp_get_proc_bind_(void)528 omp_get_proc_bind_ (void)
529 {
530   return omp_get_proc_bind ();
531 }
532 
533 int32_t
omp_get_num_places_(void)534 omp_get_num_places_ (void)
535 {
536   return omp_get_num_places ();
537 }
538 
539 int32_t
omp_get_place_num_procs_(const int32_t * place_num)540 omp_get_place_num_procs_ (const int32_t *place_num)
541 {
542   return omp_get_place_num_procs (*place_num);
543 }
544 
545 int32_t
omp_get_place_num_procs_8_(const int64_t * place_num)546 omp_get_place_num_procs_8_ (const int64_t *place_num)
547 {
548   return omp_get_place_num_procs (TO_INT (*place_num));
549 }
550 
551 void
omp_get_place_proc_ids_(const int32_t * place_num,int32_t * ids)552 omp_get_place_proc_ids_ (const int32_t *place_num, int32_t *ids)
553 {
554   omp_get_place_proc_ids (*place_num, (int *) ids);
555 }
556 
557 void
omp_get_place_proc_ids_8_(const int64_t * place_num,int64_t * ids)558 omp_get_place_proc_ids_8_ (const int64_t *place_num, int64_t *ids)
559 {
560   gomp_get_place_proc_ids_8 (TO_INT (*place_num), ids);
561 }
562 
563 int32_t
omp_get_place_num_(void)564 omp_get_place_num_ (void)
565 {
566   return omp_get_place_num ();
567 }
568 
569 int32_t
omp_get_partition_num_places_(void)570 omp_get_partition_num_places_ (void)
571 {
572   return omp_get_partition_num_places ();
573 }
574 
575 void
omp_get_partition_place_nums_(int32_t * place_nums)576 omp_get_partition_place_nums_ (int32_t *place_nums)
577 {
578   omp_get_partition_place_nums ((int *) place_nums);
579 }
580 
581 void
omp_get_partition_place_nums_8_(int64_t * place_nums)582 omp_get_partition_place_nums_8_ (int64_t *place_nums)
583 {
584   if (gomp_places_list == NULL)
585     return;
586 
587   struct gomp_thread *thr = gomp_thread ();
588   if (thr->place == 0)
589     gomp_init_affinity ();
590 
591   unsigned int i;
592   for (i = 0; i < thr->ts.place_partition_len; i++)
593     *place_nums++ = (int64_t) thr->ts.place_partition_off + i;
594 }
595 
596 void
omp_set_default_device_(const int32_t * device_num)597 omp_set_default_device_ (const int32_t *device_num)
598 {
599   return omp_set_default_device (*device_num);
600 }
601 
602 void
omp_set_default_device_8_(const int64_t * device_num)603 omp_set_default_device_8_ (const int64_t *device_num)
604 {
605   return omp_set_default_device (TO_INT (*device_num));
606 }
607 
608 int32_t
omp_get_default_device_(void)609 omp_get_default_device_ (void)
610 {
611   return omp_get_default_device ();
612 }
613 
614 int32_t
omp_get_num_devices_(void)615 omp_get_num_devices_ (void)
616 {
617   return omp_get_num_devices ();
618 }
619 
620 int32_t
omp_get_num_teams_(void)621 omp_get_num_teams_ (void)
622 {
623   return omp_get_num_teams ();
624 }
625 
626 int32_t
omp_get_team_num_(void)627 omp_get_team_num_ (void)
628 {
629   return omp_get_team_num ();
630 }
631 
632 int32_t
omp_is_initial_device_(void)633 omp_is_initial_device_ (void)
634 {
635   return omp_is_initial_device ();
636 }
637 
638 int32_t
omp_get_initial_device_(void)639 omp_get_initial_device_ (void)
640 {
641   return omp_get_initial_device ();
642 }
643 
644 int32_t
omp_get_device_num_(void)645 omp_get_device_num_ (void)
646 {
647   return omp_get_device_num ();
648 }
649 
650 int32_t
omp_get_max_task_priority_(void)651 omp_get_max_task_priority_ (void)
652 {
653   return omp_get_max_task_priority ();
654 }
655 
656 void
omp_fulfill_event_(intptr_t event)657 omp_fulfill_event_ (intptr_t event)
658 {
659   omp_fulfill_event ((omp_event_handle_t) event);
660 }
661 
662 void
omp_set_affinity_format_(const char * format,size_t format_len)663 omp_set_affinity_format_ (const char *format, size_t format_len)
664 {
665   gomp_set_affinity_format (format, format_len);
666 }
667 
668 int32_t
omp_get_affinity_format_(char * buffer,size_t buffer_len)669 omp_get_affinity_format_ (char *buffer, size_t buffer_len)
670 {
671   size_t len = strlen (gomp_affinity_format_var);
672   if (buffer_len)
673     {
674       if (len < buffer_len)
675 	{
676 	  memcpy (buffer, gomp_affinity_format_var, len);
677 	  memset (buffer + len, ' ', buffer_len - len);
678 	}
679       else
680 	memcpy (buffer, gomp_affinity_format_var, buffer_len);
681     }
682   return len;
683 }
684 
685 void
omp_display_affinity_(const char * format,size_t format_len)686 omp_display_affinity_ (const char *format, size_t format_len)
687 {
688   char *fmt = NULL, fmt_buf[256];
689   char buf[512];
690   if (format_len)
691     {
692       fmt = format_len < 256 ? fmt_buf : gomp_malloc (format_len + 1);
693       memcpy (fmt, format, format_len);
694       fmt[format_len] = '\0';
695     }
696   struct gomp_thread *thr = gomp_thread ();
697   size_t ret
698     = gomp_display_affinity (buf, sizeof buf,
699 			     format_len ? fmt : gomp_affinity_format_var,
700 			     gomp_thread_self (), &thr->ts, thr->place);
701   if (ret < sizeof buf)
702     {
703       buf[ret] = '\n';
704       gomp_print_string (buf, ret + 1);
705     }
706   else
707     {
708       char *b = gomp_malloc (ret + 1);
709       gomp_display_affinity (buf, sizeof buf,
710 			     format_len ? fmt : gomp_affinity_format_var,
711 			     gomp_thread_self (), &thr->ts, thr->place);
712       b[ret] = '\n';
713       gomp_print_string (b, ret + 1);
714       free (b);
715     }
716   if (fmt && fmt != fmt_buf)
717     free (fmt);
718 }
719 
720 int32_t
omp_capture_affinity_(char * buffer,const char * format,size_t buffer_len,size_t format_len)721 omp_capture_affinity_ (char *buffer, const char *format,
722 		       size_t buffer_len, size_t format_len)
723 {
724   char *fmt = NULL, fmt_buf[256];
725   if (format_len)
726     {
727       fmt = format_len < 256 ? fmt_buf : gomp_malloc (format_len + 1);
728       memcpy (fmt, format, format_len);
729       fmt[format_len] = '\0';
730     }
731   struct gomp_thread *thr = gomp_thread ();
732   size_t ret
733     = gomp_display_affinity (buffer, buffer_len,
734 			     format_len ? fmt : gomp_affinity_format_var,
735 			     gomp_thread_self (), &thr->ts, thr->place);
736   if (fmt && fmt != fmt_buf)
737     free (fmt);
738   if (ret < buffer_len)
739     memset (buffer + ret, ' ', buffer_len - ret);
740   return ret;
741 }
742 
743 int32_t
omp_pause_resource_(const int32_t * kind,const int32_t * device_num)744 omp_pause_resource_ (const int32_t *kind, const int32_t *device_num)
745 {
746   return omp_pause_resource (*kind, *device_num);
747 }
748 
749 int32_t
omp_pause_resource_all_(const int32_t * kind)750 omp_pause_resource_all_ (const int32_t *kind)
751 {
752   return omp_pause_resource_all (*kind);
753 }
754 
755 intptr_t
omp_init_allocator_(const intptr_t * memspace,const int32_t * ntraits,const omp_alloctrait_t * traits)756 omp_init_allocator_ (const intptr_t *memspace, const int32_t *ntraits,
757 		    const omp_alloctrait_t *traits)
758 {
759   return (intptr_t) omp_init_allocator ((omp_memspace_handle_t) *memspace,
760 					(int) *ntraits, traits);
761 }
762 
763 intptr_t
omp_init_allocator_8_(const intptr_t * memspace,const int64_t * ntraits,const omp_alloctrait_t * traits)764 omp_init_allocator_8_ (const intptr_t *memspace, const int64_t *ntraits,
765 		    const omp_alloctrait_t *traits)
766 {
767   return (intptr_t) omp_init_allocator ((omp_memspace_handle_t) *memspace,
768 					(int) *ntraits, traits);
769 }
770 
771 void
omp_destroy_allocator_(const intptr_t * allocator)772 omp_destroy_allocator_ (const intptr_t *allocator)
773 {
774   omp_destroy_allocator ((omp_allocator_handle_t) *allocator);
775 }
776 
777 void
omp_set_default_allocator_(const intptr_t * allocator)778 omp_set_default_allocator_ (const intptr_t *allocator)
779 {
780   omp_set_default_allocator ((omp_allocator_handle_t) *allocator);
781 }
782 
783 intptr_t
omp_get_default_allocator_()784 omp_get_default_allocator_ ()
785 {
786   return (intptr_t) omp_get_default_allocator ();
787 }
788 
789 #ifndef LIBGOMP_OFFLOADED_ONLY
790 
791 void
omp_display_env_(const int32_t * verbose)792 omp_display_env_ (const int32_t *verbose)
793 {
794   omp_display_env (*verbose);
795 }
796 
797 void
omp_display_env_8_(const int64_t * verbose)798 omp_display_env_8_ (const int64_t *verbose)
799 {
800   omp_display_env (!!*verbose);
801 }
802 
803 #endif /* LIBGOMP_OFFLOADED_ONLY */
804