configure.sh 10 KB

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