3434# 2. The environment variable "FC" is used to determine the identity fo the Fortran compiler/linker.
3535# 3. If "FC" is empty, a default value of "mpifort" is used.
3636
37+ # Exit on error. Append "|| true" if you expect an error.
38+ set -o errexit
39+ # Exit on error inside any functions or subshells.
40+ set -o errtrace
41+ # Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
42+ set -o nounset
43+ # Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
44+ set -o pipefail
45+ # Turn on traces, useful while debugging but commented out by default
46+ # set -o xtrace
47+
3748
3849# ---------------------
3950# Configured variables
4455#
4556
4657caf_version=' @CAF_VERSION@'
47- CAFRUN=' @MPIEXEC@'
48- if [[ ${CAFRUN} == @* @ ]]; then
58+ CAFRUN=" @MPIEXEC@"
59+ if [[ " ${CAFRUN} " == @* @ ]]; then
4960 CAFRUN=mpiexec
5061fi
5162have_failed_img=@HAVE_FAILED_IMG@
@@ -56,17 +67,82 @@ numproc_flag='@MPIEXEC_NUMPROC_FLAG@'
5667if [[ ${numproc_flag} == @* @ ]]; then
5768 numproc_flag=' -np'
5869fi
59- preflags=' @MPIEXEC_PREFLAGS@'
60- if [[ ${preflags} == @* @ ]]; then
70+ preflags=" @MPIEXEC_PREFLAGS@"
71+ if [[ " ${preflags} " == @* @ ]]; then
6172 unset preflags
6273fi
63- postflags=' @MPIEXEC_POSTFLAGS@'
64- if [[ ${postflags} == @* @ ]]; then
74+ postflags=" @MPIEXEC_POSTFLAGS@"
75+ if [[ " ${postflags} " == @* @ ]]; then
6576 unset postflags
6677fi
78+ # -------------------------
79+ # End configured variables
80+ # -------------------------
81+
82+ if [[ " ${BASH_SOURCE[0]} " != " ${0} " ]]; then
83+ __i_am_main_script=" 0" # false
84+
85+ # shellcheck disable=SC2154
86+ if [[ " ${__usage+x} " ]]; then
87+ if [[ " ${BASH_SOURCE[1]} " == " ${0} " ]]; then
88+ __i_am_main_script=" 1" # true
89+ fi
90+ __caf_tmp_source_idx=1
91+ fi
92+ else
93+ # shellcheck disable=SC2034
94+ __i_am_main_script=" 1" # true
95+ fi
96+
97+ # Set magic variables for current file, directory, os, etc.
98+ __dir=" $( cd " $( dirname " ${BASH_SOURCE[${__caf_tmp_source_idx:-0}]} " ) " && pwd) "
99+ __file=" ${__dir} /$( basename " ${BASH_SOURCE[${__caf_tmp_source_idx:-0}]} " ) "
100+ # shellcheck disable=SC2034
101+ __base=" $( basename " ${__file} " ) "
102+ cmd=" ${__base} "
103+
104+ # Set installation prefix. Compute this dynamically assuming this script is in a bin/ subdir
105+ # Dereference symbolic links and canonicalize (i.e., abs path) prefix in case stow, homebrew, etc being used
106+ # mac OS doesn't have readlink -f, so need to crawl symlinks manually.
107+ # See: https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
108+ current_dir=" ${PWD} "
109+ cd " ${__dir} " || exit 5
110+ target_file=" ${__file} "
111+ max_iter=1000
112+ iter=0
113+ while [[ -L " ${target_file} " ]]; do
114+ target_file=" $( readlink " ${target_file} " ) "
115+ cd " $( dirname " ${target_file} " ) " || exit 5
116+ target_file=" $( basename " ${target_file} " ) "
117+ if (( ++ iter >= max_iter)) ; then
118+ echo " Failed to compute OpenCoarrays instalation prefix!" >&2
119+ echo " Likely cause: circular symlink cycles." >&2
120+ echo " Aborting!" >&2
121+ exit 200
122+ fi
123+ done
124+ true_dir=" $( pwd -P) "
125+ true_dir=" ${true_dir%/ } "
126+ # shellcheck disable=SC2034
127+ prefix=" ${true_dir%/ bin} "
128+ # echo "Install prefix is ${prefix}" # for debugging
129+ cd " ${current_dir} " || exit 5
130+ # echo "Current directory is $(pwd)"
131+ # echo "This script is in ${__dir}"
132+
133+ # Error tracing
134+ # requires `set -o errtrace`
135+ __caf_err_report () {
136+ local error_code
137+ error_code=${?}
138+ echo " Error in ${__file} in function ${1} on line ${2} . Please report this error at http://bit.ly/OpenCoarrays-new-issue" >&2
139+ exit ${error_code}
140+ }
141+ # Always provide an error backtrace
142+ trap ' __caf_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
143+
67144
68145usage () {
69- cmd=" $( basename " ${0} " ) "
70146 echo " "
71147 echo " ${cmd} - Coarray Fortran executable launcher for OpenCoarrays"
72148 echo " "
@@ -75,7 +151,7 @@ usage() {
75151 echo " Options:"
76152 echo " --help, -h Show this help message"
77153 echo " --version, -v, -V Report version and copyright information"
78- echo " --wraps, -w, Report the name of the wrapped compiler "
154+ echo " --wraps, -w, Report info about the wrapped MPI launcher "
79155 echo " -np <N>, Number of images, N, to execute, N must be a positive integer"
80156 echo " --reenable-auto-cleanup Turn off failed images support (if library support is present)"
81157 echo " This option re-enables MPI auto cleanup, which is disabled by"
@@ -84,6 +160,9 @@ usage() {
84160 echo " failed image support is present, OpenCoarrays triggers cleanup"
85161 echo " explicitly when a failed/stopped image is encountered in an"
86162 echo " image control statement without a \` stat=\` clause."
163+ ehco " --show, -s, Show the command that the wrapper will execute. You can pass"
164+ echo " this as the first argument and then the additional arguments"
165+ echo " that you're planning to pass to perform a dry run."
87166 echo " "
88167 echo " Example usage:"
89168 echo " "
0 commit comments