1dnl
2dnl/*D
3dnl PAC_LIB_MPI - Check for MPI library
4dnl
5dnl Synopsis:
6dnl PAC_LIB_MPI([action if found],[action if not found])
7dnl
8dnl Output Effect:
9dnl
10dnl Notes:
11dnl Currently, only checks for lib mpi and mpi.h.  Later, we will add
12dnl MPI_Pcontrol prototype (const int or not?).
13dnl
14dnl Prerequisites:
15dnl autoconf version 2.13 (for AC_SEARCH_LIBS)
16dnl D*/
17dnl Other tests to add:
18dnl Version of MPI
19dnl MPI-2 I/O?
20dnl MPI-2 Spawn?
21dnl MPI-2 RMA?
22dnl PAC_LIB_MPI([found text],[not found text])
23AC_DEFUN([PAC_LIB_MPI],[
24dnl Set the prereq to 2.50 to avoid having
25AC_PREREQ(2.50)
26if test "X$pac_lib_mpi_is_building" != "Xyes" ; then
27  # Use CC if TESTCC is defined
28  if test "X$pac_save_level" != "X" ; then
29     pac_save_TESTCC="${TESTCC}"
30     pac_save_TESTCPP="${TESTCPP}"
31     CC="$pac_save_CC"
32     if test "X$pac_save_CPP" != "X" ; then
33         CPP="$pac_save_CPP"
34     fi
35  fi
36  # Look for MPILIB first if it is defined
37  AC_SEARCH_LIBS(MPI_Init,$MPILIB mpi mpich mpich2)
38  if test "$ac_cv_search_MPI_Init" = "no" ; then
39    ifelse($2,,
40    AC_MSG_ERROR([Could not find MPI library]),[$2])
41  fi
42  AC_CHECK_HEADER(mpi.h,pac_have_mpi_h="yes",pac_have_mpi_h="no")
43  if test $pac_have_mpi_h = "no" ; then
44    ifelse($2,,
45    AC_MSG_ERROR([Could not find mpi.h include file]),[$2])
46  fi
47  if test "X$pac_save_level" != "X" ; then
48     CC="$pac_save_TESTCC"
49     CPP="$pac_save_TESTCPP"
50  fi
51fi
52ifelse($1,,,[$1])
53])
54
55dnl This should also set MPIRUN.
56dnl
57dnl/*D
58dnl PAC_ARG_MPI_TYPES - Add command-line switches for different MPI
59dnl environments
60dnl
61dnl Synopsis:
62dnl PAC_ARG_MPI_TYPES([default])
63dnl
64dnl Output Effects:
65dnl Adds the following command line options to configure
66dnl+ \-\-with\-mpich[=path] - MPICH.  'path' is the location of MPICH commands
67dnl. \-\-with\-ibmmpi - IBM MPI
68dnl. \-\-with\-lammpi[=path] - LAM/MPI
69dnl. \-\-with\-mpichnt - MPICH NT
70dnl- \-\-with\-sgimpi - SGI MPI
71dnl If no type is selected, and a default ("mpich", "ibmmpi", or "sgimpi")
72dnl is given, that type is used as if '--with-<default>' was given.
73dnl
74dnl Sets 'CC', 'F77', 'TESTCC', 'TESTF77', and 'MPILIBNAME'.  Does `not`
75dnl perform an AC_SUBST for these values.
76dnl Also sets 'MPIBOOT' and 'MPIUNBOOT'.  These are used to specify
77dnl programs that may need to be run before and after running MPI programs.
78dnl For example, 'MPIBOOT' may start demons necessary to run MPI programs and
79dnl 'MPIUNBOOT' will stop those demons.
80dnl
81dnl The two forms of the compilers are to allow for tests of the compiler
82dnl when the MPI version of the compiler creates executables that cannot
83dnl be run on the local system (for example, the IBM SP, where executables
84dnl created with mpcc will not run locally, but executables created
85dnl with xlc may be used to discover properties of the compiler, such as
86dnl the size of data types).
87dnl
88dnl Historical note:
89dnl Some common autoconf tests, such as AC_CHECK_SIZEOF, used to require
90dnl running a program.  But some MPI compilers (often really compilation
91dnl scripts) produced programs that could only be run with special commands,
92dnl such as a batch submission system.  To allow these test programs to be
93dnl run, a separate set of compiler variables, TESTCC, TESTF77, etc.,
94dnl were defined.  However, in later versions of autoconf, it both became
95dnl unnecessary to run programs for tests such as AC_CHECK_SIZEOF and
96dnl it became necessary to define CC etc. before invoking AC_PROG_CC (and
97dnl the othe language compilers), because those commands now do much, much
98dnl more than just determining the compiler.
99dnl
100dnl To address the change, we still define the TESTCC etc. compilers where
101dnl possible to allow the use of AC_TRY_RUN when required, but we define
102dnl the CC etc variables and do not define ac_cv_prog_CC etc., as these
103dnl cause autoconf to skip all of the other initialization code that
104dnl AC_PROG_CC etc. runs.  Note also that this command must occur before
105dnl AC_PROG_CC (or anything that might cause AC_PROG_CC to be invoked).
106dnl
107dnl See also:
108dnl PAC_LANG_PUSH_COMPILERS, PAC_LIB_MPI
109dnl D*/
110AC_DEFUN([PAC_ARG_MPI_TYPES],[
111# known types
112PAC_ARG_MPI_KNOWN_TYPES
113# find compilers
114PAC_MPI_FIND_COMPILER_SCRIPTS
115PAC_MPI_FIND_COMPILERS
116# check for MPI library
117PAC_MPI_CHECK_MPI_LIB
118])
119dnl
120dnl To keep autoconf from prematurely invoking the compiler check scripts,
121dnl we need a command that first sets the compilers and a separate one
122dnl that makes any necessary checks for libraries
123dnl
124AC_DEFUN([PAC_ARG_MPI_KNOWN_TYPES],[
125AC_ARG_WITH(mpich,
126[--with-mpich=path  - Assume that we are building with MPICH],
127ac_mpi_type=mpich)
128# Allow MPICH2 as well as MPICH
129AC_ARG_WITH(mpich2,
130[--with-mpich=path  - Assume that we are building with MPICH],
131ac_mpi_type=mpich)
132AC_ARG_WITH(lammpi,
133[--with-lammpi=path  - Assume that we are building with LAM/MPI],
134ac_mpi_type=lammpi)
135AC_ARG_WITH(ibmmpi,
136[--with-ibmmpi    - Use the IBM SP implementation of MPI],
137ac_mpi_type=ibmmpi)
138AC_ARG_WITH(sgimpi,
139[--with-sgimpi    - Use the SGI implementation of MPI],
140ac_mpi_type=sgimpi)
141AC_ARG_WITH(mpichnt,
142[--with-mpichnt - Use MPICH for Windows NT ],
143ac_mpi_type=mpichnt)
144AC_ARG_WITH(mpi,
145[--with-mpi=path    - Use an MPI implementation with compile scripts mpicc
146                     and mpif77 in path/bin],ac_mpi_type=generic)
147
148if test "X$ac_mpi_type" = "X" ; then
149    if test "X$1" != "X" ; then
150        ac_mpi_type=$1
151    else
152        ac_mpi_type=unknown
153    fi
154fi
155if test "$ac_mpi_type" = "unknown" -a "$pac_lib_mpi_is_building" = "yes" ; then
156    ac_mpi_type="mpich"
157fi
158])
159dnl
160dnl Because of autoconf insists on moving code to the beginning of
161dnl certain definitions, it is *not possible* to define a single command
162dnl that selects compilation scripts and also check for other options.
163dnl Thus, this needs to be divided into
164dnl   MPI_FIND_COMPILER_SCRIPTS
165dnl which can fail (i.e., not find a script), and
166dnl   MPI_FIND_COMPILERS
167dnl which runs the various PROC_xx for the compilers.
168AC_DEFUN([PAC_MPI_FIND_COMPILER_SCRIPTS],[
169# Set defaults
170MPIRUN_NP="-np "
171MPIEXEC_N="-n "
172AC_SUBST(MPIRUN_NP)
173AC_SUBST(MPIEXEC_N)
174dnl
175AC_ARG_VAR([MPIEXEC],[Name and path of mpiexec program])
176AC_ARG_VAR([MPIRUN],[Name and path of mpirun program])
177AC_ARG_VAR([MPIBOOT],[Name and path of program to run before mpirun])
178AC_ARG_VAR([MPIUNBOOT],[Name and path of program to run after all mpirun])
179AC_ARG_VAR([MPICC],[Name and absolute path of program used to compile MPI programs in C])
180AC_ARG_VAR([MPIF77],[Name and absolute path of program used to compile MPI programs in F77])
181AC_ARG_VAR([MPICXX],[Name and absolute path of program used to compile MPI programs in C++])
182AC_ARG_VAR([MPIF90],[Name and absolute path of program used to compile MPI programs in F90])
183#
184# Check for things that will cause trouble.  For example,
185# if MPICC is defined but does not contain a / or \, then PATH_PROG will
186# ignore the value
187if test -n "$MPICC" ; then
188   case $MPICC in
189changequote(<<,>>)
190    [\\/]* | ?:[\\/]*)
191changequote([,])
192    # Ok, PATH_PROG will figure it out
193    ;;
194  *)
195    AC_MSG_ERROR([MPICC must be set to an absolute path if it is set])
196  esac
197fi
198if test -n "$MPICXX" ; then
199   case $MPICXX in
200changequote(<<,>>)
201    [\\/]* | ?:[\\/]*)
202changequote([,])
203    # Ok, PATH_PROG will figure it out
204    ;;
205  *)
206    AC_MSG_ERROR([MPICXX must be set to an absolute path if it is set])
207  esac
208fi
209if test -n "$MPIF77" ; then
210   case $MPIF77 in
211changequote(<<,>>)
212    [\\/]* | ?:[\\/]*)
213changequote([,])
214    # Ok, PATH_PROG will figure it out
215    ;;
216  *)
217    AC_MSG_ERROR([MPIF77 must be set to an absolute path if it is set])
218  esac
219fi
220if test -n "$MPIF90" ; then
221   case $MPIF90 in
222changequote(<<,>>)
223    [\\/]* | ?:[\\/]*)
224changequote([,])
225    # Ok, PATH_PROG will figure it out
226    ;;
227  *)
228    AC_MSG_ERROR([MPIF90 must be set to an absolute path if it is set])
229  esac
230fi
231
232case $ac_mpi_type in
233	mpich)
234        dnl
235        dnl This isn't correct.  It should try to get the underlying compiler
236        dnl from the mpicc and mpif77 scripts or mpireconfig
237        if test "X$pac_lib_mpi_is_building" != "Xyes" ; then
238	    PAC_PUSH_FLAG([PATH])
239            if test "$with_mpich" != "yes" -a "$with_mpich" != "no" ; then
240		# Look for commands; if not found, try adding bin to the
241		# path
242		if test ! -x $with_mpich/mpicc -a -x $with_mpich/bin/mpicc ; then
243			with_mpich="$with_mpich/bin"
244		fi
245                PATH=$with_mpich:${PATH}
246            fi
247            AC_PATH_PROG(MPICC,mpicc)
248	    if test -z "$TESTCC" ; then TESTCC=${CC-cc} ; fi
249            CC="$MPICC"
250	    # Note that autoconf may unconditionally change the value of
251	    # CC (!) in some other command. Thus, we define CCMASTER
252	    CCMASTER=$CC
253	    # Force autoconf to respect this choice
254	    ac_ct_CC=$CC
255	    # to permit configure codes to recover the correct CC.  This
256	    # is an ugly not-quite-correct workaround for the fact that
257	    # does not want you to change the C compiler once you have set it
258	    # (But since it does so unconditionally, it silently creates
259	    # bogus output files.)
260            AC_PATH_PROG(MPIF77,mpif77)
261	    if test -z "$TESTF77" ; then TESTF77=${F77-f77} ; fi
262            F77="$MPIF77"
263            AC_PATH_PROG(MPIFC,mpif90)
264	    if test -z "$TESTFC" ; then TESTFC=${FC-f90} ; fi
265            FC="$MPIFC"
266            AC_PATH_PROG(MPICXX,mpiCC)
267	    if test -z "$TESTCXX" ; then TESTCXX=${CXX-CC} ; fi
268            CXX="$MPICXX"
269	    # We may want to restrict this to the path containing mpirun
270	    AC_PATH_PROG(MPIEXEC,mpiexec)
271	    AC_PATH_PROG(MPIRUN,mpirun)
272	    AC_PATH_PROG(MPIBOOT,mpichboot)
273	    AC_PATH_PROG(MPIUNBOOT,mpichstop)
274	    PAC_POP_FLAG([PATH])
275  	    MPILIBNAME="mpich"
276        else
277	    # All of the above should have been passed in the environment!
278	    :
279        fi
280	;;
281
282        mpichnt)
283        ;;
284
285	lammpi)
286	dnl
287        dnl This isn't correct.  It should try to get the underlying compiler
288        dnl from the mpicc and mpif77 scripts or mpireconfig
289	PAC_PUSH_FLAG([PATH])
290        if test "$with_mpich" != "yes" -a "$with_mpich" != "no" ; then
291	    # Look for commands; if not found, try adding bin to the path
292		if test ! -x $with_lammpi/mpicc -a -x $with_lammpi/bin/mpicc ; then
293			with_lammpi="$with_lammpi/bin"
294		fi
295                PATH=$with_lammpi:${PATH}
296        fi
297        AC_PATH_PROG(MPICC,mpicc)
298        if test -z "$TESTCC" ; then TESTCC=${CC-cc} ; fi
299        CC="$MPICC"
300        AC_PATH_PROG(MPIF77,mpif77)
301	if test -z "$TESTCC" ; then TESTF77=${F77-f77} ; fi
302        F77="$MPIF77"
303        AC_PATH_PROG(MPIFC,mpif90)
304        TESTFC=${FC-f90}
305	if test -z "$TESTFC" ; then TESTFC=${FC-f90} ; fi
306        FC="$MPIFC"
307        AC_PATH_PROG(MPICXX,mpiCC)
308	if test -z "$TESTCXX" ; then TESTCXX=${CXX-CC} ; fi
309        CXX="$MPICXX"
310	PAC_POP_FLAG([PATH])
311  	MPILIBNAME="lammpi"
312	MPIBOOT="lamboot"
313	MPIUNBOOT="wipe"
314	MPIRUN="mpirun"
315	;;
316
317	ibmmpi)
318	AC_CHECK_PROGS(MPCC,mpcc)
319	AC_CHECK_PROGS(MPXLF,mpxlf mpfort)
320	if test -z "$MPCC" -o -z "$MPXLF" ; then
321	    AC_MSG_ERROR([Could not find IBM MPI compilation scripts.  Either mpcc or mpxlf/mpfort is missing])
322	fi
323	if test -z "$TESTCC" ; then TESTCC=${CC-xlC} ; fi
324	if test -z "$TESTF77" ; then TESTF77=${F77-xlf}; fi
325	CC=mpcc; F77=$MPXLF
326	# There is no mpxlf90, but the options langlvl and free can
327	# select the Fortran 90 version of xlf
328	if test "$enable_f90" != no ; then
329	    AC_CHECK_PROGS(MPIXLF90,mpxlf90 mpfort)
330	    if test -z "$TESTFC" ; then TESTFC=${FC-xlf90}; fi
331            if test "X$MPIXLF90" != "X" ; then
332	        FC="$MPIXLF90"
333	    else
334	    	FC="$MPXLF -qlanglvl=90ext -qfree=f90"
335	    fi
336	fi
337	MPILIBNAME=""
338	cross_compiling=yes
339	# Turn off the autoconf version 3 warning message
340	ac_tool_warned=yes
341	;;
342
343	sgimpi)
344	if test -z "$TESTCC" ; then TESTCC=${CC:=cc} ; fi
345	if test -z "$TESTF77" ; then TESTF77=${F77:=f77} ; fi
346	if test -z "$TESTCXX" ; then TESTCXX=${CXX:=CC} ; fi
347	if test -z "$TESTFC" ; then TESTFC=${FC:=f90} ; fi
348	# Must check for the MPI library in a separate macro - adding
349	# a test here will cause autoconf to prematurely define the
350	# C compiler
351	MPIRUN=mpirun
352	MPIBOOT=""
353	MPIUNBOOT=""
354	;;
355
356	generic)
357	# in $with_mpi/bin or $with_mpi
358        if test "X$MPICC" = "X" ; then
359            if test -x "$with_mpi/bin/mpicc" ; then
360                MPICC=$with_mpi/bin/mpicc
361	    elif test -x "$with_mpi/mpicc" ; then
362	        MPICC=$with_mpi/mpicc
363            fi
364        fi
365        if test "X$MPICXX" = "X" ; then
366            if test -x "$with_mpi/bin/mpicxx" ; then
367                MPICXX=$with_mpi/bin/mpicxx
368	    elif test -x "$with_mpi/mpicxx" ; then
369	        MPICXX=$with_mpi/mpicxx
370            fi
371        fi
372        if test "X$MPIF77" = "X" ; then
373            if test -x "$with_mpi/bin/mpif77" ; then
374                MPIF77=$with_mpi/bin/mpif77
375	    elif test -x "$with_mpi/mpif77" ; then
376	        MPIF77=$with_mpi/mpif77
377            fi
378        fi
379        if test "X$MPIF90" = "X" ; then
380            if test -x "$with_mpi/bin/mpif90" ; then
381                MPIF90=$with_mpi/bin/mpif90
382	    elif test -x "$with_mpi/mpif90" ; then
383	        MPIF90=$with_mpi/mpif90
384            fi
385        fi
386        if test "X$MPIEXEC" = "X" ; then
387            if test -x "$with_mpi/bin/mpiexec" ; then
388                MPIEXEC=$with_mpi/bin/mpiexec
389	    elif test -x "$with_mpi/mpiexec" ; then
390	        MPIEXEC=$with_mpi/mpiexec
391            fi
392        fi
393        CC=$MPICC
394        F77=$MPIF77
395	if test "X$MPICXX" != "X" ; then CXX=$MPICXX ; fi
396	if test "X$MPIF90" != "X" ; then F90=$MPIF90 ; fi
397	;;
398
399	*)
400	# Use the default choices for the compilers
401	;;
402esac
403])
404
405AC_DEFUN([PAC_MPI_FIND_COMPILERS],[
406# Tell autoconf to determine properties of the compilers (these are the
407# compilers for MPI programs)
408PAC_PROG_CC
409if test "$enable_f77" != no -a "$enable_fortran" != no ; then
410    AC_PROG_F77
411fi
412if test "$enable_cxx" != no ; then
413    AC_PROG_CXX
414fi
415if test "$enable_f90" != no ; then
416    PAC_PROG_FC
417fi
418])
419
420dnl
421dnl This uses the selected CC etc to check for include paths and libraries
422AC_DEFUN([PAC_MPI_CHECK_MPI_LIB],[
423AC_REQUIRE([AC_PROG_CC])
424case $ac_mpi_type in
425    mpich)
426	;;
427
428    mpichnt)
429        dnl
430        dnl This isn't adequate, but it helps with using MPICH-NT/SDK.gcc
431	PAC_PUSH_FLAG([CFLAGS])
432        CFLAGS="$CFLAGS -I$with_mpichnt/include"
433	PAC_PUSH_FLAG([CPPFLAGS])
434        CPPFLAGS="$CPPFLAGS -I$with_mpichnt/include"
435	PAC_PUSH_FLAG([LDFLAGS])
436        LDFLAGS="$LDFLAGS -L$with_mpichnt/lib"
437        AC_CHECK_LIB(mpich,MPI_Init,found="yes",found="no")
438        if test "$found" = "no" ; then
439          AC_CHECK_LIB(mpich2,MPI_Init,found="yes",found="no")
440        fi
441	if test "$enable_cxx" != no ; then
442	    AC_PROG_CXX
443	fi
444	if test "$enable_f90" != no ; then
445	    PAC_PROG_FC
446	fi
447	# Set defaults for the TEST versions if not already set
448	if test -z "$TESTCC" ; then TESTCC=${CC:=cc} ; fi
449	if test -z "$TESTF77" ; then TESTF77=${F77:=f77} ; fi
450	if test -z "$TESTCXX" ; then TESTCXX=${CXX:=CC} ; fi
451	if test -z "$TESTFC" ; then TESTFC=${FC:=f90} ; fi
452        if test "$found" = "no" ; then
453	  PAC_POP_FLAG([CFLAGS])
454	  PAC_POP_FLAG([CPPFLAGS])
455	  PAC_POP_FLAG([LDFLAGS])
456        fi
457        ;;
458
459    lammpi)
460	;;
461
462    ibmmpi)
463	;;
464
465    sgimpi)
466	AC_CHECK_LIB(mpi,MPI_Init)
467	if test "$ac_cv_lib_mpi_MPI_Init" = "yes" ; then
468	    MPILIBNAME="mpi"
469	fi
470	;;
471
472    generic)
473	AC_SEARCH_LIBS(MPI_Init,mpi mpich2 mpich)
474	if test "$ac_cv_lib_mpi_MPI_Init" = "yes" ; then
475	    MPILIBNAME="mpi"
476	fi
477	;;
478
479    *)
480	;;
481esac
482])
483
484dnl
485dnl/*D
486dnl PAC_MPI_F2C - Determine if MPI has the MPI-2 functions MPI_xxx_f2c and
487dnl   MPI_xxx_c2f
488dnl
489dnl Output Effect:
490dnl Define 'HAVE_MPI_F2C' if the routines are found.
491dnl
492dnl Notes:
493dnl Looks only for 'MPI_Request_c2f'.
494dnl D*/
495AC_DEFUN([PAC_MPI_F2C],[
496AC_CACHE_CHECK([for MPI F2C and C2F routines],
497pac_cv_mpi_f2c,
498[
499AC_TRY_LINK([#include "mpi.h"],
500[MPI_Request request;MPI_Fint a;a = MPI_Request_c2f(request);],
501pac_cv_mpi_f2c="yes",pac_cv_mpi_f2c="no")
502])
503if test "$pac_cv_mpi_f2c" = "yes" ; then
504    AC_DEFINE(HAVE_MPI_F2C,1,[Define if MPI has F2C])
505fi
506])
507dnl
508dnl/*D
509dnl PAC_HAVE_ROMIO - make mpi.h include mpio.h if romio enabled
510dnl
511dnl Output Effect:
512dnl expands @HAVE_ROMIO@ in mpi.h into #include "mpio.h"
513dnl D*/
514AC_DEFUN([PAC_HAVE_ROMIO],[
515if test "$enable_romio" = "yes" ; then HAVE_ROMIO='#include "mpio.h"'; fi
516AC_SUBST(HAVE_ROMIO)
517])
518