ax_mpi.m4 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_mpi.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_MPI([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro tries to find out how to compile programs that use MPI
  12. # (Message Passing Interface), a standard API for parallel process
  13. # communication (see http://www-unix.mcs.anl.gov/mpi/)
  14. #
  15. # On success, it sets the MPICC, MPICXX, MPIF77, or MPIFC output variable
  16. # to the name of the MPI compiler, depending upon the current language.
  17. # (This may just be $CC/$CXX/$F77/$FC, but is more often something like
  18. # mpicc/mpiCC/mpif77/mpif90.) It also sets MPILIBS to any libraries that
  19. # are needed for linking MPI (e.g. -lmpi or -lfmpi, if a special
  20. # MPICC/MPICXX/MPIF77/MPIFC was not found).
  21. #
  22. # Note that this macro should be used only if you just have a few source
  23. # files that need to be compiled using MPI. In particular, you should
  24. # neither overwrite CC/CXX/F77/FC with the values of
  25. # MPICC/MPICXX/MPIF77/MPIFC, nor assume that you can use the same flags
  26. # etc. as the standard compilers. If you want to compile a whole program
  27. # using the MPI compiler commands, use one of the macros
  28. # AX_PROG_{CC,CXX,FC}_MPI.
  29. #
  30. # ACTION-IF-FOUND is a list of shell commands to run if an MPI library is
  31. # found, and ACTION-IF-NOT-FOUND is a list of commands to run if it is not
  32. # found. If ACTION-IF-FOUND is not specified, the default action will
  33. # define HAVE_MPI.
  34. #
  35. # LICENSE
  36. #
  37. # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
  38. # Copyright (c) 2008 Julian C. Cummings <cummings@cacr.caltech.edu>
  39. #
  40. # This program is free software: you can redistribute it and/or modify it
  41. # under the terms of the GNU General Public License as published by the
  42. # Free Software Foundation, either version 3 of the License, or (at your
  43. # option) any later version.
  44. #
  45. # This program is distributed in the hope that it will be useful, but
  46. # WITHOUT ANY WARRANTY; without even the implied warranty of
  47. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  48. # Public License for more details.
  49. #
  50. # You should have received a copy of the GNU General Public License along
  51. # with this program. If not, see <http://www.gnu.org/licenses/>.
  52. #
  53. # As a special exception, the respective Autoconf Macro's copyright owner
  54. # gives unlimited permission to copy, distribute and modify the configure
  55. # scripts that are the output of Autoconf when processing the Macro. You
  56. # need not follow the terms of the GNU General Public License when using
  57. # or distributing such scripts, even though portions of the text of the
  58. # Macro appear in them. The GNU General Public License (GPL) does govern
  59. # all other use of the material that constitutes the Autoconf Macro.
  60. #
  61. # This special exception to the GPL applies to versions of the Autoconf
  62. # Macro released by the Autoconf Archive. When you make and distribute a
  63. # modified version of the Autoconf Macro, you may extend this special
  64. # exception to the GPL to apply to your modified version as well.
  65. #serial 8
  66. AU_ALIAS([ACX_MPI], [AX_MPI])
  67. AC_DEFUN([AX_MPI], [
  68. AC_PREREQ(2.50) dnl for AC_LANG_CASE
  69. AC_LANG_CASE([C], [
  70. AC_REQUIRE([AC_PROG_CC])
  71. AC_ARG_VAR(MPICC,[MPI C compiler command])
  72. AC_CHECK_PROGS(MPICC, mpicc hcc mpxlc_r mpxlc mpcc cmpicc, $CC)
  73. ax_mpi_save_CC="$CC"
  74. CC="$MPICC"
  75. AC_SUBST(MPICC)
  76. ],
  77. [C++], [
  78. AC_REQUIRE([AC_PROG_CXX])
  79. AC_ARG_VAR(MPICXX,[MPI C++ compiler command])
  80. AC_CHECK_PROGS(MPICXX, mpic++ mpicxx mpiCC hcp mpxlC_r mpxlC mpCC cmpic++, $CXX)
  81. ax_mpi_save_CXX="$CXX"
  82. CXX="$MPICXX"
  83. AC_SUBST(MPICXX)
  84. ],
  85. [Fortran 77], [
  86. AC_REQUIRE([AC_PROG_F77])
  87. AC_ARG_VAR(MPIF77,[MPI Fortran 77 compiler command])
  88. AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf_r mpxlf mpf77 cmpifc, $F77)
  89. ax_mpi_save_F77="$F77"
  90. F77="$MPIF77"
  91. AC_SUBST(MPIF77)
  92. ],
  93. [Fortran], [
  94. AC_REQUIRE([AC_PROG_FC])
  95. AC_ARG_VAR(MPIFC,[MPI Fortran compiler command])
  96. AC_CHECK_PROGS(MPIFC, mpif90 mpxlf95_r mpxlf90_r mpxlf95 mpxlf90 mpf90 cmpif90c, $FC)
  97. ax_mpi_save_FC="$FC"
  98. FC="$MPIFC"
  99. AC_SUBST(MPIFC)
  100. ])
  101. if test x = x"$MPILIBS"; then
  102. AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
  103. [C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
  104. [Fortran 77], [AC_MSG_CHECKING([for MPI_Init])
  105. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" "
  106. AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])],
  107. [Fortran], [AC_MSG_CHECKING([for MPI_Init])
  108. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" "
  109. AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])])
  110. fi
  111. AC_LANG_CASE([Fortran 77], [
  112. if test x = x"$MPILIBS"; then
  113. AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
  114. fi
  115. if test x = x"$MPILIBS"; then
  116. AC_CHECK_LIB(fmpich, MPI_Init, [MPILIBS="-lfmpich"])
  117. fi
  118. ],
  119. [Fortran], [
  120. if test x = x"$MPILIBS"; then
  121. AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
  122. fi
  123. if test x = x"$MPILIBS"; then
  124. AC_CHECK_LIB(mpichf90, MPI_Init, [MPILIBS="-lmpichf90"])
  125. fi
  126. ])
  127. if test x = x"$MPILIBS"; then
  128. AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"])
  129. fi
  130. if test x = x"$MPILIBS"; then
  131. AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"])
  132. fi
  133. dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the
  134. dnl latter uses $CPP, not $CC (which may be mpicc).
  135. AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then
  136. AC_MSG_CHECKING([for mpi.h])
  137. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]],[[]])],[AC_MSG_RESULT(yes)],[MPILIBS=""
  138. AC_MSG_RESULT(no)])
  139. dnl AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
  140. dnl AC_MSG_RESULT(no)])
  141. fi],
  142. [C++], [if test x != x"$MPILIBS"; then
  143. AC_MSG_CHECKING([for mpi.h])
  144. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <mpi.h>]],[[]])],[AC_MSG_RESULT(yes)],[MPILIBS=""
  145. AC_MSG_RESULT(no)])
  146. dnl AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
  147. dnl AC_MSG_RESULT(no)])
  148. fi],
  149. [Fortran 77], [if test x != x"$MPILIBS"; then
  150. AC_MSG_CHECKING([for mpif.h])
  151. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
  152. AC_MSG_RESULT(no)])
  153. fi],
  154. [Fortran], [if test x != x"$MPILIBS"; then
  155. AC_MSG_CHECKING([for mpif.h])
  156. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
  157. AC_MSG_RESULT(no)])
  158. fi])
  159. AC_LANG_CASE([C], [CC="$ax_mpi_save_CC"],
  160. [C++], [CXX="$ax_mpi_save_CXX"],
  161. [Fortran 77], [F77="$ax_mpi_save_F77"],
  162. [Fortran], [FC="$ax_mpi_save_FC"])
  163. AC_SUBST(MPILIBS)
  164. # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  165. if test x = x"$MPILIBS"; then
  166. $2
  167. :
  168. else
  169. ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1])
  170. :
  171. fi
  172. ])dnl AX_MPI