test_optdepends.sh 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. #!/bin/bash
  2. # Test if external packages for PETSC are installed
  3. # Fair attempt to find the directory of a header file
  4. # example find_inc "head.h" "pack"
  5. find_inc () {
  6. local INC;
  7. INC="$(find_so "$1")";
  8. # * Faster first
  9. if [ -f "${INC}" ]; then
  10. INC="${INC}";
  11. elif [ -f "${INC}"/"$1" ]; then
  12. # ** The header is inside INC (a directory) e.g.
  13. # /usr/include/scotch
  14. # /usr/include/scotch/scotch.h
  15. INC="${INC}"/"$1"
  16. elif [ -d "${INC}" ]; then
  17. # ** INC is a directory, and the header is deep inside
  18. # (hopefully faster than `pacman')
  19. INC="$(find "${INC}" -name "$1" -print -quit)";
  20. elif [ ! "x$2" == "x" ]; then
  21. # ** May be there is a package?
  22. pacman -Qs "$2" 2>&1>/dev/null && \
  23. INC="$(pacman -Qlq "$2" | grep "/$1\$" || printf "")";
  24. fi;
  25. [[ -f "${INC}" ]] && dirname "${INC}"
  26. }
  27. # Find a shared object (library; .so extension)
  28. # example: find_so libboost_mpi
  29. find_so () {
  30. whereis -b "$1" | cut -d' ' -f2
  31. }
  32. # Find directory where a pkg-config file is
  33. # example: find_pc glut
  34. find_pc () {
  35. dirname "$(pkgconf --path "$1")"
  36. }
  37. ONLY_INC="--keep-system-cflags --cflags-only-I";
  38. MPICC=$(type -p mpicc)
  39. [[ -f ${MPICC} ]] && CONFOPTS+=" --with-cc=$(which mpicc)"
  40. MPICXX=$(type -p mpicxx)
  41. [[ -f ${MPICXX} ]] && CONFOPTS+=" --with-cxx=$(which mpicxx)"
  42. MPIFORT=$(type -p mpifort)
  43. [[ -f ${MPIFORT} ]] && CONFOPTS+=" --with-fc=$(which mpifort)"
  44. # ADIOS (adios2)
  45. if [ -f "$(find_so adios2)" ]; then
  46. CONFOPTS+=" --with-adios=1"
  47. fi;
  48. # Bison
  49. # Tested by default
  50. # BOOST: Free peer-reviewed portable C++ source libraries
  51. if [ -f "$(find_so libboost_mpi.so)" ]; then
  52. CONFOPTS+=" --with-boost=1"
  53. fi;
  54. # CHOMBO
  55. # CHACO
  56. # CTETGEN
  57. # CGNS: Recording and recovering computer data
  58. CGNS_LIB="$(find_so libcgns.so)"
  59. if [ -f "${CGNS_LIB}" ] && [ -n "$(nm -D /usr/lib/libcgns.so | grep cgp_open | cut -d" " -f3)" ]; then
  60. # CGNS_INC="$(find_inc "cgnslib.h" "cgns")"
  61. # CONFOPTS+=" -I${CGNS_INC}"
  62. # CONFOPTS+=" ${CGNS_LIB}"
  63. CONFOPTS+=" --with-cgns=1"
  64. # CONFOPTS+=" --with-cgns-lib=${CGNS_LIB}"
  65. # CONFOPTS+=" --with-cgns-include=${CGNS_INC}"
  66. else
  67. CONFOPTS+=" --with-cgns=0"
  68. fi
  69. # CUDA: non-free
  70. CONFOPTS+=" --with-cuda=0"
  71. # eigen: Lightweight C++ template library for vector and
  72. # matrix math
  73. EIGEN_DIR="$(pkgconf --cflags-only-I eigen3)"
  74. EIGEN_DIR="${EIGEN_DIR##-I}"
  75. if [ -d "${EIGEN_DIR}" ]; then
  76. CONFOPTS+=" --with-eigen=1"
  77. CONFOPTS+=" --with-eigen-include=${EIGEN_DIR}"
  78. fi
  79. # fftw: Fast-Fourier Transform
  80. if [ -f "$(find_so libfftw3_mpi.so)" ]; then
  81. CONFOPTS+=" --with-fftw=1"
  82. fi
  83. # GDB: GNU debugger
  84. if [ -f "$(find_so gdb)" ]; then
  85. CONFOPTS+=" --with-debugger=gdb"
  86. fi
  87. # # GLUT (requires OpenGL)
  88. # if [ -f "$(find_so libglut.so)" ]; then
  89. # CONFOPTS+=" --with-glut=1"
  90. # CONFOPTS+=" --with-glut-pkg-config="
  91. # CONFOPTS+=" $(find_pc glut)"
  92. # fi
  93. # HDF5: large files
  94. if [[ "$(h5stat -V)" ]]; then
  95. CONFOPTS+=" --with-hdf5=1 --with-hdf5-fortran-bindings=1"
  96. fi
  97. # hwloc: abstraction of hierarchical architectures
  98. if [ -f "$(find_so libhwloc.so)" ]; then
  99. CONFOPTS+=" --with-hwloc=1"
  100. CONFOPTS+=" --with-hwloc-pkg-config="
  101. CONFOPTS="${CONFOPTS}$(find_pc hwloc)"
  102. fi
  103. # Hypre: Large and sparse linear with massive parallel
  104. # computing
  105. HYPRE_SO="$(find_so libHYPRE.so)"
  106. if [ -f "${HYPRE_SO}" ]; then
  107. CONFOPTS+=" --with-hypre=1"
  108. CONFOPTS+=" --with-hypre-lib=${HYPRE_SO}"
  109. HYPRE_INC="$(find_inc "HYPRE.h" "hypre")"
  110. CONFOPTS+=" --with-hypre-include=${HYPRE_INC}"
  111. # CONFOPTS+=" --with-hypre=1 --download-hypre=1"
  112. # CONFOPTS+=" --with-hypre=0"
  113. fi
  114. # MED: Data Modelization and Exchanges (meshes)
  115. if [ -f "$(find_so libmed.so)" ]; then
  116. CONFOPTS+=" --with-med=1"
  117. fi
  118. # METIS: Automatic meshing partitioning
  119. if [ -f "$(find_so libmetis.so)" ]; then
  120. CONFOPTS+=" --with-metis=1"
  121. fi
  122. # # MPI4Py
  123. # if [ -n "$(pacman -Qsq mpi4py)" ]; then
  124. # mpi4py_inc="$(pacman -Ql python-mpi4py | awk '/mpi4py.h$/{print $NF}')"
  125. # CONFOPTS+=" --with-mpi4py=1"
  126. # CONFOPTS+=" --with-mpi4py-include="
  127. # CONFOPTS+=" $(dirname "${mpi4py_inc}")"
  128. # CONFOPTS+=" --with-mpi4py-lib="
  129. # CONFOPTS+=" $(pacman -Ql python-mpi4py | awk '/.*\.so$/{print $NF}' | tr ' \n' ',')"
  130. # fi
  131. # MUMPS: Sparse solver library
  132. if [ -f "$(find_so libmumps_common.so)" ]; then
  133. CONFOPTS+=" --with-mumps=1"
  134. fi
  135. # NetCDF
  136. if [ -f "$(find_so libnetcdf.so)" ]; then
  137. CONFOPTS+=" --with-netcdf=1"
  138. CONFOPTS+=" --with-netcdf-pkg-config="
  139. CONFOPTS="${CONFOPTS}$(find_pc netcdf)"
  140. fi
  141. # ParMETIS (non-free)
  142. CONFOPTS+=" --with-parmetis=0"
  143. # PNG
  144. if [ -f "$(find_so libpng.so)" ]; then
  145. CONFOPTS+=" --with-png=1"
  146. CONFOPTS+=" --with-png-pkg-config="
  147. CONFOPTS="${CONFOPTS}$(find_pc libpng)"
  148. fi
  149. # PNetCDF
  150. if [ -f "$(find_so libpnetcdf.so)" ]; then
  151. CONFOPTS+=" --with-pnetcdf=1"
  152. CONFOPTS+=" --with-pnetcdf-pkg-config="
  153. CONFOPTS="${CONFOPTS}$(find_pc pnetcdf)"
  154. fi
  155. # OpenBLAS: Linear algebra libraries
  156. BLAS_SO="$(find_so libblas.so)"
  157. OPENBLAS_SO="$(find_so libopenblas.so)"
  158. LAPACK_SO="$(find_so liblapack.so)"
  159. if [ -f "${BLAS_SO}" ] && [ -f "${OPENBLAS_SO}" ] \
  160. && [ -f "${LAPACK_SO}" ]; then
  161. # With help from Satish Balay
  162. # @ 3.15.4.33.g0bac13e0fe9 2021-09-21
  163. # nm -AoD /usr/lib64/libopenblas.so | grep dgetrs_
  164. CONFOPTS+=" --with-blaslapack-lib=[${LAPACK_SO},${BLAS_SO}]"
  165. fi
  166. # OpenCL: GPU computing
  167. # Check header files
  168. # (from opencl-headers package; how to do this in a consistent way?)
  169. OPENCL_INC="/usr/include/CL/cl.h"
  170. [[ -f ${OPENCL_INC} ]] ||
  171. OPENCL_INC=$(find_inc "cl.h" "opencl-clhpp")
  172. [[ -z ${OPENCL_INC} ]] &&
  173. OPENCL_INC=$(find_inc "cl.h" "opencl-headers")
  174. [[ -z ${OPENCL_INC} ]] &&
  175. OPENCL_INC=$(find_inc "cl.h" "gegl")
  176. # Check library (find libOpenCL.so)
  177. OPENCL_SO="$(find_so libOpenCL.so)"
  178. if [ -f "${OPENCL_SO}" ] && [ -f "${OPENCL_INC}" ]; then
  179. CONFOPTS+=" --with-opencl=1"
  180. fi
  181. # # OpenGL (mesa)
  182. # deprecated (VULKAN)
  183. # OpenMP: 64 bits blas and lapack, multi-threaded
  184. if [ -f "$(find_so libomp.so)" ]; then
  185. CONFOPTS+=" --with-openmp=1"
  186. fi
  187. # # OpenMPI (dependency; should be found by pacman)
  188. # MPILIBDIR=$(dirname "$(pacman -Qlq openmpi | grep 'libmpi.so$')")
  189. # MPIINC="$(pacman -Qlq openmpi | grep 'mpi.h$')"
  190. # if [ -d "${MPILIBDIR}" ]; then
  191. # CONFOPTS+=" --with-mpi=1"
  192. # CONFOPTS+=" --with-mpi-dir=/usr/"
  193. # fi
  194. # Scalapack: Parallel memory linear algebra
  195. if [ -f "$(find_so libscalapack.so)" ]; then
  196. CONFOPTS+=" --with-scalapack=1"
  197. fi
  198. # Scotch: Partitioning with sparse matrices
  199. # TODO: general (non-pacman) way
  200. PTSCOTCH_SO="$(find_so libptscotch.so)"
  201. if [ -f "${PTSCOTCH_SO}" ]; then
  202. CONFOPTS+=" --with-ptscotch=1"
  203. SCOTCH_LIBS=$(pacman -Qlq scotch | grep '.so$'| tr '\n' ',')
  204. # Check if libscotch was compiled with bz2
  205. if [ ! -z "$(nm -D $(find_so libscotch.so) | grep bz)" ]; then
  206. SCOTCH_LIBS="${SCOTCH_LIBS}$(find_so libbz2.so)"
  207. else
  208. # Remove trailing ,
  209. SCOTCH_LIBS="${SCOTCH_LIBS%%,}"
  210. fi;
  211. CONFOPTS+=" --with-ptscotch-lib=[${SCOTCH_LIBS}]"
  212. CONFOPTS+=" --with-ptscotch-include="
  213. CONFOPTS="${CONFOPTS}$(find_inc ptscotch.h scotch)"
  214. fi
  215. # SuiteSparse: Sparse matrix library
  216. if [ -f "$(find_so libsuitesparseconfig.so)" ]; then
  217. CONFOPTS+=" --with-suitesparse=1"
  218. fi
  219. # SuperLU: Subroutines for sparsse linear systems
  220. # TODO: programatic way
  221. SUPERLU_DIR="/usr/include/superlu"
  222. if [ -d "${SUPERLU_DIR}" ]; then
  223. CONFOPTS+=" --with-superlu=1"
  224. CONFOPTS+=" --with-superlu-lib=-lsuperlu"
  225. CONFOPTS+=" --with-superlu-include=${SUPERLU_DIR}"
  226. fi
  227. # YAML: configuration files
  228. # Check library (find libyaml.so)
  229. YAML_SO="$(find_so libyaml.so)"
  230. if [ -f "${YAML_SO}" ]; then
  231. CONFOPTS+=" --with-yaml=1"
  232. fi
  233. # X: to enable ksp_xmonitor
  234. LIBX11_SO="$(find_so libX11.so)"
  235. LIBX11_DIR="$(dirname ${LIBX11_SO})"
  236. if [ -f "${LIBX11_SO}" ]; then
  237. LIBX11_INC="$(pkgconf ${ONLY_INC} x11)";
  238. LIBX11_INC="${LIBX11_INC//-I/}";
  239. CONFOPTS+=" --with-x-lib=[${LIBX11_DIR}/";
  240. # As per X11.pc, it seems that xcb.so is needed
  241. CONFOPTS="${CONFOPTS}libX11-xcb.so,${LIBX11_SO}]"
  242. CONFOPTS+=" --with-x-include=${LIBX11_INC}"
  243. fi
  244. # ZLIB
  245. if [ -f "$(find_so libzlib.so)" ] || [ -f "$(find_so libz.so)" ]; then
  246. CONFOPTS+=" --with-zlib=1"
  247. CONFOPTS+=" --with-zlib-pkg-config="
  248. CONFOPTS="${CONFOPTS}$(find_pc zlib)"
  249. fi
  250. # TetGen
  251. TETGEN_SO="$(find_so libtet.so)"
  252. if [ -f "${TETGEN_SO}" ]; then
  253. CONFOPTS+=" --with-tetgen=1"
  254. CONFOPTS+=" --with-tetgen-lib=${TETGEN_SO}"
  255. CONFOPTS+=" --with-tetgen-include=$(find_inc tetgen.h tetgen)"
  256. fi
  257. # # trilinos support
  258. #
  259. # if [ "${TRILINOS_DIR}" ]; then
  260. # CONFOPTS+=" --with-ml-dir=${TRILINOS_DIR}"
  261. # # boost support (may be useful for trilinos)
  262. # CONFOPTS+=" --with-boost=1"
  263. # fi
  264. # Incompatible with complex
  265. # # sundials support
  266. # SUNDIALS_DIR="/usr/include/sundials/"
  267. # if [ -d "${SUNDIALS_DIR}" ]; then
  268. # CONFOPTS+=" --with-sundials=1"
  269. # CONFOPTS+=" --with-sundials-include=${SUNDIALS_DIR}"
  270. # fi
  271. # # pastix support (non-free)
  272. # PASTIX_CONF=$(which pastix-conf)
  273. # if [ -f "${PASTIX_CONF}" ]; then
  274. # PASTIX_DIR="$($PASTIX_CONF --incs | sed 's/-I//')"
  275. # if [ ! -d ${PASTIX_DIR} ]; then
  276. # PASTIX_DIR="[]"
  277. # fi
  278. # #PASTIX_LIBS="$($PASTIX_CONF --libs)"
  279. # PASTIX_LIBS="[libpastix.a,librt.so,libhwloc.so,libpthread.a]"
  280. # CONFOPTS+=" --with-pastix=1"
  281. # CONFOPTS+=" --with-pastix-lib=${PASTIX_LIBS}"
  282. # CONFOPTS+=" --with-pastix-include=${PASTIX_DIR}"
  283. # fi
  284. echo "${CONFOPTS}"