Difference between revisions of "build roms"

From WikiROMS
Jump to navigationJump to search
Line 2: Line 2:


If you have more than one application (or more than one compiler), you may get tired of editing the makefile.
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, <span class="red">build.sh</span>, located in the '''ROMS/Bin''' directory. The build script uses environmental variables that overwrite the makefile targets defined with <span class="red">?=</span> syntax. This means that [[gmake | make]] will check whether an environment variable by that name is set in the script that calls make. The environment variable take precedence over the makefile value. Its scope is local to the build script execution, allowing compiling different applications at the same time. It is up to the user to choose between multiple makefiles or multiple build scripts.
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.


   <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>


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 as was necessary in previous versions of [[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 [[Subversion | 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 [https://www.myroms.org www.myroms.org].
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 [[Subversion | 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 [https://www.myroms.org www.myroms.org].


We recommend that users work with a local source code that is regularly updated with the official version at the ROMS [https://www.myroms.org/projects/src 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 [http://www.myroms.org/index.php?page=Datasets 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:
We recommend that users work with a local source code that is regularly updated with the official version at the ROMS [https://www.myroms.org/projects/src 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 [http://www.myroms.org/index.php?page=Datasets 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:

Revision as of 23:44, 1 February 2008

Build Script - build.sh, build.bash

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, build.sh, located in the ROMS/Bin directory. The build script uses environment variables to overwrite the makefile targets defined with ?= syntax. 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.

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.

Environmental Variables

Currently, the build.sh sets the following environmental variables:

  • Set the CPP option defining the particular application. This will determine the name of the ".h" header file with the application CPP definitions.
    setenv ROMS_APPLICATION DOUBLE_GYRE
  • Set a local environmental variable to define the path to the directories where all this project's files are kept.
    setenv MY_ROOT_DIR MyRootDir
    setenv MY_PROJECT_DIR ${MY_ROOT_DIR}/Projects
  • 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.
    setenv MY_ROMS_SRC MyROMSsrcDir
  • 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.
    setenv MY_CPP_FLAGS "-DIS4DVAR"
    to activate the Incremental, 4DVar algorithm in this particular example.
  • Set other makefile definitions with environmental variables.
    setenv USE_MPI on
    setenv USE_MPIF90 on
    setenv FORT pgi

    #setenv USE_DEBUG on
    setenv USE_LARGE on
  • Sets the path to the user's header file and analytical source files, if any. See the templates in User/Functionals.
    setenv MY_HEADER_DIR ${MY_PROJECT_DIR}/IS4DVAR
    #setenv MY_ANALYTICAL_DIR MyAnalyticalDir
  • Put the binary to execute in the following directory.
    setenv BINDIR ${MY_PROJECT_DIR}/IS4DVAR
  • Put the f90 and other object files in a project specific Build directory to avoid conflict with other projects.
    setenv SCRATCH_DIR ${MY_PROJECT_DIR}/IS4DVAR/Build
  • Go to the users source directory to compile. The options set above will pick up the application-specific code from the appropriate place.
    cd ${MY_PROJECT_DIR}
  • If appropriate, remove build directory.
    if ( $clean == 1 ) then
    make clean
    endif
  • Finally, compile application.
    if ( $parallel == 1 ) then
    make $NCPUS
    else
    make
    endif