forked from Algebraic-Programming/LPF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlpfrun.in
More file actions
1120 lines (947 loc) · 31.4 KB
/
lpfrun.in
File metadata and controls
1120 lines (947 loc) · 31.4 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
#!/bin/bash
#
# Copyright 2021 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name=`basename $0`
bash_verbose=
if echo $- | grep x ; then
bash_verbose="-x"
fi
# define a function to print help
function printhelp()
{
echo "Lightweight Parallel Foundations (LPF)"
echo "======================================"
echo "v@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ - @BUILD_DATE@"
echo
echo "SYNPOSIS:"
echo " $name [-help] [-np <procs>] [-engine <engine>] <executable> [<param 0> ...]"
echo
echo "DESCRIPTION"
echo "This command runs an executable compiled by the lpfcc frontend compiler"
echo
echo "OPTIONS"
echo " -help Shows this message"
echo
echo " -n <tasks> Defines the total number of parallel tasks available to"
echo " the runtime. These can be processes, threads, or a"
echo " combination of both, depending on the engine. By"
echo " default, it takes one."
echo
echo " -N <nodes> Defines the number of processes available to the"
echo " runtime. If omitted, the default behaviour is to use"
echo " the minimum number of processes to provide the number"
echo " of equested tasks."
echo
echo " -show Command line that will be executed by this frontend"
echo
echo " -verbose Shows various pinning information."
echo
echo " -log <level>"
echo " Set the level of log detail. The default is 0=OFF"
echo
echo " -engine <engine>"
echo " Allow you to choose the engine. Currently supported"
echo " are: pthread, mpirma, mpimsg, ibverbs, hybrid"
echo
echo " -probe <seconds>"
echo " Set the number of seconds to probe the system for BSP"
echo " machine parameters. Use 0 to disable probing, which is"
echo " the default."
echo
echo " -pinning <scatter|compact|none>"
echo " Set the pinning mode of processes to CPU cores."
echo " 'none' is the default."
echo
echo " -process-per [ <core|socket|node> | number ]"
echo " Only relevant for the hybrid engine, because it defined"
echo " how to the processes and their threads or organized. "
echo
echo " -spinlock <fast|pause|yield>"
echo " Specifies the spin-lock mode. Use 'fast' for"
echo " the tightest spinlock possible, 'pause' to allow"
echo " companion hyperthreads to use this thread's resources,"
echo " or 'yield' to allow other (OS) threads to run."
echo
echo " -a2amode <sparse|dense|hoefler>"
echo " Specifies the all-to-all mode. In most cases the"
echo " default 'sparse' is the best mode."
echo
echo " -tiny-msg-size <bytes for shared mem>:<bytes for distrib mem>"
echo " or just simply"
echo " -tiny-msg-size <bytes>"
echo " Specifies the number of bytes of a message that is"
echo " small enough to be transported along with the meta-data."
echo " Although this implies that these small messages are "
echo " buffered, it may improve speed because it eliminates"
echo " some of the start-up cost of such small messages."
echo " Increasing this size also requires extra memory. By"
echo " default this value is '16' bytes for pthreads, '128'"
echo " bytes for MPI, and '16:128' for the hybrid implementation."
echo
echo " -write-conflict-block-size <bytes>"
echo " Specifies the block size for write-conflict resolution."
echo " This number must be a power of 2."
echo
echo " -bsplib <safe|fast>[:<max_hp_regs>|unlimited]"
echo " Choose whether BSPlib mode runs in fast or safe mode."
echo " Optionally, the maximum number of memory registrations"
echo " available for hp messages can be set. "
echo " The default is 'safe' without a limitation of memory"
echo " registrations."
echo
echo " -mpirun,<MPIRUN ARG>"
echo " Passes <MPIRUN ARG> directly to the underlying mpirun,"
echo " if applicable. For the pthread engine these will be"
echo " ignored."
echo
echo " -max-mpi-msg-size <bytes>"
echo " Limits the message size for the mpimsg and mpirma"
echo " engines. Effectively, this means that any lpf_put or"
echo " lpf_get larger than <bytes> will be split up into"
echo " multiple smaller messages, all smaller than <bytes>."
echo " This is useful, if the underlying MPI implementation"
echo " experiences memory allocation/pinning difficulties."
echo " The default maximum size is INT_MAX, which is"
echo " 2147483647 on machines with 32-bit ints."
echo
echo " -ibverbs-mtu <256|512|1024|2048|4096>"
echo " Sets the maximum transfer unit (MTU) for the infiniband"
echo " devices, when using the ibverbs engine."
echo
echo " <executable>"
echo " The path to the executable to run"
echo
echo " <param 0>..."
echo " The command line parameters for the program"
echo
if [ x$engine = xmpirma -o x$engine = xmpimsg -o x$engine = xhybrid \
-o x$engine = xibverbs ]; then
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
@MPIRUN@ -help
fi
}
############# DATA STRUCTURES ################
function params_to_stream()
{
printf "%s\n" "$@"
}
# Creates a comma separated list from a newline separated stream
function plus_list_create()
{
paste -sd+
}
# Returns the first or first $1 elements from the comma separated list
function plus_list_head()
{
local n
if [ "x$1" = "x" ]; then
n=1
else
n="$1"
fi
cut -d+ -f $n
}
# Drops first or first $1 elements from the comma separated list
function plus_list_drop()
{
local n
if [ "x$1" = "x" ]; then
n=1
else
n="$1"
fi
cut -d+ -f "$((n +1 ))-"
}
# Creates a comma separated list from its parameters
function plus_list_concat()
{
params_to_stream "$@" | plus_list_create
}
# Converts a comma separated list in a tokenized list (useful for loops)
function plus_list_tokenize()
{
# sed -e '/./s/^/"/;/./s/$/"/;s/+/" "/g'
sed -e 's/+/ /g'
}
# Converts a comma separated list into a newline separated stream
function plus_list_stream()
{
sed -ne "/^\$/d;s/+/\n/g;p"
}
# Counts the number of elements in the list
function plus_list_get_size()
{
sed -ne '/^$/d;s/[^+]//gp;' | wc -c
}
function plus_list_is_empty()
{
sed -ne '/./q1;q0'
}
# From an item formatted as '3(x4)', get the 3
function item_get()
{
local element="$1"
echo "${element%%(*)}"
}
# From an item formatted as '3(x4)', get the 4
function item_get_count()
{
local element="$1"
local item="${element%%(*)}"
if [ $item = $element ]; then
echo 1
else
local a=${element##*x}
echo "${a%%)}"
fi
}
################ MPI WRAPPERS ###############
MPIRUN_ENV=
declare -a MPIRUN_STD_PARAMS
declare -a MPIRUN_LOCAL_PARAMS
function add_mpirun_param()
{
MPIRUN_STD_PARAMS=( "${MPIRUN_STD_PARAMS[@]}" "$@" )
}
function add_mpirun_local_param()
{
MPIRUN_LOCAL_PARAMS=( "${MPIRUN_LOCAL_PARAMS[@]}" "$@" )
}
# Detect the MPI implementation of MPIRUN
function mpi_detect()
{
if ( @MPIRUN@ -version 2>&1 | grep 'Intel' > /dev/null ; ) then
echo intel
elif ( @MPIRUN@ -version 2>&1 | grep 'Open MPI' > /dev/null ; ) then
echo ompi
elif ( @MPIRUN@ -version 2>&1 | grep 'HYDRA' > /dev/null ; ) then
echo mpich
# also matches MVAPICH
elif ( @MPIRUN@ -version 2>&1 | grep 'IBM Platform MPI' > /dev/null ; ) then
echo platform
else
echo generic
fi
}
function mpi_set_local_env()
{
local mpi
if [ x$3 = x ]; then
mpi=$(mpi_detect)
else
mpi=$3
fi
if [ x$mpi = xintel ]; then
add_mpirun_param "-genv" "$1" "$2"
elif [ x$mpi = xompi ]; then
add_mpirun_local_param "-x" "$1=$2"
elif [ x$mpi = xmpich ]; then
add_mpirun_param "-genv" "$1" "$2"
elif [ x$mpi = xplatform ]; then
add_mpirun_param "-e" "$1=$2"
fi
}
function mpi_disable_pinning()
{
local mpi
if [ x$1 = x ]; then
mpi=$(mpi_detect)
else
mpi=$1
fi
if [ x$mpi = xintel ]; then
MPIRUN_ENV=$( plus_list_concat $MPIRUN_ENV "I_MPI_PIN=disable" )
elif [ x$mpi = xompi ]; then
add_mpirun_param "--bind-to" "none"
elif [ x$mpi = xplatform ]; then
add_mpirun_param "-aff=skip"
fi
# MPICH doesn't do pinning
}
function mpi_use_env()
{
for x in $(echo $MPIRUN_ENV | plus_list_tokenize )
do
$show export $x
done
}
#### GENERIC wrapper
function set_local_env()
{
if [ x$engine = xpthread ]; then
$show export "$1=$2"
else
mpi_set_local_env $1 $2
fi
}
function remove_local_env()
{
if [ x$engine = xpthread ]; then
$show export -n "$1"
fi
# not implemented for MPI, because it's not really necessary
}
################ SLURM functions ###########
function slurm_hostlist_expand()
{
scontrol show hostname "$@"
}
function tasklist_create()
{
uniq -c \
| sed -e 's/^[[:space:]]*\([[:digit:]]*\)[[:space:]]\+\([^[:space:]]*\)/\2(x\1)/' \
| plus_list_create
}
function tasklist_expand()
{
function expand { eval printf "$1%.0s\\\n" {1..$2} ; };
export -f expand
plus_list_stream \
| sed -e '/(x/!s/.*/& 1/;/(x/s/\([^[:space:]]*\)(x\([[:digit:]]*\))/\1 \2/;' \
| xargs -n2 bash -c 'expand $0 "$@"' 2> /dev/null
# note: the 2> /dev/null is necessary to make xargs shut-up
# about broken pipes that are caused by subsequent commands
export -n expand
}
function tasklist_zip()
{
local as=`mktemp`
local bs=`mktemp`
local sep=$1
local n1=$( echo $2 | tasklist_expand | tee $as | wc -l )
tasklist_expand | head -n $n1 > $bs
local n2=$( cat $bs | wc -l )
head -n $n2 $as | paste -d"$sep" $bs - | tasklist_create
rm $as $bs
}
function tasklist_unzip_first()
{
local sep=$1
sed -e "s/${sep}[^(+]*//g"
}
function tasklist_unzip_second()
{
local sep=$1
sed -e "s/\(^\|+\)[^()+;]*;/\1/g"
}
function tasklist_create_common()
{
local as=`mktemp`
echo $1 | tasklist_expand > $as
tasklist_expand | paste -d\; - $as | \
tasklist_create | sed -e 's/;[^(+]*//g'
rm $as
}
function tasklist_match_sum()
{
local total=$1
local s=`mktemp`
cat > $s
local sum=0
local next_sum=0
local sep=
for x in $(plus_list_tokenize < $s)
do
local i=$( item_get $x )
local n=$( item_get_count $x )
next_sum=$((sum + i*n))
if [ $next_sum -ge $total ]; then
remainder=$(( total - sum ))
head=$(( remainder / i ))
tail=$(( remainder - head * i ))
if [ $head -gt 0 ]; then
echo -n "${sep}${i}(x${head})"
sep=+
fi
if [ $tail -gt 0 ]; then
echo -n "${sep}${tail}"
sep=+
fi
sum=$total
break
else
echo -n "${sep}${i}(x${n})"
sep=+
sum=${next_sum}
fi
done
rm $s
}
####
function VERB
{
test "x$verbose" = xyes && echo "$@"
}
# parse parameters
doPrinthelp=no
verbose=no
show=
procs=0
nodes=0
engine=pthread
probe="0.0"
pinning=none
process_per=default
loglevel=0
bsplib_safemode=1
spinlock=DEFAULT
a2amode=SPARSE
bsplib_hpregs=unlimited
tiny_size="16 128"
write_conflict_blocksize=1024
max_mpi_msg_size=
ibmtu=4096
state=
declare -a mpirun_args
mpirun_arg_number=0
declare -a other_cmds
for arg
do
case $arg in
-h|--hilfe|--ausecours|--alaide|--help|-help)
doPrinthelp=yes
shift
;;
-np|-n|-npes)
state=procs
shift
;;
-N)
state=nodes
shift
;;
-engine)
state=engine
shift
;;
-probe)
state=probe
shift
;;
-pinning)
state=pinning
shift
;;
-log)
state=loglevel
shift
;;
-bsplib)
state=bsplib
shift
;;
-process-per)
state=process_per
shift
;;
-spinlock)
state=spinlock
shift
;;
-a2amode)
state=a2amode
shift
;;
-tiny-msg-size)
state=tinysize
shift
;;
-write-conflict-block-size)
state=writeconflict
shift
;;
-show)
show=echo
shift
;;
-verbose)
verbose=yes
shift
;;
-max-mpi-msg-size)
state=maxmpimsgsize
shift
;;
-ibverbs-mtu)
state=ibmtu
shift
;;
-mpirun,*)
# add mpirun parameters
mpirun_args[$mpirun_arg_number]="${arg#-mpirun,}"
mpirun_arg_number=$((mpirun_arg_number + 1))
shift
;;
*) case $state in
procs)
procs=$arg
state=
shift
;;
nodes)
nodes=$arg
state=
shift
;;
engine)
engine=$arg
state=
shift
;;
probe)
probe="$arg"
state=
shift
;;
pinning)
pinning="$arg"
state=
shift
;;
process_per)
process_per="$arg"
state=
shift
;;
loglevel)
loglevel="$arg"
state=
shift
;;
spinlock)
case $arg in
fast) spinlock=FAST;;
pause) spinlock=PAUSE;;
yield) spinlock=YIELD;;
cond) spinlock=COND;;
*) echo "ERROR: invalid parameter for option -spinlock '$arg'"
printhelp
exit 1;
esac
state=
shift
;;
a2amode)
case $arg in
sparse) a2amode=SPARSE;;
dense) a2amode=DENSE;;
hoefler) a2amode=HOEFLER;;
*) echo "ERROR: invalid parameter for option -a2amode '$arg'"
printhelp
exit 1;
esac
state=
shift
;;
tinysize)
# the argument for can either be of the form "128" or "16:128"
if echo $arg | grep -q ':'; then
tiny_size="${arg/:/ }"
else
tiny_size="${arg} ${arg}"
fi
state=
shift
;;
writeconflict)
write_conflict_blocksize=$arg
state=
shift
;;
maxmpimsgsize)
max_mpi_msg_size=$arg
state=
shift
;;
ibmtu)
ibmtu=$arg
state=
shift
;;
bsplib)
case $arg in
safe) bsplib_safemode=1
;;
safe:*) bsplib_safemode=1
bsplib_hpregs="${arg#safe:}"
;;
fast) bsplib_safemode=0
;;
fast:*) bsplib_safemode=0
bsplib_hpregs=${arg#fast:}
;;
esac
state=
shift
if echo "$bsplib_hpregs" | grep -vq '^unlimited$\|^[[:digit:]]\+$'; then
echo "ERROR: invalid maximum number of hp registers specified using -bsplib $arg."
echo " It must be a positive integer or 'unlimited'"
exit 1
fi
;;
*) # stop parsing the command line
other_cmds=( "${other_cmds[@]}" "$@" )
break
;;
esac
;;
esac
done
if [ $doPrinthelp = yes ]; then
printhelp
exit 0
fi
if [ x$verbose = xyes ]; then
echo "VERSION @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@"
echo "DATE @BUILD_DATE@"
echo "ENGINE: $engine"
echo "PROBE DURATION: $probe seconds"
echo "PINNING: $pinning"
echo "LOG LEVEL: $loglevel"
echo "HWLOC ENABLED: @HWLOC_FOUND@"
echo "TINY MSG SIZE: $tiny_size"
if [ $engine != pthread ]; then
echo "WRITE CONFLICT BLOCK SIZE: $write_conflict_blocksize"
echo "ALL-TO-ALL MODE $a2amode"
fi
if [ $bsplib_safemode -eq 1 ]; then
echo "BSPLIB MODE: SAFE"
else
echo "BSPLIB MODE: FAST"
fi
echo "BSPLIB HP REGS: $bsplib_hpregs"
fi
# set-up common environment
LPFLIB=@CMAKE_INSTALL_PREFIX@
lpfcore_pat="@lpfcore@"
LPFCORE=( ${lpfcore_pat/ENGINE/${engine}} )
if [ "${#LPFCORE[*]}" -ne 1 ]; then
echo "INTERNAL ERROR: LPF engine was not correctly set"
exit 1
fi
if [ ! -f $LPFCORE ]; then
echo "ERROR: LPF engine ${engine} was not installed"
exit 1
fi
set_local_env "LD_LIBRARY_PATH" "$LPFLIB/lib:$LD_LIBRARY_PATH"
set_local_env "LPF_MAX_SECONDS_FOR_PROBE" "$probe"
set_local_env "LPF_LOG_LEVEL" "$loglevel"
set_local_env "LPF_ENGINE" "$engine"
set_local_env "LPF_A2A_MODE" "$a2amode"
set_local_env "LPF_TINY_MSG_SIZE" "$tiny_size"
set_local_env "LPF_WRITE_CONFLICT_BLOCK_SIZE" "$write_conflict_blocksize"
set_local_env "LPF_BSPLIB_SAFETY_MODE" "$bsplib_safemode"
set_local_env "LPF_INFINIBAND_MTU_SIZE" "$ibmtu"
if [ x$bsplib_hpregs = xunlimited ]; then
remove_local_env LPF_BSPLIB_MAX_HP_REGS
else
set_local_env "LPF_BSPLIB_MAX_HP_REGS" "$bsplib_hpregs"
fi
if [ x$max_mpi_msg_size = x ]; then
remove_local_env LPF_MPI_MAX_MSG_SIZE
else
set_local_env "LPF_MPI_MAX_MSG_SIZE" "$max_mpi_msg_size"
fi
exit_status=0
case $engine in
pthread)
if [ $mpirun_arg_number -ge 1 ]; then
echo "Ignoring mpirun parameters in pthread mode '${mpirun_args[@]}'"
fi
if [ $procs -eq 0 ]; then
if [ x"@HWLOC_FOUND@" = xYES ]; then
procs=$(@hwloc_calc@ --number-of core all)
VERB "PTHREAD TASKS: $procs (detected by hwloc)"
else
procs=
VERB "PTHREAD TASKS: (detected by LPF)"
fi
else
VERB "PTHREAD TASKS: $procs (as required by user)"
fi
bitmaps=
if [ x"@HWLOC_FOUND@" = xYES ]; then
hwcores=$(@hwloc_calc@ --number-of core all)
maxcoreid=$(( procs-1 ))
if [ $procs -gt $hwcores ]; then
maxcoreid=$(( hwcores - 1 ))
if [ $spinlock = DEFAULT ]; then
VERB "PTHREAD DETECTED OVERSUBSCRIPTION"
spinlock=PAUSE
fi
fi
if [ x$pinning = xscatter ]; then
bitmaps=$( @hwloc_distrib@ --single $procs | plus_list_create )
elif [ x$pinning = xcompact ]; then
compact_set=$( @hwloc_calc@ core:0-${maxcoreid} )
bitmaps=$( @hwloc_distrib@ --single --restrict $compact_set $procs | plus_list_create )
fi
fi
if [ $spinlock = DEFAULT ]; then
VERB "PTHREAD DETECTED AT MOST ONE THREAD PER CORE "
spinlock=FAST
fi
VERB "PTHREAD CPUMASKS: '$bitmaps' (by hwloc)"
VERB "PTHREAD SPINLOCK MODE: $spinlock"
$show export LPF_SPIN_MODE="$spinlock"
# run with designated number of processors
set_local_env LPF_PROC_PINNING "$bitmaps"
set_local_env LPF_MAX_PROCS $procs
set_local_env LD_PRELOAD "$LPFCORE"
$show "${other_cmds[@]}"
exit_status=$?
;;
mpirma|mpimsg|ibverbs)
mpi_impl=$(mpi_detect)
proc_args=
if [ x$mpi_impl = xplatform ]; then
if [ x$SLURM_NTASKS != x ]; then
VERB "DETECTED SLURM"
if [ $procs -gt 0 ]; then
VERB "MPI TASKS: $procs"
proc_args="-srun -n $procs"
else
VERB "MPI TASKS: (autodetected by mpirun)"
proc_args="-srun"
fi
else
if [ $procs -gt 0 ]; then
VERB "MPI TASKS: $procs"
proc_args="-np $procs"
else
VERB "MPI TASKS: (autodetected by mpirun)"
fi
fi
else
if [ $procs -gt 0 ]; then
VERB "MPI TASKS: $procs"
proc_args="-n $procs"
else
VERB "MPI TASKS: (autodetected by mpirun)"
fi
fi
set_local_env LD_PRELOAD "$LPFCORE"
$show @MPIRUN@ @MPIEXEC_PREFLAGS@ "${mpirun_args[@]}" \
"${MPIRUN_STD_PARAMS[@]}" "${MPIRUN_LOCAL_PARAMS[@]}"\
${proc_args} "${other_cmds[@]}" @MPIEXEC_POSTFLAGS@
exit_status=$?
;;
hybrid)
# autodetect whether SLURM is running this command
slurm=false
if [ x$SLURM_NTASKS != x ]; then
slurm=true
fi
VERB "HYBRID SLURM: $slurm"
# Set procs correctly if it wasn't
if [ $procs -eq 0 ]; then
# try to autodetect number of tasks
if $slurm; then
procs=$SLURM_NTASKS
else
procs=1
fi
fi
if $slurm && test $procs -ge $SLURM_NTASKS; then
procs=$SLURM_NTASKS
fi
VERB "HYBRID TASKS: $procs"
# Set nodes correctly if it wasnt
if [ $nodes -eq 0 ]; then
# try to autodetect number of nodes
if $slurm; then
nodes=$SLURM_JOB_NUM_NODES
else
nodes=$procs
fi
fi
if [ $nodes -ge $procs ]; then
nodes=$procs;
fi
if $slurm && test $nodes -ge $SLURM_JOB_NUM_NODES ; then
nodes=$SLURM_JOB_NUM_NODES
fi
VERB "HYBRID NODES: $nodes"
# autodetect MPI implementation
mpi_impl=$(mpi_detect)
# set process_per by default to per socket if more than one
# node is used. Use only one process if run on one node.
# Note that we only have socket information when in SLURM mode
if [ x${process_per} = xdefault ] ; then
if $slurm && [ $nodes -gt 1 ] ; then
process_per=socket
else
process_per=node
fi
VERB "HYBRID DEFAULT PROCESSES PER NODE: $process_per"
fi
# Launch job depending on job scheduler
if $slurm ; then
threadlist="$( echo $SLURM_TASKS_PER_NODE | sed -e 's/,/+/g' \
| tasklist_match_sum $procs)"
else
high=$(( ( procs + nodes - 1) / nodes ))
low=$(( procs / nodes ))
head=$(( procs % nodes ))
tail=$(( nodes - head ))
if [ $head -gt 0 ]; then
threadlist="${high}(x${head})+${low}(x${tail})"
else
threadlist="${low}(x${tail})"
fi
fi
single=no
case ${process_per} in
socket)
if $slurm ; then
# get machine info from SLURM
sockets=$(sinfo -N -h --nodes="$SLURM_JOB_NODELIST" -o "%X" | \
head -n $nodes | tasklist_create )
check_count=$( echo $sockets | tasklist_expand | wc -l )
# check whether that information is complete
if [ $check_count -lt $nodes ]; then
echo "ERROR: Slurm doesn't know number of sockets for all nodes"
echo " Please, use another value for the -process-per option"
exit 1
fi
threadlist=$( echo $threadlist | tasklist_zip ';' $sockets )
single="single"
VERB "HYBRID PROCESS MAPPING: One process per socket"
VERB "HYBRID PINNING: Exact pinning enabled"
else
echo "ERROR: No socket information available. Please use"
echo " option -process-per <number>"
exit 1
fi
;;
node)
one_proc_per_node=$( yes 1 | head -n $nodes | tasklist_create )
threadlist=$( echo $threadlist | tasklist_zip ';' $one_proc_per_node )
VERB "HYBRID PROCESS MAPPING: One process per compute node"
if $slurm ; then single="single"; VERB "HYBRID PINNING: exact pinning enabled";fi
;;
core)
threadlist=$( echo $threadlist | tasklist_expand | head -n $nodes | tasklist_create )
threadlist=$( echo $threadlist | tasklist_zip ';' $threadlist )
VERB "HYBRID PROCESS MAPPING: One process per processor core"
if $slurm ; then single="single"; VERB "HYBRID PINNING: exact pinning enabled";fi
;;
*) number=${process_per}
if ( echo $number | grep -q '[^[:digit:]]' ; ) || test $number -le 0 ; then
echo "ERROR: Valid arguments for -process-per are socket, node,"