Autoconf MPI macros

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all!

We are using the GNU autotools and MPI in a number of our projects, and
we found that the AX_MPI macro from the autoconf macro archive has a few
shortcomings.

The problem is that AX_MPI starts to do anything only after the standard
C compiler has been found via AC_PROG_CC. If you want to compile the
whole package using MPI and simply replace CC with the MPI compiler,
this can lead to serious trouble. Assume the following case (seen on an
IBM AIX machine):
* gcc is installed
* the MPI compiler is xlc (the IBM compiler)

If I use AX_MPI in configure.ac, the following will happen in configure:
* AC_PROG_CC will recognize "gcc" as standard C compiler
* it will furthermore determine the options that gcc uses to generate
dependencies
* then, AX_MPI will recognize the MPI compiler "xlc"
* CC will be set to "xlc"

When I compile, this means that the compiler tries to generate
dependencies using the compiler xlc with the options of gcc. In this
particular case, the option (-MD if I'm not mistaken) caused xlc to
output profiling information into the .c-file and thus effectively
destroyed the C-code.

I believe that the correct way to avoid this problem is a set of new
macros AX_PROG_{FC,CCCXX}_MPI that are used in configure.ac instead of
AC_PROG_{CC,FC,CXX}. I have attached the macro AX_PROG_CC_MPI, and a git
clone of the autoconf macro archive containing the macro can be found at

  https://github.com/olenz/autoconf-archive

Internally, the MPI macro uses the standard macro AC_PROG_CC to find the
compiler, and directly sets CC to a working MPI version.

I propose to include these macros into the autoconf macro archive, and
to extend the docs of AX_MPI to point to these macros.

Greetings
  Olaf

-- 
Dr. rer. nat. Olaf Lenz
Institut fÃr Computerphysik, Pfaffenwaldring 27, D-70569 Stuttgart
Phone: +49-711-685-63607
# ===========================================================================
#       http://www.gnu.org/software/autoconf-archive/ax_prog_cc_mpi.html
# ===========================================================================
#
# SYNOPSIS
#
#   AX_PROG_CC_MPI([MPI-WANTED-TEST[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]])
#
# DESCRIPTION
#
#   This macro tries to find out how to compile C programs that use MPI
#   (Message Passing Interface), a standard API for parallel process
#   communication (see http://www-unix.mcs.anl.gov/mpi/).
#   The macro has to be used instead of the standard macro AC_PROG_CC
#   and will replace the standard variable CC with the found compiler.
#
#   MPI-WANTED-TEST is used to test whether MPI is actually wanted by
#   the user. If the test fails, the macro will not try to find MPI
#   and call AC_PROG_CC to find a standard C compiler instead. If the
#   test is omitted, the macro will try to find MPI and fail if it is
#   not found. 
#
#   When MPI is found, ACTION-IF-FOUND will be executed, otherwise
#   ACTION-IF-NOT-FOUND is executed. If ACTION-IF-FOUND is not set,
#   the macro will define HAVE_MPI.
#
# EXAMPLE
#
#  # If --with-mpi=auto is used, try to find MPI, but use standard C
#  compiler if it is not found.
#  # If --with-mpi=yes is used, try to find MPI and fail if it isn't
#  # found.
#  # If --with-mpi=no is used, use a standard C compiler instead.
#  AC_ARG_WITH(mpi, [AS_HELP_STRING([--with-mpi],
#      [compile with MPI (parallelization) support. If none is found,
#      MPI is not used. Default: auto])
#  ],,[with_mpi=auto])
#
#  AX_PROG_CC_MPI([test x"$with_mpi" != xno],[use_mpi=yes],[
#    use_mpi=no
#    if test x"$with_mpi" = xyes; then
#      AC_MSG_FAILURE([MPI compiler requested, but couldn't use MPI.])
#    else
#      AC_MSG_WARN([No MPI compiler found, won't use MPI.])
#    fi
#  ])
#
# LICENSE
#
#   Copyright (c) 2010,2011 Olaf Lenz <olenz@xxxxxxxxxxxxxxxxxxxx>
#
#   This program is free software: you can redistribute it and/or modify it
#   under the terms of the GNU General Public License as published by the
#   Free Software Foundation, either version 3 of the License, or (at your
#   option) any later version.
#
#   This program is distributed in the hope that it will be useful, but
#   WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
#   Public License for more details.
#
#   You should have received a copy of the GNU General Public License along
#   with this program. If not, see <http://www.gnu.org/licenses/>.
#
#   As a special exception, the respective Autoconf Macro's copyright owner
#   gives unlimited permission to copy, distribute and modify the configure
#   scripts that are the output of Autoconf when processing the Macro. You
#   need not follow the terms of the GNU General Public License when using
#   or distributing such scripts, even though portions of the text of the
#   Macro appear in them. The GNU General Public License (GPL) does govern
#   all other use of the material that constitutes the Autoconf Macro.
#
#   This special exception to the GPL applies to versions of the Autoconf
#   Macro released by the Autoconf Archive. When you make and distribute a
#   modified version of the Autoconf Macro, you may extend this special
#   exception to the GPL to apply to your modified version as well.

#serial 1

AC_DEFUN([AX_PROG_CC_MPI], [
AC_PREREQ(2.50) dnl for AC_LANG_CASE

# Check for compiler
AC_REQUIRE([_AX_PROG_CC_MPI],[_AX_PROG_CC_MPI([$1])])

AS_IF([test x"$_ax_prog_cc_mpi_mpi_wanted" = xno], 
  [ ax_prog_cc_mpi_mpi_found=no ],
  [
    # test whether MPI_Init is available now
    AC_CHECK_FUNC(MPI_Init,[ ax_prog_cc_mpi_mpi_found=yes ],
    [
      # if not, try to find it in a library
      AC_SEARCH_LIBS(MPI_Init, [mpi mpich],
        [ ax_prog_cc_mpi_mpi_found=yes ],
        [ ax_prog_cc_mpi_mpi_found=no ])
    ])

    echo "ax_prog_cc_mpi_mpi_found=$ax_prog_cc_mpi_mpi_found"
    # Check for header
    AS_IF([test x"$ax_only_mpi_found" = xyes], [
      AC_MSG_CHECKING([for mpi.h])
      AC_TRY_COMPILE([#include <mpi.h>],,[
        AC_MSG_RESULT(yes)
      ], [
        AC_MSG_RESULT(no)
	ax_prog_cc_mpi_mpi_found=no
      ])
    ])
])

# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
AS_IF([test x"$ax_prog_cc_mpi_mpi_found" = xyes], [
        ifelse([$2],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$2])
        :
],[
        $3
        :
])

])dnl AX_PROG_CC_MPI

