source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/lib/mct/m4/acx_mpi.m4 @ 4775

Last change on this file since 4775 was 4775, checked in by aclsce, 5 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 4.8 KB
Line 
1dnl @synopsis ACX_MPI([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
2dnl
3dnl @summary figure out how to compile/link code with MPI
4dnl
5dnl This macro tries to find out how to compile programs that use MPI
6dnl (Message Passing Interface), a standard API for parallel process
7dnl communication (see http://www-unix.mcs.anl.gov/mpi/)
8dnl
9dnl On success, it sets the MPICC, MPICXX, or MPIF77 output variable to
10dnl the name of the MPI compiler, depending upon the current language.
11dnl (This may just be $CC/$CXX/$F77, but is more often something like
12dnl mpicc/mpiCC/mpif77.) It also sets MPILIBS to any libraries that are
13dnl needed for linking MPI (e.g. -lmpi, if a special
14dnl MPICC/MPICXX/MPIF77 was not found).
15dnl
16dnl If you want to compile everything with MPI, you should set:
17dnl
18dnl     CC="$MPICC" #OR# CXX="$MPICXX" #OR# F77="$MPIF77"
19dnl     LIBS="$MPILIBS $LIBS"
20dnl
21dnl NOTE: The above assumes that you will use $CC (or whatever) for
22dnl linking as well as for compiling. (This is the default for automake
23dnl and most Makefiles.)
24dnl
25dnl The user can force a particular library/compiler by setting the
26dnl MPICC/MPICXX/MPIF77 and/or MPILIBS environment variables.
27dnl
28dnl ACTION-IF-FOUND is a list of shell commands to run if an MPI
29dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
30dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
31dnl default action will define HAVE_MPI.
32dnl
33dnl @category InstalledPackages
34dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
35dnl @author Julian Cummings <cummings@cacr.caltech.edu>
36dnl @version 2006-10-13
37dnl @license GPLWithACException
38
39AC_DEFUN([ACX_MPI], [
40AC_PREREQ(2.50) dnl for AC_LANG_CASE
41
42AC_LANG_CASE([C], [
43        AC_REQUIRE([AC_PROG_CC])
44        AC_ARG_VAR(MPICC,[MPI C compiler command])
45        AC_CHECK_PROGS(MPICC, mpicc hcc mpxlc_r mpxlc mpcc cmpicc, $CC)
46        acx_mpi_save_CC="$CC"
47        CC="$MPICC"
48        AC_SUBST(MPICC)
49],
50[C++], [
51        AC_REQUIRE([AC_PROG_CXX])
52        AC_ARG_VAR(MPICXX,[MPI C++ compiler command])
53        AC_CHECK_PROGS(MPICXX, mpic++ mpicxx mpiCC hcp mpxlC_r mpxlC mpCC cmpic++, $CXX)
54        acx_mpi_save_CXX="$CXX"
55        CXX="$MPICXX"
56        AC_SUBST(MPICXX)
57],
58[Fortran 77], [
59        AC_REQUIRE([AC_PROG_F77])
60        AC_ARG_VAR(MPIF77,[MPI Fortran 77 compiler command])
61        AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf mpf77 mpif90 mpf90 mpxlf90 mpxlf95 mpxlf_r cmpifc cmpif90c, $F77)
62        acx_mpi_save_F77="$F77"
63        F77="$MPIF77"
64        AC_SUBST(MPIF77)
65],
66[Fortran], [
67        AC_REQUIRE([AC_PROG_FC])
68        AC_ARG_VAR(MPIFC,[MPI Fortran compiler command])
69        AC_CHECK_PROGS(MPIFC, mpif90 hf90 mpxlf90 mpxlf95 mpf90 cmpifc cmpif90c, $FC)
70        acx_mpi_save_FC="$FC"
71        FC="$MPIFC"
72        AC_SUBST(MPIFC)
73])
74
75if test x = x"$MPILIBS"; then
76        AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
77                [C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
78                [Fortran 77], [AC_MSG_CHECKING([for MPI_Init])
79                        AC_LINK_IFELSE([AC_LANG_PROGRAM([],[      call MPI_Init])],[MPILIBS=" "
80                                AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])],
81                [Fortran], [AC_MSG_CHECKING([for MPI_Init])
82                        AC_LINK_IFELSE([AC_LANG_PROGRAM([],[      call MPI_Init])],[MPILIBS=" "
83                                AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])])
84fi
85AC_LANG_CASE([Fortran 77], [
86        if test x = x"$MPILIBS"; then
87                AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
88        fi
89        if test x = x"$MPILIBS"; then
90                AC_CHECK_LIB(fmpich, MPI_Init, [MPILIBS="-lfmpich"])
91        fi
92],
93[Fortran], [
94        if test x = x"$MPILIBS"; then
95                AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
96        fi
97        if test x = x"$MPILIBS"; then
98                AC_CHECK_LIB(mpichf90, MPI_Init, [MPILIBS="-lmpichf90"])
99        fi
100])
101if test x = x"$MPILIBS"; then
102        AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"])
103fi
104if test x = x"$MPILIBS"; then
105        AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"])
106fi
107
108dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the
109dnl latter uses $CPP, not $CC (which may be mpicc).
110AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then
111        AC_MSG_CHECKING([for mpi.h])
112        AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
113                AC_MSG_RESULT(no)])
114fi],
115[C++], [if test x != x"$MPILIBS"; then
116        AC_MSG_CHECKING([for mpi.h])
117        AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
118                AC_MSG_RESULT(no)])
119fi],
120[Fortran 77], [if test x != x"$MPILIBS"; then
121        AC_MSG_CHECKING([for mpif.h])
122        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[      include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
123                AC_MSG_RESULT(no)])
124fi],
125[Fortran], [if test x != x"$MPILIBS"; then
126        AC_MSG_CHECKING([for mpif.h])
127        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[      include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
128                AC_MSG_RESULT(no)])
129fi])
130
131AC_LANG_CASE([C], [CC="$acx_mpi_save_CC"],
132        [C++], [CXX="$acx_mpi_save_CXX"],
133        [Fortran 77], [F77="$acx_mpi_save_F77"],
134        [Fortran], [FC="$acx_mpi_save_FC"])
135
136AC_SUBST(MPILIBS)
137
138# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
139if test x = x"$MPILIBS"; then
140        $2
141        :
142else
143        ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1])
144        :
145fi
146])dnl ACX_MPI
Note: See TracBrowser for help on using the repository browser.