fortran.c 17 KB

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