dnl _AX_PROG_CC_MPI is an internal macro required by AX_PROG_CC_MPI.
dnl To ensure the right expansion order, the main function AX_PROG_CC_MPI
dnl has to be split into two parts.
AC_DEFUN([_AX_PROG_CC_MPI], [
  AC_ARG_VAR(MPICC,[MPI C compiler command])
  ifelse([$1],,[_ax_prog_cc_mpi_mpi_wanted=yes],[
    AC_MSG_CHECKING([whether to compile using MPI])
    if $1; then
      _ax_prog_cc_mpi_mpi_wanted=yes
    else
      _ax_prog_cc_mpi_mpi_wanted=no
    fi
    AC_MSG_RESULT($_ax_prog_cc_mpi_mpi_wanted)
  ])
  if test x"$_ax_prog_cc_mpi_mpi_wanted" = xyes; then
    if test -z "$CC" && test -n "$MPICC"; then
      CC="$MPICC"
    else
      AC_CHECK_TOOLS([CC], [mpicc hcc mpxlc_r mpxlc mpcc cmpicc])
    fi
  fi
  AC_PROG_CC

])dnl _AX_PROG_CC_MPI
begin:vcard
fn:Olaf Lenz
n:Lenz;Olaf
org;quoted-printable;quoted-printable:Universit=C3=A4t Stuttgart;Institut f=C3=BCr Computerphysik
adr:;;Pfaffenwaldring 27;Stuttgart;;70569;Germany
email;internet:olenz@xxxxxxxxxxxxxxxxxxxx
title:Dr. rer. nat.
tel;work:+49.711.685.63607
tel;fax:+49.711.685.63658 
url:http://www.icp.uni-stuttgart.de/~icp/Olaf_Lenz
version:2.1
end:vcard

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
https://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux