Skip to content

Commit

Permalink
All-sky example useful for timing (#220)
Browse files Browse the repository at this point in the history
Revises the all-sky example to be useful for timing benchmarks.  Removes use of NCHOME environment variable, removes (optional) use of GPTL timing library in RFMIP examples. Revises aerosol optics for GPUs.
  • Loading branch information
RobertPincus committed Jul 4, 2023
1 parent 1cb0a4e commit 36d7969
Show file tree
Hide file tree
Showing 15 changed files with 772 additions and 536 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/containerized-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
FC: ${{ matrix.fortran-compiler }}
FCFLAGS: ${{ matrix.fcflags }}
# Make variables:
NCHOME: /dummy
NFHOME: /opt/netcdf-fortran
RRTMGP_ROOT: ${{ github.workspace }}
RRTMGP_DATA: ${{ github.workspace }}/rrtmgp-data
Expand All @@ -76,6 +75,7 @@ jobs:
with:
repository: earth-system-radiation/rrtmgp-data
path: rrtmgp-data
ref: feature-timing
#
# Cache RFMIP files
#
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
with:
repository: earth-system-radiation/rrtmgp-data
path: rrtmgp-data
ref: feature-timing
#
# Synchronize the package index
#
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/self-hosted-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ jobs:
FC: ftn
FCFLAGS: ${{ matrix.fcflags }}
# Make variables:
NCHOME: /dummy
NFHOME: /dummy
RRTMGP_ROOT: ${{ github.workspace }}
RRTMGP_DATA: ${{ github.workspace }}/rrtmgp-data
RTE_KERNELS: ${{ matrix.rte-kernels }}
Expand All @@ -62,6 +60,7 @@ jobs:
with:
repository: earth-system-radiation/rrtmgp-data
path: rrtmgp-data
ref: feature-timing
#
# Finalize build environment
#
Expand Down
29 changes: 18 additions & 11 deletions examples/all-sky/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ VPATH = ../:$(RRTMGP_ROOT)/rrtmgp-frontend # Needed for cloud_optics and aerosol
#
# Extra sources -- extensions to RRTMGP classes, shared infrastructure, local sources
#
ADDITIONS = mo_load_coefficients.o mo_simple_netcdf.o mo_cloud_optics_rrtmgp.o mo_load_cloud_coefficients.o
ADDITIONS += mo_garand_atmos_io.o
ADDITIONS = mo_load_coefficients.o mo_simple_netcdf.o
ADDITIONS += mo_cloud_optics_rrtmgp.o mo_load_cloud_coefficients.o
ADDITIONS += mo_aerosol_optics_rrtmgp_merra.o mo_load_aerosol_coefficients.o

#
Expand All @@ -41,20 +41,27 @@ rrtmgp_allsky: $(ADDITIONS) rrtmgp_allsky.o

rrtmgp_allsky.o: $(ADDITIONS) rrtmgp_allsky.F90

mo_cloud_optics_rrtmgp.o: mo_cloud_optics_rrtmgp.F90
mo_load_coefficients.o: mo_simple_netcdf.o mo_load_coefficients.F90
mo_garand_atmos_io.o: mo_simple_netcdf.o mo_garand_atmos_io.F90
mo_load_cloud_coefficients.o: mo_simple_netcdf.o mo_cloud_optics_rrtmgp.o mo_load_cloud_coefficients.F90
mo_cloud_optics_rrtmgp.o: mo_cloud_optics_rrtmgp.F90
mo_aerosol_optics_rrtmgp_merra.o: mo_aerosol_optics_rrtmgp_merra.F90
mo_load_coefficients.o: mo_simple_netcdf.o mo_load_coefficients.F90
mo_load_cloud_coefficients.o: mo_simple_netcdf.o mo_cloud_optics_rrtmgp.o mo_load_cloud_coefficients.F90
mo_load_aerosol_coefficients.o: mo_simple_netcdf.o mo_aerosol_optics_rrtmgp_merra.o mo_load_aerosol_coefficients.F90

tests:
cp ${RRTMGP_DATA}/examples/all-sky/inputs/garand-atmos-1.nc rrtmgp-allsky.nc
$(RUN_CMD) ./rrtmgp_allsky rrtmgp-allsky.nc ${RRTMGP_DATA}/rrtmgp-gas-lw-g256.nc ${RRTMGP_DATA}/rrtmgp-clouds-lw.nc ${RRTMGP_DATA}/rrtmgp-aerosols-merra-lw.nc 128
$(RUN_CMD) ./rrtmgp_allsky rrtmgp-allsky.nc ${RRTMGP_DATA}/rrtmgp-gas-sw-g224.nc ${RRTMGP_DATA}/rrtmgp-clouds-sw.nc ${RRTMGP_DATA}/rrtmgp-aerosols-merra-sw.nc 128
$(RUN_CMD) ./rrtmgp_allsky 24 72 1 rrtmgp-allsky-lw.nc \
${RRTMGP_DATA}/rrtmgp-gas-lw-g256.nc ${RRTMGP_DATA}/rrtmgp-clouds-lw.nc ${RRTMGP_DATA}/rrtmgp-aerosols-merra-lw.nc
$(RUN_CMD) ./rrtmgp_allsky 24 72 1 rrtmgp-allsky-sw.nc \
${RRTMGP_DATA}/rrtmgp-gas-sw-g224.nc ${RRTMGP_DATA}/rrtmgp-clouds-sw.nc ${RRTMGP_DATA}/rrtmgp-aerosols-merra-sw.nc
$(RUN_CMD) ./rrtmgp_allsky 24 72 1 rrtmgp-allsky-lw-no-aerosols.nc \
${RRTMGP_DATA}/rrtmgp-gas-lw-g256.nc ${RRTMGP_DATA}/rrtmgp-clouds-lw.nc
$(RUN_CMD) ./rrtmgp_allsky 24 72 1 rrtmgp-allsky-sw-no-aerosols.nc \
${RRTMGP_DATA}/rrtmgp-gas-sw-g224.nc ${RRTMGP_DATA}/rrtmgp-clouds-sw.nc

check:
python ./compare-to-reference.py
python ./compare-to-reference.py --allsky_file rrtmgp-allsky-lw.nc
python ./compare-to-reference.py --allsky_file rrtmgp-allsky-sw.nc
python ./compare-to-reference.py --allsky_file rrtmgp-allsky-lw-no-aerosols.nc
python ./compare-to-reference.py --allsky_file rrtmgp-allsky-sw-no-aerosols.nc

clean:
-rm rrtmgp_allsky *.o *.optrpt ../*.optrpt *.mod
-rm rrtmgp_allsky *.o *.optrpt ../*.optrpt *.mod *.nc
10 changes: 5 additions & 5 deletions examples/all-sky/compare-to-reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
parser = argparse.ArgumentParser(
description="Compares all-sky example output to file in reference "
"directory")
parser.add_argument("--allsky_file", type=str, default="rrtmgp-allsky.nc",
parser.add_argument("--allsky_file", type=str, default="rrtmgp-allsky-lw.nc",
dest="file",
help="Name of file inputs and outputs for "
"all-sky problem (same for test and reference)")
Expand All @@ -35,13 +35,13 @@
ref = xr.open_dataset(ref_file)

failed = False
for v in ['lw_flux_up', 'lw_flux_dn', 'sw_flux_up', 'sw_flux_dn',
'sw_flux_dir']:
for v in tst.variables:
if np.any(np.isnan(ref.variables[v].values)):
raise Exception(v + ": some ref values are missing. Now that is strange.")
if np.all(np.isnan(tst.variables[v].values)):
raise Exception("All test values are missing. Were the tests run?")
if np.any(np.isnan(tst.variables[v].values)):
raise Exception(
"Some test values are missing. Now that is strange.")
raise Exception(v + ":Some test values are missing. Now that is strange.")

# express as (tst-ref).variables[v].values when replacing reference file
# to have same number of columns
Expand Down
62 changes: 62 additions & 0 deletions examples/all-sky/make_problem_size_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#! /usr/bin/env python
#
# This script...
#
import argparse
import csv
import os

# template: exe ncol nlay nloops output_file k_dist clouds aeorsols

# specify: kdist, optional clouds, aerosols. specify nloops
# Toggle clouds and aerosols?
# Loop over sets of ncol, nlay,
# output name


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="Description here ")
# Argument parseing described at
# https://stackoverflow.com/questions/15753701/how-can-i-pass-a-list-as-a-command-line-argument-with-argparse
parser.add_argument("-x", "--executable",
type=str,
default="./rrtmgp_allsky",
help="Path to exectuable")
parser.add_argument("-c", "--ncol",
type=lambda items: [int(i) for i in list(csv.reader([items]))[0]],
default="2,4,8,16",
help="Number of columns (multiple e.g. 2,4,8,16)")
parser.add_argument("-l", "--nlay",
type=lambda items: [int(i) for i in list(csv.reader([items]))[0]],
default="32, 64, 96",
help="Number of layers (multiple e.g. 32,64.96)")
parser.add_argument("-i", "--nloops",
type=int, default=1,
help="Number of loops (same for all ncol)")
parser.add_argument("-o", "--output_file",
type=str,
default="rrtmgp-allsky-output.nc",
help="Path to output file")
parser.add_argument("-k", "--k_distribution",
type=str,
required = True,
help="Path to gas optics file [required]")
parser.add_argument("-cl", "--cloud_optics",
type=str, default="",
help="Path to cloud optics file")
parser.add_argument("-a", "--aerosol_optics",
type=str, default="",
help="Path to aerosol optics file")
args = parser.parse_args()

# Can't supply aerosols without clouds
if(args.cloud_optics == "" and args.aerosol_optics != ""):
raise AssertionError("Need to supply cloud optics if providing aerosol optics")

# Every combo of ncol, nlay
for l in args.nlay:
for i in args.ncol:
print(f"{args.executable} {i:6d} {l:4d} {args.nloops:3d} " + \
f"{args.output_file} {args.k_distribution}" + \
f"{args.cloud_optics} {args.aerosol_optics}")
Loading

0 comments on commit 36d7969

Please sign in to comment.