| 1 |
# =========================================================================== |
| 2 |
# https://www.gnu.org/software/autoconf-archive/ax_prog_cc_mpi.html |
| 3 |
# =========================================================================== |
| 4 |
# |
| 5 |
# SYNOPSIS |
| 6 |
# |
| 7 |
# AX_PROG_CC_MPI([MPI-WANTED-TEST[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]]) |
| 8 |
# |
| 9 |
# DESCRIPTION |
| 10 |
# |
| 11 |
# This macro tries to find out how to compile C programs that use MPI |
| 12 |
# (Message Passing Interface), a standard API for parallel process |
| 13 |
# communication (see http://www-unix.mcs.anl.gov/mpi/). The macro has to |
| 14 |
# be used instead of the standard macro AC_PROG_CC and will replace the |
| 15 |
# standard variable CC with the found compiler. |
| 16 |
# |
| 17 |
# MPI-WANTED-TEST is used to test whether MPI is actually wanted by the |
| 18 |
# user. If MPI-WANTED_TEST is omitted or if it succeeds, the macro will |
| 19 |
# try to find out how to use MPI, if it fails, the macro will call |
| 20 |
# AC_PROG_CC to find a standard C compiler instead. |
| 21 |
# |
| 22 |
# When MPI is found, ACTION-IF-FOUND will be executed, if MPI is not found |
| 23 |
# (or MPI-WANTED-TEST fails) ACTION-IF-NOT-FOUND is executed. If |
| 24 |
# ACTION-IF-FOUND is not set, the macro will define HAVE_MPI. |
| 25 |
# |
| 26 |
# The following example demonstrates usage of the macro: |
| 27 |
# |
| 28 |
# # If --with-mpi=auto is used, try to find MPI, but use standard C compiler if it is not found. |
| 29 |
# # If --with-mpi=yes is used, try to find MPI and fail if it isn't found. |
| 30 |
# # If --with-mpi=no is used, use a standard C compiler instead. |
| 31 |
# AC_ARG_WITH(mpi, [AS_HELP_STRING([--with-mpi], |
| 32 |
# [compile with MPI (parallelization) support. If none is found, |
| 33 |
# MPI is not used. Default: auto]) |
| 34 |
# ],,[with_mpi=auto]) |
| 35 |
# # |
| 36 |
# AX_PROG_CC_MPI([test x"$with_mpi" != xno],[use_mpi=yes],[ |
| 37 |
# use_mpi=no |
| 38 |
# if test x"$with_mpi" = xyes; then |
| 39 |
# AC_MSG_FAILURE([MPI compiler requested, but couldn't use MPI.]) |
| 40 |
# else |
| 41 |
# AC_MSG_WARN([No MPI compiler found, won't use MPI.]) |
| 42 |
# fi |
| 43 |
# ]) |
| 44 |
# |
| 45 |
# LICENSE |
| 46 |
# |
| 47 |
# Copyright (c) 2010,2011 Olaf Lenz <[email protected]> |
| 48 |
# |
| 49 |
# This program is free software: you can redistribute it and/or modify it |
| 50 |
# under the terms of the GNU General Public License as published by the |
| 51 |
# Free Software Foundation, either version 3 of the License, or (at your |
| 52 |
# option) any later version. |
| 53 |
# |
| 54 |
# This program is distributed in the hope that it will be useful, but |
| 55 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 56 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 57 |
# Public License for more details. |
| 58 |
# |
| 59 |
# You should have received a copy of the GNU General Public License along |
| 60 |
# with this program. If not, see <https://www.gnu.org/licenses/>. |
| 61 |
# |
| 62 |
# As a special exception, the respective Autoconf Macro's copyright owner |
| 63 |
# gives unlimited permission to copy, distribute and modify the configure |
| 64 |
# scripts that are the output of Autoconf when processing the Macro. You |
| 65 |
# need not follow the terms of the GNU General Public License when using |
| 66 |
# or distributing such scripts, even though portions of the text of the |
| 67 |
# Macro appear in them. The GNU General Public License (GPL) does govern |
| 68 |
# all other use of the material that constitutes the Autoconf Macro. |
| 69 |
# |
| 70 |
# This special exception to the GPL applies to versions of the Autoconf |
| 71 |
# Macro released by the Autoconf Archive. When you make and distribute a |
| 72 |
# modified version of the Autoconf Macro, you may extend this special |
| 73 |
# exception to the GPL to apply to your modified version as well. |
| 74 |
|
| 75 |
#serial 2 |
| 76 |
|
| 77 |
AC_DEFUN([AX_PROG_CC_MPI], [ |
| 78 |
AC_PREREQ(2.50) |
| 79 |
|
| 80 |
# Check for compiler |
| 81 |
# Needs to be split off into an extra macro to ensure right expansion |
| 82 |
# order. |
| 83 |
AC_REQUIRE([_AX_PROG_CC_MPI],[_AX_PROG_CC_MPI([$1])]) |
| 84 |
|
| 85 |
AS_IF([test x"$_ax_prog_cc_mpi_mpi_wanted" = xno], |
| 86 |
[ _ax_prog_cc_mpi_mpi_found=no ], |
| 87 |
[ |
| 88 |
AC_LANG_PUSH([C]) |
| 89 |
# test whether MPI_Init is available |
| 90 |
# We do not use AC_SEARCH_LIBS here, as it caches its outcome and |
| 91 |
# thus disallows corresponding calls in the other AX_PROG_*_MPI |
| 92 |
# macros. |
| 93 |
for lib in NONE mpi mpich; do |
| 94 |
save_LIBS=$LIBS |
| 95 |
if test x"$lib" = xNONE; then |
| 96 |
AC_MSG_CHECKING([for function MPI_Init]) |
| 97 |
else |
| 98 |
AC_MSG_CHECKING([for function MPI_Init in -l$lib]) |
| 99 |
LIBS="-l$lib $LIBS" |
| 100 |
fi |
| 101 |
AC_LINK_IFELSE([AC_LANG_CALL([],[MPI_Init])], |
| 102 |
[ _ax_prog_cc_mpi_mpi_found=yes ], |
| 103 |
[ _ax_prog_cc_mpi_mpi_found=no ]) |
| 104 |
AC_MSG_RESULT($_ax_prog_cc_mpi_mpi_found) |
| 105 |
if test "x$_ax_prog_cc_mpi_mpi_found" = "xyes"; then |
| 106 |
break; |
| 107 |
fi |
| 108 |
LIBS=$save_LIBS |
| 109 |
done |
| 110 |
|
| 111 |
# Check for header |
| 112 |
AS_IF([test x"$_ax_prog_cc_mpi_mpi_found" = xyes], [ |
| 113 |
AC_MSG_CHECKING([for mpi.h]) |
| 114 |
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <mpi.h>])], |
| 115 |
[ AC_MSG_RESULT(yes)], |
| 116 |
[ AC_MSG_RESULT(no) |
| 117 |
_ax_prog_cc_mpi_mpi_found=no |
| 118 |
]) |
| 119 |
]) |
| 120 |
AC_LANG_POP([C]) |
| 121 |
]) |
| 122 |
|
| 123 |
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: |
| 124 |
AS_IF([test x"$_ax_prog_cc_mpi_mpi_found" = xyes], [ |
| 125 |
ifelse([$2],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$2]) |
| 126 |
: |
| 127 |
],[ |
| 128 |
$3 |
| 129 |
: |
| 130 |
]) |
| 131 |
|
| 132 |
])dnl AX_PROG_CC_MPI |
| 133 |
|
| 134 |
dnl _AX_PROG_CC_MPI is an internal macro required by AX_PROG_CC_MPI. |
| 135 |
dnl To ensure the right expansion order, the main function AX_PROG_CC_MPI |
| 136 |
dnl has to be split into two parts. |
| 137 |
dnl |
| 138 |
dnl Known MPI C compilers: |
| 139 |
dnl mpicc |
| 140 |
dnl mpixlc_r |
| 141 |
dnl mpixlc |
| 142 |
dnl hcc |
| 143 |
dnl mpxlc_r |
| 144 |
dnl mpxlc |
| 145 |
dnl sxmpicc NEC SX |
| 146 |
dnl mpifcc Fujitsu |
| 147 |
dnl mpgcc |
| 148 |
dnl mpcc |
| 149 |
dnl cmpicc |
| 150 |
dnl cc |
| 151 |
dnl |
| 152 |
AC_DEFUN([_AX_PROG_CC_MPI], [ |
| 153 |
AC_ARG_VAR(MPICC,[MPI C compiler command]) |
| 154 |
ifelse([$1],,[_ax_prog_cc_mpi_mpi_wanted=yes],[ |
| 155 |
AC_MSG_CHECKING([whether to compile using MPI]) |
| 156 |
if $1; then |
| 157 |
_ax_prog_cc_mpi_mpi_wanted=yes |
| 158 |
else |
| 159 |
_ax_prog_cc_mpi_mpi_wanted=no |
| 160 |
fi |
| 161 |
AC_MSG_RESULT($_ax_prog_cc_mpi_mpi_wanted) |
| 162 |
]) |
| 163 |
if test x"$_ax_prog_cc_mpi_mpi_wanted" = xyes; then |
| 164 |
if test -z "$CC" && test -n "$MPICC"; then |
| 165 |
CC="$MPICC" |
| 166 |
else |
| 167 |
AC_CHECK_TOOLS([CC], [mpicc mpixlc_r mpixlc hcc mpxlc_r mpxlc sxmpicc mpifcc mpgcc mpcc cmpicc cc gcc]) |
| 168 |
fi |
| 169 |
fi |
| 170 |
AC_PROG_CC |
| 171 |
])dnl _AX_PROG_CC_MPI |