diff --git a/.gitignore b/.gitignore index 50b0866e6..492d9980f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ # Fortran *.mod -*.o \ No newline at end of file +*.o +build +bin diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..ad264b09e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,171 @@ +# Set minimum CMake version to latest version on Gadi: +cmake_minimum_required(VERSION 3.24.2) + +project( + CABLE + LANGUAGES Fortran +) + +option(CABLE_MPI "Build the MPI executable" OFF) + +# third party libs +find_package(PkgConfig REQUIRED) +pkg_check_modules(NETCDF REQUIRED IMPORTED_TARGET "netcdf-fortran") + +set(CABLE_INTEL_Fortran_FLAGS -fp-model precise) +set(CABLE_INTEL_Fortran_FLAGS_DEBUG -O0 -g -traceback -fpe0) +set(CABLE_INTEL_Fortran_FLAGS_RELEASE -O2) + +# CMake $<...> syntax is explained here: +# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#introduction +set(CABLE_EXE_NAME "$,cable-mpi,cable>") + +set( + CABLE_SRCS_SERIAL + src/offline/cable_driver.F90 +) +set( + CABLE_SRCS_MPI + src/offline/cable_mpidrv.F90 + src/offline/cable_mpicommon.F90 + src/offline/cable_mpimaster.F90 + src/offline/cable_mpiworker.F90 + src/science/pop/pop_mpi.F90 +) +set( + CABLE_SRCS_COMMON + src/science/casa-cnp/bgcdriver.F90 + src/science/casa-cnp/biogeochem_casa.F90 + src/offline/cable_abort.F90 + src/science/misc/cable_air.F90 + src/science/canopy/cable_canopy.F90 + src/science/misc/cable_carbon.F90 + src/offline/cable_checks.F90 + src/science/misc/cable_climate.F90 + src/util/cable_climate_type_mod.F90 + src/util/cable_common.F90 + src/offline/cable_cru_TRENDY.F90 + src/offline/cable_define_types.F90 + src/science/gw_hydro/cable_gw_hydro.F90 + src/offline/cable_initialise.F90 + src/offline/cable_input.F90 + src/offline/cable_iovars.F90 + src/offline/cable_LUC_EXPT.F90 + src/params/cable_maths_constants_mod.F90 + src/offline/cable_metutils.F90 + src/offline/cable_namelist_input.F90 + src/params/cable_other_constants_mod.F90 + src/offline/cable_output.F90 + src/offline/cable_parameters.F90 + src/offline/cable_pft_params.F90 + src/offline/cable_phenology.F90 + src/params/cable_photo_constants_mod.F90 + src/params/cable_phys_constants_mod.F90 + src/offline/cable_plume_mip.F90 + src/science/gw_hydro/cable_psm.F90 + src/offline/cable_read.F90 + src/science/roughness/cable_roughness.F90 + src/util/cable_runtime_opts_mod.F90 + src/offline/cable_site.F90 + src/science/sli/cable_sli_main.F90 + src/science/sli/cable_sli_numbers.F90 + src/science/sli/cable_sli_roots.F90 + src/science/sli/cable_sli_solve.F90 + src/science/sli/cable_sli_utils.F90 + src/offline/cable_soil_params.F90 + src/offline/cable_weathergenerator.F90 + src/offline/cable_write.F90 + src/offline/casa_cable.F90 + src/science/casa-cnp/casa_cnp.F90 + src/science/casa-cnp/casa_dimension.F90 + src/science/casa-cnp/casa_feedback.F90 + src/science/casa-cnp/casa_inout.F90 + src/offline/casa_ncdf.F90 + src/offline/casa_offline_inout.F90 + src/offline/CASAONLY_LUC.F90 + src/science/casa-cnp/casa_param.F90 + src/science/casa-cnp/casa_phenology.F90 + src/science/casa-cnp/casa_readbiome.F90 + src/science/casa-cnp/casa_rplant.F90 + src/science/casa-cnp/casa_sumcflux.F90 + src/science/casa-cnp/casa_variable.F90 + src/science/albedo/cbl_albedo.F90 + src/science/soilsnow/cbl_conductivity.F90 + src/science/canopy/cbl_dryLeaf.F90 + src/science/canopy/cbl_friction_vel.F90 + src/science/canopy/cbl_fwsoil.F90 + src/science/soilsnow/cbl_GW.F90 + src/science/soilsnow/cbl_hyd_redistrib.F90 + src/science/radiation/cbl_init_radiation.F90 + src/science/canopy/cbl_latent_heat.F90 + src/offline/cbl_model_driver_offline.F90 + src/science/soilsnow/cbl_Oldconductivity.F90 + src/science/canopy/cbl_photosynthesis.F90 + src/science/canopy/cbl_pot_evap_snow.F90 + src/science/canopy/cbl_qsat.F90 + src/science/radiation/cbl_radiation.F90 + src/science/soilsnow/cbl_remove_trans.F90 + src/science/radiation/cbl_rhoch.F90 + src/science/radiation/cbl_sinbet.F90 + src/science/soilsnow/cbl_smoisturev.F90 + src/science/soilsnow/cbl_snowAccum.F90 + src/science/soilsnow/cbl_snow_aging.F90 + src/science/albedo/cbl_snow_albedo.F90 + src/science/soilsnow/cbl_snowCheck.F90 + src/science/soilsnow/cbl_snowDensity.F90 + src/science/soilsnow/cbl_snowl_adjust.F90 + src/science/soilsnow/cbl_snowMelt.F90 + src/science/albedo/cbl_soilColour_albedo.F90 + src/science/soilsnow/cbl_soilfreeze.F90 + src/science/soilsnow/cbl_soilsnow_data.F90 + src/science/soilsnow/cbl_soilsnow_init_special.F90 + src/science/soilsnow/cbl_soilsnow_main.F90 + src/science/radiation/cbl_spitter.F90 + src/science/soilsnow/cbl_stempv.F90 + src/science/canopy/cbl_SurfaceWetness.F90 + src/science/soilsnow/cbl_surfbv.F90 + src/science/soilsnow/cbl_thermal.F90 + src/science/soilsnow/cbl_trimb.F90 + src/science/canopy/cbl_wetleaf.F90 + src/science/canopy/cbl_within_canopy.F90 + src/science/canopy/cbl_zetar.F90 + src/params/grid_constants_cbl.F90 + src/science/landuse/landuse3.F90 + src/science/landuse/landuse_constant.F90 + src/offline/landuse_inout.F90 + src/util/masks_cbl.F90 + src/science/pop/pop_constants.F90 + src/science/pop/pop_def.F90 + src/science/pop/pop_io.F90 + src/science/pop/POPLUC.F90 + src/science/pop/POP.F90 + src/science/pop/pop_types.F90 + src/science/roughness/roughnessHGT_effLAI_cbl.F90 + src/offline/spincasacnp.F90 +) +set( + CABLE_SRCS + "$,${CABLE_SRCS_MPI},${CABLE_SRCS_SERIAL}>" + ${CABLE_SRCS_COMMON} +) + +add_executable(cable ${CABLE_SRCS}) + +set_target_properties(cable PROPERTIES OUTPUT_NAME ${CABLE_EXE_NAME}) + +if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") + target_compile_options( + cable + PRIVATE + ${CABLE_INTEL_Fortran_FLAGS} + "$<$:${CABLE_INTEL_Fortran_FLAGS_RELEASE}>" + "$<$:${CABLE_INTEL_Fortran_FLAGS_DEBUG}>" + ) +endif() + +target_link_libraries( + cable + PkgConfig::NETCDF +) + +install(TARGETS cable RUNTIME) diff --git a/build.bash b/build.bash new file mode 100755 index 000000000..b0e32fa2c --- /dev/null +++ b/build.bash @@ -0,0 +1,80 @@ +#!/bin/bash + +nproc_default=4 + +script_name=$(basename "${0}") + +show_help() { + cat << EOF +Usage: ./$script_name [OPTIONS] + +Build script wrapper around CMake. Supplied arguments that do not match the +options below will be passed to CMake when generating the build system. + +Options: + --clean Delete build directory before invoking CMake. + --mpi Compile MPI executable. + -h, --help Show this screen. + +Enabling debug mode: + + The release build is default. To enable debug mode, specify the CMake option + -DCMAKE_BUILD_TYPE=Debug when invoking $script_name. + +Enabling verbose output from Makefile builds: + + To enable more verbose output from Makefile builds, specify the CMake option + -DCMAKE_VERBOSE_MAKEFILE=ON when invoking $script_name. + +Parallel compilation: + + By default, the number of parallel jobs used in the compilation is + $nproc_default. This value can be overwritten by setting the environment + variable CMAKE_BUILD_PARALLEL_LEVEL. + +EOF +} + +cmake_args=(-DCMAKE_BUILD_TYPE=Release) + +# Argument parsing adapted and stolen from http://mywiki.wooledge.org/BashFAQ/035#Complex_nonstandard_add-on_utilities +while [ $# -gt 0 ]; do + case $1 in + --clean) + rm -r build + ;; + --mpi) + mpi=1 + cmake_args+=(-DCABLE_MPI="ON") + cmake_args+=(-DCMAKE_Fortran_COMPILER="mpif90") + ;; + -h|--help) + show_help + exit + ;; + ?*) + cmake_args+=("$1") + ;; + esac + shift +done + +if hostname -f | grep gadi.nci.org.au > /dev/null; then + . /etc/bashrc + module purge + module add cmake/3.24.2 + module add intel-compiler/2019.5.281 + module add netcdf/4.6.3 + # This is required so that the netcdf-fortran library is discoverable by + # pkg-config: + prepend_path PKG_CONFIG_PATH "${NETCDF_BASE}/lib/Intel/pkgconfig" + if [[ -n $mpi ]]; then + module add intel-mpi/2019.5.281 + fi +fi + +export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:=$nproc_default}" + +cmake -S . -B build "${cmake_args[@]}" &&\ +cmake --build build &&\ +cmake --install build --prefix . diff --git a/documentation/docs/developer_guide/other_resources/build_system.md b/documentation/docs/developer_guide/other_resources/build_system.md new file mode 100644 index 000000000..b0405ca9c --- /dev/null +++ b/documentation/docs/developer_guide/other_resources/build_system.md @@ -0,0 +1,34 @@ +For CABLE offline applications, the underlying build system is [CMake](https://cmake.org) based. CMake is widely used in the C, C++ and Fortran communities and there are many great resources out there on the web, in particular: + +- [Mastering CMake](https://cmake.org/cmake/help/book/mastering-cmake/index.html) +- [Effective Modern CMake](https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1) +- [Creating a CMake project (with Fortran)](https://fortran-lang.org/learn/building_programs/build_tools/#creating-a-cmake-project) +- [An Introduction to Modern CMake](https://cliutils.gitlab.io/modern-cmake/) + +## Adding source files + +Source files can be added easily by adding to the list of source files in [CMakeLists.txt][CMakeLists.txt]. + +## Setting compiler flags + +The recommended compiler flags for debug and release builds are set in the [CMakeLists.txt][CMakeLists.txt] file via [`target_compile_options`](https://cmake.org/cmake/help/latest/command/target_compile_options.html). These can be modified if required. + +???+ warning + Compiler flags should be guarded by a check on the compiler ID as they are generally compiler specific. See [`CMAKE__COMPILER_ID`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html) for a list of supported compiler IDs. + +Alternatively, compiler flags can be specified when invoking `cmake` by specifying `-DCMAKE_Fortran_FLAGS=` when generating the project, however the per configuration default flags may take precedence (see [`CMAKE__FLAGS`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS.html) for more details). + +## Adding external dependencies (libraries) + +When linking against external third-party libraries, we strongly recommend not to hard code library paths, include paths, link flags or compiler flags in the CMakeLists.txt file. This ensures that the build system is portable and insulated from changes to library versions and dependencies. + +Instead, CMake should query the required flags for a given library from the library itself. To do this, we recommend using either CMake's [`find_package` mechanism](https://cmake.org/cmake/help/book/mastering-cmake/chapter/Finding%20Packages.html) or a tool such as [`pkg-config`](https://en.wikipedia.org/wiki/Pkg-config) (see the [FindPkgConfig](https://cmake.org/cmake/help/latest/module/FindPkgConfig.html) module for using `pkg-config` with CMake.). The dependencies should provide exported targets which can be used via [`target_link_libraries`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html). + +For an example, see how the netcdf-fortran dependency was added in [CMakeLists.txt][CMakeLists.txt]. + +If these approaches are not supported by the external library, please report this as a bug to its maintainers. If the library is an open-source project, consider sending a patch. + +???+ warning + For most cases, CMake's `find_package` should be used in **Config** mode. `find_package` in **Module** mode should only be used if the library is part of the [CMake module distribution](https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#manual:cmake-modules(7)). + +[CMakeLists.txt]: https://github.com/CABLE-LSM/CABLE/blob/main/CMakeLists.txt diff --git a/documentation/docs/user_guide/installation.md b/documentation/docs/user_guide/installation.md index 22bb5b927..6ddaa2c52 100644 --- a/documentation/docs/user_guide/installation.md +++ b/documentation/docs/user_guide/installation.md @@ -2,7 +2,10 @@ To install CABLE you need to have the following already installed on your system: -- git +- `git` +- `cmake` +- `pkg-config` +- MPI (for parallel applications) - a Fortran compiler - the netCDF library @@ -11,20 +14,20 @@ To install CABLE you need to have the following already installed on your system ``` mermaid graph TD - A(Clone CABLE with git):::UserAction -->|Serial?| B(Run `offline/build3.sh`):::UserAction; - B --> D[load modules, set compiler flags, create .tmp/ directory]; - D -->|Serial?| E[Run `make`]; - E --> G[executable `cable`]:::Output; - A -->|Parallel?| C(Run `offline/build3.sh mpi`):::UserAction; + A(Clone CABLE with git):::UserAction -->|Serial?| B(Run `./build.bash`):::UserAction; + B --> D[load modules and invoke `cmake`]; + D -->|Serial?| E; + E[executable `cable`]:::Output; + A -->|Parallel?| C(Run `./build.bash --mpi`):::UserAction; C --> D; - D -->|Parallel?| F[Run `make mpi`]; - F --> H[executable `cable_mpi`]:::Output; - click A "http://cable.readthedocs.io/en/latest/user_guide/installation/#getting-the-cable-source-code" - click B "http://cable.readthedocs.io/en/latest/user_guide/installation/#launching-the-build" - click C "http://cable.readthedocs.io/en/latest/user_guide/installation/#launching-the-build" - click D "http://cable.readthedocs.io/en/latest/user_guide/installation/#description-of-the-build-process" - click E "http://cable.readthedocs.io/en/latest/user_guide/installation/#description-of-the-build-process" - click F "http://cable.readthedocs.io/en/latest/user_guide/installation/#description-of-the-build-process" + D -->|Parallel?| F; + F[executable `cable-mpi`]:::Output; + click A "#getting-the-cable-source-code" + click B "#launching-the-build" + click C "#launching-the-build" + click D "#description-of-the-build-process" + click E "#description-of-the-build-process" + click F "#description-of-the-build-process" UserAction ---- Automatic ---- Output; @@ -54,6 +57,8 @@ In principle, the only requirements for building and running CABLE are a Fortran Whilst we have endeavoured to make CABLE as portable as possible, and indeed we have used CABLE on a variety of platforms, our discussion here is limited to building CABLE on UNIX/Linux platforms only. Specifically, on Gadi@NCI, using Intel Fortran compiler. On other HPC systems there are likely modules available for both Fortran and netCDF. We recommend to get advice from your local system administrators. +See [**Build System**][build-system] for more extensive documentation on the build system. + CABLE has the directory structure: science/ @@ -74,58 +79,53 @@ CABLE supports both serial and parallel applications. ???+ tip "Multiprocessor for global simulations" For global (or regional) offline simulations, CABLE can still be run in serial mode (about 15 minutes/year for GSWP global run at 1x1 degree resolution). However, running on multiple processors speeds up the simulation considerably. -CABLE can be built using the BASH script [build3.sh][build3] in the **offline/** directory. +CABLE can be built using the BASH script [build.bash][build.bash] in the project root directory. ???+ tip "Build on other HPC" - The function *host_gadi* in the build script shows the appropriate configuration to build on Gadi. - This may be of use as a template building CABLE on another Linux/HPC system. + Gadi specific configuration is guarded by a check on the current hostname (see [here][build.bash-hostname-check]). This may be of use as a template for building CABLE on another Linux/HPC system. For advice on issues relating to porting to other HPC systems, please get in touch with ACCESS-NRI either via GitHub or the [ACCESS-Hive Forum][hive-forum-cable]. + -Both the serial and parallel executable for CABLE offline are built in the `offline/` directory by executing -the build script. +Executables are built in the `/build` directory. Once built successfully, they are then installed in the `/bin` directory. To build the serial model execute: - ./build3.sh + ./build.bash -To build the parallel model execute the same build script but with the argument **mpi**. +To build the parallel model execute the same build script but with the `--mpi` flag. - ./build3.sh mpi + ./build.bash --mpi ???+ warning If you need to switch between a serial compilation and a parallel compilation, you need to completely [clean the previous build][clean-build] first. -### Description of the build process +### Cleaning the build -The build script: +From time to time, it might be useful to clean a previous build completely and restart the build from scratch. This is required when switching between serial and parallel builds. -1. loads modules for the Fortran compiler and the netCDF library -2. sets the compiler flags -3. creates a hidden temporary directory (`.tmp/`) in which it then compiles CABLE. -4. executes `make` in the hidden temporary directory +To clean the previous build prior to compiling, specify the `--clean` flag to `build.bash`. -The [Makefile][makefile] compiles the serial executable by default (via `make`) and compiles the MPI executable via the `mpi` target (via `make mpi`). + ./build.bash --clean -The hidden `.tmp/` directory is really only needed for technical reasons and you should never need to go -into the `.tmp/` directory. However, if for some reason you want the **.o** object files created by the compiler, they persist in this directory. Alternatively, it is sometimes useful to verify that the files you want to compile are actually making it into this directory. This is particularly relevant if you are adding new files to CABLE. +### Enabling debug mode -???+ warning "Do not change files under `.tmp/`" - If you change the files in `.tmp/` directly, the next build will not pick up these changes and will overwrite them. +The release build is default. To enable debug mode, specify the CMake option `-DCMAKE_BUILD_TYPE=Debug` when invoking `build.bash`. -One of the features of the build process is that only source files which are -modified are re-built, followed by their dependents. This is possible because the `.tmp/` directory is -overwritten by the build script, preserving timestamps of the source files from their original location. +### Enabling verbose output from Makefile builds -### Cleaning the build +To enable more verbose output from Makefile builds, specify the CMake option `-DCMAKE_VERBOSE_MAKEFILE=ON` when invoking `build.bash`. -From time to time, it might be useful to clean a previous build completely and restart the build from scratch. This is required when switching between serial and parallel builds. +### Parallel compilation -To clean the build, you need to run: +By default, the compilation is done in parallel. The number of parallel jobs can be overwritten by setting the environment variable [`CMAKE_BUILD_PARALLEL_LEVEL`](https://cmake.org/cmake/help/latest/envvar/CMAKE_BUILD_PARALLEL_LEVEL.html). - ./build3.sh clean +???+ tip + Run `./build.bash --help` for information on supported options. [cable-github]: https://github.com/CABLE-LSM/cable.git [NCI]: https://nci.org.au [registration]: https://trac.nci.org.au/trac/cable/wiki/CABLE_Registration -[build3]: https://github.com/CABLE-LSM/CABLE/blob/main/src/offline/build3.sh -[makefile]: https://github.com/CABLE-LSM/CABLE/blob/main/src/offline/Makefile +[build.bash]: https://github.com/CABLE-LSM/CABLE/blob/main/build.bash +[build.bash-hostname-check]: https://github.com/CABLE-LSM/CABLE/blob/main/build.bash#L45-L55 [clean-build]: installation.md/#cleaning-the-build +[build-system]: ../developer_guide/other_resources/build_system.md +[hive-forum-cable]: https://forum.access-hive.org.au/c/land/cable/18 \ No newline at end of file diff --git a/documentation/docs/user_guide/uber_quick_guide.md b/documentation/docs/user_guide/uber_quick_guide.md index 9530ad176..8f0aea573 100644 --- a/documentation/docs/user_guide/uber_quick_guide.md +++ b/documentation/docs/user_guide/uber_quick_guide.md @@ -5,15 +5,15 @@ Assuming you have computing resources on gadi@NCI, installing and running CABLE 1. Clone the source code: git clone https://github.com/CABLE-LSM/CABLE.git - cd CABLE/offline + cd CABLE 1. Build a serial version of CABLE - ./build3.sh + ./build.bash 1. Execute this serial version of CABLE - ./cable + ./bin/cable ## In slightly more detail diff --git a/documentation/mkdocs.yml b/documentation/mkdocs.yml index d1cde8d11..cbc5aaab0 100644 --- a/documentation/mkdocs.yml +++ b/documentation/mkdocs.yml @@ -98,6 +98,7 @@ nav: - Scientific documentation: developer_guide/documentation_guidelines/science_doc.md - Other resources: - Coding standards: developer_guide/other_resources/coding_standards.md + - Build System: developer_guide/other_resources/build_system.md - Cheat Sheets: developer_guide/other_resources/cheat_sheets.md - CABLE's release process: developer_guide/other_resources/release_process.md - API documentation: developer_guide/other_resources/api.md diff --git a/src/offline/Makefile b/src/offline/Makefile deleted file mode 100644 index 0354fc268..000000000 --- a/src/offline/Makefile +++ /dev/null @@ -1,359 +0,0 @@ -#============================================================================== -# This file is part of the -# Australian Community Atmosphere Biosphere Land Exchange (CABLE) model. -# This work is licensed under the CABLE Academic User Licence Agreement -# (the "Licence"). -# You may not use this file except in compliance with the Licence. -# A copy of the Licence and registration form can be obtained from -# http://www.cawcr.gov.au/projects/access/cable -# You need to register and read the Licence agreement before use. -# Please contact cable_help@nf.nci.org.au for any questions on -# registration and the Licence. -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the Licence is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the Licence for the specific language governing permissions and -# limitations under the Licence. -# ============================================================================== -# -# Purpose: builds CABLE executable for offline case -# -# Contact: Bernard.Pak@csiro.au -# -# History: Additions for CASA-CNP - -# Additions for SLI (Vanessa Haverd) -# Additions for SpinCASA (Lars Nieradzik) -# Additions for POP, climate and phenology (Vanessa Haverd) -# Additions for Land use change (Vanessa Haverd) -# ============================================================================== -########################################################################## - -# these are all the files we are compiling -LSRC := bgcdriver.F90 \ - biogeochem_casa.F90 \ - cable_abort.F90 \ - cable_air.F90 \ - cable_canopy.F90 \ - cable_carbon.F90 \ - cable_checks.F90 \ - cable_climate.F90 \ - cable_climate_type_mod.F90 \ - cable_common.F90 \ - cable_cru_TRENDY.F90 \ - cable_define_types.F90 \ - cable_gw_hydro.F90 \ - cable_initialise.F90 \ - cable_input.F90 \ - cable_iovars.F90 \ - cable_LUC_EXPT.F90 \ - cable_maths_constants_mod.F90 \ - cable_metutils.F90 \ - cable_namelist_input.F90 \ - cable_other_constants_mod.F90 \ - cable_output.F90 \ - cable_parameters.F90 \ - cable_pft_params.F90 \ - cable_phenology.F90 \ - cable_photo_constants_mod.F90 \ - cable_phys_constants_mod.F90 \ - cable_plume_mip.F90 \ - cable_psm.F90 \ - cable_read.F90 \ - cable_roughness.F90 \ - cable_runtime_opts_mod.F90 \ - cable_site.F90 \ - cable_sli_main.F90 \ - cable_sli_numbers.F90 \ - cable_sli_roots.F90 \ - cable_sli_solve.F90 \ - cable_sli_utils.F90 \ - cable_soil_params.F90 \ - cable_weathergenerator.F90 \ - cable_write.F90 \ - casa_cable.F90 \ - casa_cnp.F90 \ - casa_dimension.F90 \ - casa_feedback.F90 \ - casa_inout.F90 \ - casa_ncdf.F90 \ - casa_offline_inout.F90 \ - CASAONLY_LUC.F90 \ - casa_param.F90 \ - casa_phenology.F90 \ - casa_readbiome.F90 \ - casa_rplant.F90 \ - casa_sumcflux.F90 \ - casa_variable.F90 \ - cbl_albedo.F90 \ - cbl_conductivity.F90 \ - cbl_dryLeaf.F90 \ - cbl_friction_vel.F90 \ - cbl_fwsoil.F90 \ - cbl_GW.F90 \ - cbl_hyd_redistrib.F90 \ - cbl_init_radiation.F90 \ - cbl_latent_heat.F90 \ - cbl_model_driver_offline.F90 \ - cbl_Oldconductivity.F90 \ - cbl_photosynthesis.F90 \ - cbl_pot_evap_snow.F90 \ - cbl_qsat.F90 \ - cbl_radiation.F90 \ - cbl_remove_trans.F90 \ - cbl_rhoch.F90 \ - cbl_sinbet.F90 \ - cbl_smoisturev.F90 \ - cbl_snowAccum.F90 \ - cbl_snow_aging.F90 \ - cbl_snow_albedo.F90 \ - cbl_snowCheck.F90 \ - cbl_snowDensity.F90 \ - cbl_snowl_adjust.F90 \ - cbl_snowMelt.F90 \ - cbl_soilColour_albedo.F90 \ - cbl_soilfreeze.F90 \ - cbl_soilsnow_data.F90 \ - cbl_soilsnow_init_special.F90 \ - cbl_soilsnow_main.F90 \ - cbl_spitter.F90 \ - cbl_stempv.F90 \ - cbl_SurfaceWetness.F90 \ - cbl_surfbv.F90 \ - cbl_thermal.F90 \ - cbl_trimb.F90 \ - cbl_wetleaf.F90 \ - cbl_within_canopy.F90 \ - cbl_zetar.F90 \ - grid_constants_cbl.F90 \ - landuse3.F90 \ - landuse_constant.F90 \ - landuse_inout.F90 \ - masks_cbl.F90 \ - pop_constants.F90 \ - pop_def.F90 \ - pop_io.F90 \ - POPLUC.F90 \ - POP.F90 \ - pop_types.F90 \ - roughnessHGT_effLAI_cbl.F90 \ - spincasacnp.F90 - -# this is the executable we are building -PROG_SERIAL = cable -PROG_MPI = cable-mpi - -# from the compiled object files -OBJS := ${LSRC:.F90=.o} - -#suffixes we use -.SUFFIXES: -.SUFFIXES: .F90 .o -#default rules for these suffixes -.F90.o: - $(FC) $(CFLAGS) -c $< - -SUPPRESS_FLAGS := -warn nostderrors -diag-disable 10145 - -# the first target is the default target -.PHONY: serial -serial: cable_driver.F90 $(OBJS) - $(FC) $(SUPPRESS_FLAGS) $(CFLAGS) -o $(PROG_SERIAL) $^ $(LDFLAGS) - -.PHONY: mpi -mpi: cable_mpidrv.F90 cable_mpicommon.o cable_mpimaster.o cable_mpiworker.o pop_mpi.o $(OBJS) - $(FC) $(SUPPRESS_FLAGS) $(CFLAGS) -o $(PROG_MPI) $^ $(LDFLAGS) - -cable_mpicommon.o: cable_mpicommon.F90 $(OBJS) -pop_mpi.o: pop_mpi.F90 cable_mpicommon.o $(OBJS) -cable_mpiworker.o: cable_mpiworker.F90 cable_mpicommon.o pop_mpi.o $(OBJS) -cable_mpimaster.o: cable_mpimaster.F90 cable_mpicommon.o cable_mpiworker.o pop_mpi.o $(OBJS) - -# dependencies, compilation rules for ALL files needed for "all" (LSRC) -#================================================================ -#├── params -grid_constants_cbl.o: grid_constants_cbl.F90 -cable_maths_constants_mod.o: cable_maths_constants_mod.F90 -cable_phys_constants_mod.o: cable_phys_constants_mod.F90 -cable_other_constants_mod.o: cable_other_constants_mod.F90 grid_constants_cbl.o -cable_photo_constants_mod.o: cable_photo_constants_mod.F90 -cable_runtime_opts_mod.o: cable_runtime_opts_mod.F90 -cable_pft_params.o: cable_pft_params.F90 cable_define_types.o grid_constants_cbl.o -cable_soil_params.o: cable_soil_params.F90 cable_define_types.o -casa_param.o: casa_param.F90 - -##│   ├── casa-cnp -bgcdriver.o: bgcdriver.F90 biogeochem_casa.o pop_types.o POP.o cable_phenology.o -biogeochem_casa.o: biogeochem_casa.F90 casa_rplant.o pop_types.o casa_inout.o -casa_feedback.o: casa_feedback.F90 -casa_readbiome.o: casa_readbiome.F90 casa_variable.o -casa_rplant.o: casa_rplant.F90 casa_cnp.o -casa_sumcflux.o: casa_sumcflux.F90 - -#var decs/allocs -casa_dimension.o: casa_dimension.F90 - -#tech files including IO manipulation -masks_cbl.o: masks_cbl.F90 -casa_ncdf.o: casa_ncdf.F90 cable_define_types.o cable_common.o -cable_abort.o: cable_abort.F90 cable_iovars.o cable_define_types.o - -#science seperated subrs - -roughnessHGT_effLAI_cbl.o: roughnessHGT_effLAI_cbl.F90 - -#science partially seperated subrs -#albedo -cbl_albedo.o: cbl_albedo.F90 cbl_snow_albedo.o cbl_rhoch.o cable_define_types.o cable_common.o -cbl_snow_albedo.o: cbl_snow_albedo.F90 cbl_soilColour_albedo.o cable_phys_constants_mod.o -cbl_soilColour_albedo.o: cbl_soilColour_albedo.F90 -#radiation -cbl_rhoch.o: cbl_rhoch.F90 -cbl_spitter.o: cbl_spitter.F90 -cbl_sinbet.o: cbl_sinbet.F90 cable_maths_constants_mod.o -cbl_radiation.o: cbl_radiation.F90 cable_define_types.o cable_common.o cbl_init_radiation.o cable_phys_constants_mod.o -cbl_init_radiation.o: cbl_init_radiation.F90 cable_other_constants_mod.o cable_maths_constants_mod.o cable_define_types.o cable_common.o cbl_spitter.o cbl_rhoch.o -#soilsnow -cbl_soilsnow_data.o: cbl_soilsnow_data.F90 cable_phys_constants_mod.o cable_define_types.o cable_common.o -cbl_trimb.o: cbl_trimb.F90 cbl_soilsnow_data.o -cbl_soilfreeze.o: cbl_soilfreeze.F90 cbl_soilsnow_data.o cable_phys_constants_mod.o cable_define_types.o cable_common.o -cbl_snowMelt.o: cbl_snowMelt.F90 cbl_soilsnow_data.o cable_define_types.o -cbl_snowl_adjust.o: cbl_snowl_adjust.F90 cbl_soilsnow_data.o cable_define_types.o -cbl_snowDensity.o: cbl_snowDensity.F90 cbl_soilsnow_data.o cable_define_types.o -cbl_snowCheck.o: cbl_snowCheck.F90 cbl_soilsnow_data.o cable_define_types.o cable_common.o -cbl_snowAccum.o: cbl_snowAccum.F90 cbl_soilsnow_data.o cable_define_types.o cable_common.o -cbl_snow_aging.o: cbl_snow_aging.F90 cable_phys_constants_mod.o cable_common.o -cbl_remove_trans.o: cbl_remove_trans.F90 cbl_soilsnow_data.o cable_define_types.o cable_common.o -cbl_hyd_redistrib.o: cbl_hyd_redistrib.F90 cbl_soilsnow_data.o cable_define_types.o cable_common.o -cbl_conductivity.o: cbl_conductivity.F90 cbl_soilsnow_data.o cable_define_types.o -cbl_Oldconductivity.o: cbl_Oldconductivity.F90 cbl_soilsnow_data.o cable_define_types.o -cbl_GW.o: cbl_GW.F90 cbl_soilsnow_data.o cbl_trimb.o cbl_Oldconductivity.o cbl_conductivity.o cable_define_types.o cable_common.o -cbl_thermal.o: cbl_thermal.F90 cbl_soilsnow_data.o cbl_snowCheck.o cbl_snowDensity.o cbl_snowAccum.o cbl_snowMelt.o cbl_snowl_adjust.o cbl_GW.o -cbl_surfbv.o: cbl_surfbv.F90 cbl_soilsnow_data.o cable_define_types.o cable_common.o cbl_smoisturev.o -cbl_stempv.o: cbl_stempv.F90 cbl_trimb.o cbl_soilsnow_data.o cbl_conductivity.o cbl_Oldconductivity.o -cbl_smoisturev.o: cbl_smoisturev.F90 cbl_trimb.o cbl_soilsnow_data.o cable_define_types.o cable_common.o -cbl_soilsnow_init_special.o: cbl_soilsnow_init_special.F90 cbl_soilsnow_data.o cable_iovars.o -cbl_soilsnow_main.o: cbl_soilsnow_main.F90 cbl_soilsnow_data.o cbl_soilfreeze.o cbl_snowMelt.o cbl_snowl_adjust.o cbl_snowDensity.o cbl_snowCheck.o cbl_snowAccum.o cbl_remove_trans.o cbl_hyd_redistrib.o cbl_conductivity.o cbl_Oldconductivity.o cbl_GW.o cbl_thermal.o cbl_surfbv.o cbl_stempv.o cbl_smoisturev.o - -#science subrs -casa_phenology.o: casa_phenology.F90 - -cable_air.o: cable_air.F90 cable_define_types.o cable_common.o cable_phys_constants_mod.o - -cable_canopy.o: cable_canopy.F90 cbl_friction_vel.o cbl_pot_evap_snow.o cbl_qsat.o cbl_zetar.o cbl_latent_heat.o cbl_wetleaf.o cbl_within_canopy.o cbl_SurfaceWetness.o cbl_dryLeaf.o cbl_fwsoil.o cbl_photosynthesis.o cable_maths_constants_mod.o cable_phys_constants_mod.o cable_other_constants_mod.o cable_photo_constants_mod.o cable_define_types.o cbl_radiation.o cable_roughness.o cable_air.o cable_common.o cable_sli_utils.o cable_sli_main.o cable_gw_hydro.o cable_iovars.o cable_psm.o cable_gw_hydro.o cable_climate_type_mod.o - -cbl_friction_vel.o: cbl_friction_vel.F90 -cbl_pot_evap_snow.o: cbl_pot_evap_snow.F90 cbl_qsat.o -cbl_qsat.o: cbl_qsat.F90 -cbl_zetar.o: cbl_zetar.F90 -cbl_latent_heat.o: cbl_latent_heat.F90 cable_define_types.o -cbl_wetleaf.o: cbl_wetleaf.F90 cable_define_types.o -cbl_within_canopy.o: cbl_within_canopy.F90 cable_define_types.o cable_common.o cbl_qsat.o -cbl_SurfaceWetness.o: cbl_SurfaceWetness.F90 cable_define_types.o cable_common.o cable_phys_constants_mod.o -cbl_dryLeaf.o: cbl_dryLeaf.F90 cbl_photosynthesis.o cbl_fwsoil.o cable_define_types.o cable_common.o cable_phys_constants_mod.o cable_photo_constants_mod.o -cbl_fwsoil.o: cbl_fwsoil.F90 cable_define_types.o cable_common.o -cbl_photosynthesis.o: cbl_photosynthesis.F90 cable_define_types.o cable_other_constants_mod.o cable_photo_constants_mod.o - -cable_carbon.o: cable_carbon.F90 cable_define_types.o cable_common.o - -cbl_model_driver_offline.o: cbl_model_driver_offline.F90 grid_constants_cbl.o cable_phys_constants_mod.o cable_carbon.o cbl_soilsnow_main.o cable_canopy.o cable_define_types.o cable_roughness.o cbl_radiation.o cbl_albedo.o casa_variable.o cable_common.o cable_gw_hydro.o cable_psm.o masks_cbl.o cbl_snow_aging.o - -cable_checks.o: cable_checks.F90 cbl_radiation.o cable_common.o - -cable_define_types.o: cable_define_types.F90 - -cable_iovars.o: cable_iovars.F90 cable_define_types.o - -cable_read.o: cable_read.F90 cable_iovars.o cable_abort.o - -cable_initialise.o: cable_initialise.F90 cable_read.o cable_iovars.o cable_abort.o cable_define_types.o - -cable_write.o: cable_write.F90 cable_iovars.o cable_abort.o cable_define_types.o casa_variable.o - -cable_metutils.o: cable_metutils.F90 - -cable_input.o: cable_input.F90 pop_types.o POP.o cable_checks.o cable_abort.o cable_read.o cable_initialise.o cbl_sinbet.o \ - cable_parameters.o cable_common.o cable_LUC_EXPT.o POPLUC.o casa_inout.o cable_metutils.o casa_readbiome.o - -cable_output.o: cable_output.F90 cable_abort.o cable_checks.o cable_write.o cable_common.o - -cable_parameters.o: cable_parameters.F90 cable_define_types.o cable_iovars.o cable_abort.o casa_variable.o cable_common.o cable_LUC_EXPT.o casa_phenology.o - -cable_roughness.o: cable_roughness.F90 cable_phys_constants_mod.o cable_define_types.o cable_common.o roughnessHGT_effLAI_cbl.o cable_other_constants_mod.o - - -casa_variable.o: casa_variable.F90 POP.o casa_dimension.o casa_param.o - -spincasacnp.o: spincasacnp.F90 cable_define_types.o cable_carbon.o cable_common.o \ - casa_variable.o casa_phenology.o casa_cable.o casa_ncdf.o pop_types.o POP.o - -CASAONLY_LUC.o: CASAONLY_LUC.F90 cable_define_types.o cable_carbon.o cable_common.o casa_variable.o pop_types.o POP.o POPLUC.o cable_LUC_EXPT.o casa_ncdf.o casa_offline_inout.o - -casa_cable.o: casa_cable.F90 pop_types.o POP.o cable_define_types.o cable_carbon.o casa_variable.o \ - cable_phenology.o casa_cnp.o casa_inout.o casa_ncdf.o biogeochem_casa.o - -landuse_constant.o: landuse_constant.F90 cable_define_types.o casa_dimension.o - -casa_cnp.o: casa_cnp.F90 cable_define_types.o casa_variable.o landuse_constant.o casa_phenology.o cable_common.o - -casa_inout.o: casa_inout.F90 POP.o cable_define_types.o cable_iovars.o casa_variable.o casa_cnp.o casa_ncdf.o casa_offline_inout.o -casa_offline_inout.o: casa_offline_inout.F90 POP.o cable_define_types.o cable_iovars.o casa_variable.o casa_cnp.o casa_ncdf.o - -cable_common.o: cable_common.F90 cable_iovars.o cable_pft_params.o cable_soil_params.o cable_runtime_opts_mod.o - -POP.o: POP.F90 cable_define_types.o pop_def.o pop_constants.o pop_types.o - -POPLUC.o: POPLUC.F90 pop_def.o pop_types.o cable_define_types.o cable_iovars.o casa_variable.o cable_common.o cable_runtime_opts_mod.o casa_ncdf.o - -cable_LUC_EXPT.o: cable_LUC_EXPT.F90 cable_define_types.o cable_iovars.o casa_variable.o cable_common.o casa_ncdf.o - -pop_io.o: pop_io.F90 pop_constants.o pop_types.o casa_variable.o cable_common.o casa_ncdf.o - -pop_def.o: pop_def.F90 - -pop_constants.o: pop_constants.F90 pop_def.o - -pop_types.o: pop_types.F90 pop_def.o pop_constants.o - -cable_sli_main.o: cable_sli_main.F90 cable_define_types.o cable_sli_numbers.o cable_sli_roots.o cable_sli_solve.o - -cable_sli_numbers.o: cable_sli_numbers.F90 cable_define_types.o - -cable_sli_roots.o: cable_sli_roots.F90 cable_sli_numbers.o cable_define_types.o - -cable_sli_solve.o: cable_sli_solve.F90 cable_sli_numbers.o cable_sli_roots.o cable_sli_utils.o cable_define_types.o - -cable_sli_utils.o: cable_sli_utils.F90 cable_sli_numbers.o cable_define_types.o - -cable_plume_mip.o: cable_plume_mip.F90 cable_iovars.o cable_define_types.o cable_checks.o cable_weathergenerator.o - -cable_cru_TRENDY.o: cable_cru_TRENDY.F90 cable_iovars.o cable_define_types.o cable_checks.o \ - cable_weathergenerator.o casa_variable.o - -cable_weathergenerator.o: cable_weathergenerator.F90 - -cable_climate.o: cable_climate.F90 cable_define_types.o cable_iovars.o cable_common.o casa_ncdf.o - -cable_climate_type_mod.o: cable_climate_type_mod.F90 - -cable_phenology.o: cable_phenology.F90 cable_define_types.o cable_iovars.o cable_common.o casa_variable.o casa_phenology.o - -cable_gw_hydro.o: cable_gw_hydro.F90 cbl_thermal.o cbl_trimb.o cable_iovars.o cable_define_types.o cable_common.o - -cable_psm.o: cable_psm.F90 cable_define_types.o cable_common.o cable_air.o - -cable_namelist_input.o: cable_namelist_input.F90 - -cable_site.o: cable_site.F90 cable_iovars.o cable_common.o - - -landuse3.o: landuse3.F90 cable_define_types.o casa_dimension.o landuse_constant.o cable_common.o \ - cable_iovars.o casa_variable.o casa_phenology.o - -landuse_inout.o: landuse_inout.F90 cable_define_types.o landuse_constant.o landuse3.o cable_common.o cable_iovars.o cable_abort.o - -# make clean option -clean: - rm -fr .tmp - diff --git a/src/offline/build3.sh b/src/offline/build3.sh deleted file mode 100755 index c5c25e702..000000000 --- a/src/offline/build3.sh +++ /dev/null @@ -1,176 +0,0 @@ -#!/bin/bash - -#build script for CABLE -#Simplified from previous build script. Only set up for raijin -#Usage: -#> ./build3 -# OR -#> ./build3 mpi -#builds MPI version of CABLE - -## gadi.nci.org.au -host_gadi() -{ - . /etc/bashrc - module purge - module add intel-compiler/2019.5.281 - module add netcdf/4.6.3 - # This is required so that the netcdf-fortran library is discoverable by - # pkg-config: - prepend_path PKG_CONFIG_PATH "${NETCDF_BASE}/lib/Intel/pkgconfig" - - if ! pkg-config --exists netcdf-fortran; then - echo -e "\nUnable to find netcdf-fortran via pkg-config. Exiting...\n" - exit 1 - fi - - if [[ $1 = 'mpi' ]]; then - module add intel-mpi/2019.5.281 - export FC='mpif90' - else - export FC='ifort' - fi - - CFLAGS="-O2 -fp-model precise" - - if [[ $1 = 'MGK' ]]; then - CFLAGS='-O2' - fi - - if [[ $1 = 'debug' ]]; then - CFLAGS='-O0 -traceback -g -fp-model precise -ftz -fpe0' - #CFLAGS='-O0 -traceback -g -fp-model precise -ftz -fpe0 -check all,noarg_temp_created' - fi - - CFLAGS+=" $(pkg-config --cflags netcdf-fortran)" - export CFLAGS - LDFLAGS=$(pkg-config --libs netcdf-fortran) - export LDFLAGS - - if [[ $1 = 'mpi' ]]; then - build_build mpi - else - build_build - fi - cd ../ - build_status -} - -clean_build() -{ - rm -fr .tmp - echo '' - echo 'cleaning up' - echo '' - echo 'Press Enter too continue buiding, Control-C to abort now.' - echo '' - read dummy -} - - -build_build() -{ - if [[ ! -d .tmp ]]; then - mkdir .tmp - fi - - if [[ -f cable ]]; then - echo '' - echo 'cable executable exists. copying to dated backup file' - echo '' - mv cable cable.`date +%d.%m.%y` - fi - - # directories contain source code - ALB="../science/albedo" - RAD="../science/radiation" - CAN="../science/canopy" - CNP="../science/casa-cnp" - GWH="../science/gw_hydro" - MIS="../science/misc" - ROU="../science/roughness" - SOI="../science/soilsnow" - LUC="../science/landuse" - OFF="../offline" - UTI="../util" - PAR="../params" - SLI="../science/sli" - POP="../science/pop" - /bin/cp -p $ALB/*90 ./.tmp - /bin/cp -p $CAN/*90 ./.tmp - /bin/cp -p $CNP/*90 ./.tmp - /bin/cp -p $GWH/*90 ./.tmp - /bin/cp -p $MIS/*90 ./.tmp - /bin/cp -p $RAD/*90 ./.tmp - /bin/cp -p $ROU/*90 ./.tmp - /bin/cp -p $SOI/*90 ./.tmp - /bin/cp -p $SLI/*90 ./.tmp - /bin/cp -p $POP/*90 ./.tmp - /bin/cp -p $LUC/*90 ./.tmp - /bin/cp -p $OFF/*90 ./.tmp - -/bin/cp -p $UTI/*90 ./.tmp -/bin/cp -p $PAR/*90 ./.tmp - -/bin/cp -p Makefile ./.tmp - -cd .tmp/ - -echo '' -echo "Build setup complete." -echo 'Compiling now ...' -echo '' - -echo '' -echo 'Building from source common across serial and MPI applications' -echo '' -echo '' -echo 'Building drivers for either serial or MPI application' -echo '' - -if [[ $1 = 'mpi' ]]; then - make mpi -else - make -fi - -} - -build_status() -{ - if [[ -f .tmp/cable ]]; then - mv .tmp/cable . - echo '' - echo 'BUILD OK' - echo '' - elif [[ -f .tmp/cable-mpi ]]; then - mv .tmp/cable-mpi . - echo '' - echo 'BUILD OK' - echo '' - else - echo '' - echo 'Oooops. Something went wrong' - echo '' - fi - exit -} -########################################### -## build.ksh - MAIN SCRIPT STARTS HERE ## -########################################### - -if [[ $1 = 'clean' ]]; then - clean_build -fi - -if [[ $1 = 'mpi' ]]; then - echo '' - echo "Building cable_mpi" - echo '' - host_gadi mpi -else - echo '' - echo "Building cable (serial)" - echo '' - host_gadi $1 -fi