GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — MatRemote/testremotebatch.m at master · IRFM/MatRemote

Expand file tree

/

testremotebatch.m

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
424 lines (422 loc) · 13.1 KB
/

testremotebatch.m

Copy path

File metadata and controls

executable file
·
424 lines (422 loc) · 13.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
%
% /////////////////////////////////////////
%
% Software name : MatRemote, part of LUKE
%
% Authors : Yves Savoye-Peysson and Joan Decker
%
% Copyright holders : Commissariat a l'Energie Atomique et aux Energies Alternatives (CEA), France
%
% CEA authorizes the use of the LUKE software under the CeCILL-C open source license https://cecill.info/licences/Licence_CeCILL-C_V1-en.html
%
% The terms and conditions of the CeCILL-C license are deemed to be accepted upon downloading the software and/or exercising any of the rights granted under the CeCILL-C license.
%
% /////////////////////////////////////////
%
function soutputs = testremotebatch(sinputs,remote,debugmode,link_mode,displaymode)
% ------------------------------------------------
% test for remote batch using a standard function.
% ------------------------------------------------
%
% This function tests the MatRemote package using either batch or direct
% calculations. Given the option sinputs, three modes can be tested :
%
% - the direct use of remoterunbatch and remotegetbatch
%
% - the use of matremote_jd(fun,args_in,remote,job), where 'fun' is the
% matlab function to be executed remotely, 'args_in' are the arguments used
% by 'fun', 'remote' is the remote (or local!) profile, and the optional
% input 'job' specifies job parameters.
%
% - the use of matremote_jd by returning job info to be checked later
%
% by J. Decker, Y. Peysson and M. Schneider (CEA/IRFM)
%
% INPUTS :
%
% - sinputs : can be
% o a number : (0) use remoterunbatch and wait for result with remotegetbatch
% (1) use matremote_jd and wait for result
% (2) use matremote_jd and return job for later check
% o a cell array containing the job(s) started earlier with option (job = 2), or the results of completed jobs
%
% - remote : only if isnumeric(sinputs)
% o (NaN) : load all profiles and ask for user selection
% o (struct) : profile contained in structure 'remote'
% o (string) : identification of profile to be selected as remote_(string).m
% (default) o ('') : load & return all profiles
% o ('local') : idendify and return local cluster
%
% - debugmode : [0 or 1] if 1, provides step by step information, and save diary file in remote job folder
%
% - link_mode : connection mode prescription
% o NaN : (default) use value from remote.link_mode
% o [] : give priority to (0) ssh key pair, (3) ssh proxy jump, (1) ssh bridge, (2) url/ftp bridge
% o 0 : ssh key pair enforced
% o 1 : ssh bridge enforced
% o 2 : url/ftp bridge enforced
% o 3 : ssh proxy jump enforced
%
% - displaymode :
% o (0) display results only,
% o (1) (default) display job status evolution
% o (2) display step by step
%
% OUTPUTS :
%
% - soutputs is a cell array containing
% o a structure containing the job started with option (job = 2)
% o the job output or error message if the job is completed
%
% The test works by checking remote access and transfers, remote path,
% remote matlab version, remote command (remotetest), variable transfer ('The best code is : ')
% and environment variable ('luke').
%
%
% Set path to MatRemote & MatTools toolboxes
%
matremote_path = [fileparts(which(mfilename)),filesep];
mattools_path = [matremote_path,'../MatTools/'];% change if needed
%
addpath(matremote_path);% MatRemote toolbox
addpath([matremote_path,'Profiles/']);% remote profiles
addpath(mattools_path);% MatTools toolbox
%
sinput.strin = 'The best code is : ';% input to function remotetest
testvar = 'luke'; % test variable
%
globals = who('global');
if ~isempty(globals)
clear(globals{:});
end
%
% Displaymode
%
if nargin < 5
displaymode = 1;% display job status evolution
end
%
% link_mode
%
if nargin < 4
link_mode = NaN;% use value from remote.link_mode
end
%
% Debugmode
%
if nargin < 3
debugmode = 0;% default mode is direct use of remoterunbatch and remotegetbatch
end
%
% Test direct calculation with matremote_jd
%
if debugmode
setenv('TESTVAR',testvar);
[err,~,soutput_init] = matremote_jd('remotetest',{sinput});
%
if ~isempty(err)
soutput_init.err = err;
end
end
%
% Test remote calculation
%
if nargin < 1
sinputs = 0;% default mode is direct use of remoterunbatch and remotegetbatch
end
%
if nargin < 2
remote = '';% test all profiles
end
%
if isempty(remote)
remotestr = 'all';
elseif ischar(remote)
remotestr = remote;
elseif isnan(remote)
remotestr = 'NaN';
elseif isstruct(remote)
remotestr = remote.hostname;
else
error('Input argument remote not understood.')
end
%
if isnumeric(sinputs)% start new test
%
% Select local and remote profiles to be tested
%
[remoteprofiles,profilestr] = load_remoteprofiles_jd(remote,true,true,NaN,NaN,true,debugmode,link_mode);
%
nrem = length(remoteprofiles);
%
soutputs = cell(1,nrem);% output structure cell array: can be output, jobs, or error message depending on options and results
%
% loop on tested profiles
%
for irem = 1:nrem
%
disp(' ');
disp('-------------------------------------------------------------------')
disp([' ---> Testing profile [',profilestr{irem},']']);
disp('-------------------------------------------------------------------')
disp(' ');
%
remote = remoteprofiles(irem);
%remote.disp_cmd = 1;
%
test_job = matstandardjob_jd;
%
test_job.wait = 0;%1;% (0) return hand (1) wait for result
test_job.nodes = 1;%number of nodes required
test_job.ppn = 1;%number of cores required
test_job.memory = 2000;% memory required (in mb) - leave empty if no requirement
test_job.walltime = 1;%[];% time required (integers - in hours) - leave empty if no requirement
test_job.rempause = 1/60;% in minutes
%
if sinputs <= 1 % wait for result
test_job.remtimout = 5;% in minutes
else% return hand for later check
test_job.remtimout = 0;% in minutes
end
%
test_job.env.TESTVAR = testvar;
test_job.debugmode = debugmode;
%
% uncomment the next two lines to try local calc. with different
% local and remote folders
%
% test_job.localdatapath = [pwd,filesep];
% test_job.remotedatapath = '/tmp/';
%
try
if sinputs == 0 % use remoterunbatch and wait for result with remotegetbatch
%
test_job.env.remotematfnc = 'remotetest'; % matlab function to be called remotely by remotematrun (case of direct call)
%
test_job = remoterunbatch(remote,test_job,sinput,displaymode);
%
if isfield(test_job,'err')
soutputs{irem}.err = test_job.err;
else
[~,soutputs{irem}] = remotegetbatch(test_job,displaymode,0);
end
%
else% use matremote_jd
%
test_job.funcopy = true;% to copy function remotetest to remote folder
test_job.env.remotematfnc = 'runmat'; % matlab function to be called remotely by remotematrun (case of standard call using runmat)
test_job.displaymode = displaymode;
%
[err,test_job,soutput] = matremote_jd('remotetest',{sinput},remote,test_job);
%
if ~isempty(err)
soutputs{irem}.err = err;
elseif ~isempty(soutput) % job completed
soutputs{irem} = soutput;
else
soutputs{irem}.job = test_job;
end
%
end
catch job_err
soutputs{irem}.err = job_err.message;
end
%
end
%
else% check previously started job
%
nrem = length(sinputs);
%
soutputs = cell(1,nrem);% output structure cell array: can be output, jobs, or error message depending on options and results
%
% loop on tested profiles
%
profilestr = cell(1,nrem);
%
for irem = 1:nrem
%
profilestr{irem} = sinputs{irem}.profilestr;
%
if isfield(sinputs{irem},'job') % previously running job
%
[err,test_job,soutput] = matremote_jd(sinputs{irem}.job);
%
if ~isempty(err)
soutputs{irem}.err = err;
elseif ~isempty(soutput) % job completed
soutputs{irem} = soutput;
else
soutputs{irem}.job = test_job;
end
%
else% previously completed jobs
%
soutputs{irem} = sinputs{irem};
%
end
%
end
%
end
%
if isempty(link_mode)
link_modestr = '_empty_link_mode';
link_modestr2 = 'empty link mode';
elseif isnan(link_mode)
link_modestr = '_link_mode_NaN';
link_modestr2 = 'link mode = NaN';
else
link_modestr = ['_link_mode_',num2str(link_mode)];
link_modestr2 = ['link mode = ',num2str(link_mode)];
end
%
if isnumeric(sinputs)
calcmodestr = num2str(sinputs);
else
calcmodestr = '2';
end
%
testdate = datestr(now,29);
%
diaryname = ['res_testremotebatch_',matversion_yp,'_',remotestr,'_',testdate,link_modestr,'.log'];
%
if input_dke_yp(['Do you want to save the results in the log file ',diaryname,' ? (y/n)'],'y',{'y','n'}) == 'y'
%
if exist(diaryname,'file')
delete(diaryname);
end
%
diary(diaryname);
%
else
diaryname = '';
end
%
% Display results
%
disp(' ');
disp('-------------------------------------------------------------------')
disp(' TEST RESULTS');
disp(' ');
disp([' test on ',testdate,' with ',link_modestr2,' and calc mode = ',calcmodestr,' from guest ',hostname_jd,' running Matlab version ',version]);
disp(' ');
disp('-------------------------------------------------------------------')
disp(' ');
%
if debugmode
disp(' ---> Direct local calculation');
disp(' ');
%
if isfield(soutput_init,'err')
%
% failed test
%
disp('The remote job failed : ');
disperr_jd(soutput_init.err)
%
elseif isfield(soutput_init,'strout')
%
% result - should read 'The best code is : luke - running under matlab version : ', followed by the requested remote matlab version
%
disp(soutput_init.strout)
%
else
%
% failed test
%
disp('The direct local calculation failed for unknown reasons');
%
end
end
%
resstr = cell(1,nrem);
profilestr1 = cell(1,nrem);
profilestr2 = cell(1,nrem);
profilestr3 = cell(1,nrem);
nstr1 = 0;
nstr2 = 0;
nstr3 = 0;
%
for irem = 1:nrem
%
disp(' ');
disp('-------------------------------------------------------------------')
disp(' ');
disp([' ---> Profile [',profilestr{irem},']']);
disp(' ');
%
soutputs{irem}.profilestr = profilestr{irem};
%
isep1 = strfind(profilestr{irem},' :');
isep2 = strfind(profilestr{irem},')');
profilestr1{irem} = profilestr{irem}(1:isep1-1);
profilestr2{irem} = profilestr{irem}(isep1+3:isep2);
profilestr3{irem} = profilestr{irem}(isep2+2:end);
nstr1 = max([nstr1,length(profilestr1{irem})]);
nstr2 = max([nstr2,length(profilestr2{irem})]);
nstr3 = max([nstr3,length(profilestr3{irem})]);
%
if isfield(soutputs{irem},'err')
%
% failed test
%
disp('The remote job failed : ');
disperr_jd(soutputs{irem}.err);
%
resstr{irem} = 'X';
%
elseif isfield(soutputs{irem},'job')
%
% job started and returned for later check
%
if ~isempty(soutputs{irem}.job.id)
%
disp(['The remote job is running under id ',soutputs{irem}.job.id]);
%
else
%
disp(['The remote job is running under time id ',soutputs{irem}.job.timeid]);
%
end
%
resstr{irem} = 'R';
%
elseif isfield(soutputs{irem},'strout')
%
% result - should read 'The best code is : luke - running under matlab version : ', followed by the requested remote matlab version
%
disp(soutputs{irem}.strout)
%
if any(strfind(soutputs{irem}.strout,'luke')) % test OK
resstr{irem} = 'O';
else
resstr{irem} = 'X';
end
else
%
% failed test
%
disp('The remote job failed for unknown reasons');
%
resstr{irem} = 'X';
%
end
end
%
disp(' ');
disp('-------------------------------------------------------------------')
disp(' SUMMARY');
disp('-------------------------------------------------------------------')
disp(' ');
%
for irem = 1:nrem
%
disp([resstr{irem},' ',profilestr1{irem},repmat(' ',[1,4+nstr1-length(profilestr1{irem})]),profilestr2{irem},repmat(' ',[1,4+nstr2-length(profilestr2{irem})]),profilestr3{irem}])
%
end
%
if ~isempty(diaryname)
diary off
end
%
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.