Difference between revisions of "build roms"

From WikiROMS
Jump to navigationJump to search
(part of big rewrite)   (change visibility)
Line 1: Line 1:
<div class="title">Build Script - <span class="red">build.sh, build.bash</span></div>
<div class="title">Build Script - <span class="red">build.sh, build.bash</span></div>


If you have more than one application (or more than one compiler), you may get tired of editing the makefile.
As mentioned in [[makefile]], you need to provide settings for some user-defined choices before you can compile ROMS. If you have more than one application (or more than one compiler), you may get tired of editing the [[makefile]]. One option is to have a makefile for each configuration, then type:
One option is to have a makefile for each configuration, then type "make -f makefile.circle_pgi", for instance. If that's too cumbersome, there's also an option of keeping track of the user-defined choices in a build script, <span class="red">build.sh</span>, located in the '''ROMS/Bin''' directory. The build script uses environment variables to overwrite the makefile targets defined with <span class="red">?=</span> syntax. [[gmake | make]] will check whether an environment variable by that name exists for each such variable in the makefile, since the environment variable take precedence. Its scope is local to the build script execution, allowing one to compile different applications at the same time. The user is free to choose between multiple makefiles or multiple build scripts.
  make -f makefile.circle_pgi
for instance. If that's too cumbersome, there's also an option of keeping track of the user-defined choices in a build script. There are now two of these scripts in the '''ROMS/Bin''' directory: '''build.sh''' (which is surprisingly a '''csh''' script) and '''build.bash'''. The build scripts use environment variables to provide values for the list above, overwriting those found in the ROMS '''makefile'''. Just as in the multiple '''makefile''' option, you will need as many build scripts as you have applications. The scope of these variables is local to the build script, allowing you to compile different applications at the same time from the same sources as long as each '''$(SCRATCH_DIR)''' is unique.


   <div class="box">'''Usage:'''<br /><br /><span class="red">  ./build.sh [options]</span><br /><br />'''Options:'''<br /><br /><span class="red">  -j [N]</span>    Compile in parallel using <span class="red">N</span> CPUs. Omit argument to compile on all availabe CPUs.<br /><span class="red">  -noclean</span>  Do not clean already compiled objects.<br /><br />'''Example:'''<br /><br /><span class="green">  ./build.sh -j 2</span></div>
   <div class="box">'''Usage:'''<br /><br /><span class="red">  ./build.sh [options]</span><br /><br />'''Options:'''<br /><br /><span class="red">  -j [N]</span>    Compile in parallel using <span class="red">N</span> CPUs. Omit argument to compile on all availabe CPUs.<br /><span class="red">  -noclean</span>  Do not clean already compiled objects.<br /><br />'''Example:'''<br /><br /><span class="green">  ./build.sh -j 2</span></div>
Line 31: Line 32:
Notice that there is a local copy of the header file '''double_gyre.h''' containing the CPP options to use in this application. We highly recommend that the user have a local copy of the header file instead of editing the distributed files in the '''ROMS/Include''' directory. During the compilation <span class="red">build.sh</span> will direct make to use the appropriate one.
Notice that there is a local copy of the header file '''double_gyre.h''' containing the CPP options to use in this application. We highly recommend that the user have a local copy of the header file instead of editing the distributed files in the '''ROMS/Include''' directory. During the compilation <span class="red">build.sh</span> will direct make to use the appropriate one.


===Environmental Variables===
===Environment Variables===


Currently, the <span class="purple">build.sh</span> sets the following environmental variables:
Currently, the <span class="purple">build.sh</span> and <span class="purple">build.bash</span> set the following environment variables described in [[makefile]] as well as a few local to the scripts:


* Set the CPP option defining the particular application. This will determine the name of the ".h" header file with the application CPP definitions. <div class="box"><span class="blue"> setenv</span> <span class="red">ROMS_APPLICATION</span>  [[DOUBLE_GYRE]]</div>
   
 
* Set a local environmental variable to define the path to the directories where all this project's files are kept.<div class="box"><span class="blue"> setenv</span> <span class="red">MY_ROOT_DIR</span>        MyRootDir<br /><span class="blue"> setenv</span><span class="red"> MY_PROJECT_DIR</span>    ${<span class="red">MY_ROOT_DIR</span>}/Projects</div>
 
