1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
|
/*
* kmp_ftn_entry.h -- Fortran entry linkage support for OpenMP.
*/
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.txt for details.
//
//===----------------------------------------------------------------------===//
#ifndef FTN_STDCALL
# error The support file kmp_ftn_entry.h should not be compiled by itself.
#endif
#ifdef KMP_STUB
#error #include "kmp_stub.h"
#endif
#include "kmp_i18n.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/*
* For compatibility with the Gnu/MS Open MP codegen, omp_set_num_threads(),
* omp_set_nested(), and omp_set_dynamic() [in lowercase on MS, and w/o
* a trailing underscore on Linux* OS] take call by value integer arguments.
* + omp_set_max_active_levels()
* + omp_set_schedule()
*
* For backward compatibility with 9.1 and previous Intel compiler, these
* entry points take call by reference integer arguments.
*/
#ifdef KMP_GOMP_COMPAT
# if (KMP_FTN_ENTRIES == KMP_FTN_PLAIN) || (KMP_FTN_ENTRIES == KMP_FTN_UPPER)
# define PASS_ARGS_BY_VALUE 1
# endif
#endif
#if KMP_OS_WINDOWS
# if (KMP_FTN_ENTRIES == KMP_FTN_PLAIN) || (KMP_FTN_ENTRIES == KMP_FTN_APPEND)
# define PASS_ARGS_BY_VALUE 1
# endif
#endif
// This macro helps to reduce code duplication.
#ifdef PASS_ARGS_BY_VALUE
#define KMP_DEREF
#else
#define KMP_DEREF *
#endif
void FTN_STDCALL
FTN_SET_STACKSIZE( int KMP_DEREF arg )
{
#ifdef KMP_STUB
__kmps_set_stacksize( KMP_DEREF arg );
#else
// __kmp_aux_set_stacksize initializes the library if needed
__kmp_aux_set_stacksize( (size_t) KMP_DEREF arg );
#endif
}
void FTN_STDCALL
FTN_SET_STACKSIZE_S( size_t KMP_DEREF arg )
{
#ifdef KMP_STUB
__kmps_set_stacksize( KMP_DEREF arg );
#else
// __kmp_aux_set_stacksize initializes the library if needed
__kmp_aux_set_stacksize( KMP_DEREF arg );
#endif
}
int FTN_STDCALL
FTN_GET_STACKSIZE( void )
{
#ifdef KMP_STUB
return __kmps_get_stacksize();
#else
if ( ! __kmp_init_serial ) {
__kmp_serial_initialize();
};
return (int)__kmp_stksize;
#endif
}
size_t FTN_STDCALL
FTN_GET_STACKSIZE_S( void )
{
#ifdef KMP_STUB
return __kmps_get_stacksize();
#else
if ( ! __kmp_init_serial ) {
__kmp_serial_initialize();
};
return __kmp_stksize;
#endif
}
void FTN_STDCALL
FTN_SET_BLOCKTIME( int KMP_DEREF arg )
{
#ifdef KMP_STUB
__kmps_set_blocktime( KMP_DEREF arg );
#else
int gtid, tid;
kmp_info_t *thread;
gtid = __kmp_entry_gtid();
tid = __kmp_tid_from_gtid(gtid);
thread = __kmp_thread_from_gtid(gtid);
__kmp_aux_set_blocktime( KMP_DEREF arg, thread, tid );
#endif
}
int FTN_STDCALL
FTN_GET_BLOCKTIME( void )
{
#ifdef KMP_STUB
return __kmps_get_blocktime();
#else
int gtid, tid;
kmp_info_t *thread;
kmp_team_p *team;
gtid = __kmp_entry_gtid();
tid = __kmp_tid_from_gtid(gtid);
thread = __kmp_thread_from_gtid(gtid);
team = __kmp_threads[ gtid ] -> th.th_team;
/* These must match the settings used in __kmp_wait_sleep() */
if ( __kmp_dflt_blocktime == KMP_MAX_BLOCKTIME ) {
KF_TRACE(10, ( "kmp_get_blocktime: T#%d(%d:%d), blocktime=%d\n",
gtid, team->t.t_id, tid, KMP_MAX_BLOCKTIME) );
return KMP_MAX_BLOCKTIME;
}
#ifdef KMP_ADJUST_BLOCKTIME
else if ( __kmp_zero_bt && !get__bt_set( team, tid ) ) {
KF_TRACE(10, ( "kmp_get_blocktime: T#%d(%d:%d), blocktime=%d\n",
gtid, team->t.t_id, tid, 0) );
return 0;
}
#endif /* KMP_ADJUST_BLOCKTIME */
else {
KF_TRACE(10, ( "kmp_get_blocktime: T#%d(%d:%d), blocktime=%d\n",
gtid, team->t.t_id, tid, get__blocktime( team, tid ) ) );
return get__blocktime( team, tid );
};
#endif
}
void FTN_STDCALL
FTN_SET_LIBRARY_SERIAL( void )
{
#ifdef KMP_STUB
__kmps_set_library( library_serial );
#else
// __kmp_user_set_library initializes the library if needed
__kmp_user_set_library( library_serial );
#endif
}
void FTN_STDCALL
FTN_SET_LIBRARY_TURNAROUND( void )
{
#ifdef KMP_STUB
__kmps_set_library( library_turnaround );
#else
// __kmp_user_set_library initializes the library if needed
__kmp_user_set_library( library_turnaround );
#endif
}
void FTN_STDCALL
FTN_SET_LIBRARY_THROUGHPUT( void )
{
#ifdef KMP_STUB
__kmps_set_library( library_throughput );
#else
// __kmp_user_set_library initializes the library if needed
__kmp_user_set_library( library_throughput );
#endif
}
void FTN_STDCALL
FTN_SET_LIBRARY( int KMP_DEREF arg )
{
#ifdef KMP_STUB
__kmps_set_library( KMP_DEREF arg );
#else
enum library_type lib;
lib = (enum library_type) KMP_DEREF arg;
// __kmp_user_set_library initializes the library if needed
__kmp_user_set_library( lib );
#endif
}
int FTN_STDCALL
FTN_GET_LIBRARY (void)
{
#ifdef KMP_STUB
return __kmps_get_library();
#else
if ( ! __kmp_init_serial ) {
__kmp_serial_initialize();
}
return ((int) __kmp_library);
#endif
}
int FTN_STDCALL
FTN_SET_AFFINITY( void **mask )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return -1;
#else
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
return __kmp_aux_set_affinity( mask );
#endif
}
int FTN_STDCALL
FTN_GET_AFFINITY( void **mask )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return -1;
#else
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
return __kmp_aux_get_affinity( mask );
#endif
}
int FTN_STDCALL
FTN_GET_AFFINITY_MAX_PROC( void )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return 0;
#else
//
// We really only NEED serial initialization here.
//
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
if ( ! ( KMP_AFFINITY_CAPABLE() ) ) {
return 0;
}
#if KMP_GROUP_AFFINITY && !KMP_USE_HWLOC
if ( __kmp_num_proc_groups > 1 ) {
return (int)KMP_CPU_SETSIZE;
}
#endif /* KMP_GROUP_AFFINITY */
return __kmp_xproc;
#endif
}
void FTN_STDCALL
FTN_CREATE_AFFINITY_MASK( void **mask )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
*mask = NULL;
#else
//
// We really only NEED serial initialization here.
//
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
# if KMP_USE_HWLOC
*mask = (hwloc_cpuset_t)hwloc_bitmap_alloc();
# else
*mask = kmpc_malloc( __kmp_affin_mask_size );
# endif
KMP_CPU_ZERO( (kmp_affin_mask_t *)(*mask) );
#endif
}
void FTN_STDCALL
FTN_DESTROY_AFFINITY_MASK( void **mask )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
// Nothing
#else
//
// We really only NEED serial initialization here.
//
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
if ( __kmp_env_consistency_check ) {
if ( *mask == NULL ) {
KMP_FATAL( AffinityInvalidMask, "kmp_destroy_affinity_mask" );
}
}
# if KMP_USE_HWLOC
hwloc_bitmap_free((hwloc_cpuset_t)(*mask));
# else
kmpc_free( *mask );
# endif
*mask = NULL;
#endif
}
int FTN_STDCALL
FTN_SET_AFFINITY_MASK_PROC( int KMP_DEREF proc, void **mask )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return -1;
#else
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
return __kmp_aux_set_affinity_mask_proc( KMP_DEREF proc, mask );
#endif
}
int FTN_STDCALL
FTN_UNSET_AFFINITY_MASK_PROC( int KMP_DEREF proc, void **mask )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return -1;
#else
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
return __kmp_aux_unset_affinity_mask_proc( KMP_DEREF proc, mask );
#endif
}
int FTN_STDCALL
FTN_GET_AFFINITY_MASK_PROC( int KMP_DEREF proc, void **mask )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return -1;
#else
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
return __kmp_aux_get_affinity_mask_proc( KMP_DEREF proc, mask );
#endif
}
/* ------------------------------------------------------------------------ */
/* sets the requested number of threads for the next parallel region */
void FTN_STDCALL
xexpand(FTN_SET_NUM_THREADS)( int KMP_DEREF arg )
{
#ifdef KMP_STUB
// Nothing.
#else
__kmp_set_num_threads( KMP_DEREF arg, __kmp_entry_gtid() );
#endif
}
/* returns the number of threads in current team */
int FTN_STDCALL
xexpand(FTN_GET_NUM_THREADS)( void )
{
#ifdef KMP_STUB
return 1;
#else
// __kmpc_bound_num_threads initializes the library if needed
return __kmpc_bound_num_threads(NULL);
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_MAX_THREADS)( void )
{
#ifdef KMP_STUB
return 1;
#else
int gtid;
kmp_info_t *thread;
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
gtid = __kmp_entry_gtid();
thread = __kmp_threads[ gtid ];
//return thread -> th.th_team -> t.t_current_task[ thread->th.th_info.ds.ds_tid ] -> icvs.nproc;
return thread -> th.th_current_task -> td_icvs.nproc;
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_THREAD_NUM)( void )
{
#ifdef KMP_STUB
return 0;
#else
int gtid;
#if KMP_OS_DARWIN || KMP_OS_FREEBSD || KMP_OS_NETBSD
gtid = __kmp_entry_gtid();
#elif KMP_OS_WINDOWS
if (!__kmp_init_parallel ||
(gtid = (int)((kmp_intptr_t)TlsGetValue( __kmp_gtid_threadprivate_key ))) == 0) {
// Either library isn't initialized or thread is not registered
// 0 is the correct TID in this case
return 0;
}
--gtid; // We keep (gtid+1) in TLS
#elif KMP_OS_LINUX
#ifdef KMP_TDATA_GTID
if ( __kmp_gtid_mode >= 3 ) {
if ((gtid = __kmp_gtid) == KMP_GTID_DNE) {
return 0;
}
} else {
#endif
if (!__kmp_init_parallel ||
(gtid = (kmp_intptr_t)(pthread_getspecific( __kmp_gtid_threadprivate_key ))) == 0) {
return 0;
}
--gtid;
#ifdef KMP_TDATA_GTID
}
#endif
#else
#error Unknown or unsupported OS
#endif
return __kmp_tid_from_gtid( gtid );
#endif
}
int FTN_STDCALL
FTN_GET_NUM_KNOWN_THREADS( void )
{
#ifdef KMP_STUB
return 1;
#else
if ( ! __kmp_init_serial ) {
__kmp_serial_initialize();
}
/* NOTE: this is not syncronized, so it can change at any moment */
/* NOTE: this number also includes threads preallocated in hot-teams */
return TCR_4(__kmp_nth);
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_NUM_PROCS)( void )
{
#ifdef KMP_STUB
return 1;
#else
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
return __kmp_avail_proc;
#endif
}
void FTN_STDCALL
xexpand(FTN_SET_NESTED)( int KMP_DEREF flag )
{
#ifdef KMP_STUB
__kmps_set_nested( KMP_DEREF flag );
#else
kmp_info_t *thread;
/* For the thread-private internal controls implementation */
thread = __kmp_entry_thread();
__kmp_save_internal_controls( thread );
set__nested( thread, ( (KMP_DEREF flag) ? TRUE : FALSE ) );
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_NESTED)( void )
{
#ifdef KMP_STUB
return __kmps_get_nested();
#else
kmp_info_t *thread;
thread = __kmp_entry_thread();
return get__nested( thread );
#endif
}
void FTN_STDCALL
xexpand(FTN_SET_DYNAMIC)( int KMP_DEREF flag )
{
#ifdef KMP_STUB
__kmps_set_dynamic( KMP_DEREF flag ? TRUE : FALSE );
#else
kmp_info_t *thread;
/* For the thread-private implementation of the internal controls */
thread = __kmp_entry_thread();
// !!! What if foreign thread calls it?
__kmp_save_internal_controls( thread );
set__dynamic( thread, KMP_DEREF flag ? TRUE : FALSE );
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_DYNAMIC)( void )
{
#ifdef KMP_STUB
return __kmps_get_dynamic();
#else
kmp_info_t *thread;
thread = __kmp_entry_thread();
return get__dynamic( thread );
#endif
}
int FTN_STDCALL
xexpand(FTN_IN_PARALLEL)( void )
{
#ifdef KMP_STUB
return 0;
#else
kmp_info_t *th = __kmp_entry_thread();
#if OMP_40_ENABLED
if ( th->th.th_teams_microtask ) {
// AC: r_in_parallel does not work inside teams construct
// where real parallel is inactive, but all threads have same root,
// so setting it in one team affects other teams.
// The solution is to use per-team nesting level
return ( th->th.th_team->t.t_active_level ? 1 : 0 );
}
else
#endif /* OMP_40_ENABLED */
return ( th->th.th_root->r.r_in_parallel ? FTN_TRUE : FTN_FALSE );
#endif
}
void FTN_STDCALL
xexpand(FTN_SET_SCHEDULE)( kmp_sched_t KMP_DEREF kind, int KMP_DEREF modifier )
{
#ifdef KMP_STUB
__kmps_set_schedule( KMP_DEREF kind, KMP_DEREF modifier );
#else
/* TO DO */
/* For the per-task implementation of the internal controls */
__kmp_set_schedule( __kmp_entry_gtid(), KMP_DEREF kind, KMP_DEREF modifier );
#endif
}
void FTN_STDCALL
xexpand(FTN_GET_SCHEDULE)( kmp_sched_t * kind, int * modifier )
{
#ifdef KMP_STUB
__kmps_get_schedule( kind, modifier );
#else
/* TO DO */
/* For the per-task implementation of the internal controls */
__kmp_get_schedule( __kmp_entry_gtid(), kind, modifier );
#endif
}
void FTN_STDCALL
xexpand(FTN_SET_MAX_ACTIVE_LEVELS)( int KMP_DEREF arg )
{
#ifdef KMP_STUB
// Nothing.
#else
/* TO DO */
/* We want per-task implementation of this internal control */
__kmp_set_max_active_levels( __kmp_entry_gtid(), KMP_DEREF arg );
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_MAX_ACTIVE_LEVELS)( void )
{
#ifdef KMP_STUB
return 0;
#else
/* TO DO */
/* We want per-task implementation of this internal control */
return __kmp_get_max_active_levels( __kmp_entry_gtid() );
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_ACTIVE_LEVEL)( void )
{
#ifdef KMP_STUB
return 0; // returns 0 if it is called from the sequential part of the program
#else
/* TO DO */
/* For the per-task implementation of the internal controls */
return __kmp_entry_thread() -> th.th_team -> t.t_active_level;
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_LEVEL)( void )
{
#ifdef KMP_STUB
return 0; // returns 0 if it is called from the sequential part of the program
#else
/* TO DO */
/* For the per-task implementation of the internal controls */
return __kmp_entry_thread() -> th.th_team -> t.t_level;
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_ANCESTOR_THREAD_NUM)( int KMP_DEREF level )
{
#ifdef KMP_STUB
return ( KMP_DEREF level ) ? ( -1 ) : ( 0 );
#else
return __kmp_get_ancestor_thread_num( __kmp_entry_gtid(), KMP_DEREF level );
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_TEAM_SIZE)( int KMP_DEREF level )
{
#ifdef KMP_STUB
return ( KMP_DEREF level ) ? ( -1 ) : ( 1 );
#else
return __kmp_get_team_size( __kmp_entry_gtid(), KMP_DEREF level );
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_THREAD_LIMIT)( void )
{
#ifdef KMP_STUB
return 1; // TO DO: clarify whether it returns 1 or 0?
#else
if ( ! __kmp_init_serial ) {
__kmp_serial_initialize();
};
/* global ICV */
return __kmp_max_nth;
#endif
}
int FTN_STDCALL
xexpand(FTN_IN_FINAL)( void )
{
#ifdef KMP_STUB
return 0; // TO DO: clarify whether it returns 1 or 0?
#else
if ( ! TCR_4(__kmp_init_parallel) ) {
return 0;
}
return __kmp_entry_thread() -> th.th_current_task -> td_flags.final;
#endif
}
#if OMP_40_ENABLED
kmp_proc_bind_t FTN_STDCALL
xexpand(FTN_GET_PROC_BIND)( void )
{
#ifdef KMP_STUB
return __kmps_get_proc_bind();
#else
return get__proc_bind( __kmp_entry_thread() );
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_NUM_TEAMS)( void )
{
#ifdef KMP_STUB
return 1;
#else
kmp_info_t *thr = __kmp_entry_thread();
if ( thr->th.th_teams_microtask ) {
kmp_team_t *team = thr->th.th_team;
int tlevel = thr->th.th_teams_level;
int ii = team->t.t_level; // the level of the teams construct
int dd = team -> t.t_serialized;
int level = tlevel + 1;
KMP_DEBUG_ASSERT( ii >= tlevel );
while( ii > level )
{
for( dd = team -> t.t_serialized; ( dd > 0 ) && ( ii > level ); dd--, ii-- )
{
}
if( team -> t.t_serialized && ( !dd ) ) {
team = team->t.t_parent;
continue;
}
if( ii > level ) {
team = team->t.t_parent;
ii--;
}
}
if ( dd > 1 ) {
return 1; // teams region is serialized ( 1 team of 1 thread ).
} else {
return team->t.t_parent->t.t_nproc;
}
} else {
return 1;
}
#endif
}
int FTN_STDCALL
xexpand(FTN_GET_TEAM_NUM)( void )
{
#ifdef KMP_STUB
return 0;
#else
kmp_info_t *thr = __kmp_entry_thread();
if ( thr->th.th_teams_microtask ) {
kmp_team_t *team = thr->th.th_team;
int tlevel = thr->th.th_teams_level; // the level of the teams construct
int ii = team->t.t_level;
int dd = team -> t.t_serialized;
int level = tlevel + 1;
KMP_DEBUG_ASSERT( ii >= tlevel );
while( ii > level )
{
for( dd = team -> t.t_serialized; ( dd > 0 ) && ( ii > level ); dd--, ii-- )
{
}
if( team -> t.t_serialized && ( !dd ) ) {
team = team->t.t_parent;
continue;
}
if( ii > level ) {
team = team->t.t_parent;
ii--;
}
}
if ( dd > 1 ) {
return 0; // teams region is serialized ( 1 team of 1 thread ).
} else {
return team->t.t_master_tid;
}
} else {
return 0;
}
#endif
}
#if KMP_MIC || KMP_OS_DARWIN
static int __kmp_default_device = 0;
int FTN_STDCALL
FTN_GET_DEFAULT_DEVICE( void )
{
return __kmp_default_device;
}
void FTN_STDCALL
FTN_SET_DEFAULT_DEVICE( int KMP_DEREF arg )
{
__kmp_default_device = KMP_DEREF arg;
}
int FTN_STDCALL
FTN_GET_NUM_DEVICES( void )
{
return 0;
}
#endif // KMP_MIC || KMP_OS_DARWIN
#if ! KMP_OS_LINUX
int FTN_STDCALL
xexpand(FTN_IS_INITIAL_DEVICE)( void )
{
return 1;
}
#else
// This internal function is used when the entry from the offload library
// is not found.
int _Offload_get_device_number( void ) __attribute__((weak));
int FTN_STDCALL
xexpand(FTN_IS_INITIAL_DEVICE)( void )
{
if( _Offload_get_device_number ) {
return _Offload_get_device_number() == -1;
} else {
return 1;
}
}
#endif // ! KMP_OS_LINUX
#endif // OMP_40_ENABLED
#ifdef KMP_STUB
typedef enum { UNINIT = -1, UNLOCKED, LOCKED } kmp_stub_lock_t;
#endif /* KMP_STUB */
#if KMP_USE_DYNAMIC_LOCK
void FTN_STDCALL
FTN_INIT_LOCK_WITH_HINT( void **user_lock, uintptr_t KMP_DEREF hint )
{
#ifdef KMP_STUB
*((kmp_stub_lock_t *)user_lock) = UNLOCKED;
#else
__kmpc_init_lock_with_hint( NULL, __kmp_entry_gtid(), user_lock, KMP_DEREF hint );
#endif
}
void FTN_STDCALL
FTN_INIT_NEST_LOCK_WITH_HINT( void **user_lock, uintptr_t KMP_DEREF hint )
{
#ifdef KMP_STUB
*((kmp_stub_lock_t *)user_lock) = UNLOCKED;
#else
__kmpc_init_nest_lock_with_hint( NULL, __kmp_entry_gtid(), user_lock, KMP_DEREF hint );
#endif
}
#endif
/* initialize the lock */
void FTN_STDCALL
xexpand(FTN_INIT_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
*((kmp_stub_lock_t *)user_lock) = UNLOCKED;
#else
__kmpc_init_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
/* initialize the lock */
void FTN_STDCALL
xexpand(FTN_INIT_NEST_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
*((kmp_stub_lock_t *)user_lock) = UNLOCKED;
#else
__kmpc_init_nest_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
void FTN_STDCALL
xexpand(FTN_DESTROY_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
*((kmp_stub_lock_t *)user_lock) = UNINIT;
#else
__kmpc_destroy_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
void FTN_STDCALL
xexpand(FTN_DESTROY_NEST_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
*((kmp_stub_lock_t *)user_lock) = UNINIT;
#else
__kmpc_destroy_nest_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
void FTN_STDCALL
xexpand(FTN_SET_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
if ( *((kmp_stub_lock_t *)user_lock) == UNINIT ) {
// TODO: Issue an error.
}; // if
if ( *((kmp_stub_lock_t *)user_lock) != UNLOCKED ) {
// TODO: Issue an error.
}; // if
*((kmp_stub_lock_t *)user_lock) = LOCKED;
#else
__kmpc_set_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
void FTN_STDCALL
xexpand(FTN_SET_NEST_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
if ( *((kmp_stub_lock_t *)user_lock) == UNINIT ) {
// TODO: Issue an error.
}; // if
(*((int *)user_lock))++;
#else
__kmpc_set_nest_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
void FTN_STDCALL
xexpand(FTN_UNSET_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
if ( *((kmp_stub_lock_t *)user_lock) == UNINIT ) {
// TODO: Issue an error.
}; // if
if ( *((kmp_stub_lock_t *)user_lock) == UNLOCKED ) {
// TODO: Issue an error.
}; // if
*((kmp_stub_lock_t *)user_lock) = UNLOCKED;
#else
__kmpc_unset_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
void FTN_STDCALL
xexpand(FTN_UNSET_NEST_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
if ( *((kmp_stub_lock_t *)user_lock) == UNINIT ) {
// TODO: Issue an error.
}; // if
if ( *((kmp_stub_lock_t *)user_lock) == UNLOCKED ) {
// TODO: Issue an error.
}; // if
(*((int *)user_lock))--;
#else
__kmpc_unset_nest_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
int FTN_STDCALL
xexpand(FTN_TEST_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
if ( *((kmp_stub_lock_t *)user_lock) == UNINIT ) {
// TODO: Issue an error.
}; // if
if ( *((kmp_stub_lock_t *)user_lock) == LOCKED ) {
return 0;
}; // if
*((kmp_stub_lock_t *)user_lock) = LOCKED;
return 1;
#else
return __kmpc_test_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
int FTN_STDCALL
xexpand(FTN_TEST_NEST_LOCK)( void **user_lock )
{
#ifdef KMP_STUB
if ( *((kmp_stub_lock_t *)user_lock) == UNINIT ) {
// TODO: Issue an error.
}; // if
return ++(*((int *)user_lock));
#else
return __kmpc_test_nest_lock( NULL, __kmp_entry_gtid(), user_lock );
#endif
}
double FTN_STDCALL
xexpand(FTN_GET_WTIME)( void )
{
#ifdef KMP_STUB
return __kmps_get_wtime();
#else
double data;
#if ! KMP_OS_LINUX
// We don't need library initialization to get the time on Linux* OS.
// The routine can be used to measure library initialization time on Linux* OS now.
if ( ! __kmp_init_serial ) {
__kmp_serial_initialize();
};
#endif
__kmp_elapsed( & data );
return data;
#endif
}
double FTN_STDCALL
xexpand(FTN_GET_WTICK)( void )
{
#ifdef KMP_STUB
return __kmps_get_wtick();
#else
double data;
if ( ! __kmp_init_serial ) {
__kmp_serial_initialize();
};
__kmp_elapsed_tick( & data );
return data;
#endif
}
/* ------------------------------------------------------------------------ */
void * FTN_STDCALL
FTN_MALLOC( size_t KMP_DEREF size )
{
// kmpc_malloc initializes the library if needed
return kmpc_malloc( KMP_DEREF size );
}
void * FTN_STDCALL
FTN_CALLOC( size_t KMP_DEREF nelem, size_t KMP_DEREF elsize )
{
// kmpc_calloc initializes the library if needed
return kmpc_calloc( KMP_DEREF nelem, KMP_DEREF elsize );
}
void * FTN_STDCALL
FTN_REALLOC( void * KMP_DEREF ptr, size_t KMP_DEREF size )
{
// kmpc_realloc initializes the library if needed
return kmpc_realloc( KMP_DEREF ptr, KMP_DEREF size );
}
void FTN_STDCALL
FTN_FREE( void * KMP_DEREF ptr )
{
// does nothing if the library is not initialized
kmpc_free( KMP_DEREF ptr );
}
void FTN_STDCALL
FTN_SET_WARNINGS_ON( void )
{
#ifndef KMP_STUB
__kmp_generate_warnings = kmp_warnings_explicit;
#endif
}
void FTN_STDCALL
FTN_SET_WARNINGS_OFF( void )
{
#ifndef KMP_STUB
__kmp_generate_warnings = FALSE;
#endif
}
void FTN_STDCALL
FTN_SET_DEFAULTS( char const * str
#ifndef PASS_ARGS_BY_VALUE
, int len
#endif
)
{
#ifndef KMP_STUB
#ifdef PASS_ARGS_BY_VALUE
int len = (int)KMP_STRLEN( str );
#endif
__kmp_aux_set_defaults( str, len );
#endif
}
/* ------------------------------------------------------------------------ */
#if OMP_40_ENABLED
/* returns the status of cancellation */
int FTN_STDCALL
xexpand(FTN_GET_CANCELLATION)(void) {
#ifdef KMP_STUB
return 0 /* false */;
#else
// initialize the library if needed
if ( ! __kmp_init_serial ) {
__kmp_serial_initialize();
}
return __kmp_omp_cancellation;
#endif
}
int FTN_STDCALL
FTN_GET_CANCELLATION_STATUS(int cancel_kind) {
#ifdef KMP_STUB
return 0 /* false */;
#else
return __kmp_get_cancellation_status(cancel_kind);
#endif
}
#endif // OMP_40_ENABLED
// GCC compatibility (versioned symbols)
#ifdef KMP_USE_VERSION_SYMBOLS
/*
These following sections create function aliases (dummy symbols) for the omp_* routines.
These aliases will then be versioned according to how libgomp ``versions'' its
symbols (OMP_1.0, OMP_2.0, OMP_3.0, ...) while also retaining the
default version which libomp uses: VERSION (defined in exports_so.txt)
If you want to see the versioned symbols for libgomp.so.1 then just type:
objdump -T /path/to/libgomp.so.1 | grep omp_
Example:
Step 1) Create __kmp_api_omp_set_num_threads_10_alias
which is alias of __kmp_api_omp_set_num_threads
Step 2) Set __kmp_api_omp_set_num_threads_10_alias to version: omp_set_num_threads@OMP_1.0
Step 2B) Set __kmp_api_omp_set_num_threads to default version : omp_set_num_threads@@VERSION
*/
// OMP_1.0 aliases
xaliasify(FTN_SET_NUM_THREADS, 10);
xaliasify(FTN_GET_NUM_THREADS, 10);
xaliasify(FTN_GET_MAX_THREADS, 10);
xaliasify(FTN_GET_THREAD_NUM, 10);
xaliasify(FTN_GET_NUM_PROCS, 10);
xaliasify(FTN_IN_PARALLEL, 10);
xaliasify(FTN_SET_DYNAMIC, 10);
xaliasify(FTN_GET_DYNAMIC, 10);
xaliasify(FTN_SET_NESTED, 10);
xaliasify(FTN_GET_NESTED, 10);
xaliasify(FTN_INIT_LOCK, 10);
xaliasify(FTN_INIT_NEST_LOCK, 10);
xaliasify(FTN_DESTROY_LOCK, 10);
xaliasify(FTN_DESTROY_NEST_LOCK, 10);
xaliasify(FTN_SET_LOCK, 10);
xaliasify(FTN_SET_NEST_LOCK, 10);
xaliasify(FTN_UNSET_LOCK, 10);
xaliasify(FTN_UNSET_NEST_LOCK, 10);
xaliasify(FTN_TEST_LOCK, 10);
xaliasify(FTN_TEST_NEST_LOCK, 10);
// OMP_2.0 aliases
xaliasify(FTN_GET_WTICK, 20);
xaliasify(FTN_GET_WTIME, 20);
// OMP_3.0 aliases
xaliasify(FTN_SET_SCHEDULE, 30);
xaliasify(FTN_GET_SCHEDULE, 30);
xaliasify(FTN_GET_THREAD_LIMIT, 30);
xaliasify(FTN_SET_MAX_ACTIVE_LEVELS, 30);
xaliasify(FTN_GET_MAX_ACTIVE_LEVELS, 30);
xaliasify(FTN_GET_LEVEL, 30);
xaliasify(FTN_GET_ANCESTOR_THREAD_NUM, 30);
xaliasify(FTN_GET_TEAM_SIZE, 30);
xaliasify(FTN_GET_ACTIVE_LEVEL, 30);
xaliasify(FTN_INIT_LOCK, 30);
xaliasify(FTN_INIT_NEST_LOCK, 30);
xaliasify(FTN_DESTROY_LOCK, 30);
xaliasify(FTN_DESTROY_NEST_LOCK, 30);
xaliasify(FTN_SET_LOCK, 30);
xaliasify(FTN_SET_NEST_LOCK, 30);
xaliasify(FTN_UNSET_LOCK, 30);
xaliasify(FTN_UNSET_NEST_LOCK, 30);
xaliasify(FTN_TEST_LOCK, 30);
xaliasify(FTN_TEST_NEST_LOCK, 30);
// OMP_3.1 aliases
xaliasify(FTN_IN_FINAL, 31);
#if OMP_40_ENABLED
// OMP_4.0 aliases
xaliasify(FTN_GET_PROC_BIND, 40);
xaliasify(FTN_GET_NUM_TEAMS, 40);
xaliasify(FTN_GET_TEAM_NUM, 40);
xaliasify(FTN_GET_CANCELLATION, 40);
xaliasify(FTN_IS_INITIAL_DEVICE, 40);
#endif /* OMP_40_ENABLED */
#if OMP_41_ENABLED
// OMP_4.1 aliases
#endif
#if OMP_50_ENABLED
// OMP_5.0 aliases
#endif
// OMP_1.0 versioned symbols
xversionify(FTN_SET_NUM_THREADS, 10, "OMP_1.0");
xversionify(FTN_GET_NUM_THREADS, 10, "OMP_1.0");
xversionify(FTN_GET_MAX_THREADS, 10, "OMP_1.0");
xversionify(FTN_GET_THREAD_NUM, 10, "OMP_1.0");
xversionify(FTN_GET_NUM_PROCS, 10, "OMP_1.0");
xversionify(FTN_IN_PARALLEL, 10, "OMP_1.0");
xversionify(FTN_SET_DYNAMIC, 10, "OMP_1.0");
xversionify(FTN_GET_DYNAMIC, 10, "OMP_1.0");
xversionify(FTN_SET_NESTED, 10, "OMP_1.0");
xversionify(FTN_GET_NESTED, 10, "OMP_1.0");
xversionify(FTN_INIT_LOCK, 10, "OMP_1.0");
xversionify(FTN_INIT_NEST_LOCK, 10, "OMP_1.0");
xversionify(FTN_DESTROY_LOCK, 10, "OMP_1.0");
xversionify(FTN_DESTROY_NEST_LOCK, 10, "OMP_1.0");
xversionify(FTN_SET_LOCK, 10, "OMP_1.0");
xversionify(FTN_SET_NEST_LOCK, 10, "OMP_1.0");
xversionify(FTN_UNSET_LOCK, 10, "OMP_1.0");
xversionify(FTN_UNSET_NEST_LOCK, 10, "OMP_1.0");
xversionify(FTN_TEST_LOCK, 10, "OMP_1.0");
xversionify(FTN_TEST_NEST_LOCK, 10, "OMP_1.0");
// OMP_2.0 versioned symbols
xversionify(FTN_GET_WTICK, 20, "OMP_2.0");
xversionify(FTN_GET_WTIME, 20, "OMP_2.0");
// OMP_3.0 versioned symbols
xversionify(FTN_SET_SCHEDULE, 30, "OMP_3.0");
xversionify(FTN_GET_SCHEDULE, 30, "OMP_3.0");
xversionify(FTN_GET_THREAD_LIMIT, 30, "OMP_3.0");
xversionify(FTN_SET_MAX_ACTIVE_LEVELS, 30, "OMP_3.0");
xversionify(FTN_GET_MAX_ACTIVE_LEVELS, 30, "OMP_3.0");
xversionify(FTN_GET_ANCESTOR_THREAD_NUM, 30, "OMP_3.0");
xversionify(FTN_GET_LEVEL, 30, "OMP_3.0");
xversionify(FTN_GET_TEAM_SIZE, 30, "OMP_3.0");
xversionify(FTN_GET_ACTIVE_LEVEL, 30, "OMP_3.0");
// the lock routines have a 1.0 and 3.0 version
xversionify(FTN_INIT_LOCK, 30, "OMP_3.0");
xversionify(FTN_INIT_NEST_LOCK, 30, "OMP_3.0");
xversionify(FTN_DESTROY_LOCK, 30, "OMP_3.0");
xversionify(FTN_DESTROY_NEST_LOCK, 30, "OMP_3.0");
xversionify(FTN_SET_LOCK, 30, "OMP_3.0");
xversionify(FTN_SET_NEST_LOCK, 30, "OMP_3.0");
xversionify(FTN_UNSET_LOCK, 30, "OMP_3.0");
xversionify(FTN_UNSET_NEST_LOCK, 30, "OMP_3.0");
xversionify(FTN_TEST_LOCK, 30, "OMP_3.0");
xversionify(FTN_TEST_NEST_LOCK, 30, "OMP_3.0");
// OMP_3.1 versioned symbol
xversionify(FTN_IN_FINAL, 31, "OMP_3.1");
#if OMP_40_ENABLED
// OMP_4.0 versioned symbols
xversionify(FTN_GET_PROC_BIND, 40, "OMP_4.0");
xversionify(FTN_GET_NUM_TEAMS, 40, "OMP_4.0");
xversionify(FTN_GET_TEAM_NUM, 40, "OMP_4.0");
xversionify(FTN_GET_CANCELLATION, 40, "OMP_4.0");
xversionify(FTN_IS_INITIAL_DEVICE, 40, "OMP_4.0");
#endif /* OMP_40_ENABLED */
#if OMP_41_ENABLED
// OMP_4.1 versioned symbols
#endif
#if OMP_50_ENABLED
// OMP_5.0 versioned symbols
#endif
#endif // KMP_USE_VERSION_SYMBOLS
#ifdef __cplusplus
} //extern "C"
#endif // __cplusplus
// end of file //
|