-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgasnet_internal.c
More file actions
3230 lines (2922 loc) · 124 KB
/
Copy pathgasnet_internal.c
File metadata and controls
3230 lines (2922 loc) · 124 KB
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
/* $Source: github.com:BerkeleyLab/gasnet.git/gasnet_internal.c $
* Description: GASNet implementation of internal helpers
* Copyright 2002, Dan Bonachea <bonachea@cs.berkeley.edu>
* Terms of use are as specified in license.txt
*/
#include <gasnet_internal.h>
#include <gasnet_am.h>
#include <gasnet_tools.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h> /* time, ctime */
#if HAVE_MALLOC_H && !PLATFORM_OS_OPENBSD /* OpenBSD warns that malloc.h is obsolete */
#include <malloc.h>
#endif
/* set to non-zero for verbose error reporting */
int gasneti_VerboseErrors = 1;
/* ------------------------------------------------------------------------------------ */
/* generic atomics support */
#if defined(GASNETI_BUILD_GENERIC_ATOMIC32) || defined(GASNETI_BUILD_GENERIC_ATOMIC64)
#ifdef GASNETI_ATOMIC_LOCK_TBL_DEFNS
GASNETI_ATOMIC_LOCK_TBL_DEFNS(gasneti_malloc)
#endif
#ifdef GASNETI_GENATOMIC32_DEFN
GASNETI_GENATOMIC32_DEFN
#endif
#ifdef GASNETI_GENATOMIC64_DEFN
GASNETI_GENATOMIC64_DEFN
#endif
#endif
/* ------------------------------------------------------------------------------------ */
#if GASNETI_THROTTLE_POLLERS
gasneti_atomic_t gasneti_throttle_haveusefulwork = gasneti_atomic_init(0);
gasneti_mutex_t gasneti_throttle_spinpoller = GASNETI_MUTEX_INITIALIZER;
#endif
#if GASNET_DEBUG
GASNETI_THREADKEY_DEFINE(gasneti_throttledebug_key);
#endif
#define GEX_VERSION_STR _STRINGIFY(GEX_SPEC_VERSION_MAJOR) "." _STRINGIFY(GEX_SPEC_VERSION_MINOR)
GASNETI_IDENT(gasneti_IdentString_EXAPIVersion, "$GASNetEXAPIVersion: " GEX_VERSION_STR " $");
#define GASNET_VERSION_STR _STRINGIFY(GASNETI_SPEC_VERSION_MAJOR)
GASNETI_IDENT(gasneti_IdentString_APIVersion, "$GASNetAPIVersion: " GASNET_VERSION_STR " $");
#define GASNETI_THREAD_MODEL_STR _STRINGIFY(GASNETI_THREAD_MODEL)
GASNETI_IDENT(gasneti_IdentString_ThreadModel, "$GASNetThreadModel: GASNET_" GASNETI_THREAD_MODEL_STR " $");
#define GASNETI_SEGMENT_CONFIG_STR _STRINGIFY(GASNETI_SEGMENT_CONFIG)
GASNETI_IDENT(gasneti_IdentString_SegConfig, "$GASNetSegment: GASNET_SEGMENT_" GASNETI_SEGMENT_CONFIG_STR " $");
#ifdef GASNETI_BUG1389_WORKAROUND
GASNETI_IDENT(gasneti_IdentString_ConservativeLocalCopy, "$GASNetConservativeLocalCopy: 1 $");
#endif
#if GASNETI_CLIENT_THREADS
GASNETI_IDENT(gasneti_IdentString_ThreadInfoOpt, "$GASNetThreadInfoOpt: " _STRINGIFY(GASNETI_THREADINFO_OPT) " $");
#endif
#if GASNETI_SWIZZLE
GASNETI_IDENT(gasneti_IdentString_Swizzle, "$GASNetSwizzle: 1 $");
#endif
/* embed a string with complete configuration info to support versioning checks */
GASNETI_IDENT(gasneti_IdentString_libraryConfig, "$GASNetConfig: (libgasnet.a) " GASNET_CONFIG_STRING " $");
/* the canonical conduit name */
GASNETI_IDENT(gasneti_IdentString_ConduitName, "$GASNetConduitName: " GASNET_CONDUIT_NAME_STR " $");
int gasneti_init_done = 0; /* true after init */
int gasneti_attach_done = 0; /* true after attach */
extern void gasneti_checkinit(void) {
if (!gasneti_init_done)
gasneti_fatalerror("Illegal call to GASNet before library initialization. Please use gex_Client_Init() to initialize GASNet.");
}
extern void gasneti_checkattach(void) {
gasneti_checkinit();
if (!gasneti_attach_done)
gasneti_fatalerror("Illegal call to GASNet before gasnet_attach() initialization");
}
void (*gasnet_client_attach_hook)(void *, uintptr_t) = NULL;
int gasneti_wait_mode = GASNET_WAIT_SPIN;
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(RELEASE_MAJOR_,GASNET_RELEASE_VERSION_MAJOR)) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(RELEASE_MINOR_,GASNET_RELEASE_VERSION_MINOR)) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(RELEASE_PATCH_,GASNET_RELEASE_VERSION_PATCH)) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_THREAD_MODEL) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_SEGMENT_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_DEBUG_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_TRACE_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_STATS_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_MALLOC_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_SRCLINES_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_ALIGN_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_PSHM_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_PTR_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_TIMER_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_MEMBAR_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_ATOMIC_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_ATOMIC32_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_ATOMIC64_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_TIOPT_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_MK_CLASS_CUDA_UVA_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_MK_CLASS_HIP_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(GASNETI_MK_CLASS_ZE_CONFIG) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(HIDDEN_AM_CONCUR_,GASNET_HIDDEN_AM_CONCURRENCY_LEVEL)) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(CACHE_LINE_BYTES_,GASNETI_CACHE_LINE_BYTES)) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(GASNETI_TM0_ALIGN_,GASNETI_TM0_ALIGN)) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(CORE_,GASNET_CORE_NAME)) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(EXTENDED_,GASNET_EXTENDED_NAME)) = 1;
#if GASNET_CONDUIT_OFI
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(OFI_PROVIDER_,GASNETC_OFI_PROVIDER_IDENT)) = 1;
#endif
/* global definitions of GASNet-wide internal variables
not subject to override */
gex_Rank_t gasneti_mynode = (gex_Rank_t)-1;
gex_Rank_t gasneti_nodes = 0;
// a necessary evil - see the declaration in gasnet_help.h
gasneti_TM_t gasneti_thing_that_goes_thunk_in_the_dark = NULL;
/* Default global definitions of GASNet-wide internal variables
if conduits override one of these, they must
still provide variable or macro definitions for these tokens */
#if defined(_GASNET_GETMAXSEGMENTSIZE_DEFAULT)
uintptr_t gasneti_MaxLocalSegmentSize = 0;
uintptr_t gasneti_MaxGlobalSegmentSize = 0;
#endif
#ifdef _GASNETI_PROGRESSFNS_DEFAULT
GASNETI_PROGRESSFNS_LIST(_GASNETI_PROGRESSFNS_DEFINE_FLAGS)
#endif
#if GASNET_DEBUG
static void gasneti_disabled_progressfn(void) {
gasneti_fatalerror("Called a disabled progress function");
}
gasneti_progressfn_t gasneti_debug_progressfn_bool = gasneti_disabled_progressfn;
gasneti_progressfn_t gasneti_debug_progressfn_counted = gasneti_disabled_progressfn;
#endif
void gasneti_empty_pf(void) {}
gasnet_seginfo_t *gasneti_seginfo = NULL;
gasnet_seginfo_t *gasneti_seginfo_aux = NULL;
// TODO: this is proof-of-concept and not a scalable final solution (bug 4088)
// Note that (gasneti_seginfo_tbl[0] == gasneti_seginfo) to simplify some logic.
gasnet_seginfo_t *gasneti_seginfo_tbl[GASNET_MAXEPS] = {NULL, };
/* ------------------------------------------------------------------------------------ */
/* conduit-independent sanity checks */
extern void gasneti_check_config_preinit(void) {
gasneti_static_assert(sizeof(int8_t) == 1);
gasneti_static_assert(sizeof(uint8_t) == 1);
gasneti_static_assert(sizeof(gasnete_anytype8_t) == 1);
#ifndef INTTYPES_16BIT_MISSING
gasneti_static_assert(sizeof(int16_t) == 2);
gasneti_static_assert(sizeof(uint16_t) == 2);
gasneti_static_assert(sizeof(gasnete_anytype16_t) == 2);
#endif
gasneti_static_assert(sizeof(int32_t) == 4);
gasneti_static_assert(sizeof(uint32_t) == 4);
gasneti_static_assert(sizeof(gasnete_anytype32_t) == 4);
gasneti_static_assert(sizeof(int64_t) == 8);
gasneti_static_assert(sizeof(uint64_t) == 8);
gasneti_static_assert(sizeof(gasnete_anytype64_t) == 8);
gasneti_static_assert(sizeof(uintptr_t) >= sizeof(void *));
#define CHECK_DT(id, type) do { \
gasneti_assert_always(gasneti_dt_valid(id)); \
gasneti_assert_always_uint(gasneti_dt_size(id) ,==, sizeof(type)); \
gasneti_assert_always(!!gasneti_dt_int(id) == !gasneti_dt_fp(id)); \
} while (0)
#define CHECK_INT_DT(id, type, sign) do { \
CHECK_DT(id, type); \
gasneti_assert_always(gasneti_dt_int(id)); \
gasneti_assert_always(gasneti_dt_##sign(id)); \
gasneti_assert_always(!!gasneti_dt_signed(id) == !gasneti_dt_unsigned(id)); \
} while (0)
#define CHECK_FP_DT(id, type) do { \
CHECK_DT(id, type); \
gasneti_assert_always(gasneti_dt_fp(id)); \
} while (0)
CHECK_INT_DT(GEX_DT_I32, int32_t, signed);
CHECK_INT_DT(GEX_DT_U32, uint32_t, unsigned);
CHECK_INT_DT(GEX_DT_I64, int64_t, signed);
CHECK_INT_DT(GEX_DT_U64, uint64_t, unsigned);
CHECK_FP_DT(GEX_DT_FLT, float);
CHECK_FP_DT(GEX_DT_DBL, double);
gasneti_assert_always(gasneti_dt_valid_reduce(GEX_DT_USER));
gasneti_assert_always(!gasneti_dt_valid_atomic(GEX_DT_USER));
gasneti_assert_always(!gasneti_dt_int(GEX_DT_USER));
gasneti_assert_always(!gasneti_dt_fp(GEX_DT_USER));
gasneti_assert_always(!gasneti_dt_signed(GEX_DT_USER));
gasneti_assert_always(!gasneti_dt_unsigned(GEX_DT_USER));
#undef CHECK_DT
#undef CHECK_INT_DT
#undef CHECK_FP_DT
#define _CHECK_OP(id, pred1, pred2, pred3) do { \
gasneti_assert_always(gasneti_op_atomic(id)); \
gasneti_assert_always(gasneti_op_int(id)); \
gasneti_assert_always(!!gasneti_op_0arg(id) + \
!!gasneti_op_1arg(id) + \
!!gasneti_op_2arg(id) == 1); \
gasneti_assert_always(gasneti_op_##pred1(id)); \
gasneti_assert_always(gasneti_op_##pred2(id)); \
gasneti_assert_always(gasneti_op_##pred3(id)); \
} while (0)
#define CHECK_ARITH_OP(stem, reduce_pred, fp_pred) do { \
gasneti_assert_always(!gasneti_op_fetch(GEX_OP_##stem)); \
_CHECK_OP(GEX_OP_##stem, reduce_pred, fp_pred, valid); \
gasneti_assert_always(gasneti_op_fetch(GEX_OP_F##stem)); \
_CHECK_OP(GEX_OP_F##stem, not_reduce, fp_pred, valid); \
} while (0)
#define CHECK_ACCESSOR(stem, pred) do { \
gasneti_assert_always(gasneti_op_valid(GEX_OP_##stem)); \
_CHECK_OP(GEX_OP_##stem, fp, not_reduce, pred); \
} while (0)
#define CHECK_USER(stem) do { \
gasneti_assert_always(gasneti_op_valid(GEX_OP_##stem)); \
gasneti_assert_always(gasneti_op_valid_reduce(GEX_OP_##stem)); \
gasneti_assert_always(!gasneti_op_valid_atomic(GEX_OP_##stem)); \
gasneti_assert_always(gasneti_op_int(GEX_OP_##stem)); \
gasneti_assert_always(gasneti_op_fp(GEX_OP_##stem)); \
} while (0)
#define gasneti_op_not_reduce !gasneti_op_reduce
#define gasneti_op_not_fetch !gasneti_op_fetch
#define gasneti_op_not_fp !gasneti_op_fp
CHECK_ARITH_OP(AND, reduce, not_fp);
CHECK_ARITH_OP(OR, reduce, not_fp);
CHECK_ARITH_OP(XOR, reduce, not_fp);
CHECK_ARITH_OP(ADD, reduce, fp);
CHECK_ARITH_OP(SUB, not_reduce, fp);
CHECK_ARITH_OP(MULT, reduce, fp);
CHECK_ARITH_OP(MIN, reduce, fp);
CHECK_ARITH_OP(MAX, reduce, fp);
CHECK_ARITH_OP(INC, not_reduce, fp);
CHECK_ARITH_OP(DEC, not_reduce, fp);
CHECK_ACCESSOR(SET, not_fetch);
CHECK_ACCESSOR(CAS, not_fetch);
CHECK_ACCESSOR(GET, fetch);
CHECK_ACCESSOR(SWAP, fetch);
CHECK_ACCESSOR(FCAS, fetch);
CHECK_USER(USER);
CHECK_USER(USER_NC);
#undef _CHECK_OP
#undef CHECK_ARITH_OP
#undef CHECK_ACCESSOR
#undef CHECK_USER
#undef gasneti_op_not_reduce
#undef gasneti_op_not_fetch
#undef gasneti_op_not_fp
#if WORDS_BIGENDIAN
#if PLATFORM_ARCH_LITTLE_ENDIAN
#error endianness disagreement: PLATFORM_ARCH_LITTLE_ENDIAN and WORDS_BIGENDIAN are both set
#endif
gasneti_assert_always(!gasneti_isLittleEndian());
#else
#if PLATFORM_ARCH_BIG_ENDIAN
#error endianness disagreement: PLATFORM_ARCH_BIG_ENDIAN and !WORDS_BIGENDIAN
#endif
gasneti_assert_always(gasneti_isLittleEndian());
#endif
/* check GASNET_PAGESIZE is a power of 2 and > 0 */
gasneti_static_assert(GASNET_PAGESIZE > 0);
gasneti_static_assert(GASNETI_POWEROFTWO(GASNET_PAGESIZE));
gasneti_static_assert(SIZEOF_GEX_RMA_VALUE_T == sizeof(gex_RMA_Value_t));
gasneti_static_assert(SIZEOF_GEX_RMA_VALUE_T >= sizeof(int));
gasneti_static_assert(SIZEOF_GEX_RMA_VALUE_T >= sizeof(void *));
#if PLATFORM_ARCH_32 && !PLATFORM_ARCH_64
gasneti_static_assert(sizeof(void*) == 4);
#elif !PLATFORM_ARCH_32 && PLATFORM_ARCH_64
gasneti_static_assert(sizeof(void*) == 8);
#else
#error must #define exactly one of PLATFORM_ARCH_32 or PLATFORM_ARCH_64
#endif
#if defined(GASNETI_UNI_BUILD)
if (gasneti_cpu_count() > 1)
gasneti_fatalerror("GASNet was built in uniprocessor (non-SMP-safe) configuration, "
"but executed on an SMP. Please re-run GASNet configure with --enable-smp-safe and rebuild");
#endif
{ static int firstcall = 1;
if (firstcall) { /* miscellaneous conduit-independent initializations */
firstcall = 0;
#if GASNET_DEBUG && GASNETI_THREADS
gasneti_threadkey_init(gasneti_throttledebug_key);
#endif
gasneti_memcheck_all();
}
}
}
static void gasneti_check_portable_conduit(void);
static void gasneti_check_architecture(void);
int gasneti_malloc_munmap_disabled = 0;
extern void gasneti_check_config_postattach(void) {
gasneti_check_config_preinit();
/* verify sanity of the core interface */
gasneti_assert_always_uint(gex_AM_MaxArgs() ,>=, 2*MAX(sizeof(int),sizeof(void*)));
gasneti_assert_always_uint(gex_AM_LUBRequestMedium() ,>=, 512);
gasneti_assert_always_uint(gex_AM_LUBReplyMedium() ,>=, 512);
gasneti_assert_always_uint(gex_AM_LUBRequestLong() ,>=, 512);
gasneti_assert_always_uint(gex_AM_LUBReplyLong() ,>=, 512);
gasneti_assert_always_uint(gasneti_nodes ,>=, 1);
gasneti_assert_always_uint(gasneti_mynode ,<, gasneti_nodes);
{ static int firstcall = 1;
if (firstcall) { /* miscellaneous conduit-independent initializations */
firstcall = 0;
#ifndef GASNET_DISABLE_MUNMAP_DEFAULT
#define GASNET_DISABLE_MUNMAP_DEFAULT 0
#endif
if (gasneti_getenv_yesno_withdefault("GASNET_DISABLE_MUNMAP",GASNET_DISABLE_MUNMAP_DEFAULT)) {
#if HAVE_PTMALLOC
mallopt(M_TRIM_THRESHOLD, -1);
mallopt(M_MMAP_MAX, 0);
GASNETI_TRACE_PRINTF(I,("Setting mallopt M_TRIM_THRESHOLD=-1 and M_MMAP_MAX=0"));
gasneti_malloc_munmap_disabled = 1;
#else
if (gasneti_verboseenv())
gasneti_console0_message("WARNING","GASNET_DISABLE_MUNMAP set on an unsupported platform");
else
GASNETI_TRACE_PRINTF(I,("WARNING: GASNET_DISABLE_MUNMAP set on an unsupported platform"));
#endif
}
#if GASNET_NDEBUG
gasneti_check_portable_conduit();
gasneti_check_architecture();
#endif
}
}
gasneti_memcheck_all();
gasneti_flush_streams(); // flush above messages, and ensure FS_SYNC envvar is initted
}
/* ------------------------------------------------------------------------------------ */
// Helpers for debug checks
#if GASNET_DEBUG
void gasneti_check_inject(int for_reply GASNETI_THREAD_FARG) {
gasneti_threaddata_t * const mythread = GASNETI_MYTHREAD;
if (!mythread) return; // Some conduits communicate very early
if (mythread->reply_handler_active) {
gasneti_fatalerror("Invalid GASNet call (communication injection or poll) while executing a Reply handler");
}
if (mythread->request_handler_active && !for_reply) {
gasneti_fatalerror("Invalid GASNet call (communication injection or poll) while executing a Request handler");
}
// NPAM checks are distinct to allow that entire subsytem to be overridden
gasneti_checknpam(for_reply GASNETI_THREAD_PASS);
// TODO: check for HSL context
}
// Resets all state indicative of restricted context.
// This is intended for use within `gasnet-exit()` which *is* valid from
// handler context, and is known to run with HSLs held on error paths.
// There is currently no other known-valid reason to use this call.
void gasneti_check_inject_reset(GASNETI_THREAD_FARG_ALONE) {
gasneti_threaddata_t * const mythread = GASNETI_MYTHREAD;
if (!mythread) return; // Some conduits communicate very early
mythread->reply_handler_active = 0;
mythread->request_handler_active = 0;
// TODO: reset HSL context
}
#endif
/* ------------------------------------------------------------------------------------ */
#ifndef _GASNET_ERRORNAME
extern const char *gasnet_ErrorName(int errval) {
switch (errval) {
case GASNET_OK: return "GASNET_OK";
case GASNET_ERR_NOT_INIT: return "GASNET_ERR_NOT_INIT";
case GASNET_ERR_BAD_ARG: return "GASNET_ERR_BAD_ARG";
case GASNET_ERR_RESOURCE: return "GASNET_ERR_RESOURCE";
case GASNET_ERR_BARRIER_MISMATCH: return "GASNET_ERR_BARRIER_MISMATCH";
case GASNET_ERR_NOT_READY: return "GASNET_ERR_NOT_READY";
default: return "*unknown*";
}
}
#endif
#ifndef _GASNET_ERRORDESC
extern const char *gasnet_ErrorDesc(int errval) {
switch (errval) {
case GASNET_OK: return "No error";
case GASNET_ERR_NOT_INIT: return "GASNet message layer not initialized";
case GASNET_ERR_BAD_ARG: return "Invalid function parameter passed";
case GASNET_ERR_RESOURCE: return "Problem with requested resource";
case GASNET_ERR_BARRIER_MISMATCH: return "Barrier id's mismatched";
case GASNET_ERR_NOT_READY: return "Non-blocking operation not complete";
default: return "no description available";
}
}
#endif
/* ------------------------------------------------------------------------------------ */
extern void gasneti_freezeForDebugger(void) {
if (gasneti_getenv_yesno_withdefault("GASNET_FREEZE",0)) {
gasneti_freezeForDebuggerNow(&gasnet_frozen,"gasnet_frozen");
}
}
/* ------------------------------------------------------------------------------------ */
// Client management
#ifdef GASNETC_CLIENT_EXTRA_DECLS
GASNETC_CLIENT_EXTRA_DECLS
#endif
#ifndef _GEX_CLIENT_T
#ifndef gasneti_import_client
gasneti_Client_t gasneti_import_client(gex_Client_t _client) {
const gasneti_Client_t _real_client = GASNETI_IMPORT_POINTER(gasneti_Client_t,_client);
GASNETI_IMPORT_MAGIC(_real_client, CLIENT);
return _real_client;
}
gasneti_Client_t gasneti_import_client_valid(gex_Client_t client) {
gasneti_assert(client != GEX_CLIENT_INVALID);
return gasneti_import_client(client);
}
#endif
#ifndef gasneti_export_client
gex_Client_t gasneti_export_client(gasneti_Client_t _real_client) {
GASNETI_CHECK_MAGIC(_real_client, GASNETI_CLIENT_MAGIC);
return GASNETI_EXPORT_POINTER(gex_Client_t, _real_client);
}
#endif
// TODO-EX: either ensure name is unique OR perform "auto-increment" according to flags
gasneti_Client_t gasneti_alloc_client(
const char *name,
gex_Flags_t flags)
{
gasneti_Client_t client;
#ifdef GASNETC_SIZEOF_CLIENT_T
size_t alloc_size = GASNETC_SIZEOF_CLIENT_T();
gasneti_assert_uint(alloc_size ,>=, sizeof(*client));
#else
size_t alloc_size = sizeof(*client);
#endif
client = gasneti_malloc(alloc_size);
GASNETI_INIT_MAGIC(client, GASNETI_CLIENT_MAGIC);
client->_tm0 = NULL;
client->_name = gasneti_strdup(name);
client->_cdata = NULL;
client->_flags = flags;
gasneti_assert_always(sizeof(client->_next_ep_index) >= sizeof(gex_EP_Index_t));
gasneti_weakatomic32_set(&client->_next_ep_index, 0, 0);
memset(client->_ep_tbl, 0, sizeof(client->_ep_tbl));
#ifdef GASNETC_CLIENT_INIT_HOOK
GASNETC_CLIENT_INIT_HOOK(client);
#else
size_t extra = alloc_size - sizeof(*client);
if (extra) memset(client + 1, 0, extra);
#endif
return client;
}
void gasneti_free_client(gasneti_Client_t client)
{
#ifdef GASNETI_CLIENT_FINI_HOOK
GASNETI_CLIENT_FINI_HOOK(client);
#endif
gasneti_free((/*non-const*/char*)client->_name);
GASNETI_INIT_MAGIC(client, GASNETI_CLIENT_BAD_MAGIC);
gasneti_free(client);
}
#endif // _GEX_CLIENT_T
/* ------------------------------------------------------------------------------------ */
// Segment management
#ifdef GASNETC_SEGMENT_EXTRA_DECLS
GASNETC_SEGMENT_EXTRA_DECLS
#endif
#ifndef _GEX_SEGMENT_T
#ifndef gasneti_import_segment
gasneti_Segment_t gasneti_import_segment(gex_Segment_t _segment) {
const gasneti_Segment_t _real_segment = GASNETI_IMPORT_POINTER(gasneti_Segment_t,_segment);
GASNETI_IMPORT_MAGIC(_real_segment, SEGMENT);
return _real_segment;
}
gasneti_Segment_t gasneti_import_segment_valid(gex_Segment_t segment) {
gasneti_assert(segment != GEX_SEGMENT_INVALID);
return gasneti_import_segment(segment);
}
#endif
#ifndef gasneti_export_segment
gex_Segment_t gasneti_export_segment(gasneti_Segment_t _real_segment) {
GASNETI_CHECK_MAGIC(_real_segment, GASNETI_SEGMENT_MAGIC);
return GASNETI_EXPORT_POINTER(gex_Segment_t, _real_segment);
}
#endif
const gasnet_seginfo_t gasneti_null_segment = {0};
// TODO-EX: probably need to add to a per-client container of some sort
gasneti_Segment_t gasneti_alloc_segment(
gasneti_Client_t client,
void *addr,
uintptr_t size,
gex_MK_t kind,
int client_allocated,
gex_Flags_t flags)
{
gasneti_Segment_t segment;
#ifdef GASNETC_SIZEOF_SEGMENT_T
size_t alloc_size = GASNETC_SIZEOF_SEGMENT_T();
gasneti_assert_uint(alloc_size ,>=, sizeof(*segment));
#else
size_t alloc_size = sizeof(*segment);
#endif
segment = gasneti_malloc(alloc_size);
GASNETI_INIT_MAGIC(segment, GASNETI_SEGMENT_MAGIC);
segment->_client = client;
segment->_cdata = NULL;
segment->_kind = kind;
segment->_flags = flags;
segment->_addr = addr;
segment->_ub = (void*)((uintptr_t)addr + size);
segment->_size = size;
segment->_client_allocated = client_allocated;
#ifdef GASNETC_SEGMENT_INIT_HOOK
GASNETC_SEGMENT_INIT_HOOK(segment);
#else
size_t extra = alloc_size - sizeof(*segment);
if (extra) memset(segment + 1, 0, extra);
#endif
return segment;
}
void gasneti_free_segment(gasneti_Segment_t segment)
{
#ifdef GASNETI_SEGMENT_FINI_HOOK
GASNETI_SEGMENT_FINI_HOOK(segment);
#endif
GASNETI_INIT_MAGIC(segment, GASNETI_SEGMENT_BAD_MAGIC);
gasneti_free(segment);
}
#endif // _GEX_SEGMENT_T
extern int gex_Segment_Attach(
gex_Segment_t *segment_p,
gex_TM_t e_tm,
uintptr_t length)
{
gasneti_TM_t i_tm = gasneti_import_tm_nonpair(e_tm);
GASNETI_TRACE_PRINTF(O,("gex_Segment_Attach: segment_p=%p tm="GASNETI_TMSELFFMT" length=%"PRIuPTR,
(void*)segment_p, GASNETI_TMSELFSTR(e_tm), length));
GASNETI_CHECK_INJECT();
if (! segment_p) {
gasneti_fatalerror("Invalid call to gex_Segment_Attach with NULL segment_p");
}
if (! e_tm) {
gasneti_fatalerror("Invalid call to gex_Segment_Attach with NULL e_tm");
}
// TODO-EX: remove if/when this limitation is removed
static int once = 1;
if (once) once = 0;
else gasneti_fatalerror("gex_Segment_Attach: current implementation can be called at most once");
// Final value for EVERYTHING, error value for FAST/LARGE
*segment_p = GEX_SEGMENT_INVALID;
#if GASNET_SEGMENT_EVERYTHING
gex_Event_Wait(gex_Coll_BarrierNB(e_tm, 0));
#else
if (length == 0) {
GASNETI_RETURN_ERRR(BAD_ARG, "size must be non-zero");
}
if ((length % GASNET_PAGESIZE) != 0) {
GASNETI_RETURN_ERRR(BAD_ARG, "size is not page-aligned");
}
if (length > gasneti_MaxLocalSegmentSize) {
GASNETI_RETURN_ERRR(BAD_ARG, "size is too large, exceeds current value of gasnet_getMaxLocalSegmentSize()");
}
/* create a segment collectively */
// TODO-EX: this implementation only works *once*
// TODO-EX: need to pass proper flags (e.g. pshm and bind) instead of 0
if (GASNET_OK != gasneti_segmentAttach(segment_p, e_tm, length, 0)) {
GASNETI_RETURN_ERRR(RESOURCE,"Error attaching segment");
}
#endif
#if GASNETC_SEGMENT_ATTACH_HOOK
if (GASNET_OK != gasnetc_segment_attach_hook(*segment_p, e_tm)) {
GASNETI_RETURN_ERRR(RESOURCE,"Error attaching segment (conduit hook)");
}
#endif
return GASNET_OK;
}
extern int gex_Segment_Create(
gex_Segment_t *segment_p,
gex_Client_t e_client,
gex_Addr_t address,
uintptr_t length,
gex_MK_t kind,
gex_Flags_t flags)
{
gasneti_Client_t i_client = gasneti_import_client(e_client);
// TODO: tracing of "kind"
GASNETI_TRACE_PRINTF(O,("gex_Segment_Create: client='%s' address=%p length=%"PRIuPTR" flags=%d",
i_client ? i_client->_name : "(NULL)", address, length, flags));
GASNETI_CHECK_INJECT();
if (! segment_p) {
gasneti_fatalerror("Invalid call to gex_Segment_Create() with NULL segment_p");
}
if (! i_client) {
gasneti_fatalerror("Invalid call to gex_Segment_Create() with NULL client");
}
if (flags) {
gasneti_fatalerror("Invalid call to gex_Segment_Create() with non-zero flags");
}
if (! length) {
gasneti_fatalerror("Invalid call to gex_Segment_Create() with zero length");
}
if (kind == GEX_MK_INVALID) {
gasneti_fatalerror("Invalid call to gex_Segment_Create() with kind = GEX_MK_INVALID");
}
// Create the Segment object, allocating memory if appropriate
int rc = gasneti_segmentCreate(segment_p, i_client, address, length, kind, flags);
#if GASNETC_SEGMENT_CREATE_HOOK
if (rc == GASNET_OK) {
rc = gasnetc_segment_create_hook(*segment_p);
if (rc) { // Conduit hook failed. So cleanup conduit-independent resources
gasneti_Segment_t i_segment = gasneti_import_segment(*segment_p);
gasneti_assert_zeroret( gasneti_segmentDestroy(i_segment, 0) );
}
}
#endif
GASNETI_RETURN(rc);
}
extern void gex_Segment_Destroy(
gex_Segment_t e_segment,
gex_Flags_t flags)
{
GASNETI_TRACE_PRINTF(O,("gex_Segment_Destroy: segment=%p flags=%d",
(void*)e_segment, flags));
GASNETI_CHECK_INJECT();
if (!e_segment) {
gasneti_fatalerror("Invalid call to gex_Segment_Destroy() with NULL segment");
}
if (flags) {
gasneti_fatalerror("Invalid call to gex_Segment_Destroy() with non-zero flags");
}
// TODO: check reference count, once implemented
gasneti_Segment_t i_segment = gasneti_import_segment(e_segment);
gasneti_assert_zeroret( gasneti_segmentDestroy(i_segment, 1) );
}
/* ------------------------------------------------------------------------------------ */
// Endpoint management
#ifdef GASNETC_EP_EXTRA_DECLS
GASNETC_EP_EXTRA_DECLS
#endif
#ifndef _GEX_EP_T
#ifndef gasneti_import_ep
gasneti_EP_t gasneti_import_ep(gex_EP_t _ep) {
const gasneti_EP_t _real_ep = GASNETI_IMPORT_POINTER(gasneti_EP_t,_ep);
GASNETI_IMPORT_MAGIC(_real_ep, EP);
return _real_ep;
}
gasneti_EP_t gasneti_import_ep_valid(gex_EP_t ep) {
gasneti_assert(ep != GEX_EP_INVALID);
return gasneti_import_ep(ep);
}
#endif
#ifndef gasneti_export_ep
gex_EP_t gasneti_export_ep(gasneti_EP_t _real_ep) {
GASNETI_CHECK_MAGIC(_real_ep, GASNETI_EP_MAGIC);
return GASNETI_EXPORT_POINTER(gex_EP_t, _real_ep);
}
#endif
// Static on the assumption that all callers will reside in this file
// TODO: might subsume into gex_EP_Create() if there are no other callers
static gasneti_EP_t gasneti_alloc_ep(
gasneti_Client_t client,
gex_EP_Capabilities_t caps,
gex_Flags_t flags,
int new_index)
{
gasneti_EP_t endpoint;
#ifdef GASNETC_SIZEOF_EP_T
size_t alloc_size = GASNETC_SIZEOF_EP_T();
gasneti_assert_uint(alloc_size ,>=, sizeof(*endpoint));
#else
size_t alloc_size = sizeof(*endpoint);
#endif
endpoint = gasneti_malloc(alloc_size);
GASNETI_INIT_MAGIC(endpoint, GASNETI_EP_MAGIC);
endpoint->_client = client;
endpoint->_cdata = NULL;
endpoint->_segment = NULL;
endpoint->_orig_caps = endpoint->_caps = caps;
endpoint->_flags = flags;
endpoint->_index = new_index;
gasneti_assert(! client->_ep_tbl[new_index]);
client->_ep_tbl[new_index] = endpoint;
gasneti_amtbl_init(endpoint);
#ifndef GASNETC_EP_INIT_HOOK
size_t extra = alloc_size - sizeof(*endpoint);
if (extra) memset(endpoint + 1, 0, extra);
#endif
return endpoint;
}
// Static on the assumption that all callers will reside in this file
static void gasneti_free_ep(gasneti_EP_t endpoint)
{
#ifdef GASNETI_EP_FINI_HOOK
GASNETI_EP_FINI_HOOK(endpoint);
#endif
GASNETI_INIT_MAGIC(endpoint, GASNETI_EP_BAD_MAGIC);
gasneti_free(endpoint);
}
#endif // _GEX_EP_T
extern int gex_EP_Create(
gex_EP_t *ep_p,
gex_Client_t e_client,
gex_EP_Capabilities_t caps,
gex_Flags_t flags)
{
gasneti_Client_t client = gasneti_import_client(e_client);
// TODO: formatted printing for capabilities
GASNETI_TRACE_PRINTF(O,("gex_EP_Create: client='%s' capabilities=%d flags=%d",
client ? client->_name : "(NULL)", caps, flags));
GASNETI_CHECK_INJECT();
if (! client) {
gasneti_fatalerror("Invalid call to gex_EP_Create with NULL client");
}
if (!ep_p) {
gasneti_fatalerror("Invalid call to gex_EP_Create with NULL ep_p");
}
GASNETI_CHECK_ERRR((! caps), BAD_ARG,
"no capabilities were requested");
GASNETI_CHECK_ERRR((caps & ~GEX_EP_CAPABILITY_ALL), BAD_ARG,
"invalid capabilities were requested");
// Currently require/demand that primordial EP have ALL capabilities
gasneti_assert(gasneti_weakatomic32_read(&client->_next_ep_index, 0)
|| caps == GEX_EP_CAPABILITY_ALL);
// TODO: any other validation of caps
// TODO: maybe silently OR-in {VIS,AD,COLL} dependencies?
// TODO: any validation of flags? any conditional behaviors?
uint32_t new_index = gasneti_weakatomic32_add(&client->_next_ep_index, 1, 0) - 1;
if_pf (new_index >= GASNET_MAXEPS) {
gasneti_weakatomic32_decrement(&client->_next_ep_index, 0);
GASNETI_RETURN_ERRR(RESOURCE,"would exceed per-client EP limit of " _STRINGIFY(GASNET_MAXEPS));
}
gasneti_EP_t ep = gasneti_alloc_ep(client, caps, flags, new_index);
// TODO: any need/want to omit on non-primordial EPs?
{ /* core API handlers */
gex_AM_Entry_t *ctable = (gex_AM_Entry_t *)gasnetc_get_handlertable();
int len = 0;
int numreg = 0;
gasneti_assert(ctable);
while (ctable[len].gex_fnptr) len++; /* calc len */
if (gasneti_amregister(ep, ctable, len,
GASNETC_HANDLER_BASE, GASNETE_HANDLER_BASE,
0, &numreg) != GASNET_OK)
GASNETI_RETURN_ERRR(RESOURCE,"Error registering core API handlers");
gasneti_assert_int(numreg ,==, len);
}
// TODO: any need/want to omit on non-primordial EPs?
{ /* extended API handlers */
gex_AM_Entry_t *etable = (gex_AM_Entry_t *)gasnete_get_handlertable();
int len = 0;
int numreg = 0;
gasneti_assert(etable);
while (etable[len].gex_fnptr) len++; /* calc len */
if (gasneti_amregister(ep, etable, len,
GASNETE_HANDLER_BASE, GASNETI_CLIENT_HANDLER_BASE,
0, &numreg) != GASNET_OK)
GASNETI_RETURN_ERRR(RESOURCE,"Error registering extended API handlers");
gasneti_assert_int(numreg ,==, len);
}
#ifdef GASNETC_EP_INIT_HOOK
int rc = GASNETC_EP_INIT_HOOK(ep);
if (rc != GASNET_OK) {
gasneti_free_ep(ep);
ep = NULL;
}
#else
int rc = GASNET_OK;
#endif
*ep_p = gasneti_export_ep(ep);
return rc;
}
/* ------------------------------------------------------------------------------------ */
// TM management
#ifdef GASNETC_TM_EXTRA_DECLS
GASNETC_TM_EXTRA_DECLS
#endif
#ifndef _GEX_TM_T
#ifndef gasneti_import_tm
gasneti_TM_t gasneti_import_tm(gex_TM_t _tm) {
gasneti_assert(_tm != GEX_TM_INVALID);
const gasneti_TM_t _real_tm = GASNETI_IMPORT_POINTER(gasneti_TM_t,_tm);
if (! gasneti_i_tm_is_pair(_real_tm)) {
GASNETI_IMPORT_MAGIC(_real_tm, TM);
}
return _real_tm;
}
#endif
#ifndef gasneti_import_tm_nonpair
gasneti_TM_t gasneti_import_tm_nonpair(gex_TM_t _tm) {
gasneti_assert(_tm != GEX_TM_INVALID);
const gasneti_TM_t _real_tm = GASNETI_IMPORT_POINTER(gasneti_TM_t,_tm);
if (gasneti_i_tm_is_pair(_real_tm)) {
gasneti_fatalerror("Invalid use of a TM-Pair where such is prohibited");
}
GASNETI_IMPORT_MAGIC(_real_tm, TM);
return _real_tm;
}
#endif
#ifndef gasneti_export_tm
gex_TM_t gasneti_export_tm(gasneti_TM_t _real_tm) {
GASNETI_CHECK_MAGIC(_real_tm, GASNETI_TM_MAGIC);
return GASNETI_EXPORT_POINTER(gex_TM_t, _real_tm);
}
#endif
// TODO-EX: probably need to add to a per-client container of some sort
extern gasneti_TM_t gasneti_alloc_tm(
gasneti_EP_t ep,
gex_Rank_t rank,
gex_Rank_t size,
gex_Flags_t flags)
{
gasneti_assert_uint(rank ,<, size);
gasneti_assert_uint(size ,>, 0);
gasneti_assert(ep);
gasneti_assert(ep->_client);
const int is_tm0 = (ep->_client->_tm0 == NULL);
gasneti_TM_t tm;
#ifdef GASNETC_SIZEOF_TM_T
size_t actual_sz = GASNETC_SIZEOF_TM_T();
gasneti_assert_uint(actual_sz ,>=, sizeof(*tm));
#else
size_t actual_sz = sizeof(*tm);
#endif
#if GASNETI_TM0_ALIGN
// TM0 is aligned to GASNETI_TM0_ALIGN, and all others to half that
size_t disalign = (is_tm0 ? 0 : GASNETI_TM0_ALIGN/2);
tm = (gasneti_TM_t)(disalign + (uintptr_t)gasneti_malloc_aligned(GASNETI_TM0_ALIGN, actual_sz + disalign));
#else
tm = gasneti_malloc(actual_sz);
#endif
GASNETI_INIT_MAGIC(tm, GASNETI_TM_MAGIC);
tm->_ep = ep;
tm->_cdata = NULL;
tm->_flags = flags;
tm->_rank = rank;
tm->_size = size;
tm->_coll_team = NULL;
#ifdef GASNETC_TM_INIT_HOOK
GASNETC_TM_INIT_HOOK(tm);
#else
size_t extra = actual_sz - sizeof(*tm);
if (extra) memset(tm + 1, 0, extra);
#endif
if (is_tm0) {
gasneti_legacy_alloc_tm_hook(tm); // init g2ex layer if appropriate
ep->_client->_tm0 = tm;
// TODO-EX: Please remove this!
gasneti_assert(! gasneti_thing_that_goes_thunk_in_the_dark);
gasneti_thing_that_goes_thunk_in_the_dark = tm;
}
return tm;
}
void gasneti_free_tm(gasneti_TM_t tm)
{
#ifdef GASNETI_TM_FINI_HOOK
GASNETI_TM_FINI_HOOK(tm);
#endif
GASNETI_INIT_MAGIC(tm, GASNETI_TM_BAD_MAGIC);
gasneti_free_aligned((void*)((uintptr_t)tm - (GASNETI_TM0_ALIGN/2)));
}
#endif // _GEX_TM_T
/* ------------------------------------------------------------------------------------ */
// TM-pair is NOT an object type, but must masquerade as a gex_TM_t.
// Therefore, we handle swizzling and internal/external type distinction
// in the same manner as for object types (but no MAGIC).
#ifndef gasneti_import_tm_pair
gasneti_TM_Pair_t gasneti_import_tm_pair(gex_TM_t tm) {
gasneti_assert(tm != GEX_TM_INVALID);
gasneti_assert(gasneti_e_tm_is_pair(tm));
return GASNETI_IMPORT_POINTER(gasneti_TM_Pair_t,tm);
}
#endif
#ifndef gasneti_export_tm_pair
gex_TM_t gasneti_export_tm_pair(gasneti_TM_Pair_t tm_pair) {
gasneti_assert(gasneti_i_tm_is_pair((gasneti_TM_t) tm_pair));
return GASNETI_EXPORT_POINTER(gex_TM_t, tm_pair);
}
#endif
// Helper for "mappable" queries
// return the bound segment for local ep_idx
// i_tm is provided only to retrieve the Client
gasneti_Segment_t gasneti_epidx_to_segment(gasneti_TM_t i_tm, gex_EP_Index_t ep_idx) {
// TODO: multi-client would extract from i_tm OR signature may change to take client
gasneti_Client_t i_client = gasneti_import_client(gasneti_THUNK_CLIENT);
gasneti_assert_int(ep_idx ,<, GASNET_MAXEPS);
gasneti_assert_int(ep_idx ,<, gasneti_weakatomic32_read(&i_client->_next_ep_index, 0));