EcoExtreML / STEMMUS_SCOPE

Integrated code of SCOPE and STEMMUS
https://EcoExtreML.github.io/STEMMUS_SCOPE
GNU General Public License v3.0
14 stars 6 forks source link

High execution time of stemmus_scope #80

Open SarahAlidoost opened 2 years ago

SarahAlidoost commented 2 years ago

@BSchilperoort used MATLAB function profiler to explore execution time for functions in stemmus_scope model. Some functions like ebal, RTMf, RTMz cause high compute time. We found that these are related to the spectrum resolution and the number of canopy layers.

STEMMUS_SCOPE uses all of the Fluorescence wavelengths and Excitation wavelengths, see here. However, SCOPE uses only some of them, see here. Fewer wavelengths will improve the execution time significantly.

STEMMUS_SCOPE uses 60 for canopy layers, see here. However, SCOPE calculates it as canopy.nlayers = ceil(10*canopy.LAI) + ((meteo.Rin < 200) & options.MoninObukhov)*60, see here. If this equation is used to get the number of layers, it results 30 for most of the sites. Fewer canopy layers will improve the execution time too.

@Yunfei-Wang1993 , @yijianzeng , @bobzsu please have a look at this issue. We can discuss it further tomorrow. We can inspect the results of the profiler more to see if there are other factors as well.

BSchilperoort commented 2 years ago

So that everyone can easily look at the profiler results, I have uploaded them here: PT-Mi1_profile_results.zip The results are for a single site, with 1 week of forcing data at 1/2 hour resolution. Just open file0.html to view the results.

@SarahAlidoost note that that canopy nlayer equation will result in 60 -- 100 layers at night (as R_in will be low at night, it is a quick way to try to account for the dominance of radiative heat transfer during stable atmospheric conditions.)

SarahAlidoost commented 2 years ago

See more info techniques-for-improving-performance

SarahAlidoost commented 2 years ago

The workarounds to address the issue are:

Other factors to be explored in the future:

yijianzeng commented 2 years ago

@SarahAlidoost @BSchilperoort In terms of re-starting and saving the workspace, i was using the below script. ws2struct.m

struct2ws.m

Yunfei-Wang1993 commented 2 years ago

Hi, all, Sorry for missing the meeting last week. Thanks, Bart and Sarah, for pointing out these issues. I studied the recording of the meeting and some points could be discussed with you.

  1. The reason why 30 times iteration was implement in the ebal.m file is that we need to calculate leaf water potential (PSI) in each iteration, however, the PSI is also need by the calculation of heat fluxes (heatfluxes.m). I think all of you have got it.
  2. For the twice calculation of ei, the second calculation can be commented or deleted.
  3. For the running time of STEMMUS-SCOPE, it is not only attribute to SCOPE. The running time of STEMMUS increase with the time step increasing non-linearly. The reason is that there are many global variables are saved in work space and these variables will occupy the memory. Maybe Yijian kowns it.
  4. For the 170 site running, I think we could try to run 170 sites with the current version of STEMMUS-SCOPE, because couple the new SCOPE2.0 with STEMMUS also need some time. For speed up STEMMUS-SCOPE, there are some practices:
  5. Reduce the canopy layers from 60 to 30 and reduce the resolution of spectrum. As you know, SCOPE 2.0 have implemented it and we can refer to the latest version of SCOPE 2.0. Actually, I tried coupled SCOPE 2.0 with STEMMUS last year. However, the estimation of soil temperature was very strange. So, I used the SCOPE 1.73 and modified the energy balance functions refereed to SCOPE 2.0.
  6. Optimize the structure of STEMMUS, for example, some large variables (e.g. Sim_Theta, Sim_Temp, et al.), which saved in work space, can be saved in the output files. As I kown, the running time of SCOPE increase with time step increasing linearly. If this problem was solved, we will not need to separate 30 years into 30 one-year running.
  7. Modify the code, for example, comment or delete the second calculation of ei in heatfluxes.m file.
  8. Decrease the convergence criteria. Best regards, Yunfei 2022年7月13日 下午7:53,SarahAlidoost @.**@.>> 写道:

The workarounds to address the issue are:

Other factors to be explored in the future:

— Reply to this email directly, view it on GitHubhttps://github.com/EcoExtreML/STEMMUS_SCOPE/issues/80#issuecomment-1183126300, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALXM2A7BFXWBF7TCQOLD4YTVT2U33ANCNFSM53KNKWQA. You are receiving this because you were mentioned.Message ID: @.***>

bobzsu commented 2 years ago
  1. For spectral ranges: wlE = (400:5:750)'; %spectral.wlE'; % Excitation wavelengths wlF = (640:4:850)';%spectral.wlF'; % Fluorescence wavelengths can be adapted. (with a reduction factor of 4-5 in iterations)

  2. For canopy layers: canopy.nlayers = ceil(10canopy.LAI) + ((meteo.Rin < 200) & options.MoninObukhov)60; canopy.nlayers = max(2, canopy.nlayers); % patch for LAI < 0.1 these changes in SCOPE2.0 can be updated in STEMMUS-SCOPE. (30 layers is not needed for low LAI; dLAI=0.1 is used for numerical approximations of the radiative transfer equations)

  3. in ebal.m,
    need to check: maxEBercu = max(max(max(abs(EBercu))));

need to check the maxEBer values used for:

in https://github.com/EcoExtreML/STEMMUS_SCOPE/blob/4cdb0e28349c8b5fb469f99b0689495b70c8076b/src/STEMMUS_SCOPE.m#L312 %% 6. Numerical parameters (iteration stops etc) iter.maxit = 100; % maximum number of iterations iter.maxEBer = 5; %[W m-2] maximum accepted error in energy bal. iter.Wc = 1; % Weight coefficient for iterative calculation of Tc

Solution could be to set total energy balance residual to reach maxEBer.

  1. what is the unit used here for PSI - m? if abs(PSI-PSI1)<0.0001
bobzsu commented 2 years ago

the spectral ranges should be changed in RTMf.m (not in define_bands.m)
For spectral ranges: wlE = (400:5:750)'; %spectral.wlE'; % Excitation wavelengths wlF = (640:4:850)';%spectral.wlF'; % Fluorescence wavelengths can be adapted. (with a reduction factor of 4-5 in iterations)

yijianzeng commented 2 years ago

Hi, Bob, Yunfei, Sarah, Bart, I just did a quick debugging, and found several points that need attentions:

@Yunfei-Wang1993 Yunfei, please help go through this.