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_get_level)
71 ialias_redirect (omp_get_ancestor_thread_num)
72 ialias_redirect (omp_get_team_size)
73 ialias_redirect (omp_get_active_level)
74 ialias_redirect (omp_in_final)
75 ialias_redirect (omp_get_cancellation)
76 ialias_redirect (omp_get_proc_bind)
77 ialias_redirect (omp_get_num_places)
78 ialias_redirect (omp_get_place_num_procs)
79 ialias_redirect (omp_get_place_proc_ids)
80 ialias_redirect (omp_get_place_num)
81 ialias_redirect (omp_get_partition_num_places)
82 ialias_redirect (omp_get_partition_place_nums)
83 ialias_redirect (omp_set_default_device)
84 ialias_redirect (omp_get_default_device)
85 ialias_redirect (omp_get_num_devices)
86 ialias_redirect (omp_get_num_teams)
87 ialias_redirect (omp_get_team_num)
88 ialias_redirect (omp_is_initial_device)
89 ialias_redirect (omp_get_initial_device)
90 ialias_redirect (omp_get_max_task_priority)
91 ialias_redirect (omp_pause_resource)
92 ialias_redirect (omp_pause_resource_all)
93 ialias_redirect (omp_init_allocator)
94 ialias_redirect (omp_destroy_allocator)
95 ialias_redirect (omp_set_default_allocator)
96 ialias_redirect (omp_get_default_allocator)
97 #endif
98 
99 #ifndef LIBGOMP_GNU_SYMBOL_VERSIONING
100 # define gomp_init_lock__30 omp_init_lock_
101 # define gomp_destroy_lock__30 omp_destroy_lock_
102 # define gomp_set_lock__30 omp_set_lock_
103 # define gomp_unset_lock__30 omp_unset_lock_
104 # define gomp_test_lock__30 omp_test_lock_
105 # define gomp_init_nest_lock__30 omp_init_nest_lock_
106 # define gomp_destroy_nest_lock__30 omp_destroy_nest_lock_
107 # define gomp_set_nest_lock__30 omp_set_nest_lock_
108 # define gomp_unset_nest_lock__30 omp_unset_nest_lock_
109 # define gomp_test_nest_lock__30 omp_test_nest_lock_
110 #endif
111 
112 void
113 gomp_init_lock__30 (omp_lock_arg_t lock)
114 {
115 #ifndef OMP_LOCK_DIRECT
116   omp_lock_arg (lock) = malloc (sizeof (omp_lock_t));
117 #endif
118   gomp_init_lock_30 (omp_lock_arg (lock));
119 }
120 
121 void
gomp_init_nest_lock__30(omp_nest_lock_arg_t lock)122 gomp_init_nest_lock__30 (omp_nest_lock_arg_t lock)
123 {
124 #ifndef OMP_NEST_LOCK_DIRECT
125   omp_nest_lock_arg (lock) = malloc (sizeof (omp_nest_lock_t));
126 #endif
127   gomp_init_nest_lock_30 (omp_nest_lock_arg (lock));
128 }
129 
130 void
gomp_destroy_lock__30(omp_lock_arg_t lock)131 gomp_destroy_lock__30 (omp_lock_arg_t lock)
132 {
133   gomp_destroy_lock_30 (omp_lock_arg (lock));
134 #ifndef OMP_LOCK_DIRECT
135   free (omp_lock_arg (lock));
136   omp_lock_arg (lock) = NULL;
137 #endif
138 }
139 
140 void
gomp_destroy_nest_lock__30(omp_nest_lock_arg_t lock)141 gomp_destroy_nest_lock__30 (omp_nest_lock_arg_t lock)
142 {
143   gomp_destroy_nest_lock_30 (omp_nest_lock_arg (lock));
144 #ifndef OMP_NEST_LOCK_DIRECT
145   free (omp_nest_lock_arg (lock));
146   omp_nest_lock_arg (lock) = NULL;
147 #endif
148 }
149 
150 void
gomp_set_lock__30(omp_lock_arg_t lock)151 gomp_set_lock__30 (omp_lock_arg_t lock)
152 {
153   gomp_set_lock_30 (omp_lock_arg (lock));
154 }
155 
156 void
gomp_set_nest_lock__30(omp_nest_lock_arg_t lock)157 gomp_set_nest_lock__30 (omp_nest_lock_arg_t lock)
158 {
159   gomp_set_nest_lock_30 (omp_nest_lock_arg (lock));
160 }
161 
162 void
gomp_unset_lock__30(omp_lock_arg_t lock)163 gomp_unset_lock__30 (omp_lock_arg_t lock)
164 {
165   gomp_unset_lock_30 (omp_lock_arg (lock));
166 }
167 
168 void
gomp_unset_nest_lock__30(omp_nest_lock_arg_t lock)169 gomp_unset_nest_lock__30 (omp_nest_lock_arg_t lock)
170 {
171   gomp_unset_nest_lock_30 (omp_nest_lock_arg (lock));
172 }
173 
174 int32_t
gomp_test_lock__30(omp_lock_arg_t lock)175 gomp_test_lock__30 (omp_lock_arg_t lock)
176 {
177   return gomp_test_lock_30 (omp_lock_arg (lock));
178 }
179 
180 int32_t
gomp_test_nest_lock__30(omp_nest_lock_arg_t lock)181 gomp_test_nest_lock__30 (omp_nest_lock_arg_t lock)
182 {
183   return gomp_test_nest_lock_30 (omp_nest_lock_arg (lock));
184 }
185 
186 #ifdef LIBGOMP_GNU_SYMBOL_VERSIONING
187 void
gomp_init_lock__25(omp_lock_25_arg_t lock)188 gomp_init_lock__25 (omp_lock_25_arg_t lock)
189 {
190 #ifndef OMP_LOCK_25_DIRECT
191   omp_lock_25_arg (lock) = malloc (sizeof (omp_lock_25_t));
192 #endif
193   gomp_init_lock_25 (omp_lock_25_arg (lock));
194 }
195 
196 void
gomp_init_nest_lock__25(omp_nest_lock_25_arg_t lock)197 gomp_init_nest_lock__25 (omp_nest_lock_25_arg_t lock)
198 {
199 #ifndef OMP_NEST_LOCK_25_DIRECT
200   omp_nest_lock_25_arg (lock) = malloc (sizeof (omp_nest_lock_25_t));
201 #endif
202   gomp_init_nest_lock_25 (omp_nest_lock_25_arg (lock));
203 }
204 
205 void
gomp_destroy_lock__25(omp_lock_25_arg_t lock)206 gomp_destroy_lock__25 (omp_lock_25_arg_t lock)
207 {
208   gomp_destroy_lock_25 (omp_lock_25_arg (lock));
209 #ifndef OMP_LOCK_25_DIRECT
210   free (omp_lock_25_arg (lock));
211   omp_lock_25_arg (lock) = NULL;
212 #endif
213 }
214 
215 void
gomp_destroy_nest_lock__25(omp_nest_lock_25_arg_t lock)216 gomp_destroy_nest_lock__25 (omp_nest_lock_25_arg_t lock)
217 {
218   gomp_destroy_nest_lock_25 (omp_nest_lock_25_arg (lock));
219 #ifndef OMP_NEST_LOCK_25_DIRECT
220   free (omp_nest_lock_25_arg (lock));
221   omp_nest_lock_25_arg (lock) = NULL;
222 #endif
223 }
224 
225 void
gomp_set_lock__25(omp_lock_25_arg_t lock)226 gomp_set_lock__25 (omp_lock_25_arg_t lock)
227 {
228   gomp_set_lock_25 (omp_lock_25_arg (lock));
229 }
230 
231 void
gomp_set_nest_lock__25(omp_nest_lock_25_arg_t lock)232 gomp_set_nest_lock__25 (omp_nest_lock_25_arg_t lock)
233 {
234   gomp_set_nest_lock_25 (omp_nest_lock_25_arg (lock));
235 }
236 
237 void
gomp_unset_lock__25(omp_lock_25_arg_t lock)238 gomp_unset_lock__25 (omp_lock_25_arg_t lock)
239 {
240   gomp_unset_lock_25 (omp_lock_25_arg (lock));
241 }
242 
243 void
gomp_unset_nest_lock__25(omp_nest_lock_25_arg_t lock)244 gomp_unset_nest_lock__25 (omp_nest_lock_25_arg_t lock)
245 {
246   gomp_unset_nest_lock_25 (omp_nest_lock_25_arg (lock));
247 }
248 
249 int32_t
gomp_test_lock__25(omp_lock_25_arg_t lock)250 gomp_test_lock__25 (omp_lock_25_arg_t lock)
251 {
252   return gomp_test_lock_25 (omp_lock_25_arg (lock));
253 }
254 
255 int32_t
gomp_test_nest_lock__25(omp_nest_lock_25_arg_t lock)256 gomp_test_nest_lock__25 (omp_nest_lock_25_arg_t lock)
257 {
258   return gomp_test_nest_lock_25 (omp_nest_lock_25_arg (lock));
259 }
260 
261 omp_lock_symver (omp_init_lock_)
omp_lock_symver(omp_destroy_lock_)262 omp_lock_symver (omp_destroy_lock_)
263 omp_lock_symver (omp_set_lock_)
264 omp_lock_symver (omp_unset_lock_)
265 omp_lock_symver (omp_test_lock_)
266 omp_lock_symver (omp_init_nest_lock_)
267 omp_lock_symver (omp_destroy_nest_lock_)
268 omp_lock_symver (omp_set_nest_lock_)
269 omp_lock_symver (omp_unset_nest_lock_)
270 omp_lock_symver (omp_test_nest_lock_)
271 #endif
272 
273 #define TO_INT(x) ((x) > INT_MIN ? (x) < INT_MAX ? (x) : INT_MAX : INT_MIN)
274 
275 void
276 omp_set_dynamic_ (const int32_t *set)
277 {
278   omp_set_dynamic (*set);
279 }
280 
281 void
omp_set_dynamic_8_(const int64_t * set)282 omp_set_dynamic_8_ (const int64_t *set)
283 {
284   omp_set_dynamic (!!*set);
285 }
286 
287 #pragma GCC diagnostic push
288 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
289 void
omp_set_nested_(const int32_t * set)290 omp_set_nested_ (const int32_t *set)
291 {
292   omp_set_nested (*set);
293 }
294 
295 void
omp_set_nested_8_(const int64_t * set)296 omp_set_nested_8_ (const int64_t *set)
297 {
298   omp_set_nested (!!*set);
299 }
300 #pragma GCC diagnostic pop
301 
302 void
omp_set_num_threads_(const int32_t * set)303 omp_set_num_threads_ (const int32_t *set)
304 {
305   omp_set_num_threads (*set);
306 }
307 
308 void
omp_set_num_threads_8_(const int64_t * set)309 omp_set_num_threads_8_ (const int64_t *set)
310 {
311   omp_set_num_threads (TO_INT (*set));
312 }
313 
314 int32_t
omp_get_dynamic_(void)315 omp_get_dynamic_ (void)
316 {
317   return omp_get_dynamic ();
318 }
319 
320 #pragma GCC diagnostic push
321 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
322 int32_t
omp_get_nested_(void)323 omp_get_nested_ (void)
324 {
325   return omp_get_nested ();
326 }
327 #pragma GCC diagnostic pop
328 
329 int32_t
omp_in_parallel_(void)330 omp_in_parallel_ (void)
331 {
332   return omp_in_parallel ();
333 }
334 
335 int32_t
omp_get_max_threads_(void)336 omp_get_max_threads_ (void)
337 {
338   return omp_get_max_threads ();
339 }
340 
341 int32_t
omp_get_num_procs_(void)342 omp_get_num_procs_ (void)
343 {
344   return omp_get_num_procs ();
345 }
346 
347 int32_t
omp_get_num_threads_(void)348 omp_get_num_threads_ (void)
349 {
350   return omp_get_num_threads ();
351 }
352 
353 int32_t
omp_get_thread_num_(void)354 omp_get_thread_num_ (void)
355 {
356   return omp_get_thread_num ();
357 }
358 
359 double
omp_get_wtick_(void)360 omp_get_wtick_ (void)
361 {
362   return omp_get_wtick ();
363 }
364 
365 double
omp_get_wtime_(void)366 omp_get_wtime_ (void)
367 {
368   return omp_get_wtime ();
369 }
370 
371 void
omp_set_schedule_(const int32_t * kind,const int32_t * chunk_size)372 omp_set_schedule_ (const int32_t *kind, const int32_t *chunk_size)
373 {
374   omp_set_schedule (*kind, *chunk_size);
375 }
376 
377 void
omp_set_schedule_8_(const int32_t * kind,const int64_t * chunk_size)378 omp_set_schedule_8_ (const int32_t *kind, const int64_t *chunk_size)
379 {
380   omp_set_schedule (*kind, TO_INT (*chunk_size));
381 }
382 
383 void
omp_get_schedule_(int32_t * kind,int32_t * chunk_size)384 omp_get_schedule_ (int32_t *kind, int32_t *chunk_size)
385 {
386   omp_sched_t k;
387   int cs;
388   omp_get_schedule (&k, &cs);
389   /* For now mask off GFS_MONOTONIC, because OpenMP 4.5 code will not
390      expect to see it.  */
391   *kind = k & ~GFS_MONOTONIC;
392   *chunk_size = cs;
393 }
394 
395 void
omp_get_schedule_8_(int32_t * kind,int64_t * chunk_size)396 omp_get_schedule_8_ (int32_t *kind, int64_t *chunk_size)
397 {
398   omp_sched_t k;
399   int cs;
400   omp_get_schedule (&k, &cs);
401   /* See above.  */
402   *kind = k & ~GFS_MONOTONIC;
403   *chunk_size = cs;
404 }
405 
406 int32_t
omp_get_thread_limit_(void)407 omp_get_thread_limit_ (void)
408 {
409   return omp_get_thread_limit ();
410 }
411 
412 void
omp_set_max_active_levels_(const int32_t * levels)413 omp_set_max_active_levels_ (const int32_t *levels)
414 {
415   omp_set_max_active_levels (*levels);
416 }
417 
418 void
omp_set_max_active_levels_8_(const int64_t * levels)419 omp_set_max_active_levels_8_ (const int64_t *levels)
420 {
421   omp_set_max_active_levels (TO_INT (*levels));
422 }
423 
424 int32_t
omp_get_max_active_levels_(void)425 omp_get_max_active_levels_ (void)
426 {
427   return omp_get_max_active_levels ();
428 }
429 
430 int32_t
omp_get_supported_active_levels_(void)431 omp_get_supported_active_levels_ (void)
432 {
433   return omp_get_supported_active_levels ();
434 }
435 
436 int32_t
omp_get_level_(void)437 omp_get_level_ (void)
438 {
439   return omp_get_level ();
440 }
441 
442 int32_t
omp_get_ancestor_thread_num_(const int32_t * level)443 omp_get_ancestor_thread_num_ (const int32_t *level)
444 {
445   return omp_get_ancestor_thread_num (*level);
446 }
447 
448 int32_t
omp_get_ancestor_thread_num_8_(const int64_t * level)449 omp_get_ancestor_thread_num_8_ (const int64_t *level)
450 {
451   return omp_get_ancestor_thread_num (TO_INT (*level));
452 }
453 
454 int32_t
omp_get_team_size_(const int32_t * level)455 omp_get_team_size_ (const int32_t *level)
456 {
457   return omp_get_team_size (*level);
458 }
459 
460 int32_t
omp_get_team_size_8_(const int64_t * level)461 omp_get_team_size_8_ (const int64_t *level)
462 {
463   return omp_get_team_size (TO_INT (*level));
464 }
465 
466 int32_t
omp_get_active_level_(void)467 omp_get_active_level_ (void)
468 {
469   return omp_get_active_level ();
470 }
471 
472 int32_t
omp_in_final_(void)473 omp_in_final_ (void)
474 {
475   return omp_in_final ();
476 }
477 
478 int32_t
omp_get_cancellation_(void)479 omp_get_cancellation_ (void)
480 {
481   return omp_get_cancellation ();
482 }
483 
484 int32_t
omp_get_proc_bind_(void)485 omp_get_proc_bind_ (void)
486 {
487   return omp_get_proc_bind ();
488 }
489 
490 int32_t
omp_get_num_places_(void)491 omp_get_num_places_ (void)
492 {
493   return omp_get_num_places ();
494 }
495 
496 int32_t
omp_get_place_num_procs_(const int32_t * place_num)497 omp_get_place_num_procs_ (const int32_t *place_num)
498 {
499   return omp_get_place_num_procs (*place_num);
500 }
501 
502 int32_t
omp_get_place_num_procs_8_(const int64_t * place_num)503 omp_get_place_num_procs_8_ (const int64_t *place_num)
504 {
505   return omp_get_place_num_procs (TO_INT (*place_num));
506 }
507 
508 void
omp_get_place_proc_ids_(const int32_t * place_num,int32_t * ids)509 omp_get_place_proc_ids_ (const int32_t *place_num, int32_t *ids)
510 {
511   omp_get_place_proc_ids (*place_num, (int *) ids);
512 }
513 
514 void
omp_get_place_proc_ids_8_(const int64_t * place_num,int64_t * ids)515 omp_get_place_proc_ids_8_ (const int64_t *place_num, int64_t *ids)
516 {
517   gomp_get_place_proc_ids_8 (TO_INT (*place_num), ids);
518 }
519 
520 int32_t
omp_get_place_num_(void)521 omp_get_place_num_ (void)
522 {
523   return omp_get_place_num ();
524 }
525 
526 int32_t
omp_get_partition_num_places_(void)527 omp_get_partition_num_places_ (void)
528 {
529   return omp_get_partition_num_places ();
530 }
531 
532 void
omp_get_partition_place_nums_(int32_t * place_nums)533 omp_get_partition_place_nums_ (int32_t *place_nums)
534 {
535   omp_get_partition_place_nums ((int *) place_nums);
536 }
537 
538 void
omp_get_partition_place_nums_8_(int64_t * place_nums)539 omp_get_partition_place_nums_8_ (int64_t *place_nums)
540 {
541   if (gomp_places_list == NULL)
542     return;
543 
544   struct gomp_thread *thr = gomp_thread ();
545   if (thr->place == 0)
546     gomp_init_affinity ();
547 
548   unsigned int i;
549   for (i = 0; i < thr->ts.place_partition_len; i++)
550     *place_nums++ = (int64_t) thr->ts.place_partition_off + i;
551 }
552 
553 void
omp_set_default_device_(const int32_t * device_num)554 omp_set_default_device_ (const int32_t *device_num)
555 {
556   return omp_set_default_device (*device_num);
557 }
558 
559 void
omp_set_default_device_8_(const int64_t * device_num)560 omp_set_default_device_8_ (const int64_t *device_num)
561 {
562   return omp_set_default_device (TO_INT (*device_num));
563 }
564 
565 int32_t
omp_get_default_device_(void)566 omp_get_default_device_ (void)
567 {
568   return omp_get_default_device ();
569 }
570 
571 int32_t
omp_get_num_devices_(void)572 omp_get_num_devices_ (void)
573 {
574   return omp_get_num_devices ();
575 }
576 
577 int32_t
omp_get_num_teams_(void)578 omp_get_num_teams_ (void)
579 {
580   return omp_get_num_teams ();
581 }
582 
583 int32_t
omp_get_team_num_(void)584 omp_get_team_num_ (void)
585 {
586   return omp_get_team_num ();
587 }
588 
589 int32_t
omp_is_initial_device_(void)590 omp_is_initial_device_ (void)
591 {
592   return omp_is_initial_device ();
593 }
594 
595 int32_t
omp_get_initial_device_(void)596 omp_get_initial_device_ (void)
597 {
598   return omp_get_initial_device ();
599 }
600 
601 int32_t
omp_get_max_task_priority_(void)602 omp_get_max_task_priority_ (void)
603 {
604   return omp_get_max_task_priority ();
605 }
606 
607 void
omp_fulfill_event_(intptr_t event)608 omp_fulfill_event_ (intptr_t event)
609 {
610   omp_fulfill_event ((omp_event_handle_t) event);
611 }
612 
613 void
omp_set_affinity_format_(const char * format,size_t format_len)614 omp_set_affinity_format_ (const char *format, size_t format_len)
615 {
616   gomp_set_affinity_format (format, format_len);
617 }
618 
619 int32_t
omp_get_affinity_format_(char * buffer,size_t buffer_len)620 omp_get_affinity_format_ (char *buffer, size_t buffer_len)
621 {
622   size_t len = strlen (gomp_affinity_format_var);
623   if (buffer_len)
624     {
625       if (len < buffer_len)
626 	{
627 	  memcpy (buffer, gomp_affinity_format_var, len);
628 	  memset (buffer + len, ' ', buffer_len - len);
629 	}
630       else
631 	memcpy (buffer, gomp_affinity_format_var, buffer_len);
632     }
633   return len;
634 }
635 
636 void
omp_display_affinity_(const char * format,size_t format_len)637 omp_display_affinity_ (const char *format, size_t format_len)
638 {
639   char *fmt = NULL, fmt_buf[256];
640   char buf[512];
641   if (format_len)
642     {
643       fmt = format_len < 256 ? fmt_buf : gomp_malloc (format_len + 1);
644       memcpy (fmt, format, format_len);
645       fmt[format_len] = '\0';
646     }
647   struct gomp_thread *thr = gomp_thread ();
648   size_t ret
649     = gomp_display_affinity (buf, sizeof buf,
650 			     format_len ? fmt : gomp_affinity_format_var,
651 			     gomp_thread_self (), &thr->ts, thr->place);
652   if (ret < sizeof buf)
653     {
654       buf[ret] = '\n';
655       gomp_print_string (buf, ret + 1);
656     }
657   else
658     {
659       char *b = gomp_malloc (ret + 1);
660       gomp_display_affinity (buf, sizeof buf,
661 			     format_len ? fmt : gomp_affinity_format_var,
662 			     gomp_thread_self (), &thr->ts, thr->place);
663       b[ret] = '\n';
664       gomp_print_string (b, ret + 1);
665       free (b);
666     }
667   if (fmt && fmt != fmt_buf)
668     free (fmt);
669 }
670 
671 int32_t
omp_capture_affinity_(char * buffer,const char * format,size_t buffer_len,size_t format_len)672 omp_capture_affinity_ (char *buffer, const char *format,
673 		       size_t buffer_len, size_t format_len)
674 {
675   char *fmt = NULL, fmt_buf[256];
676   if (format_len)
677     {
678       fmt = format_len < 256 ? fmt_buf : gomp_malloc (format_len + 1);
679       memcpy (fmt, format, format_len);
680       fmt[format_len] = '\0';
681     }
682   struct gomp_thread *thr = gomp_thread ();
683   size_t ret
684     = gomp_display_affinity (buffer, buffer_len,
685 			     format_len ? fmt : gomp_affinity_format_var,
686 			     gomp_thread_self (), &thr->ts, thr->place);
687   if (fmt && fmt != fmt_buf)
688     free (fmt);
689   if (ret < buffer_len)
690     memset (buffer + ret, ' ', buffer_len - ret);
691   return ret;
692 }
693 
694 int32_t
omp_pause_resource_(const int32_t * kind,const int32_t * device_num)695 omp_pause_resource_ (const int32_t *kind, const int32_t *device_num)
696 {
697   return omp_pause_resource (*kind, *device_num);
698 }
699 
700 int32_t
omp_pause_resource_all_(const int32_t * kind)701 omp_pause_resource_all_ (const int32_t *kind)
702 {
703   return omp_pause_resource_all (*kind);
704 }
705 
706 intptr_t
omp_init_allocator_(const intptr_t * memspace,const int32_t * ntraits,const omp_alloctrait_t * traits)707 omp_init_allocator_ (const intptr_t *memspace, const int32_t *ntraits,
708 		    const omp_alloctrait_t *traits)
709 {
710   return (intptr_t) omp_init_allocator ((omp_memspace_handle_t) *memspace,
711 					(int) *ntraits, traits);
712 }
713 
714 intptr_t
omp_init_allocator_8_(const intptr_t * memspace,const int64_t * ntraits,const omp_alloctrait_t * traits)715 omp_init_allocator_8_ (const intptr_t *memspace, const int64_t *ntraits,
716 		    const omp_alloctrait_t *traits)
717 {
718   return (intptr_t) omp_init_allocator ((omp_memspace_handle_t) *memspace,
719 					(int) *ntraits, traits);
720 }
721 
722 void
omp_destroy_allocator_(const intptr_t * allocator)723 omp_destroy_allocator_ (const intptr_t *allocator)
724 {
725   omp_destroy_allocator ((omp_allocator_handle_t) *allocator);
726 }
727 
728 void
omp_set_default_allocator_(const intptr_t * allocator)729 omp_set_default_allocator_ (const intptr_t *allocator)
730 {
731   omp_set_default_allocator ((omp_allocator_handle_t) *allocator);
732 }
733 
734 intptr_t
omp_get_default_allocator_()735 omp_get_default_allocator_ ()
736 {
737   return (intptr_t) omp_get_default_allocator ();
738 }
739