rundke_remote

PURPOSE ^

SYNOPSIS ^

function rundke_remote(remlist,link_mode,remtimout)

DESCRIPTION ^

 This function runs the LH Karney benchmark remotely on a selection of hosts. 
   - If it is called with remtimout > 0, the function waits for each calculation to be completed 
   - If it is called with remtimout = 0, the function saves the jobs in a LUKE_RESULTS file
   - If it is called without arguments, it loads the previously saved LUKE_RESULTS file if it exists, and check the results.

 INPUTS :
       - remlist : remote profile selection
           o NaN : (default) test all profiles
           o []  : prompt for profile selection
           o ex : [1:3,6,8] : profile selection
       - link_mode : connection mode prescription
           o -1  : local profiles only
           o NaN : (default) use value from remote.link_mode
           o []  : give priority to (0) ssh key pair, (1) ssh bridge, (2) url/ftp bridge
           o 0   : ssh key pair enforced
           o 1   : ssh bridge enforced
           o 2   : url/ftp bridge enforced
       - remtimout : timeout for remote calculations, in minutes. Use (0) to return later and check results by running this script again

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function rundke_remote(remlist,link_mode,remtimout)
0002 %
0003 % This function runs the LH Karney benchmark remotely on a selection of hosts.
0004 %   - If it is called with remtimout > 0, the function waits for each calculation to be completed
0005 %   - If it is called with remtimout = 0, the function saves the jobs in a LUKE_RESULTS file
0006 %   - If it is called without arguments, it loads the previously saved LUKE_RESULTS file if it exists, and check the results.
0007 %
0008 % INPUTS :
0009 %       - remlist : remote profile selection
0010 %           o NaN : (default) test all profiles
0011 %           o []  : prompt for profile selection
0012 %           o ex : [1:3,6,8] : profile selection
0013 %       - link_mode : connection mode prescription
0014 %           o -1  : local profiles only
0015 %           o NaN : (default) use value from remote.link_mode
0016 %           o []  : give priority to (0) ssh key pair, (1) ssh bridge, (2) url/ftp bridge
0017 %           o 0   : ssh key pair enforced
0018 %           o 1   : ssh bridge enforced
0019 %           o 2   : url/ftp bridge enforced
0020 %       - remtimout : timeout for remote calculations, in minutes. Use (0) to return later and check results by running this script again
0021 %
0022 if nargin < 3,
0023     remtimout = 10;% timeout for remote calculations, in minutes. Use (0) to return later and check results by running this script again
0024 end
0025 %
0026 if nargin < 2 || (~isempty(link_mode) && (~isnumeric(link_mode) || ~isscalar(link_mode) || ~any(link_mode == [0:2]))),
0027     link_mode = NaN;% bridge mode : (NaN) follow remote, ([]) priority to ssh, (0) ssh only, (1) bridge only
0028 end
0029 %
0030 if nargin < 1 || (~isempty(remlist) && ~isnumeric(remlist)),
0031     remlist = [];% Interactive mode
0032 end
0033 %
0034 permission = test_permissions_yp;
0035 %
0036 if ~permission 
0037     disp('Please move the script to a local folder where you have write permission before to run it')
0038     return;
0039 end
0040 %
0041 rempause = 1/60;%pause between job checks (in minutes) (only for remtimout > 0)
0042 %
0043 debugmode = 0;% debug mode (0) off (1) on
0044 cleanmode = 2;% clean job files/folders : both on remote and local (2), only on remote (1) or not at all (0)
0045 luke_memory = 2000;% job memory in mb
0046 luke_walltime = '01:00';% job walltime in hours (number or full description '00:00' for hours and minutes
0047 enforce = 0;% (0) : exit if remote calculation failed, (1): if remote calculation failed, it is done locally
0048 %
0049 opt.save = 1;% save individual results in LUKE_RESULTS files (WARNING : Use absolute simul.path to save locally with local cluster)
0050 %
0051 mdce_opt = 0;% option for testing distributed computing inside remote calculation
0052 %
0053 localdatadir = 'LUKE_RESULTS_files_remote/';
0054 %
0055 % ***********************This part must be specified by the user, run make files if necessary) *****************************
0056 %
0057 id_simul = 'LH_karney_remote';%Simulation ID
0058 path_simul = '';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path
0059 %
0060 psin_S = [];%Normalized poloidal flux grid where calculations are performed (0 < psin_S < 1) (If one value: local calculation only, not used if empty)
0061 rho_S = [0.5];%Normalized radial flux grid where calculations are performed (0 < rho_S < 1) (If one value: local calculation only, not used if empty)
0062 %
0063 id_path = '';%For all paths used by DKE solver
0064 path_path = '';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path
0065 %
0066 id_equil = 'TScyl';%For plasma equilibrium
0067 path_equil = '';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path
0068 %
0069 id_dkeparam = 'UNIFORM10010020';%For DKE code parameters
0070 path_dkeparam = '';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path
0071 %
0072 id_display = 'NO_DISPLAY';%For output code display
0073 path_display = '';%if nothing is specified, the working directory is first used and then MatLab is looking in all the path
0074 %
0075 %************************************************************************************************************************************
0076 %************************************************************************************************************************************
0077 %************************************************************************************************************************************
0078 %
0079 [dkepath,equil,dkeparam,dkedisplay] = load_structures_yp('dkepath',id_path,path_path,'equil',id_equil,path_equil,'dkeparam',id_dkeparam,path_dkeparam,'dkedisplay',id_display,path_display);
0080 %
0081 %************************************************************************************************************************************
0082 %
0083 wavestruct.omega_lh = [4]*2*pi*1e9; %(GHz -> rad/s). Wave frequency [1,1] Indicative, no effect in small FLR limit opt_lh > 0
0084 %Option parameter for cross-comparison between old LH code:
0085 %    - (1): 1/vpar dependence
0086 %    - (2): no 1/vpar dependence and old grid technique for Dlh calculations (Karney, Shoucri) (see rfdiff_dke_jd)
0087 wavestruct.opt_lh = 2; % [1,1]
0088 %
0089 % Choose (vparmin_lh,vparmax_lh) or (Nparmin_lh,Nparmax_lh) for square n// LH wave power spectrum,
0090 % or (Npar_lh,dNpar_lh) for Gaussian shape
0091 %
0092 wavestruct.norm_ref = 1;%Normalization procedure for the LH quasilinear diffusion coefficient and spectrum boundaries
0093 %
0094 wavestruct.yNparmin_lh = [NaN];%LH wave square N// Spectrum: Lower limit [1,n_scenario_lh]
0095 wavestruct.yNparmax_lh = [NaN];%LH wave square N// Spectrum: Upper limit [1,n_scenario_lh]
0096 wavestruct.yNpar_lh = [NaN];%LH wave Gaussian N// Spectrum: peak [1,n_scenario_lh]
0097 wavestruct.ydNpar_lh = [NaN];%LH wave Gaussian N// Spectrum: width [1,n_scenario_lh]
0098 %
0099 %   Note: this diffusion coefficient is different from the general QL D0. It has a benchmarking purpose only
0100 wavestruct.yD0_in_c_lh = [1];%Central LH QL diffusion coefficient (nhuth_ref*pth_ref^2 or nhuth*pth^2) [1,n_scenario_lh]
0101 %
0102 wavestruct.yD0_in_lh_prof = [0];%Quasilinear diffusion coefficient radial profile: (0) uniform, (1) gaussian radial profile [1,n_scenario_lh]
0103 wavestruct.ypeak_lh = [NaN];%Radial peak position of the LH quasi-linear diffusion coefficient (r/a on midplane) [1,n_scenario_lh]
0104 wavestruct.ywidth_lh = [NaN];%Radial width of the LH quasi-linear diffusion coefficient (r/a on midplane) [1,n_scenario_lh]
0105 %
0106 wavestruct.ythetab_lh = [0]*pi/180;%(deg -> rad). Poloidal location of LH beam [0..2pi] [1,n_scenario_lh]
0107 %               (0) from local values Te and ne, (1) from central values Te0 and ne0
0108 %
0109 %************************************************************************************************************************************
0110 %
0111 if exist('dmumpsmex');dkeparam.invproc = -2;end
0112 %
0113 dkeparam.boundary_mode_f = 0;%Number of points where the Maxwellian distribution is enforced from p = 0 (p=0, free conservative mode but param_inv(1) must be less than 1e-4, otherwise 1e-3 is OK most of the time. Sensitive to the number of points in p)
0114 dkeparam.norm_mode_f = 1;%Local normalization of f0 at each iteration: (0) no, the default value when the numerical conservative scheme is correct, (1) yes
0115 dkeparam.tn = [50000,100000];% 2 time steps to tn=100000 best for asymptotic solution
0116 dkeparam.rt_mode = 1;% necessary to use run_lukert
0117 %
0118 dkeparam.rho_S = rho_S;% radial flux grid points enforced
0119 dkeparam.psin_S = psin_S;% radial flux grid points enforced
0120 %
0121 dkeparam.clustermode.coll_dke_jd.scheduler.mode = mdce_opt;
0122 dkeparam.clustermode.eecoll_dke_yp.scheduler.mode = mdce_opt;
0123 %
0124 % RELATIVISTIC CASE
0125 %
0126 dkeparam.pnmax_S = 30;
0127 %
0128 wavestruct.yvparmin_lh = [4];%LH wave square N// Spectrum: Lower limit of the plateau (vth_ref or vth) [1,n_scenario_lh]
0129 wavestruct.yvparmax_lh = [7];%LH wave square N// Spectrum: Upper limit of the plateau (vth_ref or vth) [1,n_scenario_lh]
0130 %
0131 waves{1} = make_idealLHwave_jd(equil,wavestruct);
0132 %
0133 opt.fields = {'Znorm','Zcurr','ZP0'};% select fields to be returned from lukestructs. Use NaN to return all fields.
0134 %
0135 % generate luke_inputs structure
0136 %
0137 lukestruct.equil = equil;
0138 lukestruct.dkeparam = dkeparam;
0139 lukestruct.dkedisplay = dkedisplay;
0140 lukestruct.waves = waves;
0141 lukestruct.opt = opt;
0142 %
0143 % local calculation
0144 %
0145 disp('--> Local calculation')
0146 %
0147 lukestruct_0 = run_lukert(lukestruct,dkepath);
0148 %
0149 Znorm_0 = lukestruct_0.output.Znorm;
0150 Zcurr_0 = lukestruct_0.output.Zcurr;
0151 ZP0_0 = lukestruct_0.output.ZP0;
0152 %
0153 % simulation filename
0154 %
0155 filename = [path_simul,'LUKE_RESULTS_',id_equil,'_',id_simul,'.mat'];
0156 %
0157 % check if current jobs exists to load possible existing jobs
0158 %
0159 if nargin == 0 && exist(filename,'file'),% load existing simulation
0160     %
0161     load(filename,'lukestructs','remlist','link_mode','remtimout');
0162     %
0163     dkepath = setpath_luke_jd('',link_mode);
0164     %
0165     nrem = length(lukestructs);%remlist
0166     %
0167 else% new simulation
0168     %
0169     % profiles in dkepath.remote tested
0170     %
0171     if ~exist('dkepath','var'),
0172         dkepath = setpath_luke_jd('',link_mode,0);
0173     else
0174         dkepath = setpath_luke_jd(dkepath,link_mode,0);
0175     end
0176     %
0177     if isfield(dkepath,'remote'),
0178         nrem = length(dkepath.remote);
0179         if isempty(remlist),
0180             remlist = input_dke_yp('Please identify profiles to be tested.',1:nrem,[1;nrem]);
0181         elseif isnan(remlist),
0182             remlist = 1:nrem;
0183         else
0184             remlist(remlist > nrem) = [];
0185         end
0186     else
0187         remlist = [];
0188     end
0189     %
0190     nrem = length(remlist);
0191     %
0192     dkepath.clustermode.run_lukert.scheduler.mode = 0;%no distribution of LUKE on the remote machine
0193     dkepath.clustermode.run_lukert.scheduler.remtimout = remtimout;
0194     dkepath.clustermode.run_lukert.scheduler.rempause = rempause;
0195     dkepath.clustermode.run_lukert.scheduler.memory = luke_memory;
0196     dkepath.clustermode.run_lukert.scheduler.walltime = luke_walltime;
0197     dkepath.clustermode.run_lukert.scheduler.debugmode = debugmode;
0198     dkepath.clustermode.run_lukert.scheduler.cleanmode = cleanmode;
0199     dkepath.clustermode.run_lukert.scheduler.enforce = enforce;% exit if remote calculation failed
0200     if opt.save,
0201         dkepath.clustermode.run_lukert.scheduler.localdatadir = localdatadir;
0202         if exist(localdatadir,'dir') && length(dir(localdatadir)) > 2,
0203             delete([localdatadir,'*']);
0204         end
0205     end
0206     %
0207     lukestructs = repmat({lukestruct},[1,nrem]);
0208 end
0209 %
0210 for remnum = 1:nrem,
0211     %
0212     if ~isnan(remlist), % new calculation
0213         %
0214         dkepath.clustermode.run_lukert.scheduler.remnum = remlist(remnum);
0215         %
0216         lukestructs{remnum}.simul.locid = [id_simul,'_',num2str(remlist(remnum))];
0217         %
0218         disp(['--> Calculation with remote number ',num2str(remlist(remnum)),', host: ',dkepath.remote(remlist(remnum)).host])
0219     end
0220     %
0221     lukestructs{remnum} = run_lukert(lukestructs{remnum},dkepath);
0222     %
0223 end
0224 %
0225 Znorm = cell(1,nrem);
0226 Zcurr = cell(1,nrem);
0227 ZP0 = cell(1,nrem);
0228 %
0229 flag_running = false(1,nrem);
0230 luke_warning = cell(1,nrem);
0231 %
0232 for remnum = 1:nrem,
0233     if isfield(lukestructs{remnum},'output'),
0234         if isfield(lukestructs{remnum},'warning')
0235             luke_warning{remnum} = [' **** WARNING : ',lukestructs{remnum}.warning];
0236         end
0237         Znorm{remnum} = lukestructs{remnum}.output.Znorm;
0238         Zcurr{remnum} = lukestructs{remnum}.output.Zcurr;
0239         ZP0{remnum} = lukestructs{remnum}.output.ZP0;
0240     elseif isfield(lukestructs{remnum},'job'),
0241         flag_running(remnum) = true;
0242     end
0243 end
0244 %
0245 j_r_k = '0.003732';
0246 p_r_k = '0.0001256';
0247 eta_r_k = '29.72';
0248 %
0249 %************************************************************************************************************************************
0250 %
0251 format
0252 %
0253 if ~isempty(link_mode) && ~isnan(link_mode),
0254     link_modestr = ['_link_mode_',num2str(link_mode)];
0255 else
0256     link_modestr = '';
0257 end
0258 %
0259 diaryname = ['res_karney_remote_',datestr(now,29),link_modestr,'.log'];
0260 %
0261 if input_dke_yp(['Do you want to save the results in the log file ',diaryname,' ? (y/n)'],'y',{'y','n'}) == 'y',
0262     %
0263     if exist(diaryname,'file'),
0264         delete(diaryname);
0265     end
0266     %
0267     diary(diaryname);
0268     %
0269 else
0270     diaryname = '';
0271 end
0272 %
0273 disp(' ')
0274 disp(' Remote profiles tested : ')
0275 disp(' ')
0276 %
0277 for remnum = 1:nrem,
0278     info_dke_yp(4,['#',num2str(remnum),' : ',dkepath.profilestr{remlist(remnum)}]);
0279 end
0280 disp(' ')
0281 
0282 disp(['----------------------'])
0283 disp(['Comparison LUKE/Karney - Relativistic case (4,7,1) - with tn = ',int2str(dkeparam.tn),', dtn = ',int2str(dkeparam.dtn),' and nit_f = ',int2str(dkeparam.nit_f)])
0284 disp(['----------------------'])
0285 %
0286 disp(['Local calculation : j = ',num2str(Zcurr_0.x_0),'/',j_r_k,' ; P = ',num2str(ZP0_0.x_rf_fsav),'/',p_r_k,' ; j/P = ',num2str(Zcurr_0.x_0./ZP0_0.x_rf_fsav),'/',eta_r_k]) 
0287 %
0288 for remnum = 1:nrem,
0289     if ~isempty(Zcurr{remnum}),
0290         disp(['Remote calc. # ',num2str(remnum),' : j = ',num2str(Zcurr{remnum}.x_0),'/',j_r_k,' ; P = ',num2str(ZP0{remnum}.x_rf_fsav),'/',p_r_k,' ; j/P = ',num2str(Zcurr{remnum}.x_0./ZP0{remnum}.x_rf_fsav),'/',eta_r_k,luke_warning{remnum}]) 
0291     elseif flag_running(remnum),
0292         disp(['Remote calc. # ',num2str(remnum),' : running'])
0293     else
0294         disp(['Remote calc. # ',num2str(remnum),' : failed'])
0295     end
0296 end
0297 %
0298 if ~isempty(diaryname),
0299     diary off
0300 end
0301 %
0302 %************************************************************************************************************************************
0303 %
0304 if remtimout == 0,
0305     if ~any(flag_running),
0306         delete(filename);% jobs completed, file deleted
0307     else
0308         save(filename);% file saved for future check
0309         info_dke_yp(2,['Data saved in ',filename]);
0310     end
0311 end
0312 %

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.