acx_mpi.m4 4.8 KB

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