forked from cdslaborg/paramonte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildParaMonte.sh
executable file
·3548 lines (3019 loc) · 165 KB
/
buildParaMonte.sh
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
####################################################################################################################################
####################################################################################################################################
####
#### MIT License
####
#### ParaMonte: plain powerful parallel Monte Carlo library.
####
#### Copyright (C) 2012-present, The Computational Data Science Lab
####
#### This file is part of the ParaMonte library.
####
#### Permission is hereby granted, free of charge, to any person obtaining a
#### copy of this software and associated documentation files (the "Software"),
#### to deal in the Software without restriction, including without limitation
#### the rights to use, copy, modify, merge, publish, distribute, sublicense,
#### and/or sell copies of the Software, and to permit persons to whom the
#### Software is furnished to do so, subject to the following conditions:
####
#### The above copyright notice and this permission notice shall be
#### included in all copies or substantial portions of the Software.
####
#### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#### EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#### MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
#### IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
#### DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
#### OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
#### OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
####
#### ACKNOWLEDGMENT
####
#### ParaMonte is an honor-ware and its currency is acknowledgment and citations.
#### As per the ParaMonte library license agreement terms, if you use any parts of
#### this library for any purposes, kindly acknowledge the use of ParaMonte in your
#### work (education/research/industry/development/...) by citing the ParaMonte
#### library as described on this page:
####
#### https://github.com/cdslaborg/paramonte/blob/main/ACKNOWLEDGMENT.md
####
####################################################################################################################################
####################################################################################################################################
#
# NOTE: Do not change the contents of this file unless you know what the consequences are.
# This is the Bash script file that builds objects, shared libraries,
# as well as the test and example binaries of the ParaMonte library on non-Windows systems.
# Upon invocation of this file from a Bash command-line interface,
# this file will first call the configuration file configParaMonte.bat to read the user's
# requested configuration for building the ParaMonte library.
####################################################################################################################################
#### set minimum requirements
####################################################################################################################################
openCoarraysVersion="2.9.0"
gnuVersionOpenCoarrays="10.1.0"
mpichVersionOpenCoarrays="3.2"
gnuVersionParaMonteCompatible="8.4.0"
cmakeVersionParaMonteCompatible="3.14.0"
intelVersionParaMonteCompatible="18.0.0"
####################################################################################################################################
#### set up color coding
####################################################################################################################################
asciiEscVal=27; Esc="$(printf "\\$(printf "%o" "${asciiEscVal}")")";
ColorReset="${Esc}[m"
ColorBold="${Esc}[1m"
Red="${Esc}[31m"
Green="${Esc}[32m"
Yellow="${Esc}[33m"
Blue="${Esc}[34m"
Magenta="${Esc}[35m"
Cyan="${Esc}[36m"
White="${Esc}[37m"
BoldRed="${Esc}[1;31m"
BoldGreen="${Esc}[1;32m"
BoldYellow="${Esc}[1;33m"
BoldBlue="${Esc}[1;34m"
BoldMagenta="${Esc}[1;35m"
BoldCyan="${Esc}[1;36m"
BoldWhite="${Esc}[1;37m"
####################################################################################################################################
#### set up the main root paths
####################################################################################################################################
BUILD_NAME="ParaMonte"; export BUILD_NAME
pmcolor="${BoldCyan}"
pmattn=" ${pmcolor}-- ${BUILD_NAME} -${ColorReset}"
pmnote="${pmattn} ${BoldYellow}NOTE:${ColorReset}"
pmwarn="${pmattn} ${BoldMagenta}WARNING:${ColorReset}"
pmfatal="${pmattn} ${BoldRed}FATAL:${ColorReset}"
warning="${BoldMagenta}WARNING${ColorReset}"
workingDir="$(pwd)"
sourceFileDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ParaMonte_ROOT_DIR="${sourceFileDir}"; export ParaMonte_ROOT_DIR
ParaMonteKernel_SRC_DIR="${ParaMonte_ROOT_DIR}/src/kernel"; export ParaMonteKernel_SRC_DIR
ParaMonteKernelVersion_SRC_INC_PATH="${ParaMonteKernel_SRC_DIR}/ParaMonte_mod@[email protected]"; export ParaMonteKernel_SRC_DIR
ParaMonteTest_SRC_DIR="${ParaMonte_ROOT_DIR}/src/kernel/tests"; export ParaMonteTest_SRC_DIR
#export ParaMonte_ROOT_DIR="${ParaMonte_ROOT_DIR:-${PWD%/}}"
ParaMonte_ROOT_BUILD_DIR="${ParaMonte_ROOT_DIR}/build"; export ParaMonte_ROOT_BUILD_DIR
if ! [ -d "${ParaMonte_ROOT_BUILD_DIR}" ]; then
mkdir -p "${ParaMonte_ROOT_BUILD_DIR}"
fi
if [[ ! -f "$(pwd)/build${BUILD_NAME}.sh" ]]; then
echo >&2
echo >&2 "${pmfatal} Build failed."
echo >&2 "${pmfatal} Please run this script inside the top-level ParaMonte library root directory."
echo >&2 "${pmfatal} This is the directory which contains this file in the GitHub repository of ParaMonte."
echo >&2
exit 1
fi
####################################################################################################################################
#### utils
####################################################################################################################################
# Compare two version strings [$1: version string 1 (v1), $2: version string 2 (v2)]
# Return values:
# 0: v1 == v2
# 1: v1 > v2
# 2: v1 < v2
function compareVersions() {
# Trivial v1 == v2 test based on string comparison
[[ "$1" == "$2" ]] && return 0
# Local variables
local regex="^(.*)-r([0-9]*)$" va1=() vr1=0 va2=() vr2=0 len i IFS="."
# Split version strings into arrays, extract trailing revisions
if [[ "$1" =~ ${regex} ]]; then
va1=(${BASH_REMATCH[1]})
[[ -n "${BASH_REMATCH[2]}" ]] && vr1=${BASH_REMATCH[2]}
else
va1=($1)
fi
if [[ "$2" =~ ${regex} ]]; then
va2=(${BASH_REMATCH[1]})
[[ -n "${BASH_REMATCH[2]}" ]] && vr2=${BASH_REMATCH[2]}
else
va2=($2)
fi
# Bring va1 and va2 to same length by filling empty fields with zeros
(( ${#va1[@]} > ${#va2[@]} )) && len=${#va1[@]} || len=${#va2[@]}
for ((i=0; i < len; ++i)); do
[[ -z "${va1[i]}" ]] && va1[i]="0"
[[ -z "${va2[i]}" ]] && va2[i]="0"
done
# Append revisions, increment length
va1+=($vr1)
va2+=($vr2)
len=$((len+1))
# *** DEBUG ***
#echo "TEST: '${va1[@]} (?) ${va2[@]}'"
# Compare version elements, check if v1 > v2 or v1 < v2
for ((i=0; i < len; ++i)); do
if (( 10#${va1[i]} > 10#${va2[i]} )); then
return 1
elif (( 10#${va1[i]} < 10#${va2[i]} )); then
return 2
fi
done
# All elements are equal, thus v1 == v2
return 0
}
verify() {
if [ $1 -eq 0 ]; then
echo >&2 "${pmattn} ${BoldGreen}The ParaMonte $2 appears to have succeeded.${ColorReset}"
else
echo >&2
echo >&2 " -- ParaMonte - FATAL: ParaMonte $2 appears to have failed."
echo >&2 " -- ParaMonte - FATAL: If the source of the error cannot be identified,"
echo >&2 " -- ParaMonte - FATAL: consider a fresh installation of ParaMonte's required compilers by calling"
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: ./install.sh --fresh"
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: If the error happens during the installation of ParaMonte prerequisites,"
echo >&2 " -- ParaMonte - FATAL: it is possible that the current existing GNU compiler collection installed"
echo >&2 " -- ParaMonte - FATAL: on your system cannot compile the downloaded version of GNU that is required"
echo >&2 " -- ParaMonte - FATAL: for ParaMonte build. In such case, make sure you have a GNU compiler collection"
echo >&2 " -- ParaMonte - FATAL: version ${gnuVersionParaMonteCompatible} or newer installed on your system, with an updated PATH environmental"
echo >&2 " -- ParaMonte - FATAL: variable, then reinstall ParaMonte."
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: If the error is solely due to the failures of some ParaMonte tests, then"
echo >&2 " -- ParaMonte - FATAL: you may want to skip the testing of the library by specifying \"-t none\" or"
echo >&2 " -- ParaMonte - FATAL: \"--test none\" when calling the ParaMonte installation script."
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: ./install.sh --test none"
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: or,"
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: ./install.sh --t none"
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: To get more help on the usage of the optional install flags, try:"
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: ./install.sh --help"
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: If all ParaMonte installation attempts fail, please report this issue at"
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: https://github.com/shahmoradi/paramonte/issues"
echo >&2 " -- ParaMonte - FATAL: "
echo >&2 " -- ParaMonte - FATAL: or by contacting the ParaMonte authors directly (e.g., [email protected])."
echo >&2
echo >&2
echo >&2 " ${pmattn} gracefully exiting."
echo >&2
exit 1
fi
}
####################################################################################################################################
#### determine the platform
####################################################################################################################################
UNAME_PLATFORM="$(uname -s)"
case "${UNAME_PLATFORM}" in
Linux*) PLATFORM=linux;;
Darwin*) PLATFORM=darwin;;
CYGWIN*) PLATFORM=cygwin;;
MINGW*) PLATFORM=mingw;;
*) PLATFORM="unknown:${UNAME_PLATFORM}"
esac
if [[ "$PLATFORM" =~ .*"unknown".* ]]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: Build failed. unrecognized platform - ${PLATFORM}"
echo >&2 "-- ${BUILD_NAME} - FATAL: The supported platforms include: Linux, Darwin, CYGWIN, MINGW"
echo >&2 "-- ${BUILD_NAME} - FATAL: The ParaMonte build has been only tested on Linux and Darwin platforms."
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
else
export PLATFORM
fi
UNAME_PLATFORM_FULL="$(uname -a)"
if [[ "$UNAME_PLATFORM_FULL" =~ .*"Microsoft".* && "$UNAME_PLATFORM_FULL" =~ .*"Linux".* ]]; then
isWSL=true
else
isWSL=false
fi
isMacOS=false
isLinux=false
isMingw=false
isCygwin=false
isWindows=false
if [[ "${UNAME_PLATFORM}" =~ .*"Darwin".* ]]; then
isMacOS=true
OSNAME="macOS"
elif [[ "${UNAME_PLATFORM}" =~ .*"Linux".* ]]; then
isLinux=true
OSNAME="Linux"
elif [[ "${UNAME_PLATFORM}" =~ .*"CYGWIN".* ]]; then
OSNAME="Cygwin"
isWindows=true
isCygwin=true
elif [[ "${UNAME_PLATFORM}" =~ .*"MINGW".* ]]; then
OSNAME="MinGW"
isWindows=true
isMingw=true
fi
export isMacOS
export isLinux
export isWindows
export isCygwin
export isMingw
export OSNAME
export isWSL
####################################################################################################################################
#### determine the architecture
####################################################################################################################################
ARCHITECTURE=$(uname -p)
if [[ "$ARCHITECTURE" =~ .*"64".* ]]; then
ARCHITECTURE="x64"
else
ARCHITECTURE=$(uname -m)
if [[ "$ARCHITECTURE" =~ .*"64".* ]]; then ARCHITECTURE="x64"; fi
fi
export ARCHITECTURE
####################################################################################################################################
#### set the ParaMonte version (to be used by cmake)
####################################################################################################################################
read -r ParaMonteVersion < .VERSION
unset fppParaMonteVersion
unset FPP_PARAMONTE_VERSION_FLAG
if ! [ -z ${ParaMonteVersion+x} ]; then
export ParaMonteVersion
# NOTE: uncomment the following line, if you wish to insert the ParaMonte version to the source code via Cmake via the compiler preprocessor.
# fppParaMonteVersion="${ParaMonteVersion}"; export fppParaMonteVersion
# write the version source include file.
if ! [ -f "${ParaMonteKernelVersion_SRC_INC_PATH}" ] || [ "$(grep -c "${ParaMonteVersion}" "${ParaMonteKernelVersion_SRC_INC_PATH}")" = "0" ]; then
echo "! WARNING - DO NOT CHANGE THE CONTENTS OF THIS FILE MANUALLY." > "${ParaMonteKernelVersion_SRC_INC_PATH}"
echo "! WARNING - This file is auto-generated by the ParaMonte build scripts." >> "${ParaMonteKernelVersion_SRC_INC_PATH}"
echo "self%version = \"${ParaMonteVersion}\"" >> "${ParaMonteKernelVersion_SRC_INC_PATH}"
fi
fi
#echo "$(cat ./auxil/.ParaMonteBanner)"
####################################################################################################################################
#### report build setup
####################################################################################################################################
echo >&2
echo >&2 "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo >&2 ":::: ::::"
echo >&2 " ParaMonte library version ${ParaMonteVersion} build on ${OSNAME} "
echo >&2 ":::: ::::"
echo >&2 "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo >&2
echo >&2
echo >&2 "-- ${BUILD_NAME} - working directory: $(pwd)"
echo >&2 "-- ${BUILD_NAME} - source file directory: ${sourceFileDir}"
echo >&2 "-- ${BUILD_NAME} - current system's platform: ${OSNAME}"
echo >&2 "-- ${BUILD_NAME} - current system's architecture: ${ARCHITECTURE}"
echo >&2
echo >&2
echo >&2 "-- ${BUILD_NAME} - ParaMonte_ROOT_DIR: ${ParaMonte_ROOT_DIR}"
echo >&2 "-- ${BUILD_NAME} - ParaMonteTest_SRC_DIR: ${ParaMonteTest_SRC_DIR}"
echo >&2 "-- ${BUILD_NAME} - ParaMonteKernel_SRC_DIR: ${ParaMonteKernel_SRC_DIR}"
echo >&2 "-- ${BUILD_NAME} - ParaMonte_ROOT_BUILD_DIR: ${ParaMonte_ROOT_BUILD_DIR}"
echo >&2
####################################################################################################################################
#### usage
####################################################################################################################################
usage()
{
cat << EndOfMessage
usage:
buildParaMonte.sh
-L <language: C/C++/Fortran/MATLAB/Python>
-s <compiler suite: intel/gnu>
-b <build mode: release/testing/debug>
-l <library type: static/shared>
-c <coarray: none/single/shared/distributed>
-m <mpi enabled: true/false>
-i <C-Fortran interface enabled: true/false>
-e <heap allocation enabled: true/false>
-t <ParaMonte test run enabled: none/all/pm/nopm>
-x <ParaMonte example run enabled: true/false>
-f <path to Fortran compiler>
-M <path to mpiexec>
-F <purge the existing prerequisite library installations and perform a fresh installation>
-y <assume yes as answer to all installation permission inquiries>
-B <perform GCC bootstrap installation>
-n <default number of processors for parallel application>
-j <default number of processors for parallel builds>
-a <clean bash variables upon exit from the script>
-h <help on the script usage>
example:
buildParaMonte.sh -b release -l shared -c none -m true -i true -d true -n 3
flag definitions:
-L | --lang : the ParaMonte library interface programming language: C, C++, Fortran, MATLAB, Python
-s | --compiler_suite : the ParaMonte library build compiler suite: intel, gnu
-b | --build : the ParaMonte library build type: release, testing, debug
-l | --lib : the ParaMonte library type: static, shared (or equivalently, dynamic)
-c | --caf : the ParaMonte library Coarray Fortran parallelism type: none, single, shared, distributed
-m | --mpi_enabled : the ParaMonte library MPI parallelism enabled?: true, false
-i | --cfi_enabled : the ParaMonte library C-Fortran interface enabled? must be true if the library is to be called from non-Fortran languages: true, false
-e | --heap_enabled : the ParaMonte library heap array allocation enabled?: true, false
-t | --test : the ParaMonte library test run enabled?: none, all, pm, nopm
-x | --exam_enabled : the ParaMonte library examples run enabled?: true, false
-D | --deploy : release the shared library dependencies in the binary release of the ParaMonte library (this is mostly useful for the library developers)
-f | --fortran : path to Fortran compiler. If provided, the ParaMonte library will be built via the specified compiler.
-M | --mpiexec : path to mpiexec routine. If provided, it will be used to find the MPI library.
-F | --fresh : enables a fresh installation of all of the prerequisites of ParaMonte library. Applicable only to GNU compiler suite.
-y | --yes-to-all : if a fresh installation of all of the prerequisites is needed, automatically answer yes to all permission requests.
-B | --bootstrap : enables robust bootstrap build when building the required GCC version with an old GCC version. Applicable only to GNU compiler suite.
-n | --nproc : the default number of processes (coarray images) on which the ParaMonte examples/tests (if any) will be run: positive integer
-j | --njob : the default number of processes via which the ParaMonte library will be built for the requested configuration: positive integer
-a | --clean : clean the environmental variables upon exit, if flag is provided.
-h | --help : help with the script usage
EndOfMessage
}
####################################################################################################################################
# Configure ParaMonte Build
####################################################################################################################################
cmakeInstallEnabled=false
cafInstallEnabled=false
gnuInstallEnabled=false
mpiInstallEnabled=false
CMAKE_NJOB=""
unset PMCS
unset BTYPE
unset LTYPE
unset TTYPE
unset CAFTYPE
unset MPI_ENABLED
unset CFI_ENABLED
unset GCC_BOOTSTRAP
unset MPIEXEC_PATH_USER
unset HEAP_ARRAY_ENABLED
unset INTERFACE_LANGUAGE
unset FOR_COARRAY_NUM_IMAGES
unset Fortran_COMPILER_PATH_USER
ParaMonteExample_RUN_ENABLED=true
localInstallationEnabled=false
freshInstallEnabled=false
YES_TO_ALL_DISABLED=true
PERFPROF_ENABLED=false
CODECOV_ENABLED=false
DRYRUN_ENABLED=false
deploy_enabled=false
CLEAN=false
chmod a+x ./configParaMonte.sh
echo >&2
echo >&2 "-- ${BUILD_NAME} - configuring ParaMonte Build..."
echo >&2 "-- ${BUILD_NAME} - default configuration: "
source ./configParaMonte.sh
#output=$("./configParaMonte.sh")
#echo "${output}"
while [ "$1" != "" ]; do
case $1 in
-L | --lang ) shift
INTERFACE_LANGUAGE=$1
;;
-s | --compiler_suite ) shift
PMCS=$1; export PMCS;
;;
-b | --build ) shift
BTYPE=$1; export BTYPE
;;
-l | --lib ) shift
LTYPE=$1; if [ "${LTYPE}" = "dynamic" ]; then LTYPE=shared; fi; export LTYPE
;;
-c | --caf ) shift
CAFTYPE=$1; export CAFTYPE
;;
-m | --mpi_enabled ) shift
MPI_ENABLED=$1; export MPI_ENABLED
;;
-i | --cfi_enabled ) shift
CFI_ENABLED=$1; export CFI_ENABLED
;;
-e | --heap_enabled ) shift
HEAP_ARRAY_ENABLED=$1; export HEAP_ARRAY_ENABLED
;;
-t | --test ) shift
TTYPE=$1; export TTYPE
;;
-x | --exam_enabled ) shift
ParaMonteExample_RUN_ENABLED=$1; export ParaMonteExample_RUN_ENABLED
;;
-D | --deploy ) deploy_enabled=true; export deploy_enabled
;;
-f | --fortran ) shift
Fortran_COMPILER_PATH_USER=$1; export Fortran_COMPILER_PATH_USER
;;
-M | --mpiexec ) shift
MPIEXEC_PATH_USER=$1; export MPIEXEC_PATH_USER
;;
-n | --nproc ) shift
FOR_COARRAY_NUM_IMAGES=$1; export FOR_COARRAY_NUM_IMAGES
;;
-j | --njob ) shift
CMAKE_JOB="-j $1";
;;
-F | --fresh ) freshInstallEnabled=true; export freshInstallEnabled
;;
-o | --local ) localInstallationEnabled=true; export localInstallationEnabled
;;
-d | --dryrun ) DRYRUN_ENABLED=true; export DRYRUN_ENABLED
;;
-c | --codecov ) CODECOV_ENABLED=true; export CODECOV_ENABLED
;;
-p | --perfprof ) PERFPROF_ENABLED=true; export PERFPROF_ENABLED
;;
-y | --yes-to-all ) YES_TO_ALL_DISABLED=false; export YES_TO_ALL_DISABLED
;;
-B | --bootstrap ) GCC_BOOTSTRAP="--bootstrap"; export GCC_BOOTSTRAP
;;
-a | --clean ) shift
CLEAN=true
;;
-h | --help ) usage
exit
;;
* ) echo >&2 "-- ${BUILD_NAME} - FATAL: the input flag is not recognized: $1"
usage
exit 1
esac
shift
done
echo >&2
echo >&2 "-- ${BUILD_NAME} - current requested configuration: "
. ./configParaMonte.sh
####################################################################################################################################
# check flag consistencies
####################################################################################################################################
if [ -z ${INTERFACE_LANGUAGE+x} ]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: The environmental INTERFACE_LANGUAGE must be specified as input."
echo >&2
usage
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
CAF_ENABLED=false
if [ "${CAFTYPE}" = "single" ] || [ "${CAFTYPE}" = "shared" ] || [ "${CAFTYPE}" = "distributed" ]; then
CAF_ENABLED=true
fi
export CAF_ENABLED
if [ "${isMacOS}" = "true" ]; then
#if [[ "${PMCS}" =~ .*"intel".* ]]; then
if [[ ${PMCS} == [iI][nN][tT][eE][lL] ]]; then
if [[ "${MPI_ENABLED}" =~ .*"true".* ]]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: incompatible input flags specified by the user:"
echo >&2 "-- ${BUILD_NAME} - FATAL: -s | --compiler_suite : ${PMCS}"
echo >&2 "-- ${BUILD_NAME} - FATAL: -m | --mpi_enabled : ${MPI_ENABLED}"
echo >&2 "-- ${BUILD_NAME} - FATAL: \"--compiler_suite ${PMCS}\" cannot be used along with \"--mpi_enabled ${MPI_ENABLED}\" on macOS."
echo >&2 "-- ${BUILD_NAME} - FATAL: For parallel ParaMonte builds on macOS, use \"--compiler_suite gnu\" instead."
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
if [[ "${CAF_ENABLED}" =~ .*"true".* ]]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: incompatible input flags specified by the user:"
echo >&2 "-- ${BUILD_NAME} - FATAL: -s | --compiler_suite : ${PMCS}"
echo >&2 "-- ${BUILD_NAME} - FATAL: -c | --caf_enabled : ${CAF_ENABLED}"
echo >&2 "-- ${BUILD_NAME} - FATAL: \"--compiler_suite ${PMCS}\" cannot be used along with \"--caf_enabled ${CAF_ENABLED}\" on macOS."
echo >&2 "-- ${BUILD_NAME} - FATAL: For parallel ParaMonte builds on macOS, use \"--compiler_suite gnu\" instead."
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
else
if [ "${MPI_ENABLED}" = "true" ] || [ "${CAF_ENABLED}" = "true" ]; then PMCS="gnu"; fi
fi
fi
if [ "${CFI_ENABLED}" = "true" ]; then
if [ "${CAFTYPE}" = "shared" ] || [ "${CAFTYPE}" = "distributed" ]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: incompatible input flags specified by the user:"
echo >&2 "-- ${BUILD_NAME} - FATAL: -i | --cfi_enabled : ${CFI_ENABLED}"
echo >&2 "-- ${BUILD_NAME} - FATAL: -c | --caf : ${CAFTYPE}"
echo >&2 "-- ${BUILD_NAME} - FATAL: coarray parallelism is not available in C language."
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
fi
if [ "${MPI_ENABLED}" = "true" ]; then
if [ "${CAFTYPE}" = "shared" ] || [ "${CAFTYPE}" = "distributed" ]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: incompatible input flags specified by the user:"
echo >&2 "-- ${BUILD_NAME} - FATAL: -m | --mpi_enabled : ${MPI_ENABLED}"
echo >&2 "-- ${BUILD_NAME} - FATAL: -c | --caf : ${CAFTYPE}"
echo >&2 "-- ${BUILD_NAME} - FATAL: coarray parallelism cannot be mixed with MPI in the current version of ParaMonte."
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
fi
if [ "${LTYPE}" = "shared" ]; then
if [ "${CAFTYPE}" = "shared" ] || [ "${CAFTYPE}" = "distributed" ]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: incompatible input flags specified by the user:"
echo >&2 "-- ${BUILD_NAME} - FATAL: -l | --lib : ${LTYPE}"
echo >&2 "-- ${BUILD_NAME} - FATAL: -c | --caf : ${CAFTYPE}"
echo >&2 "-- ${BUILD_NAME} - FATAL: ParaMonte shared library build with coarray parallelism currently unsupported."
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
fi
####################################################################################################################################
#### set local dependencies paths
####################################################################################################################################
ParaMonte_REQ_DIR="${ParaMonte_ROOT_DIR}/build/prerequisites"; export ParaMonte_REQ_DIR
ParaMonte_REQ_INSTALL_DIR="${ParaMonte_REQ_DIR}/prerequisites/installations"; export ParaMonte_REQ_INSTALL_DIR
#############################################
#### set up the local CMAKE installation path
#############################################
if [ -d "${ParaMonte_REQ_INSTALL_DIR}" ]; then
CMAKE_LOCAL_INSTALLATION_PATH="$(find "${ParaMonte_REQ_INSTALL_DIR}/" -path **/bin/cmake)"
if [ -f "${CMAKE_LOCAL_INSTALLATION_PATH}" ]; then
CMAKE_LOCAL_INSTALLATION_BIN_DIR="$(dirname "${CMAKE_LOCAL_INSTALLATION_PATH}")"
export CMAKE_LOCAL_INSTALLATION_PATH
export CMAKE_LOCAL_INSTALLATION_BIN_DIR
CMAKE_LOCAL_INSTALLATION_VERSION="$(cmake --version)"
CMAKE_LOCAL_INSTALLATION_VERSION_ARRAY=($CMAKE_LOCAL_INSTALLATION_VERSION)
CMAKE_LOCAL_INSTALLATION_VERSION="${CMAKE_LOCAL_INSTALLATION_VERSION_ARRAY[2]}"
unset CMAKE_LOCAL_INSTALLATION_VERSION_ARRAY
else
unset CMAKE_LOCAL_INSTALLATION_PATH
fi
fi
############################################
#### set up the local GNU installation paths
############################################
if [ -d "${ParaMonte_REQ_INSTALL_DIR}/gnu" ]; then
GNU_LOCAL_INSTALLATION_GFORTRAN_PATH="$(find "${ParaMonte_REQ_INSTALL_DIR}/gnu" -name gfortran)"
if [ -f "${GNU_LOCAL_INSTALLATION_GFORTRAN_PATH}" ]; then
GNU_LOCAL_INSTALLATION_BIN_DIR="$(dirname "${GNU_LOCAL_INSTALLATION_GFORTRAN_PATH}")"
export GNU_LOCAL_INSTALLATION_GFORTRAN_PATH
export GNU_LOCAL_INSTALLATION_BIN_DIR
GNU_LOCAL_INSTALLATION_LIB_DIR="${GNU_LOCAL_INSTALLATION_BIN_DIR}/../lib"
if [ -d "${GNU_LOCAL_INSTALLATION_LIB_DIR}" ]; then
export GNU_LOCAL_INSTALLATION_LIB_DIR
else
unset GNU_LOCAL_INSTALLATION_LIB_DIR
fi
GNU_LOCAL_INSTALLATION_LIB64_DIR="${GNU_LOCAL_INSTALLATION_BIN_DIR}/../lib64"
if [ -d "${GNU_LOCAL_INSTALLATION_LIB64_DIR}" ]; then
export GNU_LOCAL_INSTALLATION_LIB64_DIR
else
unset GNU_LOCAL_INSTALLATION_LIB64_DIR
fi
else
unset GNU_LOCAL_INSTALLATION_GFORTRAN_PATH
fi
fi
############################################
#### set up the local MPI installation paths
############################################
if [ -d "${ParaMonte_REQ_INSTALL_DIR}" ]; then
MPI_LOCAL_INSTALLATION_MPIEXEC_PATH="$(find "${ParaMonte_REQ_INSTALL_DIR}"/ -name mpiexec)"
if [ -f "${MPI_LOCAL_INSTALLATION_MPIEXEC_PATH}" ]; then
MPI_LOCAL_INSTALLATION_BIN_DIR="$(dirname "${MPI_LOCAL_INSTALLATION_MPIEXEC_PATH}")"
export MPI_LOCAL_INSTALLATION_MPIEXEC_PATH
export MPI_LOCAL_INSTALLATION_BIN_DIR
MPI_LOCAL_INSTALLATION_LIB_DIR="${MPI_LOCAL_INSTALLATION_BIN_DIR}/../lib"
if [ -d "${MPI_LOCAL_INSTALLATION_LIB_DIR}" ]; then
export MPI_LOCAL_INSTALLATION_LIB_DIR
else
unset MPI_LOCAL_INSTALLATION_LIB_DIR
fi
MPI_LOCAL_INSTALLATION_LIB64_DIR="${MPI_LOCAL_INSTALLATION_BIN_DIR}/../lib64"
if [ -d "${MPI_LOCAL_INSTALLATION_LIB64_DIR}" ]; then
export MPI_LOCAL_INSTALLATION_LIB64_DIR
else
unset MPI_LOCAL_INSTALLATION_LIB64_DIR
fi
else
unset MPI_LOCAL_INSTALLATION_MPIEXEC_PATH
fi
fi
############################################
#### set up the local CAF installation paths
############################################
if [ -d "${ParaMonte_REQ_INSTALL_DIR}/opencoarrays" ]; then
CAF_LOCAL_INSTALLATION_WRAPPER_PATH="$(find "${ParaMonte_REQ_INSTALL_DIR}"/opencoarrays/ -path **/bin/caf)"
if [ -f "${CAF_LOCAL_INSTALLATION_WRAPPER_PATH}" ]; then
CAF_LOCAL_INSTALLATION_BIN_DIR="$(dirname "${CAF_LOCAL_INSTALLATION_WRAPPER_PATH}")"
export CAF_LOCAL_INSTALLATION_BIN_DIR
CAF_LOCAL_INSTALLATION_LIB_DIR="${CAF_LOCAL_INSTALLATION_BIN_DIR}/../lib"
if [ -d "${CAF_LOCAL_INSTALLATION_LIB_DIR}" ]; then
export CAF_LOCAL_INSTALLATION_LIB_DIR
else
unset CAF_LOCAL_INSTALLATION_LIB_DIR
fi
CAF_LOCAL_INSTALLATION_LIB64_DIR="${CAF_LOCAL_INSTALLATION_BIN_DIR}/../lib64"
if [ -d "${CAF_LOCAL_INSTALLATION_LIB64_DIR}" ]; then
export CAF_LOCAL_INSTALLATION_LIB64_DIR
else
unset CAF_LOCAL_INSTALLATION_LIB64_DIR
fi
CAF_LOCAL_INSTALLATION_SETUP_FILE="${CAF_LOCAL_INSTALLATION_BIN_DIR}/../setup.sh";
if [ -f "${CAF_LOCAL_INSTALLATION_SETUP_FILE}" ]; then
export CAF_LOCAL_INSTALLATION_SETUP_FILE
else
unset CAF_LOCAL_INSTALLATION_SETUP_FILE
fi
else
unset CAF_LOCAL_INSTALLATION_WRAPPER_PATH
fi
fi
####################################################################################################################################
#### check cmake version
####################################################################################################################################
cmakeVersion="$(cmake --version)"
cmakeVersionArray=($cmakeVersion)
cmakeVersion="${cmakeVersionArray[2]}"
if [ "${cmakeVersion}" = "" ]; then
cmakeInstallEnabled=true
else
cmakeInstallEnabled=false
compareVersions "${cmakeVersion}" "${cmakeVersionParaMonteCompatible}"
if [ "$?" = "2" ]; then
cmakeInstallEnabled=true
echo >&2 "-- ${BUILD_NAME} - failed to detect a ParaMonte-compatible installation of cmake!"
else
echo >&2 "-- ${BUILD_NAME} - the current cmake installation is ParaMonte compatible!"
fi
fi
export cmakeInstallEnabled
echo >&2
echo >&2 "-- ${BUILD_NAME} - cmake path: $(which cmake)"
echo >&2 "-- ${BUILD_NAME} - cmake version current: ${cmakeVersion}"
echo >&2 "-- ${BUILD_NAME} - cmake version required: ${cmakeVersionParaMonteCompatible}"
echo >&2 "-- ${BUILD_NAME} - cmakeInstallEnabled: ${cmakeInstallEnabled}"
####################################################################################################################################
#### set compiler suite
####################################################################################################################################
if [ -z ${PMCS+x} ]; then
SUITE_LIST="intel gnu"
else
if [[ ${PMCS} == [iI][nN][tT][eE][lL] ]]; then
PMCS=intel
SUITE_LIST=${PMCS}
else
if [[ ${PMCS} == [gG][nN][uU] ]]; then
PMCS=gnu
SUITE_LIST=${PMCS}
else
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: the requested compiler suite ${PMCS} is unrecognized."
echo >&2 "-- ${BUILD_NAME} - FATAL: please choose either intel or gnu, or drop the option."
echo >&2 "-- ${BUILD_NAME} - FATAL: The installer will automatically find the proper compiler suite."
echo >&2
usage
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
fi
fi
####################################################################################################################################
#### detect the available compiler suites, C/Fortran compilers and CAF/MPI libraries
####################################################################################################################################
gnuCCompilerName=gcc
gnuFortranCompilerName=gfortran
intelCCompilerName=icc
intelFortranCompilerName=ifort
LANG_LIST="C Fortran"
for SUITE in $SUITE_LIST
do
echo >&2
echo >&2 "-- ${BUILD_NAME}Compiler - checking for the ${SUITE} compilers and libraries presence..."
echo >&2
for LANG in $LANG_LIST
do
suiteLangCompilerName="${SUITE}${LANG}CompilerName"
suiteLangCompilerPath="${SUITE}${LANG}CompilerPath"
suiteLangCompilerVersion="${SUITE}${LANG}CompilerVersion"
if eval "command -v ${!suiteLangCompilerName} >/dev/null 2>&1"; then
eval "unset ${suiteLangCompilerPath}"
eval ${suiteLangCompilerPath}='$(command -v ${!suiteLangCompilerName})'
echo >&2 "-- ${BUILD_NAME}Compiler - the ${SUITE} ${!suiteLangCompilerName} detected at ${suiteLangCompilerPath} = ${!suiteLangCompilerPath}"
#### get compiler version
if [ "${LANG}" = "C" ]; then
eval ${suiteLangCompilerVersion}="$(${!suiteLangCompilerName} -dumpversion)"
echo >&2 "-- ${BUILD_NAME}Compiler - the ${SUITE} ${LANG} compiler version is ${suiteLangCompilerVersion} = ${!suiteLangCompilerVersion}"
elif [ "${LANG}" = "Fortran" ]; then
tempDir=$(mktemp -d "${TMPDIR:-/tmp}/cversion.XXXXXXXXX")
echo >&2 "-- ${BUILD_NAME}Compiler - changing directory to: ${tempDir}"
cd "${tempDir}" && cp "${ParaMonte_ROOT_DIR}/auxil/getCompilerVersion.f90" "./getCompilerVersion.f90"
if ${!suiteLangCompilerPath} getCompilerVersion.f90 -o getCompilerVersion.exe; then
chmod +x getCompilerVersion.exe && ./getCompilerVersion.exe && {
eval ${suiteLangCompilerVersion}='$(head -n 1 getCompilerVersion.tmp)'
echo >&2 "-- ${BUILD_NAME}Compiler - the ${SUITE} ${LANG} compiler version is ${suiteLangCompilerVersion} = ${!suiteLangCompilerVersion}"
isParaMonteCompatibleCompiler=$(head -n 1 isParaMonteCompatibleCompiler.tmp)
isGfortran10=$(head -n 1 isGfortran10.tmp); export isGfortran10
if [ "$isParaMonteCompatibleCompiler" = "true" ]; then
echo >&2 "-- ${BUILD_NAME}Compiler - the ${SUITE} ${LANG} compiler is ParaMonte compatible!"
eval "export ${suiteLangCompilerPath}"
else
echo >&2 "-- ${BUILD_NAME}Compiler - the ${SUITE} ${LANG} compiler is not ParaMonte compatible. skipping..."
unset ${suiteLangCompilerPath}
fi
rm *.tmp *.exe
} || {
echo >&2 "-- ${BUILD_NAME}Compiler - failed to detect the ${SUITE} ${LANG} compiler version. skipping..."
unset ${suiteLangCompilerPath}
}
else
echo >&2 "-- ${BUILD_NAME}Compiler - failed to detect the ${SUITE} ${LANG} compiler version. skipping..."
unset ${suiteLangCompilerPath}
fi
echo >&2 "-- ${BUILD_NAME}Compiler - changing directory to: ${ParaMonte_ROOT_DIR}"
cd "${ParaMonte_ROOT_DIR}"
rm -rf "${tempDir}"
fi
else
echo >&2 "-- ${BUILD_NAME}Compiler - the ${SUITE} ${!suiteLangCompilerName} not found. skipping..."
unset ${suiteLangCompilerPath}
fi
done
done
####################################################################################################################################
#### if no compiler has been identified and version extraction has failed,
#### try one last time by searching for the alternative compiler names.
####################################################################################################################################
if [[ "${SUITE_LIST}" =~ .*"gnu".* ]] && [ -z ${gnuFortranCompilerPath+x} ]; then
echo >&2
echo >&2 "-- ${BUILD_NAME}Compiler - searching all system paths for a the gnu Fortran compiler..."
echo >&2
#### return a comma-separated list of available compiler paths
clist=$(( IFS=:; for p in $PATH; do unset lsout; lsout=$(ls -dm "$p"/${gnuFortranCompilerName}*); if ! [[ -z "${lsout// }" ]]; then echo "${lsout}, "; fi; done ) 2>/dev/null)
for cname in $(echo $clist | sed "s/,/ /g"); do
echo >&2 "-- ${BUILD_NAME}Compiler - checking ${cname}"
gnuFortranCompilerVersion="$("${cname}" -dumpversion)" && \
gnuFortranCompilerPath="$(command -v "${cname}")" && \
gnuFortranCompilerName="$(basename "${cname}")" && \
{
echo >&2 "-- ${BUILD_NAME}Compiler - the gnu Fortran compiler version: ${gnuFortranCompilerVersion}"
echo >&2 "-- ${BUILD_NAME}Compiler - the gnu Fortran compiler path: ${gnuFortranCompilerPath}"
echo >&2 "-- ${BUILD_NAME}Compiler - the gnu Fortran compiler name: ${gnuFortranCompilerName}"
compareVersions "${gnuFortranCompilerVersion}" "${gnuVersionParaMonteCompatible}"
if [ "$?" = "2" ]; then
echo >&2 "-- ${BUILD_NAME}Compiler - the gnu Fortran compiler is not ParaMonte compatible. skipping..."
unset gnuFortranCompilerVersion
unset gnuFortranCompilerPath
else
echo >&2 "-- ${BUILD_NAME}Compiler - the gnu Fortran compiler is ParaMonte compatible!"
export gnuFortranCompilerVersion
export gnuFortranCompilerPath
export gnuFortranCompilerName
#### check for a companion C processor
#gnuFortranCompilerDir="$(dirname "${gnuFortranCompilerPath}")"
gnuCCompanionDetected=false
tempFilePath="${gnuFortranCompilerPath//gfortran/gcc}"
if [ -f "${tempFilePath}" ]; then
tempFileVersion="$("${tempFilePath}" -dumpversion)" && \
{
gnuCCompanionDetected=true
gnuCCompilerVersion="${tempFileVersion}"
gnuCCompilerPath="${tempFilePath}"
gnuCCompilerName="$(basename "${tempFilePath}")"
}
fi
if [ "${gnuCCompanionDetected}" = "true" ]; then
echo >&2 "-- ${BUILD_NAME}Compiler - a companion gnu C processor detected!"
echo >&2 "-- ${BUILD_NAME}Compiler - the gnu C compiler version: ${gnuCCompilerVersion}"
echo >&2 "-- ${BUILD_NAME}Compiler - the gnu C compiler path: ${gnuCCompilerPath}"
echo >&2 "-- ${BUILD_NAME}Compiler - the gnu C compiler name: ${gnuCCompilerName}"
export gnuCCompilerVersion
export gnuCCompilerPath
export gnuCCompilerName
else
echo >&2 "-- ${BUILD_NAME}Compiler - no companion gnu C processor detected. skipping..."
fi
break
fi
} || {
echo >&2 "-- ${BUILD_NAME}Compiler - the gnu Fortran compiler version extraction failed. skipping..."
unset ${suiteLangCompilerVersion}
unset ${suiteLangCompilerPath}
continue
}
done
fi