1# ------------------------------------------------------------- 2# PETSc 3# ------------------------------------------------------------- 4AC_DEFUN([CONFIGURE_PETSC], 5[ 6 dnl Require having scraped PETSc CXX, includes, and libs 7 AC_REQUIRE([ACSM_SCRAPE_PETSC_CONFIGURE]) 8 dnl Require having set a compiler so we can check headers, 9 dnl try compiles, try links, etc. 10 AC_REQUIRE([LIBMESH_SET_COMPILERS]) 11 12 AS_IF([test "$enablepetsc" != no], 13 [ 14 # AC_REQUIRE: 15 # If the M4 macro AC_PROG_F77 has not already been called, call 16 # it (without any arguments). Make sure to quote AC_PROG_F77 with 17 # square brackets. AC_PROG_F77 must have been defined using 18 # AC_DEFUN or else contain a call to AC_PROVIDE to indicate 19 # that it has been called. 20 AC_REQUIRE([AC_PROG_F77]) 21 22 23 # Let's use a C compiler for the AC_CHECK_HEADER test, although this is 24 # not strictly necessary... 25 AC_LANG_PUSH(C) 26 AC_CHECK_HEADER(${PETSC_DIR}/${PETSC_ARCH}/include/petscversion.h, 27 [enablepetsc=yes; enablepetsc_mpi=yes 28 petsc_version_h_file=${PETSC_DIR}/${PETSC_ARCH}/include/petscversion.h], 29 [ 30 AC_CHECK_HEADER(${PETSC_DIR}/include/petscversion.h, 31 [enablepetsc=yes; enablepetsc_mpi=yes 32 petsc_version_h_file=${PETSC_DIR}/include/petscversion.h], 33 [enablepetsc=no; enablepetsc_mpi=no]) 34 ]) 35 AC_LANG_POP 36 37 dnl We now have a -gt check for this that occurs at the end of the file, so make sure 38 dnl it is initialized to some sensible value to avoid syntax errors. 39 petsc_have_hypre=0 40 41 # Grab PETSc version and substitute into Makefile. 42 # If version 2.x, also check that PETSC_ARCH is set 43 AS_IF([test "$enablepetsc" != no], 44 [ 45 dnl Some tricks to discover the version of petsc. 46 dnl You have to have grep and sed for this to work. 47 petscmajor=`grep "define PETSC_VERSION_MAJOR" $petsc_version_h_file | sed -e "s/#define PETSC_VERSION_MAJOR[ ]*//g"` 48 petscminor=`grep "define PETSC_VERSION_MINOR" $petsc_version_h_file | sed -e "s/#define PETSC_VERSION_MINOR[ ]*//g"` 49 petscsubminor=`grep "define PETSC_VERSION_SUBMINOR" $petsc_version_h_file | sed -e "s/#define PETSC_VERSION_SUBMINOR[ ]*//g"` 50 petscrelease=`grep "define PETSC_VERSION_RELEASE" $petsc_version_h_file | sed -e "s/#define PETSC_VERSION_RELEASE[ ]*//g"` 51 petscversion=$petscmajor.$petscminor.$petscsubminor 52 petscmajorminor=$petscmajor.$petscminor.x 53 54 AS_IF([test "$petscmajor" = "2" && test "x${PETSC_ARCH}" = "x"], 55 [ 56 dnl PETSc config failed. We will try MPI at the end of this function. 57 enablepetsc=no; enablepetsc_mpi=no 58 AC_MSG_RESULT([<<< PETSc 2.x detected and "\$PETSC_ARCH" not set. PETSc disabled. >>>]) 59 ]) 60 61 dnl We look for petscconf.h in both $PETSC_DIR/include and 62 dnl $PETSC_DIR/$PETSC_ARCH/include, since it can appear in either. 63 petsc_use_debug=`cat ${PETSC_DIR}/include/petscconf.h ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h 2>/dev/null | grep -c PETSC_USE_DEBUG` 64 petsc_have_superlu_dist=`cat ${PETSC_DIR}/include/petscconf.h ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h 2>/dev/null | grep -c PETSC_HAVE_SUPERLU_DIST` 65 petsc_have_mumps=`cat ${PETSC_DIR}/include/petscconf.h ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h 2>/dev/null | grep -c PETSC_HAVE_MUMPS` 66 petsc_have_metis=`cat ${PETSC_DIR}/include/petscconf.h ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h 2>/dev/null | grep -c PETSC_HAVE_METIS` 67 petsc_have_chaco=`cat ${PETSC_DIR}/include/petscconf.h ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h 2>/dev/null | grep -c PETSC_HAVE_CHACO` 68 petsc_have_party=`cat ${PETSC_DIR}/include/petscconf.h ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h 2>/dev/null | grep -c PETSC_HAVE_PARTY` 69 petsc_have_ptscotch=`cat ${PETSC_DIR}/include/petscconf.h ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h 2>/dev/null | grep -c PETSC_HAVE_PTSCOTCH` 70 petsc_have_parmetis=`cat ${PETSC_DIR}/include/petscconf.h ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h 2>/dev/null | grep -c PETSC_HAVE_PARMETIS` 71 petsc_have_hypre=`cat ${PETSC_DIR}/include/petscconf.h ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h 2>/dev/null | grep -c PETSC_HAVE_HYPRE` 72 ], 73 [enablepetsc=no; enablepetsc_mpi=no]) 74 75 # If we haven't been disabled yet, carry on! 76 AS_IF([test $enablepetsc != no], 77 [ 78 79 # Print informative message about the version of PETSc we detected 80 AC_MSG_RESULT([<<< Found PETSc $petscversion installation in ${PETSC_DIR} ... >>>]) 81 82 # We can skip the rest of the tests because they aren't going to pass 83 AS_IF([test $enablepetsc != no], 84 [ 85 # Try to compile a trivial PETSc program to check our 86 # configuration... this should handle cases where we slipped 87 # by the tests above with an invalid PETSCINCLUDEDIRS 88 # variable, which happened when PETSc 3.6 came out. 89 AC_MSG_CHECKING(whether we can compile a trivial PETSc program) 90 AC_LANG_PUSH([C++]) 91 92 # Save the original CXXFLAGS contents 93 saveCXXFLAGS="$CXXFLAGS" 94 95 # Append PETSc include paths to the CXXFLAGS variables 96 CXXFLAGS="$saveCXXFLAGS $PETSCINCLUDEDIRS" 97 98 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 99 @%:@undef MAJOR_VERSION 100 @%:@undef MINOR_VERSION 101 @%:@include <petsc.h> 102 static char help[]=""; 103 104 int main(int argc, char **argv) 105 { 106 PetscInitialize(&argc, &argv, (char*)0,help); 107 PetscFinalize(); 108 return 0; 109 } 110 ]])],[ 111 AC_MSG_RESULT(yes) 112 ],[ 113 AC_MSG_RESULT(no) 114 enablepetsc=no; enablepetsc_mpi=no 115 ]) 116 117 # Return CXXFLAGS to their original state. 118 CXXFLAGS="$saveCXXFLAGS" 119 120 AC_LANG_POP([C++]) 121 122 123 # PETSc >= 3.5.0 should have TAO built-in, we don't currently support any other type of TAO installation. 124 petsc_have_tao=no 125 AC_MSG_CHECKING(for TAO support via PETSc) 126 AC_LANG_PUSH([C]) 127 128 # Save the original CFLAGS contents 129 saveCFLAGS="$CFLAGS" 130 131 # Append PETSc include paths to the CFLAGS variables 132 CFLAGS="$saveCFLAGS $PETSCINCLUDEDIRS" 133 134 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 135 @%:@undef MAJOR_VERSION 136 @%:@undef MINOR_VERSION 137 @%:@include <petsctao.h> 138 static char help[]=""; 139 140 int main(int argc, char **argv) 141 { 142 Tao tao; 143 PetscInitialize(&argc, &argv, (char*)0,help); 144 TaoCreate(PETSC_COMM_WORLD,&tao); 145 TaoDestroy(&tao); 146 PetscFinalize(); 147 return 0; 148 } 149 ]])],[ 150 AC_MSG_RESULT(yes) 151 petsc_have_tao=yes 152 ],[ 153 AC_MSG_RESULT(no) 154 ]) 155 156 # Return C flags to their original state. 157 CFLAGS="$saveCFLAGS" 158 159 AC_LANG_POP([C]) 160 ]) 161 ]) 162 ]) 163 164 AC_SUBST(enablepetsc) 165 166 # If PETSc is still enabled at this point, do the required AC_SUBST 167 # and AC_DEFINE commands. This prevents libmesh_config.h from having 168 # confusing information in it if the test compilation steps fail. 169 AS_IF([test $enablepetsc != no], 170 [ 171 AC_SUBST(petscversion) 172 AC_SUBST(petscmajor) 173 AC_SUBST(petscminor) 174 AC_SUBST(petscmajorminor) 175 176 AC_DEFINE_UNQUOTED(DETECTED_PETSC_VERSION_MAJOR, [$petscmajor], 177 [PETSc's major version number, as detected by petsc.m4]) 178 179 AC_DEFINE_UNQUOTED(DETECTED_PETSC_VERSION_MINOR, [$petscminor], 180 [PETSc's minor version number, as detected by petsc.m4]) 181 182 AC_DEFINE_UNQUOTED(DETECTED_PETSC_VERSION_SUBMINOR, [$petscsubminor], 183 [PETSc's subminor version number, as detected by petsc.m4]) 184 185 AC_DEFINE_UNQUOTED(DETECTED_PETSC_VERSION_RELEASE, [$petscrelease], 186 [PETSc release (1) or petsc-dev (0), as detected by petsc.m4]) 187 188 # Set a #define if PETSc was built with debugging enabled. Note 189 # that this token will appear as LIBMESH_PETSC_USE_DEBUG in our 190 # header, so it won't collide with PETSc's. It is safe to test 191 # the value of $petsc_use_debug, it is guaranteed to be either 0 192 # or nonzero. 193 AS_IF([test $petsc_use_debug -gt 0], 194 [AC_DEFINE(PETSC_USE_DEBUG, 1, [Flag indicating whether or not PETSc was configured with debugging enabled])]) 195 196 # Set a #define if PETSc was built with SuperLU_dist support 197 AS_IF([test $petsc_have_superlu_dist -gt 0], 198 [AC_DEFINE(PETSC_HAVE_SUPERLU_DIST, 1, [Flag indicating whether or not PETSc was configured with SuperLU_dist support])]) 199 200 # Set a #define if PETSc was built with MUMPS support 201 AS_IF([test $petsc_have_mumps -gt 0], 202 [AC_DEFINE(PETSC_HAVE_MUMPS, 1, [Flag indicating whether or not PETSc was configured with MUMPS support])]) 203 204 # Set a #define if PETSc was built with Chaco support 205 AS_IF([test $petsc_have_chaco -gt 0], 206 [AC_DEFINE(PETSC_HAVE_CHACO, 1, [Flag indicating whether or not PETSc was configured with CHACO support])]) 207 208 # Set a #define if PETSc was built with Party support 209 AS_IF([test $petsc_have_party -gt 0], 210 [AC_DEFINE(PETSC_HAVE_PARTY, 1, [Flag indicating whether or not PETSc was configured with PARTY support])]) 211 212 # Set a #define if PETSc was built with PTScotch support 213 AS_IF([test $petsc_have_ptscotch -gt 0], 214 [AC_DEFINE(PETSC_HAVE_PTSCOTCH, 1, [Flag indicating whether or not PETSc was configured with PTSCOTCH support])]) 215 216 # Set a #define if PETSc was built with ParMETIS support 217 AS_IF([test $petsc_have_parmetis -gt 0], 218 [AC_DEFINE(PETSC_HAVE_PARMETIS, 1, [Flag indicating whether or not PETSc was configured with ParMETIS support])]) 219 220 AC_SUBST(PETSC_ARCH) # Note: may be empty... 221 AC_SUBST(PETSC_DIR) 222 223 AC_SUBST(PETSCLINKLIBS) 224 AC_SUBST(PETSCINCLUDEDIRS) 225 AC_SUBST(PETSC_CC_INCLUDES) 226 AC_SUBST(PETSC_FC_INCLUDES) 227 228 AS_IF([test $petsc_have_hypre -gt 0], 229 [AC_DEFINE(HAVE_PETSC_HYPRE, 1, [Flag indicating whether or not PETSc was compiled with Hypre support])]) 230 231 AC_DEFINE(HAVE_PETSC, 1, [Flag indicating whether or not PETSc is available]) 232 233 AS_IF([test $petsc_have_tao != no], 234 [AC_DEFINE(HAVE_PETSC_TAO, 1, [Flag indicating whether or not the Toolkit for Advanced Optimization (TAO) is available via PETSc])]) 235 ]) 236 237 # If PETSc is not enabled, but it *was* required, error out now 238 # instead of compiling libmesh in an invalid configuration. 239 AS_IF([test "$enablepetsc" = "no" && test "$petscrequired" = "yes"], 240 dnl We return error code 3 here, since 0 means success and 1 is 241 dnl indistinguishable from other errors. Ideally, all of the 242 dnl AC_MSG_ERROR calls in our m4 files would return a different 243 dnl error code, but currently this is not implemented. 244 [AC_MSG_ERROR([*** PETSc was not found, but --enable-petsc-required was specified.], 3)]) 245 246 # If PETSc + Hypre is required, throw an error if we don't have it. 247 AS_IF([test "x$petschyprerequired" = "xyes" && test $petsc_have_hypre -eq 0], 248 [AC_MSG_ERROR([*** PETSc with Hypre was not found, but --enable-petsc-hypre-required was specified.], 4)]) 249]) 250