1 | #################################################################################################
|
---|
2 | # Copyright (c) 2010, Lawrence Livermore National Security, LLC.
|
---|
3 | # Produced at the Lawrence Livermore National Laboratory
|
---|
4 | # Written by Todd Gamblin, tgamblin@llnl.gov.
|
---|
5 | # LLNL-CODE-417602
|
---|
6 | # All rights reserved.
|
---|
7 | #
|
---|
8 | # This file is part of Libra. For details, see http://github.com/tgamblin/libra.
|
---|
9 | # Please also read the LICENSE file for further information.
|
---|
10 | #
|
---|
11 | # Redistribution and use in source and binary forms, with or without modification, are
|
---|
12 | # permitted provided that the following conditions are met:
|
---|
13 | #
|
---|
14 | # * Redistributions of source code must retain the above copyright notice, this list of
|
---|
15 | # conditions and the disclaimer below.
|
---|
16 | # * Redistributions in binary form must reproduce the above copyright notice, this list of
|
---|
17 | # conditions and the disclaimer (as noted below) in the documentation and/or other materials
|
---|
18 | # provided with the distribution.
|
---|
19 | # * Neither the name of the LLNS/LLNL nor the names of its contributors may be used to endorse
|
---|
20 | # or promote products derived from this software without specific prior written permission.
|
---|
21 | #
|
---|
22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
---|
23 | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
---|
24 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
---|
25 | # LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE
|
---|
26 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
27 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
28 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
---|
29 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
---|
30 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
31 | #################################################################################################
|
---|
32 |
|
---|
33 | #
|
---|
34 | # LX_FIND_MPI()
|
---|
35 | # ------------------------------------------------------------------------
|
---|
36 | # This macro finds an MPI compiler and extracts includes and libraries from
|
---|
37 | # it for use in automake projects. The script exports the following variables:
|
---|
38 | #
|
---|
39 | # AC_DEFINE variables:
|
---|
40 | # HAVE_MPI AC_DEFINE'd to 1 if we found MPI
|
---|
41 | #
|
---|
42 | # AC_SUBST variables:
|
---|
43 | # MPICC Name of MPI compiler
|
---|
44 | # MPI_CFLAGS Includes and defines for MPI C compilation
|
---|
45 | # MPI_CLDFLAGS Libraries and library paths for linking MPI C programs
|
---|
46 | #
|
---|
47 | # MPICXX Name of MPI C++ compiler
|
---|
48 | # MPI_CXXFLAGS Includes and defines for MPI C++ compilation
|
---|
49 | # MPI_CXXLDFLAGS Libraries and library paths for linking MPI C++ programs
|
---|
50 | #
|
---|
51 | # MPIF77 Name of MPI Fortran 77 compiler
|
---|
52 | # MPI_F77FLAGS Includes and defines for MPI Fortran 77 compilation
|
---|
53 | # MPI_F77LDFLAGS Libraries and library paths for linking MPI Fortran 77 programs
|
---|
54 | #
|
---|
55 | # MPIFC Name of MPI Fortran compiler
|
---|
56 | # MPI_FFLAGS Includes and defines for MPI Fortran compilation
|
---|
57 | # MPI_FLDFLAGS Libraries and library paths for linking MPI Fortran programs
|
---|
58 | #
|
---|
59 | # Shell variables output by this macro:
|
---|
60 | # have_C_mpi 'yes' if we found MPI for C, 'no' otherwise
|
---|
61 | # have_CXX_mpi 'yes' if we found MPI for C++, 'no' otherwise
|
---|
62 | # have_F77_mpi 'yes' if we found MPI for F77, 'no' otherwise
|
---|
63 | # have_F_mpi 'yes' if we found MPI for Fortran, 'no' otherwise
|
---|
64 | #
|
---|
65 | AC_DEFUN([LX_FIND_MPI],
|
---|
66 | [
|
---|
67 | AC_LANG_CASE(
|
---|
68 | [C], [
|
---|
69 | AC_REQUIRE([AC_PROG_CC])
|
---|
70 | if [[ ! -z "$MPICC" ]]; then
|
---|
71 | LX_QUERY_MPI_COMPILER(MPICC, [$MPICC], C)
|
---|
72 | else
|
---|
73 | LX_QUERY_MPI_COMPILER(MPICC, [mpicc mpiicc mpixlc mpipgcc], C)
|
---|
74 | fi
|
---|
75 | ],
|
---|
76 | [C++], [
|
---|
77 | AC_REQUIRE([AC_PROG_CXX])
|
---|
78 | if [[ ! -z "$MPICXX" ]]; then
|
---|
79 | LX_QUERY_MPI_COMPILER(MPICXX, [$MPICXX], CXX)
|
---|
80 | else
|
---|
81 | LX_QUERY_MPI_COMPILER(MPICXX, [mpicxx mpiCC mpic++ mpig++ mpiicpc mpipgCC mpixlC], CXX)
|
---|
82 | fi
|
---|
83 | ],
|
---|
84 | [F77], [
|
---|
85 | AC_REQUIRE([AC_PROG_F77])
|
---|
86 | if [[ ! -z "$MPIF77" ]]; then
|
---|
87 | LX_QUERY_MPI_COMPILER(MPIF77, [$MPIF77], F77)
|
---|
88 | else
|
---|
89 | LX_QUERY_MPI_COMPILER(MPIF77, [mpif77 mpiifort mpixlf77 mpixlf77_r], F77)
|
---|
90 | fi
|
---|
91 | ],
|
---|
92 | [Fortran], [
|
---|
93 | AC_REQUIRE([AC_PROG_FC])
|
---|
94 | if [[ ! -z "$MPIFC" ]]; then
|
---|
95 | LX_QUERY_MPI_COMPILER(MPIFC, [$MPIFC], F)
|
---|
96 | else
|
---|
97 | mpi_default_fc="mpif95 mpif90 mpigfortran mpif2003"
|
---|
98 | mpi_intel_fc="mpiifort"
|
---|
99 | mpi_xl_fc="mpixlf95 mpixlf95_r mpixlf90 mpixlf90_r mpixlf2003 mpixlf2003_r"
|
---|
100 | mpi_pg_fc="mpipgf95 mpipgf90"
|
---|
101 | LX_QUERY_MPI_COMPILER(MPIFC, [$mpi_default_fc $mpi_intel_fc $mpi_xl_fc $mpi_pg_fc], F)
|
---|
102 | fi
|
---|
103 | ])
|
---|
104 | ])
|
---|
105 |
|
---|
106 |
|
---|
107 | #
|
---|
108 | # LX_QUERY_MPI_COMPILER([compiler-var-name], [compiler-names], [output-var-prefix])
|
---|
109 | # ------------------------------------------------------------------------
|
---|
110 | # AC_SUBST variables:
|
---|
111 | # MPI_<prefix>FLAGS Includes and defines for MPI compilation
|
---|
112 | # MPI_<prefix>LDFLAGS Libraries and library paths for linking MPI C programs
|
---|
113 | #
|
---|
114 | # Shell variables output by this macro:
|
---|
115 | # found_mpi_flags 'yes' if we were able to get flags, 'no' otherwise
|
---|
116 | #
|
---|
117 | AC_DEFUN([LX_QUERY_MPI_COMPILER],
|
---|
118 | [
|
---|
119 | # Try to find a working MPI compiler from the supplied names
|
---|
120 | AC_PATH_PROGS($1, [$2], [not-found])
|
---|
121 |
|
---|
122 | # Figure out what the compiler responds to to get it to show us the compile
|
---|
123 | # and link lines. After this part of the macro, we'll have a valid
|
---|
124 | # lx_mpi_command_line
|
---|
125 | echo -n "Checking whether $$1 responds to '-showme:compile'... "
|
---|
126 | lx_mpi_compile_line=`$$1 -showme:compile 2>/dev/null`
|
---|
127 | if [[ "$?" -eq 0 ]]; then
|
---|
128 | echo yes
|
---|
129 | lx_mpi_link_line=`$$1 -showme:link 2>/dev/null`
|
---|
130 | else
|
---|
131 | echo no
|
---|
132 | echo -n "Checking whether $$1 responds to '-showme'... "
|
---|
133 | lx_mpi_command_line=`$$1 -showme 2>/dev/null`
|
---|
134 | if [[ "$?" -ne 0 ]]; then
|
---|
135 | echo no
|
---|
136 | echo -n "Checking whether $$1 responds to '-compile-info'... "
|
---|
137 | lx_mpi_compile_line=`$$1 -compile-info 2>/dev/null`
|
---|
138 | if [[ "$?" -eq 0 ]]; then
|
---|
139 | echo yes
|
---|
140 | lx_mpi_link_line=`$$1 -link-info 2>/dev/null`
|
---|
141 | else
|
---|
142 | echo no
|
---|
143 | echo -n "Checking whether $$1 responds to '-show'... "
|
---|
144 | lx_mpi_command_line=`$$1 -show 2>/dev/null`
|
---|
145 | if [[ "$?" -eq 0 ]]; then
|
---|
146 | echo yes
|
---|
147 | else
|
---|
148 | echo no
|
---|
149 | fi
|
---|
150 | fi
|
---|
151 | else
|
---|
152 | echo yes
|
---|
153 | fi
|
---|
154 | fi
|
---|
155 |
|
---|
156 | if [[ ! -z "$lx_mpi_compile_line" -a ! -z "$lx_mpi_link_line" ]]; then
|
---|
157 | lx_mpi_command_line="$lx_mpi_compile_line $lx_mpi_link_line"
|
---|
158 | fi
|
---|
159 |
|
---|
160 | if [[ ! -z "$lx_mpi_command_line" ]]; then
|
---|
161 | # Now extract the different parts of the MPI command line. Do these separately in case we need to
|
---|
162 | # parse them all out in future versions of this macro.
|
---|
163 | lx_mpi_defines=` echo "$lx_mpi_command_line" | grep -o -- '\(^\| \)-D\([[^\"[:space:]]]\+\|\"[[^\"[:space:]]]\+\"\)'`
|
---|
164 | lx_mpi_includes=` echo "$lx_mpi_command_line" | grep -o -- '\(^\| \)-I\([[^\"[:space:]]]\+\|\"[[^\"[:space:]]]\+\"\)'`
|
---|
165 | lx_mpi_link_paths=` echo "$lx_mpi_command_line" | grep -o -- '\(^\| \)-L\([[^\"[:space:]]]\+\|\"[[^\"[:space:]]]\+\"\)'`
|
---|
166 | lx_mpi_libs=` echo "$lx_mpi_command_line" | grep -o -- '\(^\| \)-l\([[^\"[:space:]]]\+\|\"[[^\"[:space:]]]\+\"\)'`
|
---|
167 | lx_mpi_link_args=` echo "$lx_mpi_command_line" | grep -o -- '\(^\| \)-Wl,\([[^\"[:space:]]]\+\|\"[[^\"[:space:]]]\+\"\)'`
|
---|
168 |
|
---|
169 | # Create variables and clean up newlines and multiple spaces
|
---|
170 | MPI_$3FLAGS="$lx_mpi_defines $lx_mpi_includes"
|
---|
171 | MPI_$3LDFLAGS="$lx_mpi_link_paths $lx_mpi_libs $lx_mpi_link_args"
|
---|
172 | MPI_$3FLAGS=` echo "$MPI_$3FLAGS" | tr '\n' ' ' | sed 's/^[[ \t]]*//;s/[[ \t]]*$//' | sed 's/ +/ /g'`
|
---|
173 | MPI_$3LDFLAGS=`echo "$MPI_$3LDFLAGS" | tr '\n' ' ' | sed 's/^[[ \t]]*//;s/[[ \t]]*$//' | sed 's/ +/ /g'`
|
---|
174 |
|
---|
175 | OLD_CPPFLAGS=$CPPFLAGS
|
---|
176 | OLD_LIBS=$LIBS
|
---|
177 | CPPFLAGS=$MPI_$3FLAGS
|
---|
178 | LIBS=$MPI_$3LDFLAGS
|
---|
179 |
|
---|
180 | AC_TRY_LINK([#include <mpi.h>],
|
---|
181 | [int rank, size;
|
---|
182 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
---|
183 | MPI_Comm_size(MPI_COMM_WORLD, &size);],
|
---|
184 | [# Add a define for testing at compile time.
|
---|
185 | AC_DEFINE([HAVE_MPI], [1], [Define to 1 if you have MPI libs and headers.])
|
---|
186 | have_$3_mpi='yes'],
|
---|
187 | [# zero out mpi flags so we don't link against the faulty library.
|
---|
188 | MPI_$3FLAGS=""
|
---|
189 | MPI_$3LDFLAGS=""
|
---|
190 | have_$3_mpi='no'])
|
---|
191 |
|
---|
192 | # AC_SUBST everything.
|
---|
193 | AC_SUBST($1)
|
---|
194 | AC_SUBST(MPI_$3FLAGS)
|
---|
195 | AC_SUBST(MPI_$3LDFLAGS)
|
---|
196 |
|
---|
197 | LIBS=$OLD_LIBS
|
---|
198 | CPPFLAGS=$OLD_CPPFLAGS
|
---|
199 | else
|
---|
200 | Echo Unable to find suitable MPI Compiler. Try setting $1.
|
---|
201 | have_$3_mpi='no'
|
---|
202 | fi
|
---|
203 | ])
|
---|
204 |
|
---|