forked from cdslaborg/paramonte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildParaMonte.sh
executable file
·2228 lines (1930 loc) · 99.5 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/master/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, dynamic 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 build type: release, debug, testing :: set library type: static, dynamic
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
BUILD_NAME="ParaMonte"; export BUILD_NAME
FILE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ParaMonte_ROOT_DIR="${FILE_DIR}"
ParaMonte_SRC_DIR="${ParaMonte_ROOT_DIR}/src/ParaMonte"
export ParaMonte_ROOT_DIR
#export ParaMonte_ROOT_DIR="${ParaMonte_ROOT_DIR:-${PWD%/}}"
if [[ ! -f "$(pwd)/build${BUILD_NAME}.sh" ]]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: build failed."
echo >&2 "-- ${BUILD_NAME} - FATAL: Please run this script inside the top-level ParaMonte library root directory."
echo >&2 "-- ${BUILD_NAME} - FATAL: This is the directory which contains this file in the GitHub repository of ParaMonte."
echo >&2
exit 1
fi
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} - supported platforms include: Linux, Darwin, CYGWIN, MINGW"
echo >&2 "-- ${BUILD_NAME} - 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
if [[ "${UNAME_PLATFORM}" =~ .*"Darwin".* ]]; then
isMacOS=true
OSNAME="macOS"
else
isMacOS=false
OSNAME="Linux"
fi
ARCHITECTURE=$(uname -p)
if [[ "$ARCHITECTURE" =~ .*"64".* ]]; then
ARCHITECTURE="x64"
else
ARCHITECTURE=$(uname -m)
if [[ "$ARCHITECTURE" =~ .*"64".* ]]; then ARCHITECTURE="x64"; fi
fi
export ARCHITECTURE
read -r ParaMonteVersion < .VERSION
# set ParaMonte version (to be used by cmake)
unset FPP_PARAMONTE_VERSION_FLAG
if [ -z ${ParaMonteVersion+x} ]; then
export ParaMonteVersion
fi
#echo "$(cat ./auxil/.ParaMonteBanner)"
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} - current directory: ${FILE_DIR}"
echo >&2 "-- ${BUILD_NAME} - current system's platform: ${OSNAME}"
echo >&2 "-- ${BUILD_NAME} - current system's architecture: ${ARCHITECTURE}"
####################################################################################################################################
# Configure ParaMonte Build
####################################################################################################################################
chmod a+x ./configParaMonte.sh
echo >&2
echo >&2 "-- ${BUILD_NAME} - configuring ParaMonte Build..."
echo >&2
echo >&2 "-- ${BUILD_NAME} - default configuration: "
#output=$("./configParaMonte.sh")
#echo "${output}"
. ./configParaMonte.sh
usage()
{
cat << EndOfMessage
usage:
buildParaMonte.sh
-L <language: C/Fortran/MATLAB/Python>
-s <compiler suite: intel/gnu>
-b <build mode: release/testing/debug>
-l <library type: static/dynamic>
-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: true/false>
-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>
-a <clean bash variables upon exit from the script>
-h <help on the script usage>
example:
buildParaMonte.sh -b release -l dynamic -c none -m true -i true -d true -n 3
flag definitions:
-L | --lang : the ParaMonte library interface programming language: 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, 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_enabled : the ParaMonte library test run enabled?: true, false
-x | --exam_enabled : the ParaMonte library examples run enabled?: true, false
-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
-a | --clean : clean the environmental variables upon exit, if flag is provided.
-h | --help : help with the script usage
EndOfMessage
}
unset PMCS
unset MPIEXEC_PATH
unset GCC_BOOTSTRAP
unset INTERFACE_LANGUAGE
unset Fortran_COMPILER_PATH
FRESH_INSTALL_ENABLED=false
YES_TO_ALL_DISABLED=true
CLEAN=false
while [ "$1" != "" ]; do
case $1 in
-L | --lang ) shift
INTERFACE_LANGUAGE=$1
;;
-s | --compiler_suite ) shift
PMCS=$1
;;
-b | --build ) shift
BTYPE=$1
;;
-l | --lib ) shift
LTYPE=$1
;;
-c | --caf ) shift
CAFTYPE=$1
;;
-m | --mpi_enabled ) shift
MPI_ENABLED=$1
;;
-i | --cfi_enabled ) shift
CFI_ENABLED=$1
;;
-e | --heap_enabled ) shift
HEAP_ARRAY_ENABLED=$1
;;
-t | --test_enabled ) shift
ParaMonteTest_RUN_ENABLED=$1; export ParaMonteTest_RUN_ENABLED
;;
-x | --exam_enabled ) shift
ParaMonteExample_RUN_ENABLED=$1; export ParaMonteExample_RUN_ENABLED
;;
-f | --fortran ) shift
Fortran_COMPILER_PATH=$1; export Fortran_COMPILER_PATH
;;
-M | --mpiexec ) shift
MPIEXEC_PATH=$1; export MPIEXEC_PATH
;;
-n | --nproc ) shift
FOR_COARRAY_NUM_IMAGES=$1
;;
-F | --fresh ) FRESH_INSTALL_ENABLED=true; export FRESH_INSTALL_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
export PMCS
export BTYPE
export LTYPE
export CAFTYPE
export MPI_ENABLED
export CFI_ENABLED
export FOR_COARRAY_NUM_IMAGES
echo >&2
echo >&2 "-- ${BUILD_NAME} - current requested configuration: "
#OUTPUT=$("./configParaMonte.sh")
#echo "${OUTPUT}"
. ./configParaMonte.sh
# check flag consistencies
if [ -z ${INTERFACE_LANGUAGE+x} ]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: The INTERFACE_LANGUAGE must be specified as input."
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
if [ "${isMacOS}" = "true" ]; then
if [[ "${PMCS}" =~ .*"intel".* ]]; 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}" = "dynamic" ]; 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 dynamic library build with coarray parallelism currently unsupported."
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
fi
####################################################################################################################################
# define 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 "-- ${BUILD_NAME} - ParaMonte $2 appears to have succeeded."
else
echo >&2
echo >&2 " -- ${BUILD_NAME} - FATAL: ParaMonte $2 appears to have failed."
echo >&2 " -- ${BUILD_NAME} - FATAL: If the source of the error cannot be identified,"
echo >&2 " -- ${BUILD_NAME} - FATAL: consider a fresh installation of ParaMonte's required compilers by calling"
echo >&2 " -- ${BUILD_NAME} - FATAL: "
echo >&2 " -- ${BUILD_NAME} - FATAL: ./install --fresh"
echo >&2 " -- ${BUILD_NAME} - FATAL: "
echo >&2 " -- ${BUILD_NAME} - FATAL: If the error happens during the installation of ParaMonte prerequisites"
echo >&2 " -- ${BUILD_NAME} - FATAL: it is possible that the current existing GCC compiler collection installed"
echo >&2 " -- ${BUILD_NAME} - FATAL: on your system cannot compile the downloaded version of GCC that is required"
echo >&2 " -- ${BUILD_NAME} - FATAL: for ParaMonte build. In such case, make sure you have a GCC compiler collection"
echo >&2 " -- ${BUILD_NAME} - FATAL: version 7.1 or newer installed on your system, with an updated PATH environmental"
echo >&2 " -- ${BUILD_NAME} - FATAL: variable, then reinstall ParaMonte."
echo >&2 " -- ${BUILD_NAME} - FATAL: "
echo >&2 " -- ${BUILD_NAME} - FATAL: If all ParaMonte installation attempts fail, please report this issue at"
echo >&2 " -- ${BUILD_NAME} - FATAL: "
echo >&2 " -- ${BUILD_NAME} - FATAL: https://github.com/shahmoradi/paramonte/issues"
echo >&2 " -- ${BUILD_NAME} - FATAL: "
echo >&2 " -- ${BUILD_NAME} - FATAL: or by contacting the ParaMonte authors directly (e.g., [email protected])."
echo >&2
echo >&2 " -- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
}
####################################################################################################################################
# check cmake version
####################################################################################################################################
cmakeVersion="$(cmake --version)"
#cmakeVersion=${cmakeVersion:14:18}
##echo >&2 "cmake version: ${cmakeVersion}"
#cmakeVersion=${cmakeVersion#c*[0-9]}
#cmakeVersion=${cmakeVersion%\-*}
cmakeVersionArray=($cmakeVersion)
cmakeVersion=${cmakeVersionArray[2]}
cmakeVersionRequired=3.14.0
echo "-- ${BUILD_NAME} - cmake version: ${cmakeVersion}"
echo "-- ${BUILD_NAME} - cmake version required: ${cmakeVersionRequired}"
if [ "${cmakeVersion}" = "" ]; then
cmakeInstallEnabled=true
else
cmakeInstallEnabled=false
compareVersions "${cmakeVersion}" "${cmakeVersionRequired}"
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
####################################################################################################################################
# set local dependencies
####################################################################################################################################
ParaMonte_REQ_DIR="${ParaMonte_ROOT_DIR}/build/prerequisites"
export ParaMonte_REQ_DIR
ParaMonte_REQ_INSTALL_DIR="${ParaMonte_REQ_DIR}/prerequisites/installations"
ParaMonte_GNU_ROOT_DIR="${ParaMonte_REQ_INSTALL_DIR}/gnu/8.3.0"
ParaMonte_MPI_ROOT_DIR="${ParaMonte_REQ_INSTALL_DIR}/mpich/3.2"
ParaMonte_CAF_ROOT_DIR="${ParaMonte_REQ_INSTALL_DIR}/opencoarrays/2.8.0"
ParaMonte_CMAKE_ROOT_DIR="${ParaMonte_REQ_INSTALL_DIR}/cmake/${cmakeVersionRequired}"
ParaMonte_GNU_BIN_DIR="${ParaMonte_GNU_ROOT_DIR}/bin"
ParaMonte_CAF_BIN_DIR="${ParaMonte_CAF_ROOT_DIR}/bin"
ParaMonte_MPI_BIN_DIR="${ParaMonte_MPI_ROOT_DIR}/bin"
ParaMonte_CMAKE_BIN_DIR="${ParaMonte_CMAKE_ROOT_DIR}/bin"
ParaMonte_GNU_LIB_DIR="${ParaMonte_GNU_ROOT_DIR}/lib64"
ParaMonte_MPI_LIB_DIR="${ParaMonte_MPI_ROOT_DIR}/lib"
ParaMonte_CAF_LIB_DIR="${ParaMonte_CAF_ROOT_DIR}/lib64"
ParaMonte_CAF_WRAPPER_PATH="${ParaMonte_CAF_BIN_DIR}/caf"
export ParaMonte_CAF_WRAPPER_PATH
ParaMonte_CAF_SETUP_PATH="${ParaMonte_CAF_ROOT_DIR}/setup.sh"
export ParaMonte_CAF_SETUP_PATH
ParaMonte_CMAKE_PATH="${ParaMonte_CMAKE_BIN_DIR}/cmake"
export ParaMonte_CMAKE_PATH
####################################################################################################################################
# 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 "-- ${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
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
fi
fi
####################################################################################################################################
# detect the compiler suites, C/Fortran compilers and CAF/MPI libraries
####################################################################################################################################
#prereqInstallEnabled=false
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 ${SUITE} compilers and libraries presence..."
echo >&2
for LANG in $LANG_LIST
do
suiteLangCompilerName="${SUITE}${LANG}CompilerName"
if eval "command -v ${!suiteLangCompilerName} >/dev/null 2>&1"; then
suiteLangCompilerPath="${SUITE}${LANG}CompilerPath"
eval "unset ${suiteLangCompilerPath}"
eval ${suiteLangCompilerPath}='$(command -v ${!suiteLangCompilerName})'
echo >&2 "-- ${BUILD_NAME}Compiler - ${SUITE} ${!suiteLangCompilerName} detected at: ${suiteLangCompilerPath}=${!suiteLangCompilerPath}"
# get compiler version
suiteLangCompilerVersion="${SUITE}${LANG}CompilerVersion"
if [ "${LANG}" = "C" ]; then
eval ${suiteLangCompilerVersion}="$(${!suiteLangCompilerName} -dumpversion)"
echo >&2 "-- ${BUILD_NAME}Compiler - ${SUITE} ${LANG} compiler version: ${suiteLangCompilerVersion}=${!suiteLangCompilerVersion}"
fi
if [ "${LANG}" = "Fortran" ]; then
cd ./auxil/
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 - ${SUITE} ${LANG} compiler version: ${suiteLangCompilerVersion}=${!suiteLangCompilerVersion}"
isParaMonteCompatibleCompiler=$(head -n 1 isParaMonteCompatibleCompiler.tmp)
if [ "$isParaMonteCompatibleCompiler" = "true" ]; then
echo >&2 "-- ${BUILD_NAME}Compiler - ${SUITE} ${LANG} compiler is ParaMonte compatible!"
eval "export $suiteLangCompilerPath"
else
echo >&2 "-- ${BUILD_NAME}Compiler - ${SUITE} ${LANG} compiler is not ParaMonte compatible...skipping"
unset ${suiteLangCompilerPath}
fi
rm *.tmp *.exe
#cd ..
#break
} || {
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
cd ..
fi
else
echo >&2 "-- ${BUILD_NAME}Compiler - ${SUITE} ${!suiteLangCompilerName} not found."
unset ${suiteLangCompilerPath}
fi
done
done
####################################################################################################################################
# detect MPI wrappers
####################################################################################################################################
gnuCMpiWrapperName="mpic++"
gnuFortranMpiWrapperName=mpifort
intelCMpiWrapperName=mpiicc
intelFortranMpiWrapperName=mpiifort
for SUITE in $SUITE_LIST
do
echo >&2
echo >&2 "-- ${BUILD_NAME}MPI - checking for ${SUITE} MPI wrappers and libraries presence..."
echo >&2
for LANG in $LANG_LIST
do
suiteLangMpiWrapperName="${SUITE}${LANG}MpiWrapperName"
suiteLangMpiWrapperPath="${SUITE}${LANG}MpiWrapperPath"
if eval "command -v ${!suiteLangMpiWrapperName} >/dev/null 2>&1"; then
eval "unset ${suiteLangMpiWrapperPath}"
eval ${suiteLangMpiWrapperPath}='$(command -v ${!suiteLangMpiWrapperName})'
echo >&2 "-- ${BUILD_NAME}MPI - ${SUITE} ${!suiteLangMpiWrapperName} detected at: ${suiteLangMpiWrapperPath}=${!suiteLangMpiWrapperPath}"
else
echo >&2 "-- ${BUILD_NAME}MPI - failed to detect the ${SUITE} ${LANG} MPI wrapper...skipping"
unset ${suiteLangMpiWrapperPath}
fi
done
done
####################################################################################################################################
# detect CAF wrapper
####################################################################################################################################
echo >&2
CAF_ENABLED=false
if [ "${CAFTYPE}" != "none" ]; then
CAF_ENABLED=true
#if [ -z ${intelFortranMpiWrapperPath+x} ]; then
if command -v caf >/dev/null 2>&1; then
cafCompilerPath=$(command -v caf)
echo >&2 "-- ${BUILD_NAME}CAF - OpenCoarrays Fortran compiler wrapper detected at: ${cafCompilerPath}"
cafVersion="$(caf -dumpversion)"
cafVersionRequired="7.3.0"
echo >&2 "-- ${BUILD_NAME}CAF - caf version: ${cafVersion}"
echo >&2 "-- ${BUILD_NAME}CAF - caf version required: ${cafVersionRequired}"
compareVersions "$cafVersion" "$cafVersionRequired"
if [ "$?" = "2" ]; then
cafInstallEnabled=true
mpiInstallEnabled=true
gnuInstallEnabled=true
#PMCS=caf
#COMPILER_VERSION=unknownversion
else
#if [ "$(printf '%s\n' "$cafVersionRequired" "$currentver" | sort -V | head -n1)" = "$cafVersionRequired" ]; then
echo >&2 "-- ${BUILD_NAME}CAF - OpenCoarrays Fortran compiler wrapper is ParaMonte compatible!"
fi
else
cafInstallEnabled=true
mpiInstallEnabled=true
gnuInstallEnabled=true
fi
#fi
if [ "${cafInstallEnabled}" = "true" ]; then
echo >&2 "-- ${BUILD_NAME}CAF - NOTE: OpenCoarrays caf compiler wrapper could not be found on your system."
echo >&2
fi
fi
export CAF_ENABLED
####################################################################################################################################
# set ParaMonte compiler suite
####################################################################################################################################
prereqInstallAllowed=false
if [ -z ${PMCS+x} ]; then prereqInstallAllowed=true; fi
if [ "${isMacOS}" = "true" ]; then prereqInstallAllowed=true; fi
if [ -z ${Fortran_COMPILER_PATH+x} ]; then
if [ -z ${PMCS+x} ]; then
# if no preference, then priority is with intel
if ! ${intelFortranCompilerPath+false}; then
if [ "${MPI_ENABLED}" = "true" ] || [ "${CAF_ENABLED}" = "true" ]; then
if ! ${intelFortranMpiWrapperPath+false}; then
PMCS=intel
COMPILER_VERSION=${intelFortranCompilerVersion}
Fortran_COMPILER_PATH="${intelFortranCompilerPath}"
MPIEXEC_PATH=$(dirname "${intelFortranMpiWrapperPath}")/mpiexec
#MPIEXEC_PATH=$(command -v mpiexec)
prereqInstallAllowed=false
else
PMCS=gnu
fi
else
PMCS=intel
COMPILER_VERSION=${intelFortranCompilerVersion}
Fortran_COMPILER_PATH="${intelFortranCompilerPath}"
prereqInstallAllowed=false
fi
else
PMCS=gnu
fi
else
errorOccurred=false
if [ "${PMCS}" = "intel" ]; then
if ! ${intelFortranCompilerPath+false}; then
if [ "${MPI_ENABLED}" = "true" ] || [ "${CAF_ENABLED}" = "true" ]; then
if ! ${intelFortranMpiWrapperPath+false}; then
COMPILER_VERSION=${intelFortranCompilerVersion}
Fortran_COMPILER_PATH="${intelFortranCompilerPath}"
if [ -f "${intelFortranMpiWrapperPath}" ]; then
MPIEXEC_PATH=$(dirname "${intelFortranMpiWrapperPath}")/mpiexec
else
unset MPIEXEC_PATH
fi
else
errorOccurred=true
fi
else
COMPILER_VERSION=${intelFortranCompilerVersion}
Fortran_COMPILER_PATH="${intelFortranCompilerPath}"
fi
else
errorOccurred=true
fi
fi
if [ "${errorOccurred}" = "true" ]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - FATAL: the Fortran compiler and wrapper components of the"
echo >&2 "-- ${BUILD_NAME} - FATAL: requested compiler suite ${PMCS} could not be detected."
echo >&2 "-- ${BUILD_NAME} - FATAL: Please make sure the ${PMCS} compiler suite is installed on your system"
echo >&2 "-- ${BUILD_NAME} - FATAL: and avariable in the environmental variable PATH of your shell."
echo >&2
echo >&2 "-- ${BUILD_NAME} - gracefully exiting."
echo >&2
exit 1
fi
fi
if [ "${PMCS}" = "gnu" ]; then
if ! ${gnuFortranCompilerPath+false}; then
COMPILER_VERSION=${gnuFortranCompilerVersion}
Fortran_COMPILER_PATH="${gnuFortranCompilerPath}"
gnuInstallEnabled=false
else
gnuInstallEnabled=true
if [ "${prereqInstallAllowed}" = "false" ]; then # xxx should this be true?
echo >&2
echo >&2 "-- ${BUILD_NAME} - WARNING: GNU Fortran compiler could not be found on your system."
echo >&2 "-- ${BUILD_NAME} - WARNING: If you do not have GNU compiler suite installed on your system,"
echo >&2 "-- ${BUILD_NAME} - WARNING: ParaMonte may be able to install the compiler suite for you. To do so,"
echo >&2 "-- ${BUILD_NAME} - WARNING: drop the input argument -s or --compiler_suite when calling the script."
echo >&2
fi
fi
if [ "${MPI_ENABLED}" = "true" ]; then
if [ -f "${gnuFortranMpiWrapperPath}" ]; then
MPIEXEC_PATH=$(dirname "${gnuFortranMpiWrapperPath}")/mpiexec
mpiInstallEnabled=false
else
unset MPIEXEC_PATH
mpiInstallEnabled=true
gnuInstallEnabled=true
if [ "${prereqInstallAllowed}" = "false" ]; then # xxx should this be true?
echo >&2
echo >&2 "-- ${BUILD_NAME} - WARNING: The mpiexec executable could not be found on your system."
echo >&2 "-- ${BUILD_NAME} - WARNING: If you do not have an MPI library installed on your system,"
echo >&2 "-- ${BUILD_NAME} - WARNING: ParaMonte may be able to install one for you. To do so, drop the"
echo >&2 "-- ${BUILD_NAME} - WARNING: input argument -s or --compiler_suite when calling the script."
echo >&2
fi
fi
else
mpiInstallEnabled=false
fi
if [ "${CAF_ENABLED}" = "true" ]; then
if ! ${cafCompilerPath+false}; then
COMPILER_VERSION=unknownversion
Fortran_COMPILER_PATH="${cafCompilerPath}"
cafInstallEnabled=false
else
cafInstallEnabled=true
mpiInstallEnabled=true
gnuInstallEnabled=true
fi
fi
fi
else # if fortran compiler path defined
cafInstallEnabled=false
mpiInstallEnabled=false
gnuInstallEnabled=false
PMCS=unknownsuite
COMPILER_VERSION=unknownversion
Fortran_COMPILER_NAME=${Fortran_COMPILER_PATH##*/}
echo >&2
echo >&2 "-- ${BUILD_NAME}Compiler - user-requested compiler path: ${Fortran_COMPILER_PATH}"
echo >&2 "-- ${BUILD_NAME}Compiler - user-requested compiler name: ${Fortran_COMPILER_NAME}"
if [ "${Fortran_COMPILER_NAME}" = "gfortran" ] || [ "${Fortran_COMPILER_NAME}" = "caf" ]; then
PMCS=gnu
fi
if [ "${Fortran_COMPILER_NAME}" = "ifort" ]; then
PMCS=intel
fi
if [ "${MPI_ENABLED}" = "true" ] && [ -z ${MPIEXEC_PATH+x} ]; then
mpiInstallEnabled=true
gnuInstallEnabled=true
fi
fi
#if [ "${MPI_ENABLED}" = "true" ]; then
# if ! ${intelFortranMpiWrapperPath+false} && ! ${intelFortranCompilerPath+false}; then
# PMCS=intel
# COMPILER_VERSION=${intelFortranCompilerVersion}
# else
# #if ! ${gnuFortranMpiWrapperPath+false} && ! ${gnuFortranCompilerPath+false}; then
# PMCS=gnu
# COMPILER_VERSION=${gnuFortranCompilerVersion}
# #fi
# fi
#else
# if ! ${intelFortranCompilerPath+false}; then
# PMCS=intel
# COMPILER_VERSION=${intelFortranCompilerVersion}
# else
# if ! ${gnuFortranCompilerPath+false}; then
# PMCS=gnu
# COMPILER_VERSION=${gnuFortranCompilerVersion}
# fi
# fi
#fi
#if [ "${MPI_ENABLED}" = "true" ]; then
# echo >&2
# echo >&2 "-- ${BUILD_NAME}MPI - intel Fortran MPI compiler wrapper: ${intelFortranMpiWrapperPath}"
# echo >&2 "-- ${BUILD_NAME}MPI - intel Fortran compiler: ${intelFortranCompilerPath}"
# echo >&2
# echo >&2 "-- ${BUILD_NAME}MPI - gnu Fortran MPI compiler wrapper: ${gnuFortranMpiWrapperPath}"
# echo >&2 "-- ${BUILD_NAME}MPI - gnu Fortran compiler: ${gnuFortranCompilerPath}"
# echo >&2
# if [ -z ${intelFortranMpiWrapperPath+x} ] || [ -z ${intelFortranCompilerPath+x} ]; then
# #if [ -z ${gnuFortranMpiWrapperPath+x} ] || [ -z ${gnuFortranCompilerPath+x} ]; then
# mpiInstallEnabled=true
# gnuInstallEnabled=true
# #fi
# fi
#fi
####################################################################################################################################
# set up ParaMonte library prerequisites
####################################################################################################################################
if [ "${FRESH_INSTALL_ENABLED}" = "true" ]; then
prereqInstallAllowed=true
cmakeInstallEnabled=true
cafInstallEnabled=true
mpiInstallEnabled=true
gnuInstallEnabled=true
fi
# chmod 777 -R "${ParaMonte_ROOT_DIR}/auxil/prerequisites"
if [ "${prereqInstallAllowed}" = "true" ]; then
if [ "${cafInstallEnabled}" = "true" ] || [ "${mpiInstallEnabled}" = "true" ] || [ "${gnuInstallEnabled}" = "true" ] || [ "${cmakeInstallEnabled}" = "true" ]; then
#ParaMonte_REQ_DIR="${ParaMonte_ROOT_DIR}/build/prerequisites"
#ParaMonte_CAF_SETUP_PATH="${ParaMonte_REQ_DIR}/prerequisites/installations/opencoarrays/2.8.0/setup.sh"
if [ "${FRESH_INSTALL_ENABLED}" = "true" ]; then
rm -rf "${ParaMonte_REQ_DIR}"
fi
answer=y
if [ ! -d "${ParaMonte_REQ_DIR}" ]; then
echo >&2
echo >&2 "-- ${BUILD_NAME} - WARNING: ParaMonte build with the requested configuration requires the installations"
echo >&2 "-- ${BUILD_NAME} - WARNING: of either OpenCoarrays, MPICH MPI library (on Linux) or Open-MPI MPI library (on macOS),"
echo >&2 "-- ${BUILD_NAME} - WARNING: GNU compilers, or CMAKE on your system."
echo >&2 "-- ${BUILD_NAME} - WARNING: ParaMonte can install all the prerequisites on your system from the web, if needed."
echo >&2 "-- ${BUILD_NAME} - WARNING: The prerequisites build objects may occupy up to 5Gb of your system's memory."
echo >&2
if [ "${YES_TO_ALL_DISABLED}" = "true" ]; then
answerNotGiven=true
while [ "${answerNotGiven}" = "true" ]; do
read -p "-- ${BUILD_NAME} - Do you wish to continue with the installation of the prerequisites (y/n)? " answer
if [[ $answer == [yY] || $answer == [yY][eE][sS] ]]; then
answer=y
answerNotGiven=false
fi
if [[ $answer == [nN] || $answer == [nN][oO] ]]; then
answer=n
answerNotGiven=false
fi
if [ "${answerNotGiven}" = "true" ]; then
echo >&2 "-- ${BUILD_NAME} - please enter either y or n"
fi
done
else
echo >&2 "-- ${BUILD_NAME} - Do you wish to continue with the installation of the prerequisites (y/n)? y"
answer=y
fi
echo >&2
if [ "${answer}" = "y" ]; then
echo >&2 "-- ${BUILD_NAME} - generating directory: ${ParaMonte_REQ_DIR}/"
mkdir -p "${ParaMonte_REQ_DIR}/"
tarFileName="opencoarrays.tar.gz"
#tarFileName="prerequisites.tar.gz"
cp -rv "${ParaMonte_ROOT_DIR}/auxil/${tarFileName}" "${ParaMonte_REQ_DIR}/../"
verify $? "installation setup of prerequisites"
if ! [ -d "${ParaMonte_REQ_DIR}" ]; then
mkdir "${ParaMonte_REQ_DIR}"
fi
(cd "${ParaMonte_REQ_DIR}/../" && tar xvzf "${tarFileName}" -C prerequisites --strip-components 1)
verify $? "unpacking of prerequisites"
# chmod +x -R "${ParaMonte_REQ_DIR}"
else
echo >&2 "-- ${BUILD_NAME} - WARNING: ParaMonte installation will proceed with no guarantee of success."