-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgasnet_internal.c
2024 lines (1856 loc) · 80 KB
/
gasnet_internal.c
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: bitbucket.org: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_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>
#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
#define _gasneti_atomic_lock_initializer GASNET_HSL_INITIALIZER
#define _gasneti_atomic_lock_init(x) gasnet_hsl_init(x)
#define _gasneti_atomic_lock_malloc gasneti_malloc
GASNETI_ATOMIC_LOCK_TBL_DEFNS(gasneti_hsl_atomic_, gasnet_hsl_)
#undef _gasneti_atomic_lock_initializer
#undef _gasneti_atomic_lock_init
#undef _gasneti_atomic_lock_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 GASNET_VERSION_STR _STRINGIFY(GASNET_VERSION)
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
/* 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 gasnet_init() initialization");
}
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(_CONCAT(CORE_,GASNET_CORE_NAME)) = 1;
int GASNETI_LINKCONFIG_IDIOTCHECK(_CONCAT(EXTENDED_,GASNET_EXTENDED_NAME)) = 1;
extern int gasneti_internal_idiotcheck(gasnet_handlerentry_t *table, int numentries,
uintptr_t segsize, uintptr_t minheapoffset) {
gasneti_fatalerror("GASNet client code must NOT #include <gasnet_internal.h>\n"
"gasnet_internal.h is not installed, and modifies the behavior "
"of various internal operations, such as segment safety bounds-checking.");
return GASNET_ERR_NOT_INIT;
}
/* 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 */
#ifdef _GASNET_MYNODE_DEFAULT
gasnet_node_t gasneti_mynode = (gasnet_node_t)-1;
#endif
#ifdef _GASNET_NODES_DEFAULT
gasnet_node_t gasneti_nodes = 0;
#endif
#if defined(_GASNET_GETMAXSEGMENTSIZE_DEFAULT) && !GASNET_SEGMENT_EVERYTHING
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
#ifdef _GASNETI_SEGINFO_DEFAULT
gasnet_seginfo_t *gasneti_seginfo = NULL;
gasnet_seginfo_t *gasneti_seginfo_client = NULL;
void **gasneti_seginfo_ub = NULL; /* cached result of gasneti_seginfo[i].addr + gasneti_seginfo[i].size */
void **gasneti_seginfo_client_ub = NULL;
#endif
/* ------------------------------------------------------------------------------------ */
/* conduit-independent sanity checks */
extern void gasneti_check_config_preinit(void) {
gasneti_assert_always(sizeof(int8_t) == 1);
gasneti_assert_always(sizeof(uint8_t) == 1);
gasneti_assert_always(sizeof(gasnete_anytype8_t) == 1);
#ifndef INTTYPES_16BIT_MISSING
gasneti_assert_always(sizeof(int16_t) == 2);
gasneti_assert_always(sizeof(uint16_t) == 2);
gasneti_assert_always(sizeof(gasnete_anytype16_t) == 2);
#endif
gasneti_assert_always(sizeof(int32_t) == 4);
gasneti_assert_always(sizeof(uint32_t) == 4);
gasneti_assert_always(sizeof(gasnete_anytype32_t) == 4);
gasneti_assert_always(sizeof(int64_t) == 8);
gasneti_assert_always(sizeof(uint64_t) == 8);
gasneti_assert_always(sizeof(gasnete_anytype64_t) == 8);
gasneti_assert_always(sizeof(uintptr_t) >= sizeof(void *));
#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_assert_always(GASNET_PAGESIZE > 0);
gasneti_assert_always(GASNETI_POWEROFTWO(GASNET_PAGESIZE));
gasneti_assert_always(SIZEOF_GASNET_REGISTER_VALUE_T == sizeof(gasnet_register_value_t));
gasneti_assert_always(SIZEOF_GASNET_REGISTER_VALUE_T >= sizeof(int));
gasneti_assert_always(SIZEOF_GASNET_REGISTER_VALUE_T >= sizeof(void *));
#if PLATFORM_ARCH_32 && !PLATFORM_ARCH_64
gasneti_assert_always(sizeof(void*) == 4);
#elif !PLATFORM_ARCH_32 && PLATFORM_ARCH_64
gasneti_assert_always(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);
extern void gasneti_check_config_postattach(void) {
gasneti_check_config_preinit();
/* verify sanity of the core interface */
gasneti_assert_always(gasnet_AMMaxArgs() >= 2*MAX(sizeof(int),sizeof(void*)));
gasneti_assert_always(gasnet_AMMaxMedium() >= 512);
gasneti_assert_always(gasnet_AMMaxLongRequest() >= 512);
gasneti_assert_always(gasnet_AMMaxLongReply() >= 512);
gasneti_assert_always(gasnet_nodes() >= 1);
gasneti_assert_always(gasnet_mynode() < gasnet_nodes());
{ static int firstcall = 1;
if (firstcall) { /* miscellaneous conduit-independent initializations */
firstcall = 0;
if (gasneti_getenv_yesno_withdefault("GASNET_DISABLE_MUNMAP",0)) {
#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"));
#else
GASNETI_TRACE_PRINTF(I,("WARNING: GASNET_DISABLE_MUNMAP set on an unsupported platform"));
if (gasneti_verboseenv())
fprintf(stderr, "WARNING: GASNET_DISABLE_MUNMAP set on an unsupported platform\n");
#endif
}
#if GASNET_NDEBUG
gasneti_check_portable_conduit();
#endif
}
}
gasneti_memcheck_all();
}
/* ------------------------------------------------------------------------------------ */
#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");
}
}
/* ------------------------------------------------------------------------------------ */
extern void gasneti_defaultAMHandler(gasnet_token_t token) {
gasnet_node_t srcnode = (gasnet_node_t)-1;
gasnet_AMGetMsgSource(token, &srcnode);
gasneti_fatalerror("GASNet node %i/%i received an AM message from node %i for a handler index "
"with no associated AM handler function registered",
(int)gasnet_mynode(), (int)gasnet_nodes(), (int)srcnode);
}
/* ------------------------------------------------------------------------------------ */
#if GASNETC_AMREGISTER
/* Use conduit-specific impl */
extern int gasnetc_amregister(gasnet_handler_t, gasneti_handler_fn_t);
#else
/* Use default/recommended impl */
extern gasneti_handler_fn_t gasnetc_handler[];
static int gasnetc_amregister(gasnet_handler_t index, gasneti_handler_fn_t fnptr) {
/* register a single handler */
gasneti_assert(gasnetc_handler[index] == gasneti_defaultAMHandler);
gasnetc_handler[index] = fnptr;
return GASNET_OK;
}
#endif
extern int gasneti_amregister(gasnet_handlerentry_t *table, int numentries,
int lowlimit, int highlimit,
int dontcare, int *numregistered) {
static char checkuniqhandler[256] = { 0 };
int i;
*numregistered = 0;
for (i = 0; i < numentries; i++) {
int newindex;
if ((table[i].index == 0 && !dontcare) ||
(table[i].index && dontcare)) continue;
else if (table[i].index) newindex = table[i].index;
else { /* deterministic assignment of dontcare indexes */
for (newindex = lowlimit; newindex <= highlimit; newindex++) {
if (!checkuniqhandler[newindex]) break;
}
if (newindex > highlimit) {
char s[255];
snprintf(s, sizeof(s), "Too many handlers. (limit=%i)", highlimit - lowlimit + 1);
GASNETI_RETURN_ERRR(BAD_ARG, s);
}
}
/* ensure handlers fall into the proper range of pre-assigned values */
if (newindex < lowlimit || newindex > highlimit) {
char s[255];
snprintf(s, sizeof(s), "handler index (%i) out of range [%i..%i]", newindex, lowlimit, highlimit);
GASNETI_RETURN_ERRR(BAD_ARG, s);
}
/* discover duplicates */
if (checkuniqhandler[newindex] != 0)
GASNETI_RETURN_ERRR(BAD_ARG, "handler index not unique");
checkuniqhandler[newindex] = 1;
/* register the handler */
int rc = gasnetc_amregister((gasnet_handler_t)newindex, (gasneti_handler_fn_t)table[i].fnptr);
if (GASNET_OK != rc) return rc;
/* The check below for !table[i].index is redundant and present
* only to defeat the over-aggressive optimizer in pathcc 2.1
*/
if (dontcare && !table[i].index) table[i].index = newindex;
(*numregistered)++;
}
return GASNET_OK;
}
/* ------------------------------------------------------------------------------------ */
#ifndef GASNETC_FATALSIGNAL_CALLBACK
#define GASNETC_FATALSIGNAL_CALLBACK(sig)
#endif
static void do_raise(int sig) {
#if defined(PTHREAD_MUTEX_INITIALIZER) && !GASNET_SEQ && HAVE_PTHREAD_KILL && 0
/* XXX: This works-around a bug in OpenBSD-5.2 kernel, fixed in OpenBSD-current in Nov 2012 */
/* Might fail if unimplemented OR since pthread_self() isn't required to be signal safe */
if (0 == pthread_kill(pthread_self(),sig)) return;
#endif
raise(sig);
}
void gasneti_defaultSignalHandler(int sig) {
gasneti_sighandlerfn_t oldsigpipe = NULL;
const char *signame = gasnett_signame_fromval(sig);
gasneti_assert(signame);
switch (sig) {
case SIGQUIT:
/* client didn't register a SIGQUIT handler, so just exit */
gasnet_exit(1);
break;
case SIGABRT:
case SIGILL:
case SIGSEGV:
case SIGBUS:
case SIGFPE:
oldsigpipe = gasneti_reghandler(SIGPIPE, SIG_IGN);
GASNETC_FATALSIGNAL_CALLBACK(sig); /* give conduit first crack at it */
fprintf(stderr,"*** Caught a fatal signal: %s(%i) on node %i/%i\n",
signame, sig, (int)gasnet_mynode(), (int)gasnet_nodes());
fflush(stderr);
gasnett_freezeForDebuggerErr(); /* allow freeze */
gasneti_print_backtrace_ifenabled(STDERR_FILENO); /* try to print backtrace */
(void) gasneti_reghandler(SIGPIPE, oldsigpipe);
signal(sig, SIG_DFL); /* restore default core-dumping handler and re-raise */
do_raise(sig);
break;
default:
/* translate signal to SIGQUIT */
{ static int sigquit_raised = 0;
if (sigquit_raised) {
/* sigquit was already raised - we cannot safely reraise it, so just die */
_exit(1);
} else sigquit_raised = 1;
}
oldsigpipe = gasneti_reghandler(SIGPIPE, SIG_IGN);
fprintf(stderr,"*** Caught a signal: %s(%i) on node %i/%i\n",
signame, sig, (int)gasnet_mynode(), (int)gasnet_nodes());
fflush(stderr);
(void) gasneti_reghandler(SIGPIPE, oldsigpipe);
do_raise(SIGQUIT);
}
}
extern int gasneti_set_waitmode(int wait_mode) {
const char *desc = NULL;
GASNETI_CHECKINIT();
switch (wait_mode) {
case GASNET_WAIT_SPIN: desc = "GASNET_WAIT_SPIN"; break;
case GASNET_WAIT_BLOCK: desc = "GASNET_WAIT_BLOCK"; break;
case GASNET_WAIT_SPINBLOCK: desc = "GASNET_WAIT_SPINBLOCK"; break;
default:
GASNETI_RETURN_ERRR(BAD_ARG, "illegal wait mode");
}
GASNETI_TRACE_PRINTF(I, ("gasnet_set_waitmode(%s)", desc));
#ifdef gasnetc_set_waitmode
gasnetc_set_waitmode(wait_mode);
#endif
gasneti_wait_mode = wait_mode;
return GASNET_OK;
}
/* ------------------------------------------------------------------------------------ */
/* Global environment variable handling */
extern char **environ;
static void gasneti_serializeEnvironment(uint8_t **pbuf, int *psz) {
/* flatten a snapshot of the environment to make it suitable for transmission
* here we assume the standard representation where a pointer to the environment
* is stored in a global variable 'environ' and the environment is represented as an array
* of null-terminated strings where each has the form 'key=value' and value may be empty,
* and the final string pointer is a NULL pointer
* we flatten this into a list of null-terminated 'key=value' strings,
* terminated with a double-null
*/
uint8_t *buf;
uint8_t *p;
int i;
int totalEnvSize = 0;
if (!environ) {
/* T3E stupidly omits environ support, despite documentation to the contrary */
GASNETI_TRACE_PRINTF(I,("WARNING: environ appears to be empty -- ignoring it"));
*pbuf = NULL;
*psz = 0;
return;
}
for(i = 0; environ[i]; i++)
totalEnvSize += strlen(environ[i]) + 1;
totalEnvSize++;
buf = (uint8_t *)gasneti_malloc(totalEnvSize);
p = buf;
p[0] = 0;
for(i = 0; environ[i]; i++) {
strcpy((char*)p, environ[i]);
p += strlen((char*)p) + 1;
}
*p = 0;
gasneti_assert((p+1) - buf == totalEnvSize);
*pbuf = buf;
*psz = totalEnvSize;
}
extern char *gasneti_globalEnv;
typedef struct {
int sz;
uint64_t checksum;
} gasneti_envdesc_t;
/* do the work necessary to setup the global environment for use by gasneti_getenv
broadcast the environment variables from one node to all nodes
Note this currently assumes that at least one of the compute nodes has the full
environment - systems where the environment is not propagated to any compute node
will need something more sophisticated.
exchangefn is required function for exchanging data
broadcastfn is optional (can be NULL) but highly recommended for scalability
*/
extern void gasneti_setupGlobalEnvironment(gasnet_node_t numnodes, gasnet_node_t mynode,
gasneti_bootstrapExchangefn_t exchangefn,
gasneti_bootstrapBroadcastfn_t broadcastfn) {
uint8_t *myenv;
int sz;
uint64_t checksum;
gasneti_envdesc_t myenvdesc;
gasneti_envdesc_t *allenvdesc;
gasneti_assert(exchangefn);
gasneti_serializeEnvironment(&myenv,&sz);
checksum = gasneti_checksum(myenv,sz);
myenvdesc.sz = sz;
myenvdesc.checksum = checksum;
allenvdesc = gasneti_malloc(numnodes*sizeof(gasneti_envdesc_t));
/* gather environment description from all nodes */
(*exchangefn)(&myenvdesc, sizeof(gasneti_envdesc_t), allenvdesc);
{ /* see if the node environments differ and find the largest */
int i;
int rootid = 0;
int identical = 1;
gasneti_envdesc_t rootdesc = allenvdesc[rootid];
for (i=1; i < numnodes; i++) {
if (rootdesc.checksum != allenvdesc[i].checksum ||
rootdesc.sz != allenvdesc[i].sz)
identical = 0;
if (allenvdesc[i].sz > rootdesc.sz) {
/* assume the largest env is the one we want */
rootdesc = allenvdesc[i];
rootid = i;
}
}
if (identical) { /* node environments all identical - don't bother to propagate */
gasneti_free(allenvdesc);
gasneti_free(myenv);
return;
} else {
int envsize = rootdesc.sz;
gasneti_globalEnv = gasneti_malloc(envsize);
gasneti_leak(gasneti_globalEnv);
if (broadcastfn) {
(*broadcastfn)(myenv, envsize, gasneti_globalEnv, rootid);
} else {
/* this is wasteful of memory and bandwidth, and non-scalable */
char *tmp = gasneti_malloc(envsize*numnodes);
memcpy(tmp+mynode*envsize, myenv, sz);
(*exchangefn)(tmp+mynode*envsize, envsize, tmp);
memcpy(gasneti_globalEnv, tmp+rootid*envsize, envsize);
gasneti_free(tmp);
}
gasneti_assert(gasneti_checksum(gasneti_globalEnv,envsize) == rootdesc.checksum);
gasneti_free(allenvdesc);
gasneti_free(myenv);
return;
}
}
}
/* decode src into dst, arguments permitted to overlap exactly */
extern size_t gasneti_decodestr(char *dst, const char *src) {
#define IS_HEX_DIGIT(c) (isdigit(c) || (isalpha(c) && toupper(c) <= 'F'))
#define VAL_HEX_DIGIT(c) ((unsigned int)(isdigit(c) ? (c)-'0' : 10 + toupper(c) - 'A'))
size_t dstidx = 0;
const char *p = src;
gasneti_assert(src && dst);
while (*p) {
char c;
if (p[0] == '%' && p[1] == '0' &&
p[2] && IS_HEX_DIGIT(p[2]) && p[3] && IS_HEX_DIGIT(p[3])) {
c = (char)(VAL_HEX_DIGIT(p[2]) << 4) | VAL_HEX_DIGIT(p[3]);
p += 4;
} else c = *(p++);
dst[dstidx++] = c;
}
dst[dstidx] = '\0';
return dstidx;
#undef VAL_HEX_DIGIT
#undef IS_HEX_DIGIT
}
static const char *gasneti_decode_envval(const char *val) {
static struct _gasneti_envtable_S {
const char *pre;
char *post;
struct _gasneti_envtable_S *next;
} *gasneti_envtable = NULL;
static gasneti_mutex_t gasneti_envtable_lock = GASNETI_MUTEX_INITIALIZER;
static int firsttime = 1;
static int decodeenv = 1;
if (firsttime) {
decodeenv = !gasneti_getenv("GASNET_DISABLE_ENVDECODE");
if (gasneti_init_done && gasneti_mynode != (gasnet_node_t)-1) {
gasneti_envstr_display("GASNET_DISABLE_ENVDECODE",(decodeenv?"NO":"YES"),decodeenv);
gasneti_sync_writes();
firsttime = 0;
}
} else gasneti_sync_reads();
if (!decodeenv) return val;
if (strstr(val,"%0")) {
struct _gasneti_envtable_S *p;
gasneti_mutex_lock(&gasneti_envtable_lock);
p = gasneti_envtable;
while (p) {
if (!strcmp(val, p->pre)) break;
p = p->next;
}
if (p) val = p->post;
else { /* decode it and save the result (can't trust setenv to safely set it back) */
struct _gasneti_envtable_S *newentry = gasneti_malloc(sizeof(struct _gasneti_envtable_S));
newentry->pre = gasneti_strdup(val);
newentry->post = gasneti_malloc(strlen(val)+1);
gasneti_decodestr(newentry->post, newentry->pre);
if (!strcmp(newentry->post, newentry->pre)) {
gasneti_free(newentry);
} else {
newentry->next = gasneti_envtable;
gasneti_envtable = newentry;
val = newentry->post;
}
}
gasneti_mutex_unlock(&gasneti_envtable_lock);
}
return val;
}
/* expose environment decode to external packages in case we ever need it */
extern const char * (*gasnett_decode_envval_fn)(const char *);
const char * (*gasnett_decode_envval_fn)(const char *) = &gasneti_decode_envval;
/* expression that defines whether the given process should report to the console
on env queries - needs to work before gasnet_init
1 = yes, 0 = no, -1 = not yet / don't know
*/
#define GASNETI_ENV_OUTPUT_NODE() (gasneti_mynode == 0)
extern int _gasneti_verboseenv_fn(void) {
static int verboseenv = -1;
if (verboseenv == -1) {
if (gasneti_init_done && gasneti_mynode != (gasnet_node_t)-1) {
#if GASNET_DEBUG_VERBOSE
verboseenv = GASNETI_ENV_OUTPUT_NODE();
#else
verboseenv = !!gasneti_getenv("GASNET_VERBOSEENV") && GASNETI_ENV_OUTPUT_NODE();
#endif
gasneti_sync_writes();
}
} else gasneti_sync_reads();
return verboseenv;
}
int (*gasneti_verboseenv_fn)(void) = &_gasneti_verboseenv_fn;
extern const char * _gasneti_backtraceid_fn(void) {
static char myid[255];
sprintf(myid, "[%i] ", (int)gasneti_mynode);
return myid;
}
const char *(*gasneti_backtraceid_fn)(void) = &_gasneti_backtraceid_fn;
extern void gasneti_decode_args(int *argc, char ***argv) {
static int firsttime = 1;
if (!firsttime) return; /* ignore subsequent calls, to allow early decode */
firsttime = 0;
if (!gasneti_getenv_yesno_withdefault("GASNET_DISABLE_ARGDECODE",0)) {
int argidx;
char **origargv = *argv;
for (argidx = 0; argidx < *argc; argidx++) {
if (strstr((*argv)[argidx], "%0")) {
char *tmp = gasneti_strdup((*argv)[argidx]);
int newsz = gasneti_decodestr(tmp, tmp);
if (newsz == strlen((*argv)[argidx])) gasneti_free(tmp); /* no change */
else {
int i, newcnt = 0;
for (i = 0; i < newsz; i++) if (!tmp[i]) newcnt++; /* count growth due to inserted NULLs */
if (newcnt == 0) { /* simple parameter replacement */
(*argv)[argidx] = tmp;
} else { /* need to grow argv */
char **newargv = gasneti_malloc(sizeof(char *)*(*argc+1+newcnt));
memcpy(newargv, *argv, sizeof(char *)*argidx);
newargv[argidx] = tmp; /* base arg */
memcpy(newargv+argidx+newcnt, (*argv)+argidx, sizeof(char *)*(*argc - argidx - 1));
for (i = 0; i < newsz; i++) /* hook up new args */
if (!tmp[i]) newargv[1+argidx++] = &(tmp[i+1]);
*argc += newcnt;
if (*argv != origargv) gasneti_free(*argv);
*argv = newargv;
(*argv)[*argc] = NULL; /* ensure null-termination of arg list */
}
}
}
}
}
}
/* Propagate requested env vars from GASNet global env to the local env */
void (*gasneti_propagate_env_hook)(const char *, int) = NULL; // spawner- or conduit-specific hook
extern void gasneti_propagate_env_helper(const char *environ, const char * keyname, int flags) {
const int is_prefix = flags & GASNETI_PROPAGATE_ENV_PREFIX;
const char *p = environ;
gasneti_assert(environ);
gasneti_assert(keyname && !strchr(keyname,'='));
int keylen = strlen(keyname);
while (*p) {
if (!strncmp(keyname, p, keylen) && (is_prefix || p[keylen] == '=')) {
gasneti_assert(NULL != strchr(p+keylen, '='));
char *var = gasneti_strdup(p);
char *val = strchr(var, '=');
*(val++) = '\0';
if (gasnett_decode_envval_fn) {
val = (char *)((*gasnett_decode_envval_fn)(val));
}
gasnett_setenv(var, val);
GASNETI_TRACE_PRINTF(I,("gasneti_propagate_env(%s) => '%s'", var, val));
gasneti_free(var);
if (!is_prefix) break;
}
p += strlen(p) + 1;
}
}
extern void gasneti_propagate_env(const char * keyname, int flags) {
gasneti_assert(keyname);
gasneti_assert(NULL == strchr(keyname, '='));
// First look for matches in gasneti_globalEnv (if any)
if (gasneti_globalEnv) {
gasneti_propagate_env_helper(gasneti_globalEnv, keyname, flags);
}
// Next allow conduit-specific getenv (if any) to overwrite
if (gasneti_propagate_env_hook) {
gasneti_propagate_env_hook(keyname, flags);
}
}
/* Process environment for exittimeout.
* If (GASNET_EXITTIMEOUT is set), it is returned
* else return = min(GASNET_EXITTIMEOUT_MAX,
* GASNET_EXITTIMEOUT_MIN + gasneti_nodes * GASNET_EXITTIMEOUT_FACTOR)
* Where all the GASNET_EXITTIMEOUT* tokens above are env vars.
* The arguments are defaults for MAX, MIN and FACTOR, and the lowest value to allow.
*/
extern double gasneti_get_exittimeout(double dflt_max, double dflt_min, double dflt_factor, double lower_bound)
{
double my_max = gasneti_getenv_dbl_withdefault("GASNET_EXITTIMEOUT_MAX", dflt_max);
double my_min = gasneti_getenv_dbl_withdefault("GASNET_EXITTIMEOUT_MIN", dflt_min);
double my_factor = gasneti_getenv_dbl_withdefault("GASNET_EXITTIMEOUT_FACTOR", dflt_factor);
double result = gasneti_getenv_dbl_withdefault("GASNET_EXITTIMEOUT",
MIN(my_max, my_min + my_factor * gasneti_nodes));
if (result < lower_bound) {
gasneti_assert(MIN(dflt_max, dflt_min + dflt_factor * gasneti_nodes) >= lower_bound);
if (gasneti_getenv("GASNET_EXITTIMEOUT")) {
gasneti_fatalerror("If used, environment variable GASNET_EXITTIMEOUT must be set to a value no less than %g", lower_bound);
} else {
gasneti_fatalerror("Environment variables GASNET_EXITTIMEOUT_{MAX,MIN,FACTOR} yield a timeout less than %g seconds", lower_bound);
}
}
return result;
}
/* ------------------------------------------------------------------------------------ */
/* Bits for conduits which want/need to override pthread_create() */
#if defined(PTHREAD_MUTEX_INITIALIZER) /* only if pthread.h available */ && !GASNET_SEQ
#ifndef GASNETC_PTHREAD_CREATE_OVERRIDE
/* Default is just pass through */
#define GASNETC_PTHREAD_CREATE_OVERRIDE(create_fn, thread, attr, start_routine, arg) \
(*create_fn)(thread, attr, start_routine, arg)
#endif
int gasneti_pthread_create(gasneti_pthread_create_fn_t *create_fn, pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) {
// There is no portable way to printf a pointer-to-function. This way avoids warnings with -pedantic
union { void *vp; gasneti_pthread_create_fn_t *cfp; void *(*sfp)(void *); } ucreate, ustart;
ucreate.cfp = create_fn;
ustart.sfp = start_routine;
GASNETI_TRACE_PRINTF(I, ("gasneti_pthread_create(%p, %p, %p, %p, %p)", ucreate.vp, (void *)thread, (void *)attr, ustart.vp, arg));
return GASNETC_PTHREAD_CREATE_OVERRIDE(create_fn, thread, attr, start_routine, arg);
}
#endif
/* ------------------------------------------------------------------------------------ */
static void gasneti_check_portable_conduit(void) { /* check for portable conduit abuse */
char mycore[80], myext[80];
char const *mn = GASNET_CORE_NAME_STR;
char *m;
m = mycore; while (*mn) { *m = tolower(*mn); m++; mn++; }
*m = '\0';
mn = GASNET_EXTENDED_NAME_STR;
m = myext; while (*mn) { *m = tolower(*mn); m++; mn++; }
*m = '\0';
if ( /* is a portable network conduit */
(!strcmp("mpi",mycore) && !strcmp("reference",myext))
|| (!strcmp("udp",mycore) && !strcmp("reference",myext))
|| (!strcmp("ofi",mycore) && !strcmp("ofi",myext))
|| (!strcmp("portals4",mycore) && !strcmp("portals4",myext))
) {
const char *p = GASNETI_CONDUITS;
char natives[255];
char reason[255];
natives[0] = 0;
reason[0] = 0;
while (*p) { /* look for configure-detected native conduits */
#define GASNETI_CONDUITS_DELIM " ,/;\t\n"
char name[80];
p += strspn(p,GASNETI_CONDUITS_DELIM);
if (*p) {
int len = strcspn(p,GASNETI_CONDUITS_DELIM);
strncpy(name, p, len);
name[len] = 0;
p += len;
p += strspn(p,GASNETI_CONDUITS_DELIM);
/* Ignore the portable conduits */
if (!strcmp(name,"smp")) continue;
if (!strcmp(name,"mpi")) continue;
if (!strcmp(name,"udp")) continue;
if (!strcmp(name,"ofi")) continue;
if (!strcmp(name,"portals4")) continue;
#if !GASNET_SEQ
/* Ignore conduits that lack thread safety */
if (!strcmp(name,"shmem")) continue;
#endif
if (strlen(natives)) strcat(natives,", ");
strcat(natives,name);
}
#undef GASNETI_CONDUITS_DELIM
}
if (natives[0]) {
sprintf(reason, "WARNING: Support was detected for native GASNet conduits: %s",natives);
} else { /* look for hardware devices supported by native conduits */
struct {
const char *filename;
mode_t filemode;
const char *desc;
int hwid;
} known_devs[] = {
#if PLATFORM_OS_BGQ
{ "/dont_probe_an_io_node", S_IFDIR, "", 0 }
#else
#if PLATFORM_OS_LINUX && PLATFORM_ARCH_IA64 && GASNET_SEQ
{ "/dev/hw/cpunum", S_IFDIR, "SGI Altix", 0 },
{ "/dev/xpmem", S_IFCHR, "SGI Altix", 0 },
#endif
{ "/dev/infiniband/uverbs0", S_IFCHR, "InfiniBand IBV", 2 }, /* OFED 1.0 */
#if !GASNET_SEGMENT_EVERYTHING
{ "/dev/kgni0", S_IFCHR, "Cray Gemini", 6 },
{ "/proc/kgnilnd", S_IFDIR, "Cray Gemini", 6 },
#endif
{ "/list_terminator", S_IFDIR, "", 9999 }
#endif
};
int i, lim = sizeof(known_devs)/sizeof(known_devs[0]);
for (i = 0; i < lim; i++) {
struct stat stat_buf;
if (!stat(known_devs[i].filename,&stat_buf) &&
(!known_devs[i].filemode || (known_devs[i].filemode & stat_buf.st_mode))) {
int hwid = known_devs[i].hwid;
if (strlen(natives)) strcat(natives,", ");
strcat(natives,known_devs[i].desc);
while (i < lim && hwid == known_devs[i].hwid) i++; /* don't report a network twice */
}
}
#if PLATFORM_OS_CNL
if (strlen(natives)) strcat(natives,", ");
strcat(natives,"Cray Gemini (XE and XK) or Aries (XC)");
#elif PLATFORM_OS_BGQ
if (strlen(natives)) strcat(natives,", ");
strcat(natives,"IBM PAMI (BG/Q)");
#endif
if (natives[0]) {
sprintf(reason, "WARNING: This system appears to contain recognized network hardware: %s\n"
"WARNING: which is supported by a GASNet native conduit, although\n"
"WARNING: it was not detected at configure time (missing drivers?)",
natives);
}
}
if (reason[0] && !gasneti_getenv_yesno_withdefault("GASNET_QUIET",0) && gasnet_mynode() == 0) {
fprintf(stderr,"WARNING: Using GASNet's %s-conduit, which exists for portability convenience.\n"
"%s\n"
"WARNING: You should *really* use the high-performance native GASNet conduit\n"
"WARNING: if communication performance is at all important in this program run.\n",
mycore, reason);
fflush(stderr);
}
}
}
/* ------------------------------------------------------------------------------------ */
/* Nodemap handling
*/
gasnet_node_t *gasneti_nodemap = NULL;
gasneti_nodegrp_t gasneti_myhost = {NULL,0,(gasnet_node_t)(-1),0,(gasnet_node_t)(-1)};
gasneti_nodegrp_t gasneti_mysupernode = {NULL,0,(gasnet_node_t)(-1),0,(gasnet_node_t)(-1)};
gasnet_nodeinfo_t *gasneti_nodeinfo = NULL;
/* This code is "good" for all "sensible" process layouts, where "good"
* means identifing all sharing for such a mapping in one pass and the
* term "sensible" includes:
* "Block" layouts like |0.1.2.3|4.5.6.7|8.9._._|
* or |0.1.2.3|4.5.6._|7.8.9._|
* "Block-cyclic" like |0.1.6.7|2.3.8.9|4.5._._|
* "Cyclic/Round-robin" like |0.3.6.9|1.4.7._|2.5.8._|
* and all 24 permutations of the XYZT dimensions on the BG/P.
*
* This is also "safe" for an arbitrary mapping, but may fail to
* identify some or all of the potential sharing in such a case.
*/
static void gasneti_nodemap_helper_linear(const char *ids, size_t sz, size_t stride) {
gasnet_node_t i, prev, base;
const char *p, *base_p, *prev_p;
prev = base = gasneti_nodemap[0] = 0;
prev_p = base_p = ids;
p = base_p + stride;
for (i = 1; i < gasneti_nodes; ++i, p += stride) {
if (!memcmp(p, prev_p, sz)) { /* Repeat the previous id */
gasneti_nodemap[i] = gasneti_nodemap[prev];
prev += 1; prev_p += stride;
continue;
}
gasneti_nodemap[i] = i;
if (!memcmp(p, ids, sz)) { /* Restart the first "row" */
prev = 0; prev_p = ids;
} else if (!memcmp(p, base_p, sz)) { /* Restart the previous "row" */
prev = base; prev_p = base_p;
} else if (!memcmp(p, prev_p + stride, sz)) { /* Continue current "row" if any */
prev += 1; prev_p += stride;
} else { /* Begin a new "row" */
prev = base = i; prev_p = base_p = p;
}
gasneti_nodemap[i] = gasneti_nodemap[prev];
}
}
/* This code is "good" for all possible process layouts, where "good"
* means identifing all sharing. However, the running time is O(n*log(n)).
*/
static struct {
const char *ids;
size_t sz;
size_t stride;
} _gasneti_nodemap_sort_aux;
static int _gasneti_nodemap_sort_fn(const void *a, const void *b) {
gasnet_node_t key1 = *(const gasnet_node_t *)a;
gasnet_node_t key2 = *(const gasnet_node_t *)b;
const char *val1 = _gasneti_nodemap_sort_aux.ids + key1 * _gasneti_nodemap_sort_aux.stride;
const char *val2 = _gasneti_nodemap_sort_aux.ids + key2 * _gasneti_nodemap_sort_aux.stride;
int retval = memcmp(val1, val2, _gasneti_nodemap_sort_aux.sz);
if (!retval) { /* keep sort stable */
gasneti_assert(key1 != key2);
retval = (key1 < key2) ? -1 : 1;
}
return retval;
}
static void gasneti_nodemap_helper_qsort(const char *ids, size_t sz, size_t stride) {
gasnet_node_t *work = gasneti_malloc(gasneti_nodes * sizeof(gasnet_node_t));
const char *prev_id;
int i, prev; /* If these are gasnet_node_t then bug 2634 can crash XLC */
_gasneti_nodemap_sort_aux.ids = ids;
_gasneti_nodemap_sort_aux.sz = sz;
_gasneti_nodemap_sort_aux.stride = stride;
for (i = 0; i < gasneti_nodes; ++i) work[i] = i;
qsort(work, gasneti_nodes, sizeof(gasnet_node_t), &_gasneti_nodemap_sort_fn);
prev = work[0];
gasneti_nodemap[prev] = prev;
prev_id = ids + prev*stride;
for (i = 1; i < gasneti_nodes; ++i) {
int node = work[i]; /* Also subject to bug 2634 */
const char *tmp_id = ids + node*stride;
prev = gasneti_nodemap[node] = memcmp(tmp_id, prev_id, sz) ? node : prev;
prev_id = tmp_id;
}
gasneti_free(work);
}
/* gasneti_nodemap_helper
* Construct a nodemap from a vector of "IDs"
*/
GASNETI_NEVER_INLINE(gasneti_nodemap_helper,