Skip to content

Commit

Permalink
initialize comms contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasloan25 committed Dec 13, 2024
1 parent 1d04084 commit 40425c3
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 29 deletions.
1 change: 1 addition & 0 deletions experiments/benchmarks/bucket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Profile, ProfileCanvas
const FT = Float64;

context = ClimaComms.context()
ClimaComms.init(context)
device = ClimaComms.device()
device_suffix = device isa ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"

Expand Down
1 change: 1 addition & 0 deletions experiments/benchmarks/land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Profile, ProfileCanvas
const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
context = ClimaComms.context()
ClimaComms.init(context)
device = ClimaComms.device()
device_suffix = device isa ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"

Expand Down
1 change: 1 addition & 0 deletions experiments/benchmarks/richards.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const FT = Float64;

regridder_type = :InterpolationsRegridder
context = ClimaComms.context()
ClimaComms.init(context)
device = ClimaComms.device()
device_suffix = device isa ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
outdir = "richards_benchmark_$(device_suffix)"
Expand Down
1 change: 1 addition & 0 deletions experiments/benchmarks/snowy_land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ using Test
const FT = Float64
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
context = ClimaComms.context()
ClimaComms.init(context)
device = ClimaComms.device()
device_suffix = device isa ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
outdir = "snowy_land_benchmark_$(device_suffix)"
Expand Down
1 change: 1 addition & 0 deletions experiments/integrated/fluxnet/met_drivers_FLUXNET.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using ClimaLand
import ClimaComms

context = ClimaComms.context()
ClimaComms.init(context)

