compilation.sh 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #!/usr/bin/env bash
  2. # remote_setup.sh:
  3. # Extracts the sources from the Autosubmit project bundle and compiles EC-Earth
  4. set -xuve
  5. #
  6. # Architecture
  7. #
  8. HPCARCH=%HPCARCH%
  9. CURRENT_ROOTDIR=%CURRENT_ROOTDIR%
  10. PROJNAME=%PROJECT_DESTINATION%
  11. PROJDIR=${CURRENT_ROOTDIR}/${PROJNAME}
  12. TEMPLATE_NAME=%TEMPLATE_NAME%
  13. NEMO_resolution=%NEMO_resolution%
  14. ICE=%ICE%
  15. NEMO_CONFIG=${NEMO_resolution}_${ICE}
  16. MAKE_NUMPROC=%NUMPROC%
  17. BSC_OUTCLASS=%BSC_OUTCLASS%
  18. # define which runtime we are using
  19. use_autosubmit=true
  20. [[ use_autosubmit && ${PROJNAME} == 'ecearth3' ]] && use_autosubmit_simple=true || use_autosubmit_simple=false
  21. #when using the simplified AS runtime we use the same ECEARTH_SRC_DIR definition
  22. #as in the full auto-ecearth AS runtime, to avoid having to change it in config-build and config-run
  23. #TODO set SRCDIR from ECEARTH_SRC_DIR, requires writing this script as an ec-conf template
  24. if $use_autosubmit_simple ; then
  25. SRCDIR=${CURRENT_ROOTDIR}/auto-ecearth3/sources/sources
  26. else
  27. SRCDIR=${CURRENT_ROOTDIR}/${PROJNAME}/sources/sources
  28. fi
  29. # Variables that could be used from config-build.xml should be exported
  30. export exp_name=%EXPID%
  31. # these variables are to be used for development, allowing to retain any local
  32. # changes to the sources and compile the model more quickly
  33. # EXTRACT : extract files from uploaded .tar.gz file and copy runtime files (default:true)
  34. # CLEAN : do 'make clean' for all model components (default:true)
  35. [ "%MODEL_EXTRACT%" = FALSE ] && MODEL_EXTRACT=false || MODEL_EXTRACT=true
  36. [ "%MODEL_CLEAN%" = FALSE ] && MODEL_CLEAN=false || MODEL_CLEAN=true
  37. export MODEL_CLEAN
  38. #
  39. # get model config from AS variables (for compilation only)
  40. #
  41. #ifs
  42. [[ "$TEMPLATE_NAME" = ecearth3* || "$TEMPLATE_NAME" = ifs3* ]] && ifs="ifs" || ifs=""
  43. [[ "$TEMPLATE_NAME" = ifs3* ]] && amip="amip" || amip=""
  44. #nemo
  45. if [[ "$TEMPLATE_NAME" = ecearth3* || "$TEMPLATE_NAME" = nemo3* ]]; then nemo="nemo"; lim3="lim3"; xios="xios:detached"; else nemo=""; lim3=""; xios=""; fi
  46. [[ "$TEMPLATE_NAME" = ecearth3* ]] && rnfmapper="rnfmapper" || rnfmapper=""
  47. [[ "%NEMO_remove_land%" = TRUE && ! -z $nemo ]] && elpin=":elpin" || elpin=""
  48. [ "%PISCES%" = TRUE ] && pisces="pisces" || pisces=""
  49. #others
  50. [[ "%LPJG%" = TRUE ]] && lpjg=%LPJG_CONFIG% || lpjg=""
  51. config="${ifs} ${amip} ${nemo}${elpin} ${pisces} ${lim3} ${rnfmapper} ${xios} oasis ${lpjg}"
  52. # or you can set here the components you want to build
  53. #config="ifs amip nemo rnfmapper xios oasis lpjg" # for all components (esm runtime)
  54. #config="oasis lpjg" # for LPJG-offline
  55. #
  56. # Loading of modules
  57. #
  58. set +xuve
  59. if [ ${HPCARCH} == 'ecmwf-xc40' ]
  60. then
  61. export architecture=ecmwf-cca-intel-mpi
  62. # TODO use preloadcmd from ecconf
  63. module unload PrgEnv-cray
  64. module unload PrgEnv-intel
  65. module unload PrgEnv-gnu
  66. module load PrgEnv-intel
  67. module load cray-hdf5-parallel/1.8.14
  68. module load cray-netcdf-hdf5parallel/4.3.3.1
  69. module unload eccodes
  70. module load grib_api/1.12.3
  71. elif [ ${HPCARCH} == 'finisterrae2' ]
  72. then
  73. export SCRATCH=${LUSTRE}
  74. export architecture=cesga-finisterrae2-intel-intelmpi
  75. module load intel/2016
  76. module load impi/5.1
  77. module load netcdf-fortran/4.4.3
  78. module load grib_api/1.14.5
  79. module load hdf5/1.8.16
  80. module load mkl/11.3
  81. module load gribex/370
  82. elif [ ${HPCARCH} == 'nord3' ]
  83. then
  84. export SCRATCH=/gpfs/scratch/`id -gn`/${USER}
  85. export architecture=bsc-nord3-intel-intelmpi
  86. module unload intel
  87. module load intel/2017.1
  88. elif [ ${HPCARCH} == 'marenostrum4' ]
  89. then
  90. export SCRATCH=/gpfs/scratch/`id -gn`/${USER}
  91. export architecture=bsc-marenostrum4-intel-intelmpi
  92. module unload intel
  93. module unload impi
  94. module unload mkl
  95. module load intel/2017.4
  96. module load impi/2018.4
  97. module load perl/5.26
  98. module load mkl/2018.4 # require by python/2.7.14
  99. module load python/2.7.14
  100. else
  101. error "Unsupported ec-conf architechture: ${HPCARCH}"
  102. exit 0
  103. fi
  104. module list
  105. set -xuve
  106. #
  107. # Extract Model Sources and copy runtime, only if MODEL_EXTRACT=TRUE
  108. #
  109. if ${MODEL_EXTRACT} ; then
  110. #
  111. # Extract Model Sources
  112. #
  113. cd ${CURRENT_ROOTDIR}
  114. if [ -f ${PROJNAME}.tar.gz ]; then
  115. tar -xvf ${PROJNAME}.tar.gz
  116. rm ${PROJNAME}.tar.gz
  117. # move sources into auto-ecearth3/sources to make it consistent with ECEARTH_SRC_DIR
  118. if $use_autosubmit_simple
  119. then
  120. mkdir -p ${CURRENT_ROOTDIR}/auto-ecearth3
  121. mv ${PROJNAME} ${CURRENT_ROOTDIR}/auto-ecearth3/sources
  122. ln -sf ${CURRENT_ROOTDIR}/auto-ecearth3 ${PROJNAME}
  123. fi
  124. fi
  125. #
  126. # Copy runtime
  127. # TODO check if we can link instead of copy
  128. #
  129. cd ${CURRENT_ROOTDIR}
  130. cp ${PROJNAME}/sources/runtime/autosubmit/ecconf.cfg .
  131. cp ${PROJNAME}/sources/runtime/classic/lib*.sh .
  132. cp -r ${PROJNAME}/sources/runtime/classic/ctrl/ .
  133. # should we need to override any files in classic/ctrl/ put them in the autosubmit/ctrl folder
  134. # and uncomment this line
  135. #cp -r ${PROJNAME}/sources/runtime/autosubmit/ctrl/ .
  136. if [[ -n "${BSC_OUTCLASS-}" && -d ${PROJNAME}/outclass/${BSC_OUTCLASS}/ ]]; then
  137. [ -f ${PROJNAME}/outclass/${BSC_OUTCLASS}/outclass_extra_nemo_compilation_keys.fcm ] && outclass_extra_nemo_compilation_keys=$(cat ${PROJNAME}/outclass/${BSC_OUTCLASS}/outclass_extra_nemo_compilation_keys.fcm)
  138. else
  139. echo "WARNING: you are using the outclass from ec-earth portal"
  140. fi
  141. fi # $MODEL_EXTRACT
  142. #
  143. # librunscript defines some helper functions
  144. #
  145. cd ${CURRENT_ROOTDIR}
  146. source ./librunscript.sh
  147. cd ${SRCDIR}
  148. if [ ${HPCARCH} == 'ecmwf-xc40' ]
  149. then
  150. util/ec-conf/ec-conf --platform ${architecture} -o PLT:ACTIVE:ECEARTH_SRC_DIR='${SCRATCH}/${exp_name}/auto-ecearth3/sources/sources' config-build.xml
  151. else
  152. util/ec-conf/ec-conf --platform ${architecture} config-build.xml
  153. fi
  154. if $(has_config nemo) ; then
  155. #
  156. # Select correct nemo_config
  157. #
  158. has_config pisces && NEMO_CONFIG=${NEMO_CONFIG}_PISCES
  159. ! has_config ifs && NEMO_CONFIG=${NEMO_CONFIG}_standalone
  160. if [[ ${NEMO_resolution-} != "%%NEMO_resolution%%" && ! -z ${NEMO_resolution-} ]] ; then
  161. #
  162. # NEMO compilation key
  163. #
  164. new_nemo_compilation_keys=" key_init_alloc_zero ${outclass_extra_nemo_compilation_keys-}"
  165. fcm_file=$(ls ${SRCDIR}/nemo-3.6/CONFIG/${NEMO_CONFIG}/*.fcm)
  166. for key in ${new_nemo_compilation_keys}; do
  167. if [[ $(grep ${key} ${fcm_file}) == "" ]] ; then
  168. echo adding ${key}
  169. sed -i -e 1's/$/'" "${key}' &/' ${fcm_file}
  170. fi
  171. done
  172. fi
  173. fi
  174. #
  175. # Check bin and lib directory (git-svn issue with empty folders)
  176. #
  177. if [ ! -d ifs-36r4/bin ]
  178. then
  179. mkdir ifs-36r4/bin
  180. mkdir ifs-36r4/lib
  181. fi
  182. if [ ! -d runoff-mapper/bin ]
  183. then
  184. mkdir runoff-mapper/bin
  185. mkdir runoff-mapper/lib
  186. fi
  187. if [ ! -d amip-forcing/bin ]
  188. then
  189. mkdir amip-forcing/bin
  190. mkdir amip-forcing/lib
  191. fi
  192. if [ ! -d lpjg/build ]
  193. then
  194. mkdir lpjg/build
  195. fi
  196. # minimum sanity
  197. #has_config amip nemo && error "Cannot have both nemo and amip in config!!"
  198. #
  199. # Complilation of Model Sources
  200. #
  201. # 1) OASIS
  202. if $(has_config oasis)
  203. then
  204. cd ${SRCDIR}/oasis3-mct/util/make_dir
  205. if ${MODEL_CLEAN} ; then make realclean -f TopMakefileOasis3 BUILD_ARCH=ecconf ; fi
  206. make -f TopMakefileOasis3 BUILD_ARCH=ecconf
  207. # build lucia with the ifort compiler - modify this if you use another compiler
  208. cd ${SRCDIR}/oasis3-mct/util/lucia
  209. F90=ifort ./lucia -c
  210. fi
  211. # 2) XIOS
  212. if $(has_config xios)
  213. then
  214. cd ${SRCDIR}/xios-2.5
  215. if ${MODEL_CLEAN} ; then
  216. ./make_xios --arch ecconf --use_oasis oasis3_mct --netcdf_lib netcdf4_par --job ${MAKE_NUMPROC} --full
  217. else
  218. ./make_xios --arch ecconf --use_oasis oasis3_mct --netcdf_lib netcdf4_par --job ${MAKE_NUMPROC}
  219. fi
  220. [ -f ${SRCDIR}/xios-2.5/bin/xios_server.exe ] || exit 1
  221. fi
  222. # 3) Runoff-Mapper
  223. if $(has_config rnfmapper)
  224. then
  225. cd ${SRCDIR}/runoff-mapper/src
  226. if ${MODEL_CLEAN} ; then make clean ; fi
  227. make
  228. [ -f ${SRCDIR}/runoff-mapper/bin/runoff-mapper.exe ] || exit 1
  229. fi
  230. # 4) NEMO
  231. if $(has_config nemo)
  232. then
  233. cd ${SRCDIR}/nemo-3.6/CONFIG
  234. # remove old nemo executable to make sure compilation did not fail
  235. # workaround for the issue that make_nemo does not return an exit code on failure
  236. rm -f ${SRCDIR}/nemo*/CONFIG/${NEMO_CONFIG}/BLD/bin/*.exe
  237. if ${MODEL_CLEAN} ; then ./makenemo -m ecconf -n ${NEMO_CONFIG} -j ${MAKE_NUMPROC} clean ; fi
  238. ./makenemo -m ecconf -n ${NEMO_CONFIG} -j ${MAKE_NUMPROC}
  239. [ -f ${SRCDIR}/nemo*/CONFIG/${NEMO_CONFIG}/BLD/bin/*.exe ] || exit 1
  240. fi
  241. # 5) IFS
  242. if $(has_config ifs)
  243. then
  244. set +xuve
  245. . ${SRCDIR}/util/grib_table_126/define_table_126.sh
  246. set -xuve
  247. cd ${SRCDIR}/ifs-36r4
  248. if ${MODEL_CLEAN} ; then
  249. make clean BUILD_ARCH=ecconf
  250. make realclean BUILD_ARCH=ecconf
  251. make dep-clean BUILD_ARCH=ecconf
  252. fi
  253. make -j ${MAKE_NUMPROC} BUILD_ARCH=ecconf lib
  254. make BUILD_ARCH=ecconf master
  255. [ -f ${SRCDIR}/ifs*/bin/ifsmaster* ] || exit 1
  256. fi
  257. # 6) Amip
  258. if $(has_config amip)
  259. then
  260. cd ${SRCDIR}/amip-forcing/src
  261. if ${MODEL_CLEAN} ; then make clean ; fi
  262. make
  263. [ -f ${SRCDIR}/amip*/bin/amip* ] || exit 1
  264. fi
  265. # 7) LPJ-Guess
  266. if $(has_config lpjg)
  267. then
  268. cd ${SRCDIR}/lpjg/build
  269. set +xuve
  270. module load cmake
  271. [ ${HPCARCH} == 'marenostrum4' ] && module load grib/1.14.0
  272. set -xuve
  273. cmake ..
  274. if ${MODEL_CLEAN} ; then make clean ; fi
  275. make
  276. cd ${SRCDIR}/lpjg/offline
  277. make
  278. [ -f ${SRCDIR}/lpjg/build/guess_T255 ] || exit 1
  279. fi
  280. # 8) TM5
  281. # currently does not work, make does not expand the $exp_name in ECEARTH_SRC_DIR definition in ecconfig-ecearth3.rc
  282. if $(has_config tm5)
  283. then
  284. cd ${SRCDIR}/tm5mp/
  285. #export PATH=${PATH}:${SRCDIR}/util/makedepf90/bin/:$PATH
  286. ./setup_tm5 -n -v -j ${MAKE_NUMPROC} ecconfig-ecearth3.rc
  287. [ -f ${PROJDIR}/sources/sources/tm5mp*/build/appl-tm5.x* ] || exit 1
  288. fi
  289. # 9) ELPiN
  290. if $(has_config elpin)
  291. then
  292. cd ${SRCDIR}/util/ELPiN/
  293. make clean
  294. make
  295. fi
  296. echo "Finished compiling"
  297. set +xuve
  298. #
  299. # workaround for intelremotemond process started when compiling with
  300. # intel compilers (maybe only on MN3 ?)
  301. #
  302. set +e
  303. if [ ${HPCARCH} == 'nord3' ] ; then (! pidof intelremotemond) || killall -u ${USER} intelremotemond ; fi