3
# Attempt to unwrap the MPI compiler for the current language and determine
4
# the underlying compiler.
6
# The strategy is to first compare the stdout of the version flags using
7
# a custom perl script. Next we combine stdout and sterr for the comparison.
8
# Occasionally, the MPI compiler will always report a non-zero exit status.
9
# That is the last case checked for.
10
AC_DEFUN([GA_MPI_UNWRAP], [
12
AC_PATH_PROG([PERL], [perl])
15
[cat >inside.pl <<"EOF"
17
$numargs = @S|@#ARGV + 1;
19
print "Usage: wrapped.txt naked.txt\n";
22
# Read each input file as a string (rather than a list).
24
open WRAPPED, "$ARGV[0]" or die "Could not open wrapped text file: $!";
25
$wrapped_lines = <WRAPPED>;
27
open NAKED, "$ARGV[1]" or die "Could not open naked text file: $!";
28
$naked_lines = <NAKED>;
30
# Replace newlines, + from wrapped and naked lines.
31
$wrapped_lines =~ tr/\n+/ /;
32
$naked_lines =~ tr/\n+/ /;
33
# Remove whitespace from beginning of wrapped and naked lines.
34
$wrapped_lines =~ s/^\s+//;
35
$naked_lines =~ s/^\s+//;
36
# Remove whitespace from end of wrapped and naked lines.
37
$wrapped_lines =~ s/\s+$//;
38
$naked_lines =~ s/\s+$//;
39
# If either wrapped_lines or naked_lines are empty, this is an error.
40
# It is assumed that the particular version string which created the input
41
# files should generate SOMETHING.
42
unless ($wrapped_lines) {
45
unless ($naked_lines) {
48
# Can the naked lines be found within the wrapped lines?
49
if ($wrapped_lines =~ /\Q$naked_lines\E/) {
50
#print "Found as substring\n";
53
# Are the naked lines exactly the same as the wrapped lines?
54
elsif ($wrapped_lines eq $naked_lines) {
55
#print "Found equal\n";
63
inside="$PERL inside.pl"
66
[C], [AS_CASE([$wrapped],
67
[*_r], [compilers="bgxlc_r xlc_r"],
68
[*], [compilers="bgxlc xlc pgcc pathcc icc sxcc fcc opencc suncc craycc gcc ecc cl ccc cc"])
70
[C++], [AS_CASE([$wrapped],
71
[*_r], [compilers="bgxlC_r xlC_r"],
72
[*], [compilers="icpc pgCC pathCC sxc++ xlC bgxlC openCC sunCC crayCC g++ c++ gpp aCC cxx cc++ cl.exe FCC KCC RCC CC"])
74
[Fortran 77], [AS_CASE([$wrapped],
75
[*_r], [compilers="bgxlf95_r xlf95_r bgxlf90_r xlf90_r bgxlf_r xlf_r"],
76
[*], [compilers="gfortran g95 bgxlf95 xlf95 f95 fort ifort ifc efc pgf95 pathf95 lf95 openf95 sunf95 crayftn bgxlf90 xlf90 f90 pgf90 pathf90 pghpf epcf90 sxf90 openf90 sunf90 g77 bgxlf xlf f77 frt pgf77 pathf77 cf77 fort77 fl32 af77"])
80
AS_VAR_PUSHDEF([ga_save_comp], [ga_save_[]_AC_CC[]])
81
AS_VAR_PUSHDEF([ga_orig_comp], [ga_orig_[]_AC_CC[]])
82
AS_VAR_PUSHDEF([ga_cv_mpi_naked], [ga_cv_mpi[]_AC_LANG_ABBREV[]_naked])
83
AC_CACHE_CHECK([for base $wrapped compiler], [ga_cv_mpi_naked], [
84
base="`$wrapped -show 2>/dev/null | sed 's/@<:@ @:>@.*@S|@//' | head -1`"
85
ga_save_comp="$_AC_CC"
87
AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], [ga_cv_mpi_naked="$base"])
88
_AC_CC="$ga_save_comp"
89
versions="--version -v -V -qversion"
90
found_wrapped_version=0
91
# Try separating stdout and stderr. Only compare stdout.
92
AS_IF([test "x$ga_cv_mpi_naked" = x], [
93
# prepend any CC/CXX/F77 the user may have specified
94
compilers="$ga_orig_comp $compilers"
95
echo "only comparing stdout" >&AS_MESSAGE_LOG_FD
96
for version in $versions
98
echo "trying version=$version" >&AS_MESSAGE_LOG_FD
99
rm -f mpi.txt mpi.err naked.txt naked.err
100
AS_IF([$wrapped $version 1>mpi.txt 2>mpi.err],
101
[found_wrapped_version=1
102
for naked_compiler in $compilers
104
AS_IF([test "x$naked_compiler" != "x$wrapped"],
105
[AS_IF([$naked_compiler $version 1>naked.txt 2>naked.err],
106
[AS_IF([$inside mpi.txt naked.txt >/dev/null],
107
[ga_cv_mpi_naked=$naked_compiler; break],
108
[echo "inside.pl $wrapped $naked_compiler failed, skipping" >&AS_MESSAGE_LOG_FD])],
109
[echo "$naked_compiler $version failed, skipping" >&AS_MESSAGE_LOG_FD])])
111
[echo "$wrapped $version failed, skipping" >&AS_MESSAGE_LOG_FD])
112
AS_IF([test "x$ga_cv_mpi_naked" != x], [break])
115
# Perhaps none of the MPI compilers had a zero exit status (this is bad).
116
# In this case we have to do a brute force match regardless of exit status.
117
AS_IF([test "x$found_wrapped_version" = x0], [
118
AS_IF([test "x$ga_cv_mpi_naked" = x], [
119
echo "no zero exit status found for MPI compilers" >&AS_MESSAGE_LOG_FD
120
for version in $versions
122
echo "trying version=$version" >&AS_MESSAGE_LOG_FD
123
rm -f mpi.txt mpi.err
124
$wrapped $version 1>mpi.txt 2>mpi.err
125
for naked_compiler in $compilers
127
AS_IF([test "x$naked_compiler" != "x$wrapped"],
128
[rm -f naked.txt naked.err
129
AS_IF([$naked_compiler $version 1>naked.txt 2>naked.err],
130
[AS_IF([$inside mpi.txt naked.txt >/dev/null],
131
[ga_cv_mpi_naked=$naked_compiler; break],
132
[echo "inside.pl $wrapped $naked_compiler failed, skipping" >&AS_MESSAGE_LOG_FD])],
133
[echo "$naked_compiler $version failed, skipping" >&AS_MESSAGE_LOG_FD])])
135
AS_IF([test "x$ga_cv_mpi_naked" != x], [break])
139
# Try by combining stdout/err into one file.
140
AS_IF([test "x$ga_cv_mpi_naked" = x], [
141
echo "try combining stdout and stderr into one file" >&AS_MESSAGE_LOG_FD
142
for version in $versions
144
echo "trying version=$version" >&AS_MESSAGE_LOG_FD
145
rm -f mpi.txt naked.txt
146
AS_IF([$wrapped $version 1>mpi.txt 2>&1],
147
[for naked_compiler in $compilers
149
AS_IF([test "x$naked_compiler" != "x$wrapped"],
150
[AS_IF([$naked_compiler $version 1>naked.txt 2>&1],
151
[AS_IF([$inside mpi.txt naked.txt >/dev/null],
152
[ga_cv_mpi_naked=$naked_compiler; break],
153
[echo "inside.pl $wrapped $naked_compiler failed, skipping" >&AS_MESSAGE_LOG_FD])],
154
[echo "$naked_compiler $version failed, skipping" >&AS_MESSAGE_LOG_FD])])
156
[echo "$wrapped $version failed, skipping" >&AS_MESSAGE_LOG_FD])
157
AS_IF([test "x$ga_cv_mpi_naked" != x], [break])
160
# If we got this far, then it's likely that the MPI compiler had a zero exit
161
# status when it shouldn't have for one version flag, but later had a non-zero
162
# exit status for a flag it shouldn't have. One false positive hid a false
163
# negative. In this case, brute force compare all MPI compiler output against
164
# all compiler output.
165
AS_IF([test "x$ga_cv_mpi_naked" = x], [
166
echo "we have a very badly behaving MPI compiler" >&AS_MESSAGE_LOG_FD
167
for version in $versions
169
echo "trying version=$version" >&AS_MESSAGE_LOG_FD
170
rm -f mpi.txt mpi.err
171
$wrapped $version 1>mpi.txt 2>mpi.err
172
for naked_compiler in $compilers
174
AS_IF([test "x$naked_compiler" != "x$wrapped"],
175
[rm -f naked.txt naked.err
176
AS_IF([$naked_compiler $version 1>naked.txt 2>naked.err],
177
[AS_IF([$inside mpi.txt naked.txt >/dev/null],
178
[ga_cv_mpi_naked=$naked_compiler; break],
179
[echo "inside.pl $wrapped $naked_compiler failed, skipping" >&AS_MESSAGE_LOG_FD])],
180
[echo "$naked_compiler $version failed, skipping" >&AS_MESSAGE_LOG_FD])])
182
AS_IF([test "x$ga_cv_mpi_naked" != x], [break])
185
rm -f mpi.txt mpi.err naked.txt naked.err
187
AS_IF([test "x$ga_cv_mpi_naked" = x],
188
[AC_MSG_ERROR([Could not determine the ]_AC_LANG[ compiler wrapped by MPI])],
189
[AS_IF([test "x$ga_orig_comp" != x && test "x$ga_orig_comp" != "x$ga_cv_mpi_naked"],
190
[AC_MSG_WARN([unwrapped $wrapped ($ga_cv_mpi_naked) does not match user-specified $ga_orig_comp])])])
191
AS_VAR_POPDEF([ga_save_comp])
192
AS_VAR_POPDEF([ga_cv_mpi_naked])
197
# GA_MPI_UNWRAP_PUSH()
198
# --------------------
199
# Set CC/CXX/F77/FC to their unwrapped MPI counterparts.
200
# Save their old values for restoring later.
201
AC_DEFUN([GA_MPI_UNWRAP_PUSH], [
202
ga_mpi_unwrap_push_save_CC="$CC"
203
ga_mpi_unwrap_push_save_CXX="$CXX"
204
ga_mpi_unwrap_push_save_F77="$F77"
205
ga_mpi_unwrap_push_save_FC="$FC"
206
AS_IF([test "x$ga_cv_mpic_naked" != x], [ CC="$ga_cv_mpic_naked"])
207
AS_IF([test "x$ga_cv_mpicxx_naked" != x], [CXX="$ga_cv_mpicxx_naked"])
208
AS_IF([test "x$ga_cv_mpif77_naked" != x], [F77="$ga_cv_mpif77_naked"])
209
AS_IF([test "x$ga_cv_mpifc_naked" != x], [ FC="$ga_cv_mpifc_naked"])
213
# GA_MPI_UNWRAP_POP()
214
# -------------------
215
# Restore CC/CXX/F77/FC to their MPI counterparts.
216
AC_DEFUN([GA_MPI_UNWRAP_POP], [
217
CC="$ga_mpi_unwrap_push_save_CC"
218
CXX="$ga_mpi_unwrap_push_save_CXX"
219
F77="$ga_mpi_unwrap_push_save_F77"
220
FC="$ga_mpi_unwrap_push_save_FC"