# Methods for reading in the LAI data from MODIS data
include(
Expand Down
4 changes: 2 additions & 2 deletions experiments/integrated/global/global_soil_canopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import ClimaAnalysis.Visualize as viz
import ClimaUtilities
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
context = ClimaComms.context()
ClimaComms.init(context)
outdir = generate_output_path("experiments/integrated/global")

device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
typeof(context.device) <: ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"

FT = Float64
earth_param_set = LP.LandParameters(FT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ function set_initial_conditions(land, t0)
end

context = ClimaComms.context()
ClimaComms.init(context)
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
typeof(context.device) <: ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
const FT = Float64
earth_param_set = LP.LandParameters(FT)

Expand Down
1 change: 1 addition & 0 deletions experiments/long_runs/bucket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
regridder_type = :InterpolationsRegridder
context = ClimaComms.context()
ClimaComms.init(context)
device = ClimaComms.device()
device_suffix = device isa ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
root_path = "bucket_longrun_$(device_suffix)"
Expand Down
1 change: 1 addition & 0 deletions experiments/long_runs/land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ using Poppler_jll: pdfunite
const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
context = ClimaComms.context()
ClimaComms.init(context)
device = ClimaComms.device()
device_suffix = device isa ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
root_path = "land_longrun_$(device_suffix)"
Expand Down
1 change: 1 addition & 0 deletions experiments/long_runs/land_region.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ using Poppler_jll: pdfunite
const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
context = ClimaComms.context()
ClimaComms.init(context)
device = ClimaComms.device()
device_suffix = device isa ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
root_path = "california_longrun_$(device_suffix)"
Expand Down
12 changes: 5 additions & 7 deletions experiments/long_runs/leaderboard/data_sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function get_obs_var_dict()
obs_var_dict["et"] =
(start_date) -> begin
obs_var = ClimaAnalysis.OutputVar(
ClimaLand.Artifacts.ilamb_dataset_path(;
context = "evspsbl_MODIS_et_0.5x0.5.nc",
ClimaLand.Artifacts.ilamb_dataset_path(
"evspsbl_MODIS_et_0.5x0.5.nc",
),
"et",
new_start_date = start_date,
Expand All @@ -113,9 +113,7 @@ function get_obs_var_dict()
obs_var_dict["gpp"] =
(start_date) -> begin
obs_var = ClimaAnalysis.OutputVar(
ClimaLand.Artifacts.ilamb_dataset_path(;
context = "gpp_FLUXCOM_gpp.nc",
),
ClimaLand.Artifacts.ilamb_dataset_path("gpp_FLUXCOM_gpp.nc"),
"gpp",
new_start_date = start_date,
shift_by = Dates.firstdayofmonth,
Expand All @@ -131,8 +129,8 @@ function get_obs_var_dict()
obs_var_dict["lwu"] =
(start_date) -> begin
obs_var = ClimaAnalysis.OutputVar(
ClimaLand.Artifacts.ilamb_dataset_path(;
context = "rlus_CERESed4.2_rlus.nc",
ClimaLand.Artifacts.ilamb_dataset_path(
"rlus_CERESed4.2_rlus.nc",
),
"rlus",
new_start_date = start_date,
Expand Down
1 change: 1 addition & 0 deletions experiments/long_runs/snowy_land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ using Poppler_jll: pdfunite
const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
context = ClimaComms.context()
ClimaComms.init(context)
device = ClimaComms.device()
device_suffix = device isa ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
root_path = "snowy_land_longrun_$(device_suffix)"
Expand Down
1 change: 1 addition & 0 deletions experiments/long_runs/soil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ using Poppler_jll: pdfunite
const FT = Float64;
time_interpolation_method = LinearInterpolation(PeriodicCalendar())
context = ClimaComms.context()
ClimaComms.init(context)
device = ClimaComms.device()
device_suffix = device isa ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
root_path = "soil_longrun_$(device_suffix)"
Expand Down
4 changes: 2 additions & 2 deletions experiments/standalone/Bucket/bucket_era5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ time_interpolation_method = LinearInterpolation(PeriodicCalendar())
regridder_type = :InterpolationsRegridder
FT = Float64;
context = ClimaComms.context()
ClimaComms.init(context)
earth_param_set = LP.LandParameters(FT);
# Use separate output directory for CPU and GPU runs to avoid race condition
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
typeof(context.device) <: ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
outdir = "experiments/standalone/Bucket/artifacts_era5$(regional_str)_$(device_suffix)"
output_dir = ClimaUtilities.OutputPathGenerator.generate_output_path(outdir)

Expand Down
4 changes: 2 additions & 2 deletions experiments/standalone/Bucket/global_bucket_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ end
anim_plots = false
FT = Float64;
context = ClimaComms.context()
ClimaComms.init(context)
earth_param_set = LP.LandParameters(FT);
# Use separate output directory for CPU and GPU runs to avoid race condition
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
typeof(context.device) <: ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
outdir = "experiments/standalone/Bucket/artifacts_function_$(device_suffix)"

# Construct simulation domain
Expand Down
4 changes: 2 additions & 2 deletions experiments/standalone/Bucket/global_bucket_temporalmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ end

FT = Float64;
context = ClimaComms.context()
ClimaComms.init(context)
earth_param_set = LP.LandParameters(FT);
# Use separate output directory for CPU and GPU runs to avoid race condition
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
typeof(context.device) <: ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
outdir = "experiments/standalone/Bucket/artifacts_temporalmap_$(device_suffix)"
t0 = 0.0;
# run for 50 days to test monthly file update
Expand Down
1 change: 1 addition & 0 deletions experiments/standalone/Snow/snowmip_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ climaland_dir = pkgdir(ClimaLand)
FT = Float32
param_set = LP.LandParameters(FT)
context = ClimaComms.context()
ClimaComms.init(context)

# This reads in the data and sets up the drivers, as well as computes the IC from the data
include(
Expand Down
4 changes: 2 additions & 2 deletions experiments/standalone/Soil/richards_comparison.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ clay_datapath = joinpath(bonan_data_folder, "bonan_data_clay.txt")
sand_datapath = joinpath(bonan_data_folder, "bonan_data_sand.txt")

context = ClimaComms.context()
ClimaComms.init(context)
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
typeof(context.device) <: ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
outdir = generate_output_path(
joinpath("experiments", "standalone", "Soil", device_suffix),
)
Expand Down
4 changes: 2 additions & 2 deletions experiments/standalone/Soil/richards_runoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import ClimaLand.Parameters as LP

regridder_type = :InterpolationsRegridder
context = ClimaComms.context()
ClimaComms.init(context)
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
typeof(context.device) <: ClimaComms.CPUSingleThreaded ? "cpu" : "gpu"
outdir = generate_output_path(
joinpath("experiments", "standalone", "Soil", "artifacts", device_suffix),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ export make_inputs_df
"""
make_inputs_df(site_ID)
Returns DataFrames of inputs, one unitless, one in SI units, one in commonly used units.
Returns DataFrames of inputs, one unitless, one in SI units, one in commonly used units.
"""
function make_inputs_df(
site_ID;
FT = Float64,
context = ClimaComms.SingletonCommsContext(),
context = ClimaComms.context(),
setup = make_setup(site_ID),
domain = make_domain(setup, FT),
config = make_config(site_ID),
params = make_parameters(site_ID),
drivers = make_drivers(site_ID, setup, config, params, context),
timestepper = make_timestepper(setup),
)
# Initialize the communication context
ClimaComms.init(context)

variables_name = (
"DateTime",
Expand Down
5 changes: 4 additions & 1 deletion lib/ClimaLandSimulations/src/Fluxnet/run_fluxnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ Run ClimaLand at a fluxnet site.
function run_fluxnet(
site_ID;
FT = Float64,
context = ClimaComms.SingletonCommsContext(),
context = ClimaComms.context(),
setup = make_setup(site_ID),
domain = make_domain(setup, FT),
config = make_config(site_ID),
params = make_parameters(site_ID),
drivers = make_drivers(site_ID, setup, config, params, context),
timestepper = make_timestepper(setup),
)
# Initialize the communication context
ClimaComms.init(context)

#earth_param_set = create_lsm_parameters(FT)

# Now we set up the model. For the soil model, we pick
Expand Down
6 changes: 3 additions & 3 deletions src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,16 @@ function bareground_albedo_dataset_path(; context = nothing)
end

"""
ilamb_dataset_path(; context = nothing)
ilamb_dataset_path(filename; context = nothing)
Triggers the download of the ILAMB dataset, if not already downloaded, using
Julia Artifacts, and returns the path to this file.
There are only three datasets available which are "rlus_CERESed4.2_rlus.nc",
"gpp_FLUXCOM_gpp.nc", and "evspsbl_MODIS_et_0.5x0.5.nc".
"""
function ilamb_dataset_path(; context = nothing)
return joinpath(@clima_artifact("ilamb_data"), context)
function ilamb_dataset_path(filename; context = nothing)
return joinpath(@clima_artifact("ilamb_data", context), filename)
end

end
11 changes: 10 additions & 1 deletion src/shared_utilities/Domains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ function Plane(;
comms_ctx = ClimaComms.context(),
radius_earth = 6.378e6,
) where {FT}
# Initialize the communication context
ClimaComms.init(comms_ctx)

if isnothing(longlat)
@assert xlim[1] < xlim[2]
@assert ylim[1] < ylim[2]
Expand Down Expand Up @@ -530,7 +533,7 @@ end
nelements::Tuple{Int, Int},
npolynomial::Int,
dz_tuple::Union{Tuple{FT, FT}, Nothing} = nothing,
comms_ctx = ClimaComms.SingletonCommsContext(),
comms_ctx = ClimaComms.context(),
) where {FT}
Outer constructor for the `SphericalShell` domain, using keyword arguments.
Expand All @@ -550,6 +553,9 @@ function SphericalShell(;
dz_tuple::Union{Tuple{FT, FT}, Nothing} = nothing,
comms_ctx = ClimaComms.context(),
) where {FT}
# Initialize the communication context
ClimaComms.init(comms_ctx)

@assert 0 < radius
@assert 0 < depth
vertdomain = ClimaCore.Domains.IntervalDomain(
Expand Down Expand Up @@ -646,6 +652,9 @@ function SphericalSurface(;
comms_ctx = ClimaComms.context(),
) where {FT}
@assert 0 < radius
# Initialize the communication context
ClimaComms.init(comms_ctx)

horzdomain = ClimaCore.Domains.SphereDomain(radius)
horzmesh = Meshes.EquiangularCubedSphere(horzdomain, nelements)
horztopology = Topologies.Topology2D(comms_ctx, horzmesh)
Expand Down
3 changes: 3 additions & 0 deletions src/shared_utilities/checkpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ function read_checkpoint(
context = isnothing(model) ? ClimaComms.context() :
ClimaComms.context(model),
)
# Initialize the communication context
ClimaComms.init(context)

hdfreader = InputOutput.HDF5Reader(file_path, context)
Y = InputOutput.read_field(hdfreader, "Y")
attributes = InputOutput.read_attributes(hdfreader, "/")
Expand Down
1 change: 1 addition & 0 deletions test/simulations/spatial_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ regridder_type = :InterpolationsRegridder
extrapolation_bc =
(Interpolations.Periodic(), Interpolations.Flat(), Interpolations.Flat())
context = ClimaComms.context()
ClimaComms.init(context)

earth_param_set = LP.LandParameters(FT)
radius = FT(6378.1e3)
Expand Down
1 change: 0 additions & 1 deletion test/standalone/Bucket/albedo_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ end
set_initial_cache!(p, Y, FT(0.0))

# Read in data manually
comms_ctx = ClimaComms.context(surface_space)
α_bareground = SpaceVaryingInput(path, varname, surface_space)
@test p.bucket.α_sfc == α_bareground
else
Expand Down

0 comments on commit 40425c3

Please sign in to comment.