Replies: 4 comments 8 replies
-
|
Hm, as a side note, you actually should never use Another note is that you should not create a field inside a function which computes a diagnostic. This will allocate memory for a field every time you need to compute the diagnostic. Instead you should allocate only the memory needed for the diagnostic, and then recompute the field as the simulation goes along. You can implement this kind of workflow yourself using a function for sure. However, for your case, it seems you can use abstract operations directly and avoid the function approach altogether. To present a simplified example: u10 = coupled_model.interfaces.exchanger.exchange_atmosphere_state.u # u wind component
v10 = coupled_model.interfaces.exchanger.exchange_atmosphere_state.v # v wind component
SCALE_FACTOR = 0.26
k = SCALE_FACTOR * (u10^2 + v10^2)
ocean.output_writers[:surface] = JLD2Writer(ocean.model, (; k);
schedule = TimeInterval(1days),
filename = "global_1deg_30days_sim",
indices = (:, :, grid.Nz),
overwrite_existing = true)If you would like to go about a more manual approach, you should look into using As sort of a general rule, you should not find yourself using broadcasting for computations very often, except for the trivial ones like I believe if you take this new approach you will not have issues with scalar operations. |
Beta Was this translation helpful? Give feedback.
-
|
Thank @glwagner , I appreciate the quick reply and explanation. Took your advice and got rid of the functions, now my code looks like this A,B,C,D,E = 2116.8, 136.25, 4.7353, 0.092307, 0.0007555
SCALE_FACTOR = 0.26
taux = coupled_model.interfaces.atmosphere_ocean_interface.fluxes.x_momentum;
tauy = coupled_model.interfaces.atmosphere_ocean_interface.fluxes.y_momentum;
u10 = coupled_model.interfaces.exchanger.exchange_atmosphere_state.u;
v10 = coupled_model.interfaces.exchanger.exchange_atmosphere_state.v;
SST = view(ocean.model.tracers.T, :, :, ocean.model.grid.Nz);
Sc = A - B*SST + C*SST^2 - D*SST^3 + E*SST^4;
ws = sqrt(u10^2 + v10^2);
kw = SCALE_FACTOR * ws^2 * (Sc/660)^(-0.5);
custom_outputs = (;kw, ws, Sc, taux, tauy);
ocean_outputs = merge(ocean.model.tracers, coupled_model.ocean.model.velocities, custom_outputs);
ocean.output_writers[:surface] = JLD2Writer(ocean.model, ocean_outputs;
schedule = TimeInterval(1days),
filename = "global_1deg_30days_sim",
indices = (:, :, grid.Nz),
overwrite_existing = true)Now i'm getting this error Google leads me to believe I am using too much memory on the GPU? Don't think it's because i'm testing code in a jupyter notebook. any thoughts on how to resolve this? or is my only solution to use multiple GPUs. Thanks again for the help :) |
Beta Was this translation helpful? Give feedback.
-
|
Thank you so much @glwagner !! Here is what is working (or least not giving parameter memory errors yet) sea_surface_temperature(coupled_model) = view(coupled_model.ocean.model.tracers.T, :, :, coupled_model.ocean.model.grid.Nz);
A,B,C,D,E = 2116.8, 136.25, 4.7353, 0.092307, 0.0007555
SCALE_FACTOR = 0.26 * sqrt(660)
taux = coupled_model.interfaces.atmosphere_ocean_interface.fluxes.x_momentum;
tauy = coupled_model.interfaces.atmosphere_ocean_interface.fluxes.y_momentum;
u10 = coupled_model.interfaces.exchanger.exchange_atmosphere_state.u;
v10 = coupled_model.interfaces.exchanger.exchange_atmosphere_state.v;
SST = sea_surface_temperature(coupled_model)
Sc = (((E*SST - D)*SST + C)*SST - B)*SST + A; # via Horner's method
ws = sqrt(u10^2 + v10^2);
kw = SCALE_FACTOR * (u10^2 + v10^2) / sqrt(Sc);
custom_outputs = (;kw, ws, Sc, taux, tauy);
ocean_outputs = merge(ocean.model.tracers, coupled_model.ocean.model.velocities, custom_outputs);
ocean.output_writers[:surface] = JLD2Writer(ocean.model, ocean_outputs;
schedule = TimeInterval(1days),
filename = "global_1deg_30days_sim",
indices = (:, :, grid.Nz),
overwrite_existing = true)
I appreciate all your help on this! Couple questions for my own edification
|
Beta Was this translation helpful? Give feedback.
-
|
Thanks for all the help @glwagner Is it possible to see the parameter memory error again if I increase the spatial resolution or does this error just mean the expression I am evaluating is too complex? Just trying to fully understand the meaning of the error so I know how to resolve it in the future |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! So I am trying to calculate the gas transfer velocity at each time step and save the average.
I keep getting this error message:
Which usually means I need to wrap my code in
I did this in my
compute_k_local(mod)function but am still getting this error. I've tried a few other things, but am not at a loss. My understanding is when I create a custom function it needs to return aField, it can not be anCuArrayorOffsetArray.Any help would be greatly appreciated. Thanks!
Here is the relevant bits of my code:
Beta Was this translation helpful? Give feedback.
All reactions