source: trunk/mesoscale/LMD_MM_MARS/makemeso @ 29

Last change on this file since 29 was 29, checked in by aslmd, 14 years ago

LMD_MM_MARS: script de compilation compatible old/new physics

  • Property svn:executable set to *
File size: 21.1 KB
Line 
1#! /bin/bash
2
3
4##################################
5# makemeso allows you to compile #
6# WRF with modified LMD physics  #
7##################################
8
9##############################
10# Author: A. Spiga           #
11# New version : October 2008 #
12# Last update : January 2009 #
13#               November  09 #
14#               January   11 #
15##############################
16
17#############################
18# Use:   
19#
20# makemeso                   ## basic use (real configuration)
21#
22# makemeso -d                ## no compilation, just check the name of the compile folder
23#
24# makemeso -c real           ## real-case mode [default]
25# makemeso -c convection     ## idealized mode: convective cell
26#
27# makemeso < last            ## basic use + skip questions [! script must have been executed at least once]
28# makemeso -r < last         ## basic use + skip questions + only known config
29# makemeso -nr < last        ## basic use + skip questions + only known config + no LMD phys recompile
30#
31# makemeso -j                ## just compile the LMD physics
32#
33# makemeso -g                ## debug mode
34#
35# makemeso -h                ## display options
36#
37#############################
38
39
40# todo: netcdf support
41
42
43##############################################################################################
44##############################################################################################
45##############################################################################################
46##############################################################################################
47
48donotcompile=0
49donotallow=0
50config='real'
51donotcompilephys=0
52justphys=0
53debug=0
54phys=""
55while getopts "drc:njhgp" options; do
56  case $options in
57   d ) donotcompile=1;;     ## just to check the compile folder
58   r ) donotallow=1;;       ## allow only known config (useful with 'makemeso < last')
59   c ) config="${OPTARG}";; ## idealized cases
60   n ) donotcompilephys=1;; ## do not recompile physics
61   j ) justphys=1;;         ## just compile LMD physics
62   g ) debug=1;;            ## debug mode
63   p ) phys="newphys_";;
64   h ) echo "
65# Use:   
66#
67# makemeso                   ## basic use (real configuration)
68#
69# makemeso -d                ## no compilation, just check the name of the compile folder
70#
71# makemeso -c real           ## real-case mode [default]
72# makemeso -c convection     ## idealized mode: convective cell
73#
74# makemeso < last            ## basic use + skip questions [! script must have been executed at least once]
75# makemeso -r < last         ## basic use + skip questions + only known config
76# makemeso -nr < last        ## basic use + skip questions + only known config + no LMD phys recompile
77#
78# makemeso -j                ## just compile the LMD physics
79#
80# makemeso -g                ## debug mode
81#
82# makemeso -h                ## display options
83#
84# makemeso -p                ## with new LMD physics
85" ; exit ;;
86  esac
87done   
88
89#--------------
90# talk w/ user
91#--------------
92  echo '****************************************'
93  echo ' LMD Mesoscale Model Compiler. Welcome.'
94  echo '****************************************'
95  if [[ "${phys}" == "newphys_" ]]
96  then
97    echo '***********with new physics*************'
98    echo '****************************************'
99  fi
100  # computer
101  uname -a | grep x86_64 > /dev/null
102  if [[ "$?" == 0 ]]
103  then
104    machine='64'
105  else
106    machine='32'
107  fi
108  # compiler
109  echo "Supported compiler options are "
110  echo "       <1> pgf90"
111  echo "       <2> g95"
112  echo "       <3> pgf90 + mpi"
113  echo "       <4> ifort"
114  echo "       <5> ifort + mpi"
115  echo "       <7> xlf + mpi (IBM AIX)"
116  echo "Your choice ?" ; read reply
117  case ${reply} in
118    1) compilo='pgf' ; numproc=1 ;;
119    2) compilo='g95' ; numproc=1 ;;
120    3) compilo='mpi'
121       if [[ "${WHERE_MPI}" = "" ]]
122       then
123         echo Please initialize the variable WHERE_MPI in your environnement
124         exit
125       fi
126       echo How many processors ? 1, 2, 4, 6, 8, 12, 16 ; read numproc ;;
127    4) compilo='ifort' ; numproc=1 ;;
128    5) compilo='mpifort' ; echo How many processors ? 1, 2, 4, 6, 8, 12, 16 ; read numproc ;;
129    7) compilo='mpixlf' ; echo How many processors ? 1, 2, 4, 6, 8, 12, 16 ; read numproc ;;
130### for tests
13199) compilo='gnu' ; numproc=1 ;;
132    *) echo not supported by this script ; exit ;;
133  esac
134  # dimensions
135  if [ ${donotcompile} -eq 0 ]
136  then   
137  echo Grid points in longitude ? ; read lon
138  echo Grid points in latitude ? ; read lat
139  echo Number of vertical levels ? ; read level
140  fi
141  echo Number of domains ? ; read dom
142
143###PB lecture dom si < last
144
145    case ${dom} in
146       1) single='_single' ;;
147       *) single='_nest' ;;
148    esac
149      if [ "${compilo}" = "mpi" -o "${compilo}" = "mpifort" -o "${compilo}" = "mpixlf" ]
150      then
151           single=''
152      fi
153
154testflag=''
155####
156#testflag='_test'
157####
158
159    conf_wrf="${phys}${compilo}_${machine}${single}${testflag}"
160    \rm what_folder 2> /dev/null
161    echo ${conf_wrf} > what_folder
162         if [ ${donotcompile} -eq 1 ]
163         then
164            #\rm what_folder 2> /dev/null
165            #echo '**********************'
166            #echo '*** Your folder is ...'
167            #echo '**********************'
168            #echo ${conf_wrf} | tee what_folder
169            #cat what_folder
170            #echo ${conf_wrf} > what_folder
171            #echo ${reply} > what_compilo
172            #echo ${numproc} > what_numproc
173            exit
174         fi
175  echo Number of tracers ? ; read tra
176         if [ ${tra} -eq 0 ]
177         then
178            tra=1       
179         fi
180  # folder
181  mkdir ${conf_wrf} 2> /dev/null
182  if [[ "$?" == 0 ]]
183  then
184    echo new folder ... link sources
185    if [[ "${phys}" == "newphys_" ]]
186    then
187    sed s+"mars_lmd"+"mars_lmd_new"+g copy_model > copy_model_tmp
188    exit
189    else
190    ./copy_model
191    fi
192    mv WRFV2 ${conf_wrf}/
193    cd ${conf_wrf}/WRFV2
194    cd Registry ; Registry.bash ; cd ..
195  else
196    cd ${conf_wrf}/WRFV2
197    echo Did you modify anything in the Registry or clean ? y for yes, any key for no ; read answer
198    case ${answer} in
199      y) cd Registry ; mv Registry Registry.bak ; Registry.bash ; cd .. ;;
200      *) answer='no' ;;
201    esac
202  fi
203  # summary
204  echo '**********************'
205  echo '*** Your folder is ...'
206  echo '**********************'
207  echo ${conf_wrf}
208  echo '**********************'
209  echo '****************************************'
210  echo so ...
211  echo your computer is ${machine} bits
212  echo ${compilo} is your compiler
213       if [[ "${compilo}" = "mpi" ]]
214       then
215         echo MPICH is in ${WHERE_MPI}
216       fi
217  echo you will use ${numproc} processors
218  echo you have ${lon} x points
219  echo '         '${lat} y points
220  echo '         '${level} z points
221  echo '         '${dom} domains
222  echo '         '${tra} tracers
223  echo '****************************************'
224  # save answer
225  \rm last 2> /dev/null
226  touch last
227  echo ${reply} >> last
228     if [ "${compilo}" = "mpi" -o "${compilo}" = "mpifort" -o "${compilo}" = "mpixlf" ]
229     then
230     echo ${numproc} >> last
231     fi
232  echo ${lon} >> last
233  echo ${lat} >> last
234  echo ${level} >> last
235  echo ${dom} >> last
236  echo ${tra} >> last
237  echo ${answer} >> last
238
239
240#------------
241# log files
242#------------
243  \rm log_compile 2> /dev/null
244  \rm log_error 2> /dev/null
245
246#-----------------
247# configure WRF
248#-----------------
249  mv configure.wrf configure.wrf.bak 2> /dev/null
250  ########################
251  case ${conf_wrf} in
252#######TEST TEST
253                     # GFORTRAN, 64 bits, no nesting     
254     gnu_64_single)    cd arch ; ln -sf ../configure.defaults.gfortran64 configure.defaults ; cd ..
255                       echo 15 | configure > log_compile 2> log_error
256                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf 
257                       sed s+"-L../mars_lmd/libo -llmd"+"-L../mars_lmd/libo -llmd $NETCDF/lib/libnetcdf.a"+g configure.wrf > yeah ; mv -f yeah configure.wrf ;;
258#######TEST TEST
259                     # PGF90, 32 bits, no nesting
260     pgf_32_single)    echo 1 | configure > log_compile 2> log_error
261                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
262                     # PGF90, 32 bits, nesting
263     pgf_32_nest)      echo 2 | configure > log_compile 2> log_error
264                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
265                     # PGF90, 64 bits, no nesting
266     pgf_64_single)    echo 1 | configure > log_compile 2> log_error
267                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
268                     # PGF90, 64 bits, nesting
269     pgf_64_nest)      cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
270                       echo 4 | configure > log_compile 2> log_error
271                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
272                     # G95, 32 bits, no nesting
273     g95_32_single)    echo 13 | configure > log_compile 2> log_error
274                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
275                     # G95, 64 bits, no nesting  ### we modify configure.defaults to add x86_64 next to g95 in the header comment
276     g95_64_single)    cd arch ; sed s/"PC Linux i486 i586 i686, g95 compiler"/"PC Linux i486 i586 i686 x86_64, g95 compiler"/g configure.defaults > yeahyeahyeah ; rm configure.defaults ; mv yeahyeahyeah configure.defaults ; cd ..
277                       echo 14 | configure > log_compile 2> log_error
278                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf ;;
279                       #sed s+"=       g95"+"=       /home/physastro/aspiga/mysoft/g95/g95-install/bin/x86_64-unknown-linux-gnu-g95"+g configure.wrf > yeah ; mv -f yeah configure.wrf;;
280                     # IFORT, 64 bits, no nesting
281     ifort_64_single)  echo 5 | configure > log_compile 2> log_error
282                       sed s+"-DIFORT_KLUDGE"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
283                         ## !!! NETCDF must be defined
284                         sed s+"lio_grib_share"+"lio_grib_share -L../mars_lmd/libo -llmd $NETCDF/lib/libnetcdf.a"+g configure.wrf > yeah
285                         mv -f yeah configure.wrf ;;
286     mpifort_64)     # MPI+IFORT, 64 bits, no nesting / nesting
287                       echo 9 | configure > log_compile 2> log_error
288                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
289                       sed s+"-f90=ifort"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
290                       sed s+"-cc=icc"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
291                       sed s+"-DIFORT_KLUDGE"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
292                       sed s+"O3"+"O2"+g configure.wrf > yeah ; mv -f yeah configure.wrf
293                                        #sed s+"O3"+"O0"+g configure.wrf > yeah ; mv -f yeah configure.wrf  ### pour compilation rapide
294                                        #-w -ftz -align all -fno-alias -fp-model precise >>> options indiquees dans WRF3
295                                        #http://software.intel.com/en-us/articles/performance-tools-for-software-developers-building-wrf-with-the-intel-compilers/
296                            #### NB: RSL is replaced by RSL_LITE, better memory capacity, less seg fault
297                            sed s+"../external/RSL/RSL"+"../external/RSL_LITE"+g configure.wrf > yeah ; mv -f yeah configure.wrf
298                            sed s+"-DWRF_RSL_IO"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
299                            sed s+"-DRSL"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
300                            sed s+"librsl.a"+"librsl_lite.a"+g configure.wrf > yeah ; mv -f yeah configure.wrf
301                            sed s+"../external/RSL/gen"+"../external/RSL_LITE/gen"+g configure.wrf > yeah ; mv -f yeah configure.wrf
302                            sed s+"../external/RSL/module"+"../external/RSL_LITE/module"+g configure.wrf > yeah ; mv -f yeah configure.wrf
303                            sed s+"-lrsl"+"-lrsl_lite"+g configure.wrf > yeah ; mv -f yeah configure.wrf
304                            sed s+"linux"+" "+g configure.wrf > yeah ; mv -f yeah configure.wrf
305                         ### necessary even if mpi-selector is used (no need in makegcm though)
306                         sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g > yeah ; mv -f yeah configure.wrf
307                         sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g configure.wrf > yeah ; mv -f yeah configure.wrf
308                         ## !!! NETCDF must be defined
309                         sed s+"-L../mars_lmd/libo -llmd"+"-L../mars_lmd/libo -llmd $NETCDF/lib/libnetcdf.a"+g configure.wrf > yeah
310                         mv -f yeah configure.wrf ;;
311                     # MPICH, 64 bits, no nesting / nesting
312     mpi_64)           cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
313                       echo 3 | configure > log_compile 2> log_error
314                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
315                       sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g | sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g > yeah
316                                #| sed s+"fastsse"+"fast"+g > yeah
317                       mv -f yeah configure.wrf ;;
318                       #sed s+"-fastsse"+"-O2 -Munroll -Mcache_align"+g configure.wrf > yeah
319                       ##sed s+"-fastsse"+"-O2 -fpic"+g configure.wrf > yeah ## marche pas, ILM problem
320                       ##sed s+"-fastsse"+"-mcmodel=medium -Mlarge_arrays"+g configure.wrf > yeah ## marche pas, ILM problem
321                       #mv -f yeah configure.wrf ;;
322                     # MPICH, 64 bits, OK with periodic BC but no positive definite
323     mpi_64_test)      cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
324                       echo 2 | configure > log_compile 2> log_error
325                       sed -f mars.sed configure.wrf > yeah ; mv -f yeah configure.wrf
326                       sed s+"mpif90"+"${WHERE_MPI}/mpif90"+g configure.wrf | sed s+"mpicc"+"${WHERE_MPI}/mpicc"+g | sed s+"mpicc"+"mpicc -DMPI2_SUPPORT"+g > yeah
327                       mv -f yeah configure.wrf ;;
328                     # XLF+MPICH on AIX machine (64 bits) with nesting, NB: the 32bits notice is not to be considered
329     mpixlf_32)        cd arch ; ln -sf ../configure.defaults.fix64nest configure.defaults ; cd ..
330                       echo 3 | configure > log_compile 2> log_error
331                       sed -f mars.sed configure.wrf > yeah
332                       mv -f yeah configure.wrf ;;
333                     # ANYTHING ELSE
334     *)                echo NO PRESETS ...
335                       if [ ${donotallow} -eq 0 ] 
336                       then
337                         configure
338                       else
339                         # problem when an input file is used
340                         echo 'please cd to '$PWD' and type ./configure' 
341                         exit   
342                       fi ;;
343  esac
344  ########################
345
346  if [[ "${phys}" == "newphys_" ]]
347  then
348     sed s+"CFLAGS          =       "+"CFLAGS          =       -DNEWPHYS "+g configure.wrf > yeah
349     mv -f yeah configure.wrf
350  fi
351
352  if [ ${debug} -ne 0 ]   # not working for xlf!
353  then
354    echo 'DEBUG DEBUG DEBUG DEBUG'
355    sed s+"#-g"+"-g"+g configure.wrf > yeah
356    mv -f yeah configure.wrf
357  fi
358
359exit
360
361
362##################################################
363# compile physics
364##################################################
365if [ ${donotcompilephys} -eq 0 ]
366then
367
368  cd mars_lmd/
369
370  # required size
371  #----------------
372  case ${numproc} in
373    1) physx=$(expr ${lon} - 1)
374       physy=$(expr ${lat} - 1)
375       physz=$(expr ${level} - 1) ;;
376    2) physx=$(expr ${lon} - 1)
377       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 2)
378       physz=$(expr ${level} - 1) ;;
379    4) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
380       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 2)
381       physz=$(expr ${level} - 1) ;;
382    6) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
383       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 3)
384       physz=$(expr ${level} - 1) ;;
385    8) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 2)
386       physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
387       physz=$(expr ${level} - 1) ;;
388    12) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 3)
389        physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
390        physz=$(expr ${level} - 1) ;;
391    16) physx=$(expr ${lon} - 1) ; physx=$(expr ${physx} \/ 4)
392        physy=$(expr ${lat} - 1) ; physy=$(expr ${physy} \/ 4)
393        physz=$(expr ${level} - 1) ;;
394    *) echo not supported ; exit
395  esac
396
397  # change this if you change num_soil_layers in WRF
398  # -- default is 10
399  soilsize=10
400  #soilsize=18 ## nouvelle physique
401
402  # GCM environment variables
403  #--------------------------
404  export LMDGCM=$PWD
405  export LIBOGCM=$PWD/libo
406
407  # generate the appropriate dimphys
408  #---------------------------------
409  cd libf/phymars
410  \rm dimphys.h 2> /dev/null
411  physize=$(expr ${physx} \* ${physy})
412  sed s/--xsize--/${physx}/g meso_dimphys.h_ref | sed s/--ysize--/${physy}/g | sed s/--physize--/${physize}/g | sed s/--zsize--/${physz}/g | sed s/--soilsize--/${soilsize}/g > dimphys.h
413  head -15 dimphys.h
414  cd ../..
415
416  # prepare for nesting
417  #---------------------
418  cd libf
419  duplicate${dom} 2> /dev/null
420  cd ..
421
422  # compile physics
423  #--------------------------
424  \rm libf/grid/dimensions.h 2> /dev/null
425  \rm -rf libo/* 2> /dev/null
426  echo 1. compiling LMD physics ...
427  echo compilation info in:
428  echo $PWD/libo/log_compile_phys
429
430  if [ ${debug} -ne 0 ]
431  then
432    echo 'DEBUG DEBUG DEBUG DEBUG'
433    nohup makegcm_${compilo} -debug -t ${tra} -p mars -d ${physz} meso_testphys1d | tee libo/log_compile_phys | grep 'warnings' >> libo/log_compile_phys
434  else
435    nohup makegcm_${compilo} -t ${tra} -p mars -d ${physz} meso_testphys1d | tee libo/log_compile_phys | grep 'warnings' >> libo/log_compile_phys
436  fi
437  echo ... done
438        # clean the duplicate routines
439        cd libf
440        duplicate1 2> /dev/null
441        cd ..
442
443  # merge LMD executables in one lib
444  #--------------------------------------
445  cd libo
446  mkdir temp
447  #cp -f LINUXfastI._${physz}_t${tra}_reg/*.a temp
448  cp -f LINUX*/*.a temp
449  cd temp
450  ar x libbibio.a
451  ar x libphymars.a
452  ar x libaeronomars.a
453  \rm *.a
454  ar r liblmd.a *
455  cp -f liblmd.a ..
456  cd ..
457  \rm -r temp
458  nm liblmd.a > liblmd_content
459  # finish merge
460  cd ..
461
462  # save a copy
463  #--------------
464  cp -f libo/liblmd.a libo/liblmd.a_${lon}_${lat}_${level}_${dom}_${tra}
465  echo '****************************************'
466
467  # ok
468  #----
469  cd ..
470
471  # manage nest includes in module_lmd_driver.F
472  #----
473  cp call_meso_inifis$dom.inc call_meso_inifis.inc
474  cp call_meso_physiq$dom.inc call_meso_physiq.inc
475
476
477fi
478##################################################
479# END compile physics
480##################################################
481
482#------------------
483# compile WRF
484#------------------
485if [ ${justphys} -eq 0 ]
486then
487
488  echo 2. compiling WRF dynamical core ...
489
490  if [[ ! ( -f "call_meso_physiq.inc" ) ]]
491  then
492   echo 'did you compile the physics ? no call_meso_physiq.inc !'
493   exit
494  fi
495
496  # be sure to compile with the most recent physics
497  touch phys/module_lmd_driver.F
498
499  # talk to user
500  echo '>>> YOUR CONFIG IS : '${config}
501  echo '>>> compiling ... this may be long ... <<<'
502  echo check progress in:
503  echo $PWD/log_compile
504  echo check possible errors in:
505  echo $PWD/log_error
506 
507  # compile ...
508  case ${config} in
509    'real')         compile em_real > log_compile 2> log_error
510                    # save executables 
511                    cd main
512                      if [[ -f wrf.exe ]]
513                      then
514                        echo 'Looks good ! wrf.exe is here...'
515                      fi
516                    cp -f real.exe ../../real_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
517                    cp -f wrf.exe ../../wrf_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
518                    cd ..  ;;
519    'convection')   #mkdir 'test/em_quarter_ss' 2> /dev/null
520                    compile em_quarter_ss > log_compile 2> log_error
521                    # save executables 
522                    cd main
523                      if [[ -f wrf.exe ]]
524                      then
525                        echo 'Looks good ! wrf.exe is here...'
526                      fi
527                    cp -f ideal.exe ../../ideal_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
528                    cp -f wrf.exe ../../wrf_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}.exe
529                    cd ..  ;;
530    *)              echo not supported please use ; echo real convection ; exit ;;
531  esac
532  echo '*******last lines from log_error*********'
533  tail -n 20 log_error
534fi
535
536  # the end
537  echo '****************************************'
538  echo 'done.'
539  echo '****************************************'
540  cp last ../makemeso_x${lon}_y${lat}_z${level}_d${dom}_t${tra}_p${numproc}
541  mv last ../../
542
543  # add here specific messages
544  if [[ "${dom}" != "1" ]]
545  then
546  nest=$(expr ${lon} + 4)
547  echo NB: in namelist.input, please set:
548  echo '
549  max_dom = '$dom'
550  s_we    = 1,1,
551  e_we    = '$lon','$nest',
552  s_sn    = 1,1,
553  e_sn    = '$lat','$nest',
554  s_vert  = 1,1,
555  e_vert  = '$level','$level','
556  fi
557
Note: See TracBrowser for help on using the repository browser.