configure.sh 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. #!/bin/bash
  2. rm -f *.x most_* F90_*
  3. # check for FORTRAN-90 compiler
  4. # put your favourite compiler in front if you have more than one
  5. # WARNING: Portland Group Compiler pgf is reported to be buggy
  6. for MOST_F90 in ifort gfortran xlf sunf90 nagfor f90 f95 pgf90 g95 af90 NO_F90
  7. do
  8. `hash 2>/dev/null $MOST_F90`
  9. if [ $? = 0 ] ; then break ; fi
  10. done
  11. if [ $MOST_F90 != "NO_F90" ] ; then
  12. F90_PATH=`which $MOST_F90`
  13. echo "Found FORTRAN-90 compiler at: $F90_PATH"
  14. if [ $MOST_F90 = "sunf90" ] ; then
  15. MOST_F90_OPTS="-O3"
  16. DEBUG_F90_OPTS="-g -C -ftrap=common"
  17. echo > most_precision_options "MOST_PREC=-r8"
  18. elif [ $MOST_F90 = "ifort" ] ; then
  19. MOST_F90_OPTS="-O"
  20. DEBUG_F90_OPTS="-g -C -fpe0 -traceback"
  21. echo > most_precision_options "MOST_PREC=-r8"
  22. elif [ $MOST_F90 = "nagfor" ] ; then
  23. MOST_F90_OPTS="-O -kind=byte"
  24. DEBUG_F90_OPTS="-g -C -fpe0 -traceback -kind=byte"
  25. elif [ $MOST_F90 = "gfortran" ] ; then
  26. # get major and minor version number
  27. GFMAJ=`gfortran -dumpversion | head -1 | sed -e 's/.*)//' | awk 'BEGIN {FS="."}{print $1}'`
  28. GFMIN=`gfortran -dumpversion | head -1 | sed -e 's/.*)//' | awk 'BEGIN {FS="."}{print $2}'`
  29. GFVER=`expr 100 '*' $GFMAJ + $GFMIN`
  30. echo "gfortran version " $GFMAJ.$GFMIN
  31. # flags for gfortran version >= 4.9 [ -ffpe-summary ]
  32. if [ "$GFVER" -ge "409" ] ; then
  33. MOST_F90_OPTS="-O3 -ffpe-trap=invalid,zero,overflow -ffpe-summary=none -finit-real=snan"
  34. DEBUG_F90_OPTS="-g -O0 -ffpe-trap=invalid,zero,overflow -ffpe-summary=none -fcheck=all -finit-real=snan"
  35. echo > most_precision_options "MOST_PREC=-fdefault-real-8"
  36. # flags for gfortran version 4.5 - 4.8
  37. elif [ "$GFVER" -ge "405" ] ; then
  38. MOST_F90_OPTS="-O3 -ffpe-trap=invalid,zero,overflow -finit-real=snan"
  39. DEBUG_F90_OPTS="-g -O0 -ffpe-trap=invalid,zero,overflow -fcheck=all -finit-real=snan"
  40. echo > most_precision_options "MOST_PREC=-fdefault-real-8"
  41. # flags for gfortran version 4.2, 4.3 and 4.4
  42. else
  43. MOST_F90_OPTS="-O3"
  44. DEBUG_F90_OPTS="-g -ffpe-trap=invalid,zero,overflow -fbounds-check"
  45. fi
  46. else
  47. MOST_F90_OPTS="-O"
  48. DEBUG_F90_OPTS="-g"
  49. fi
  50. echo > most_compiler "MOST_F90=$MOST_F90"
  51. echo >> most_compiler "MOST_F90_OPTS=$MOST_F90_OPTS"
  52. echo >> most_compiler "MPIMOD=mpimod_stub"
  53. echo > most_debug_options "MOST_F90_OPTS=$DEBUG_F90_OPTS"
  54. else
  55. echo "****************************************************"
  56. echo "* Sorry - didn't find any FORTRAN-90 compiler *"
  57. echo "* Please install one (e.g. gfortran or g95) *"
  58. echo "* or update list of known compilers in this script *"
  59. echo "****************************************************"
  60. exit 1
  61. fi
  62. #check for Xlib
  63. if [ -e "/usr/X11/lib64/libX11.so" ] ; then
  64. XLIB_PATH="/usr/X11/lib64"
  65. XINC_PATH="/usr/X11/lib64/include"
  66. elif [ -e "/usr/lib64/libX11.so" ] ; then
  67. XLIB_PATH="/usr/lib64"
  68. XINC_PATH="/usr/lib64/include"
  69. elif [ -e "/usr/X11/lib" ] ; then
  70. XLIB_PATH="/usr/X11/lib"
  71. XINC_PATH="/usr/X11/include"
  72. elif [ -e "/usr/lib/X11" ] ; then
  73. XLIB_PATH="/usr/lib/X11"
  74. XINC_PATH="/usr/lib/X11/include"
  75. elif [ -e "/opt/X11" ] ; then
  76. XLIB_PATH="/opt/X11"
  77. XINC_PATH="/opt/X11/include"
  78. fi
  79. if [ -n ${XLIB_PATH} ] ; then
  80. echo "Found Xlib (X11) at: $XLIB_PATH"
  81. GUILIB="-L$XLIB_PATH -lX11"
  82. else
  83. echo "**********************************************"
  84. echo "* Didn't find Xlib (X11) at standard paths *"
  85. echo "* Hopefully the compiler will find it itself *"
  86. echo "**********************************************"
  87. GUILIB=" -lX11"
  88. fi
  89. #check for C compiler
  90. # put your favourite compiler in front if you have more than one
  91. for MOST_CC in gcc cc gxlc suncc cc NO_CC
  92. do
  93. `hash 2>/dev/null $MOST_CC`
  94. if [ $? = 0 ] ; then break ; fi
  95. done
  96. if [ $MOST_CC != "NO_CC" ] ; then
  97. CC_PATH=`which $MOST_CC`
  98. echo >> most_compiler MOST_CC=$MOST_CC " # " $CC_PATH
  99. echo >> most_compiler "MOST_CC_OPTS=-O3 -I" $XINC_PATH
  100. echo "Found C compiler at: $CC_PATH"
  101. if [ $MOST_CC = "suncc" ] ; then
  102. echo >> most_debug_options "MOST_CC_OPTS=-g -C -ftrap=common"
  103. else
  104. echo >> most_debug_options "MOST_CC_OPTS=-g"
  105. fi
  106. else
  107. echo "****************************************************"
  108. echo "* Sorry - didn't find any C compiler *"
  109. echo "* Please install one (e.g. gcc or g++ *"
  110. echo "* or update list of known compilers in this script *"
  111. echo "****************************************************"
  112. exit 2
  113. fi
  114. # check for C++ compiler
  115. # put your favourite compiler in front if you have more than one
  116. for MOST_PP in c++ g++ NO_PP
  117. do
  118. `hash 2>/dev/null $MOST_PP`
  119. if [ $? = 0 ] ; then break ; fi
  120. done
  121. if [ $MOST_PP != "NO_PP" ] ; then
  122. PP_PATH=`which $MOST_PP`
  123. echo >> most_compiler MOST_PP=$MOST_PP " # " $PP_PATH
  124. echo "Found C++ compiler at: $PP_PATH"
  125. else
  126. echo "****************************************************"
  127. echo "* Sorry - didn't find any C++ compiler *"
  128. echo "* Please install one (e.g. c++ or g++ *"
  129. echo "* or update list of known compilers in this script *"
  130. echo "****************************************************"
  131. exit 2
  132. fi
  133. #check for MPI-FORTRAN-90 compiler
  134. for MPI_F90 in openmpif90 mpif90 mpf90 mpxlf90 NO_F90
  135. do
  136. `hash 2>/dev/null $MPI_F90`
  137. if [ $? = 0 ] ; then break ; fi
  138. done
  139. if [ $MPI_F90 != "NO_F90" ] ; then
  140. F90_PATH=`which $MPI_F90`
  141. if [ $MPI_F90 = "openmpif90" ] ; then
  142. MPI_RUN="openmpiexec"
  143. else
  144. MPI_RUN="mpiexec"
  145. fi
  146. echo > most_compiler_mpi "MPI_RUN=$MPI_RUN"
  147. echo >> most_compiler_mpi MOST_F90=$MPI_F90
  148. echo >> most_compiler_mpi "MOST_F90_OPTS=$MOST_F90_OPTS"
  149. echo >> most_compiler_mpi "MPIMOD=mpimod"
  150. echo "Found MPI FORTRAN-90 compiler at: $F90_PATH"
  151. else
  152. echo "********************************************"
  153. echo "* No Message Passing Interface (MPI) found *"
  154. echo "* Models run on single CPU *"
  155. echo "********************************************"
  156. fi
  157. #check for MPI-C compiler
  158. if [ $MPI_F90 != "NO_F90" ] ; then
  159. for MPI_CC in openmpicc gxlc mpicc mpcc g++ gcc NO_CC
  160. do
  161. `hash 2>/dev/null $MPI_CC`
  162. if [ $? = 0 ] ; then break ; fi
  163. done
  164. if [ $MPI_CC != "NO_CC" ] ; then
  165. CC_PATH=`which $MPI_CC`
  166. echo >> most_compiler_mpi MOST_CC=$MPI_CC
  167. echo >> most_compiler_mpi "MOST_CC_OPTS=-O3"
  168. echo "Found MPI C compiler at: $CC_PATH"
  169. else
  170. echo "********************************************"
  171. echo "* No MPI C compiler found *"
  172. echo "********************************************"
  173. fi
  174. fi
  175. #check for MPI-C++ compiler
  176. if [ $MPI_F90 != "NO_F90" ] ; then
  177. for MPI_PP in openmpicxx mpicxx NO_PP
  178. do
  179. `hash 2>/dev/null $MPI_PP`
  180. if [ $? = 0 ] ; then break ; fi
  181. done
  182. if [ $MPI_PP != "NO_PP" ] ; then
  183. PP_PATH=`which $MPI_PP`
  184. echo >> most_compiler_mpi MOST_PP=$MPI_PP
  185. echo >> most_compiler_mpi "MOST_PP_OPTS=-O3 -DMPI"
  186. echo >> most_debug_options "MOST_PP_OPTS=-g -DMPI"
  187. echo "Found MPI C++ compiler at: $PP_PATH"
  188. else
  189. echo "********************************************"
  190. echo "* No MPI C++ compiler found *"
  191. echo "********************************************"
  192. fi
  193. fi
  194. #check for 86_64 operating system
  195. MACHINE=`uname -m`
  196. #check for GNU assembler
  197. for MOST_AS in as NO_AS
  198. do
  199. `hash 2>/dev/null $MOST_AS`
  200. if [ $? = 0 ] ; then break ; fi
  201. done
  202. if [ $MOST_AS != "NO_AS" ] ; then
  203. AS_PATH=`which $MOST_AS`
  204. echo >> most_compiler MOST_AS=$MOST_AS
  205. echo >> most_compiler_mpi MOST_AS=$MOST_AS
  206. echo "Found GNU assembler at: $AS_PATH"
  207. fi
  208. # activate fast assembler Legendre module for OS X and Linux 64 bit
  209. if [ $MACHINE = "x86_64" -a $MOST_AS = "as" ] ; then
  210. # use fast vectorized assembler routines for Legendre transformation
  211. echo >> most_compiler_mpi LEGMOD=legini
  212. echo >> most_compiler_mpi LEGFAST=legfast32.o
  213. echo >> most_compiler LEGMOD=legini
  214. echo >> most_compiler LEGFAST=legfast32.o
  215. UNAMES=`uname -s`
  216. # generate correct symbol names for accessing gfortran module variables
  217. if [ $UNAMES = "Darwin" ] ; then
  218. echo "Fast Legendre Transformation : ACTIVE (Darwin)"
  219. else
  220. echo "Fast Legendre Transformation : ACTIVE (Linux)"
  221. fi
  222. else
  223. # use FORTRAN routines for Legendre transformation
  224. echo >> most_compiler_mpi LEGMOD=legsym
  225. echo >> most_compiler_mpi LEGFAST=
  226. echo >> most_compiler LEGMOD=legsym
  227. echo >> most_compiler LEGFAST=
  228. fi
  229. echo >> most_compiler "GUILIB=$GUILIB"
  230. echo >> most_compiler_mpi "GUILIB=$GUILIB"
  231. echo >> most_compiler "GUIMOD=guimod"
  232. echo >> most_compiler_mpi "GUIMOD=guimod"
  233. echo >> most_compiler "PUMAX=pumax"
  234. echo >> most_compiler_mpi "PUMAX=pumax"
  235. echo > makefile "most.x: most.c"
  236. echo >> makefile " $MOST_CC -o most.x most.c -I$XINC_PATH -lm $GUILIB"
  237. echo >> makefile "clean:"
  238. echo >> makefile " rm -f *.o *.x F90* most_*"
  239. #create directories
  240. mkdir -p puma/bld
  241. mkdir -p puma/bin
  242. mkdir -p puma/run
  243. mkdir -p plasim/bld
  244. mkdir -p plasim/bin
  245. mkdir -p plasim/run
  246. mkdir -p plasim/dat/T21_exo
  247. mkdir -p plasim/dat/T42_exo
  248. #mkdir -p cat/bld
  249. #mkdir -p cat/bin
  250. #mkdir -p cat/run
  251. #mkdir -p sam/bld
  252. #mkdir -p sam/bin
  253. #mkdir -p sam/run
  254. #check FORTRAN I/O
  255. export MOST_F90
  256. export MOST_CC
  257. HOSTNAME=`hostname`
  258. export HOSTNAME
  259. MOSTARCH=`uname -a`
  260. export MOSTARCH
  261. make -e -f makecheck
  262. ./f90check.x
  263. ./cc_check.x
  264. echo >> most_info.txt "FORTRAN Compiler: $MOST_F90"
  265. echo >> most_info.txt "C Compiler: $MOST_CC"
  266. cat most_info.txt
  267. make
  268. echo
  269. echo "configuration complete - run <most.x>"
  270. echo
  271. #
  272. #end of configure.sh