configure.sh 10 KB

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