configure.sh 11 KB

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