1dnl 2dnl PAC_MPI_LINK_CC_FUNC( MPI_CC, MPI_CFLAGS, MPI_LIBS, 3dnl HEADERS, MPI_VARS, MPI_FUNC, 4dnl [action if working], [action if not working] ) 5dnl - MPI_CC is the MPI parallel compiler, like mpich/mpicc, AIX/mpcc 6dnl - MPI_CFLAGS is the CFLAGS to MPI_CC, like "-I/usr/include" for mpi.h 7dnl - MPI_LIBS is the LIBS to MPI_CC, like "-L/usr/lib -lmpi" for libmpi.a 8dnl - HEADERS is the headers, e.g. <pthread.h>. 9dnl - MPI_VARS is the the declaration of variables needed to call MPI_FUNC 10dnl - MPI_FUNC is the body of MPI function call to be checked for existence 11dnl e.g. MPI_VARS="MPI_Request request; MPI_Fint a;" 12dnl MPI_FUNC="a = MPI_Request_c2f( request );" 13dnl if MPI_FUNC is empty, assume linking with basic MPI program. 14dnl i.e. check if MPI definitions are valid 15dnl 16AC_DEFUN(PAC_MPI_LINK_CC_FUNC,[ 17dnl - set local parallel compiler environments 18dnl so input variables can be CC, CFLAGS or LIBS 19 pac_MPI_CC="$1" 20 pac_MPI_CFLAGS="$2" 21 pac_MPI_LIBS="$3" 22dnl - save the original environment 23 pac_saved_CC="$CC" 24 pac_saved_CFLAGS="$CFLAGS" 25 pac_saved_LIBS="$LIBS" 26dnl - set the parallel compiler environment 27 AC_LANG_PUSH([C]) 28 CC="$pac_MPI_CC" 29 CFLAGS="$pac_MPI_CFLAGS" 30 LIBS="$pac_MPI_LIBS" 31 AC_LINK_IFELSE([ 32 AC_LANG_PROGRAM([ 33/* <stdlib.h> is included to get NULL defined */ 34#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H ) 35#include <stdlib.h> 36#else 37#if !defined( NULL ) 38#define NULL 0 39#endif 40#endif 41 42$4 43#include "mpi.h" 44 45 ],[ 46 int argc; char **argv; 47 $5 ; 48 MPI_Init(&argc, &argv); 49 $6 ; 50 MPI_Finalize(); 51 ]) 52 ],[pac_mpi_working=yes],[pac_mpi_working=no]) 53 CC="$pac_saved_CC" 54 CFLAGS="$pac_saved_CFLAGS" 55 LIBS="$pac_saved_LIBS" 56 AC_LANG_POP([C]) 57 if test "$pac_mpi_working" = "yes" ; then 58 ifelse([$7],,:,[$7]) 59 else 60 ifelse([$8],,:,[$8]) 61 fi 62])dnl 63dnl 64dnl PAC_MPI_LINK_F77_FUNC( MPI_F77, MPI_FFLAGS, MPI_LIBS, 65dnl MPI_VARS, MPI_FUNC, 66dnl [action if working], [action if not working] ) 67dnl - MPI_F77 is the MPI parallel compiler, like mpich/mpif77, AIX/mpxlf 68dnl - MPI_FFLAGS is the FFLAGS to MPI_F77, like "-I/usr/include" for mpif.h 69dnl - MPI_LIBS is the LIBS to MPI_F77, like "-L/usr/lib -lmpi" for libmpi.a 70dnl - MPI_VARS is the the declaration of variables needed to call MPI_FUNC 71dnl - MPI_FUNC is the body of MPI function call to be checked for existence 72dnl e.g. MPI_VARS="MPI_Request request; MPI_Fint a;" 73dnl MPI_FUNC="a = MPI_Request_c2f( request );" 74dnl if MPI_FUNC is empty, assume linking with basic MPI program. 75dnl i.e. check if MPI definitions are valid 76dnl 77AC_DEFUN(PAC_MPI_LINK_F77_FUNC,[ 78dnl - set local parallel compiler environments 79dnl so input variables can be F77, FFLAGS or LIBS 80 pac_MPI_F77="$1" 81 pac_MPI_FFLAGS="$2" 82 pac_MPI_LIBS="$3" 83dnl - save the original environment 84 pac_saved_F77="$F77" 85 pac_saved_FFLAGS="$FFLAGS" 86 pac_saved_LIBS="$LIBS" 87dnl - set the parallel compiler environment for TRY_LINK 88 AC_LANG_PUSH([Fortran 77]) 89 F77="$pac_MPI_F77" 90 FFLAGS="$pac_MPI_FFLAGS" 91 LIBS="$pac_MPI_LIBS" 92 AC_LINK_IFELSE([ 93 AC_LANG_SOURCE([ 94 include 'mpif.h' 95 integer pac_ierr 96 $4 97 call MPI_Init( pac_ierr ) 98 $5 99 call MPI_Finalize( pac_ierr ) 100 end 101 ]) 102 ],[pac_mpi_working=yes],[pac_mpi_working=no]) 103 F77="$pac_saved_F77" 104 FFLAGS="$pac_saved_FFLAGS" 105 LIBS="$pac_saved_LIBS" 106 AC_LANG_POP([Fortran 77]) 107 if test "$pac_mpi_working" = "yes" ; then 108 ifelse([$6],,:,[$6]) 109 else 110 ifelse([$7],,:,[$7]) 111 fi 112])dnl 113dnl 114dnl PAC_MPI_RUN_CC_PGM( MPI_CC, MPI_CFLAGS, 115dnl SER_CC, SER_CFLAGS, SER_LIBS, 116dnl PGM_BODY, 117dnl [action if working], [action if not working] ) 118dnl - MPI_CC MPI parallel compiler for compilation of the PGM_BODY 119dnl e.g. mpich/mpicc & AIX/mpcc 120dnl - MPI_CFLAGS FFLAGS to MPI_CC for compilation of the PGM_BODY 121dnl e.g. "-I/usr/include" for mpi.h 122dnl - SER_CC serial compiler, like AIX/xlc, to generate of serial exeutable 123dnl - SER_CFLAGS FFLAGS to SER_CC, used to generate serial executable 124dnl - SER_LIBS LIBS to SER_CC, used to generate serial executable 125dnl - PGM_BODY C program body 126dnl 127AC_DEFUN(PAC_MPI_RUN_CC_PGM,[ 128dnl - set local parallel and serial compiler environments 129dnl so input variables can be CC, CFLAGS or LIBS 130 pac_MPI_CC="$1" 131 pac_MPI_CFLAGS="$2" 132 pac_SER_CC="$3" 133 pac_SER_CFLAGS="$4" 134 pac_SER_LIBS="$5" 135 AC_LANG_PUSH([C]) 136dnl - save the original environment 137 pac_saved_CC="$CC" 138 pac_saved_CFLAGS="$CFLAGS" 139 pac_saved_LIBS="$LIBS" 140dnl - set the parallel compiler environment 141 CC="$pac_MPI_CC" 142 CFLAGS="$pac_MPI_CFLAGS" 143dnl 144 pac_mpi_working=no 145 AC_COMPILE_IFELSE([ 146 AC_LANG_SOURCE([$6]) 147 ], [ 148 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT]) 149 CC="$pac_SER_CC" 150 CFLAGS="$pac_SER_CFLAGS" 151 LIBS="pac_conftest.$OBJEXT $pac_SER_LIBS" 152dnl - To use pac_conftest.$OBJEXT as a main, a conftest.c is needed. 153dnl - Theoretically, a blank source file is all we need, but some compiler 154dnl - may complain, so use a irrelevent function here. 155 AC_RUN_IFELSE([ 156 AC_LANG_SOURCE([void foo(){}]) 157 ], [pac_mpi_working=yes]) 158 rm -f pac_conftest.$OBJEXT 159 ]) 160 CC="$pac_saved_CC" 161 CFLAGS="$pac_saved_CFLAGS" 162 LIBS="$pac_saved_LIBS" 163 AC_LANG_POP([C]) 164 if test "$pac_mpi_working" = "yes" ; then 165 ifelse([$7],,:,[$7]) 166 else 167 ifelse([$8],,:,[$8]) 168 fi 169])dnl 170dnl 171dnl PAC_MPI_RUN_F77_PGM( MPI_F77, MPI_FFLAGS, 172dnl SER_F77, SER_FFLAGS, SER_LIBS, 173dnl PGM_BODY, 174dnl [action if working], [action if not working] ) 175dnl - MPI_F77 MPI parallel compiler for compilation of the PGM_BODY 176dnl e.g. mpich/mpif77 & AIX/mpxlf 177dnl - MPI_FFLAGS FFLAGS to MPI_F77 for compilation of the PGM_BODY 178dnl e.g. "-I/usr/include" for mpif.h 179dnl - SER_F77 serial compiler, like AIX/xlf, to generate of serial exeutable 180dnl - SER_FFLAGS FFLAGS to SER_F77, used to generate serial executable 181dnl - SER_LIBS LIBS to SER_F77, used to generate serial executable 182dnl - PGM_BODY F77 program body 183dnl 184AC_DEFUN(PAC_MPI_RUN_F77_PGM,[ 185dnl - set local parallel and serial compiler environments 186dnl so input variables can be F77, FFLAGS or LIBS 187 pac_MPI_F77="$1" 188 pac_MPI_FFLAGS="$2" 189 pac_SER_F77="$3" 190 pac_SER_FFLAGS="$4" 191 pac_SER_LIBS="$5" 192 AC_LANG_PUSH([Fortran 77]) 193dnl - save the original environment 194 pac_saved_F77="$F77" 195 pac_saved_FFLAGS="$FFLAGS" 196 pac_saved_LIBS="$LIBS" 197dnl - set the parallel compiler environment 198 F77="$pac_MPI_F77" 199 FFLAGS="$pac_MPI_FFLAGS" 200dnl 201 pac_mpi_working=no 202 AC_COMPILE_IFELSE([ 203 AC_LANG_SOURCE([ 204 $6 205 ]) 206 ], [ 207 PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT]) 208 F77="$pac_SER_F77" 209 FFLAGS="$pac_SER_FFLAGS" 210 LIBS="pac_f77conftest.$OBJEXT $pac_SER_LIBS" 211dnl - To use pac_f77conftest.$OBJEXT as a main, a conftest.f is needed. 212dnl - Theoretically, a blank source file is all we need, but some compiler 213dnl - may complain, e.g. af77/af90, so use a irrelevent subroutine here. 214 AC_RUN_IFELSE([ 215 AC_LANG_SOURCE([ 216 subroutine foo() 217 end 218 ]) 219 ], [pac_mpi_working=yes]) 220 rm -f pac_f77conftest.$OBJEXT 221 ]) 222 F77="$pac_saved_F77" 223 FFLAGS="$pac_saved_FFLAGS" 224 LIBS="$pac_saved_LIBS" 225 AC_LANG_POP([Fortran 77]) 226 if test "$pac_mpi_working" = "yes" ; then 227 ifelse([$7],,:,[$7]) 228 else 229 ifelse([$8],,:,[$8]) 230 fi 231])dnl 232dnl 233dnl PAC_MPI_RUN_F77_FUNC_FROM_C( MPI_F77, MPI_FFLAGS, 234dnl MPI_CC, MPI_CFLAGS, 235dnl SER_CC, SER_CFLAGS, SER_LIBS, 236dnl [ FORTRAN routine ], [ C program ], 237dnl [action if working], [action if not working] ) 238dnl - MPI_F77 MPI parallel compiler for compilation of the FORTRAN routine 239dnl e.g. mpich/mpif77 & AIX/mpxlf. It can be serial compiler if 240dnl no MPI variables in the FORTRAN routine 241dnl - MPI_FFLAGS FFLAGS to MPI_F77 for compilation of the FORTRAN routine 242dnl e.g. "-I/usr/include" for mpif.h 243dnl - MPI_CC MPI parallel compiler for compilation of the C program 244dnl e.g. mpich/mpicc & AIX/mpcc. It can be serial compiler if 245dnl no MPI variables in the C program 246dnl - MPI_CFLAGS FFLAGS to MPI_CC for compilation of the C program 247dnl e.g. "-I/usr/include" for mpi.h 248dnl - SER_CC serial compiler, like AIX/xlc, to generate of serial exeutable 249dnl - SER_CFLAGS FFLAGS to SER_CC, used to generate serial executable 250dnl - SER_LIBS LIBS to SER_CC, used to generate serial executable 251dnl User needs to put in #define F77_NAME_xxxx to get C code to understand 252dnl the fortran subroutine name. 253dnl 254AC_DEFUN(PAC_MPI_RUN_F77_FUNC_FROM_C,[ 255dnl - set local parallel compiler environments 256dnl so input variables can be CC, CFLAGS or LIBS 257 pac_MPI_F77="$1" 258 pac_MPI_FFLAGS="$2" 259 pac_MPI_CC="$3" 260 pac_MPI_CFLAGS="$4" 261 pac_SER_CC="$5" 262 pac_SER_CFLAGS="$6" 263 pac_SER_LIBS="$7" 264dnl 265dnl - save the original environment 266 pac_saved_F77="$F77" 267 pac_saved_FFLAGS="$FFLAGS" 268 pac_saved_LIBS="$LIBS" 269dnl - set the parallel compiler environment 270 F77="$pac_MPI_F77" 271 FFLAGS="$pac_MPI_FFLAGS" 272dnl 273 AC_LANG_PUSH([Fortran 77]) 274 AC_COMPILE_IFELSE([ 275 AC_LANG_SOURCE([ 276 $8 277 ]) 278 ], [ 279 PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT]) 280dnl - set the parallel compiler environment 281 AC_LANG_PUSH([C]) 282 CC="$pac_MPI_CC" 283 CFLAGS="$pac_MPI_CFLAGS" 284 pac_mpi_working=no 285 AC_COMPILE_IFELSE([ 286 AC_LANG_SOURCE([$9]) 287 ], [ 288 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT]) 289 CC="$pac_SER_CC" 290 CFLAGS="$pac_SER_CFLAGS" 291 LIBS="pac_conftest.$OBJEXT pac_f77conftest.$OBJEXT $pac_SER_LIBS" 292dnl - To use pac_conftest.$OBJEXT as a main, a conftest.c is needed. 293dnl - Theoretically, a blank source file is all we need, but some compiler 294dnl - may complain, so use a irrelevent function here. 295 AC_RUN_IFELSE([ 296 AC_LANG_SOURCE([ void foo(){} ]) 297 ], [pac_mpi_working=yes]) 298 rm -f pac_conftest.$OBJEXT 299 ]) 300 CC="$pac_saved_CC" 301 CFLAGS="$pac_saved_CFLAGS" 302 LIBS="$pac_saved_LIBS" 303 AC_LANG_POP([C]) 304 rm -f pac_f77conftest.$OBJEXT 305 ]) 306 AC_LANG_POP([Fortran 77]) 307 F77="$pac_saved_F77" 308 FFLAGS="$pac_saved_FFLAGS" 309dnl 310 if test "$pac_mpi_working" = "yes" ; then 311 ifelse([$10],,:,[$10]) 312 else 313 ifelse([$11],,:,[$11]) 314 fi 315]) 316