* Set the path to the user's local current ROMS source code. If using '''svn''' locally, this would be the user's working copy path. Note that one advantage of maintaining your source code locally with '''svn''' is that when working simultaneously on multiple machines (e.g. a local workstation, a local cluster and a remote supercomputer) you can '''checkout''' the latest release and always get an up-to-date customized source on each machine. This script is designed to more easily allow for differing paths to the code and inputs on differing machines. <div class="box"><span class="blue"> setenv</span><span class="red"> MY_ROMS_SRC</span>        MyROMSsrcDir</div>
 
* Set tunable CPP options. Sometimes it is desirable to activate one or more CPP options to run different variants of the same application without modifying its header file. If this is the case, specify each options here using the '''-D''' syntax. Notice also that you need to use shell's quoting syntax to enclose the definition. Both single or double quotes works. <div class="box"><span class="blue"> setenv</span><span class="red"> MY_CPP_FLAGS</span>      "-D[[IS4DVAR]]"</div>to activate the Incremental, 4DVar algorithm in this particular example.
 
* Set other [[makefile]] definitions with environmental variables.<div class="box"><span class="blue"> setenv</span><span class="red"> USE_MPI</span>            on<br /><span class="blue"> setenv</span><span class="red"> USE_MPIF90</span>        on<br /><span class="blue"> setenv</span> <span class="red" >FORT</span>              pgi<br /><br /><span class="blue">#setenv</span><span class="red"> USE_DEBUG</span>          on<br /><span class="blue"> setenv</span><span class="red"> USE_LARGE</span>          on<br /></div>
 
* Sets the path to the user's header file and analytical source files, if any. See the templates in User/Functionals. <div class="box"><span class="blue"> setenv</span><span class="red"> MY_HEADER_DIR</span>      ${<span class="red">MY_PROJECT_DIR</span>}/IS4DVAR<br /><span class="blue">#setenv</span><span class="red"> MY_ANALYTICAL_DIR</span>  MyAnalyticalDir</div>
 
* Put the binary to execute in the following directory.<div class="box"><span class="blue"> setenv</span><span class="red"> BINDIR</span>            ${<span class="red">MY_PROJECT_DIR</span>}/IS4DVAR</div>
 
* Put the f90 and other object files in a project specific Build directory to avoid conflict with other projects. <div class="box"><span class="blue"> setenv</span><span class="red"> SCRATCH_DIR</span>        ${<span class="red">MY_PROJECT_DIR</span>}/IS4DVAR/Build</div>
 
* Go to the users source directory to compile. The options set above will pick up the application-specific code from the appropriate place. <div class="box"><span class="blue"> cd</span> ${<span class="red">MY_PROJECT_DIR</span>}</div>


* If appropriate, remove build directory. <div class="box"><span class="blue"> if ( $clean == 1 ) then</span><br /><span class="red">  make clean</span><br /><span class="blue"> endif</span></div>
* If appropriate, remove build directory. <div class="box"><span class="blue"> if ( $clean == 1 ) then</span><br /><span class="red">  make clean</span><br /><span class="blue"> endif</span></div>


* Finally, compile application. <div class="box"><span class="blue"> if ( $parallel == 1 ) then</span><br /><span class="red">  make $NCPUS</span><br /><span class="blue"> else</span><br /><span class="red">  make</span><br /><span class="blue"> endif</span></div>
* Finally, compile application. <div class="box"><span class="blue"> if ( $parallel == 1 ) then</span><br /><span class="red">  make $NCPUS</span><br /><span class="blue"> else</span><br /><span class="red">  make</span><br /><span class="blue"> endif</span></div>

Revision as of 21:27, 16 June 2008

Build Script - build.sh, build.bash

As mentioned in makefile, you need to provide settings for some user-defined choices before you can compile ROMS. If you have more than one application (or more than one compiler), you may get tired of editing the makefile. One option is to have a makefile for each configuration, then type:

 make -f makefile.circle_pgi

for instance. If that's too cumbersome, there's also an option of keeping track of the user-defined choices in a build script. There are now two of these scripts in the ROMS/Bin directory: build.sh (which is surprisingly a csh script) and build.bash. The build scripts use environment variables to provide values for the list above, overwriting those found in the ROMS makefile. Just as in the multiple makefile option, you will need as many build scripts as you have applications. The scope of these variables is local to the build script, allowing you to compile different applications at the same time from the same sources as long as each $(SCRATCH_DIR) is unique.

Usage:

./build.sh [options]

Options:

-j [N] Compile in parallel using N CPUs. Omit argument to compile on all availabe CPUs.
-noclean Do not clean already compiled objects.

Example:

./build.sh -j 2

The new structure of ROMS (version 3.0 or higher) allows user specific CPP definitions and analytical options to be set in a small number of separate standalone header files. Therefore, users no longer have to modify small blocks of code within huge files as was necessary in previous versions (cppdefs.h and analytical.F). This makes it easy to distribute the configuration for a specific application via a small number of source code related files plus the inputs (grid, initial conditions, and forcing NetCDF files), while allowing users of the application to keep current with central code improvements via svn. This also takes care of all licensing issues. You are free to include your own statement of your contributions in the files you distribute. The license and copyright statements by the ROMS developer group remain in the source code distributed at www.myroms.org.

We recommend that users work with a local source code that is regularly updated with the official version at the ROMS svn repository using svn update. This will allow bug fixes and new code developments to be pushed out to users and minimize the risk of a user unwittingly working with code with known flaws. There are a few standalone applications in ROMS website Datasets menu. The user can download any of these set-ups. Note that these applications do not include the source code since the user can checkout the latest version of ROMS from the svn repository. We usually create a Projects root directory containing all applications. For example, the double gyre test case (double_gyre.tar.gz) has the following directory structure:

 Projects                               root directory 
         /double_gyre                   idealized double gyre test case 
                     /Data              input NetCDF files 
                     /Forward           nonlinear model, ensembles 
                     /IS4DVAR           incremental, strong contraint 4DVar 
                     /OBS               data assimilation observations

If you check the IS4DVAR sub-directory, you will find the following files:

 Projects 
         /double_gyre 
                     /IS4DVAR 
                             /build.sh
                             /double_gyre.h
                             /job_is4dvar.sh
                             /is4dvar.in
                             /ocean_double_gyre.in
                             /s4dvar.in

Notice that there is a local copy of the header file double_gyre.h containing the CPP options to use in this application. We highly recommend that the user have a local copy of the header file instead of editing the distributed files in the ROMS/Include directory. During the compilation build.sh will direct make to use the appropriate one.

Environment Variables

Currently, the build.sh and build.bash set the following environment variables described in makefile as well as a few local to the scripts:


  • If appropriate, remove build directory.
    if ( $clean == 1 ) then
    make clean
    endif
  • Finally, compile application.
    if ( $parallel == 1 ) then
    make $NCPUS
    else
    make
    endif