source: pcp/m4/acx_mpi.m4@ 2f6525

Last change on this file since 2f6525 was 2f6525, checked in by Frederik Heber <heber@…>, 17 years ago

new MPI autoconf macro installed and changed lines in configure.ac

MPICC was set to CC which caused trouble, when different gcc version had to be used (core2 optimization). As standard mpicc is just a link to gcc with mpi headers included, in the new manner, this can easily be acounted for

  • Property mode set to 100644
File size: 4.0 KB
Line 
1dnl @synopsis ACX_MPI([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
2dnl
3dnl This macro tries to find out how to compile programs that
4dnl use MPI (Message Passing Interface), a standard API for
5dnl parallel process communication (see http://www-unix.mcs.anl.gov/mpi/)
6dnl
7dnl On success, it sets the MPICC, MPICXX, or MPIF77 output variable to
8dnl the name of the MPI compiler, depending upon the current language.
9dnl (This may just be $CC/$CXX/$F77, but is more often something like
10dnl mpicc/mpiCC/mpif77.) It also sets MPILIBS to any libraries that are
11dnl needed for linking MPI (e.g. -lmpi, if a special MPICC/MPICXX/MPIF77
12dnl was not found).
13dnl
14dnl If you want to compile everything with MPI, you should set:
15dnl
16dnl CC="$MPICC" #OR# CXX="$MPICXX" #OR# F77="$MPIF77"
17dnl LIBS="$MPILIBS $LIBS"
18dnl
19dnl The user can force a particular library/compiler by setting the
20dnl MPICC/MPICXX/MPIF77 and/or MPILIBS environment variables.
21dnl
22dnl ACTION-IF-FOUND is a list of shell commands to run if an MPI
23dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands
24dnl to run it if it is not found. If ACTION-IF-FOUND is not specified,
25dnl the default action will define HAVE_MPI.
26dnl
27dnl @version $Id: acx_mpi.m4,v 1.2 2004-01-02 14:51:12 wildenhu Exp $
28dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
29
30AC_DEFUN([ACX_MPI], [
31AC_PREREQ(2.50) dnl for AC_LANG_CASE
32
33AC_LANG_CASE([C], [
34 AC_REQUIRE([AC_PROG_CC])
35 AC_ARG_VAR(MPICC,[MPI C compiler command])
36 AC_CHECK_PROGS(MPICC, mpicc hcc mpcc mpcc_r mpxlc, $CC)
37 acx_mpi_save_CC="$CC"
38 CC="$MPICC"
39 AC_SUBST(MPICC)
40],
41[C++], [
42 AC_REQUIRE([AC_PROG_CXX])
43 AC_ARG_VAR(MPICXX,[MPI C++ compiler command])
44 AC_CHECK_PROGS(MPICXX, mpiCC mpCC hcp mpic++, $CXX)
45 acx_mpi_save_CXX="$CXX"
46 CXX="$MPICXX"
47 AC_SUBST(MPICXX)
48],
49[Fortran 77], [
50 AC_REQUIRE([AC_PROG_F77])
51 AC_ARG_VAR(MPIF77,[MPI Fortran compiler command])
52 AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf mpf77 mpif90 mpf90 mpxlf90 mpxlf95 mpxlf_r, $F77)
53 acx_mpi_save_F77="$F77"
54 F77="$MPIF77"
55 AC_SUBST(MPIF77)
56])
57
58if test x = x"$MPILIBS"; then
59 AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
60 [C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
61 [Fortran 77], [AC_MSG_CHECKING([for MPI_Init])
62 AC_TRY_LINK([],[ call MPI_Init], [MPILIBS=" "
63 AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])])
64fi
65if test x = x"$MPILIBS"; then
66 AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"])
67fi
68if test x = x"$MPILIBS"; then
69 AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"])
70fi
71
72dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the
73dnl latter uses $CPP, not $CC (which may be mpicc).
74AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then
75 AC_MSG_CHECKING([for mpi.h])
76 AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
77 AC_MSG_RESULT(no)])
78fi],
79[C++], [if test x != x"$MPILIBS"; then
80 AC_MSG_CHECKING([for mpi.h])
81 AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
82 AC_MSG_RESULT(no)])
83fi])
84dnl There are b0rked implementations that '#define main mpi_main' in their mpi.h
85dnl which will cause all tests above to fail miserably (e.g. MPICH-SCore).
86dnl TODO: prototype checking, exit instead of return from main, test C++, implement F77.
87dnl TODO: use the information already gathered...
88if test x = x"$MPILIBS"; then
89 AC_MSG_CHECKING([for last resort: compile and link a small MPI test program])
90 AC_LANG_CASE([C], [AC_LINK_IFELSE([#include <mpi.h>
91int main(int argc, char **argv)
92{
93 MPI_Init(&argc, &argv);
94 return 0;
95}
96 ], [MPILIBS=" "
97 AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])],
98 [C++], [AC_LINK_IFELSE([#include <mpi.h>
99int main(int argc, char **argv)
100{
101 MPI_Init(&argc, &argv);
102 return 0;
103}
104 ], [MPILIBS=" "
105 AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])],
106 [Fortran 77], [])
107fi
108
109AC_LANG_CASE([C], [CC="$acx_mpi_save_CC"],
110 [C++], [CXX="$acx_mpi_save_CXX"],
111 [Fortran 77], [F77="$acx_mpi_save_F77"])
112
113AC_SUBST(MPILIBS)
114
115# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
116if test x = x"$MPILIBS"; then
117 $2
118 :
119else
120 ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1])
121 :
122fi
123])dnl ACX_MPI
Note: See TracBrowser for help on using the repository browser.