source: issm/oecreview/Archive/14312-15392/ISSM-14351-14352.diff@ 15393

Last change on this file since 15393 was 15393, checked in by Mathieu Morlighem, 12 years ago

NEW: adding Archive/14312-15392 for oecreview

File size: 4.6 KB
RevLine 
[15393]1Index: ../trunk-jpl/src/m/solve/solve.m
2===================================================================
3--- ../trunk-jpl/src/m/solve/solve.m (revision 14351)
4+++ ../trunk-jpl/src/m/solve/solve.m (revision 14352)
5@@ -100,15 +100,22 @@
6 end
7
8 %wait on lock
9-if md.settings.waitonlock>0,
10- %we wait for the done file
11- islock=waitonlock(md);
12- if islock==0, %no results to be loaded
13- disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
14- else %load results
15- disp('loading results from cluster');
16+if isnan(md.settings.waitonlock),
17+ %load when user enters 'y'
18+ disp('solution launched on remote cluster. log in to detect job completion.');
19+ choice=input('Is the job successfully completed? (y/n)','s');
20+ if ~strcmp(choice,'y'),
21+ disp('Results not loaded... exiting');
22+ else
23 md=loadresultsfromcluster(md);
24 end
25+elseif md.settings.waitonlock>0,
26+ %we wait for the done file
27+ done=waitonlock(md);
28+ disp('loading results from cluster');
29+ md=loadresultsfromcluster(md);
30+elseif md.settings.waitonlock==0,
31+ disp('Model results must be loaded manually with md=loadresultsfromcluster(md);');
32 end
33
34 %post processes qmu results if necessary
35Index: ../trunk-jpl/src/m/solve/waitonlock.m
36===================================================================
37--- ../trunk-jpl/src/m/solve/waitonlock.m (revision 14351)
38+++ ../trunk-jpl/src/m/solve/waitonlock.m (revision 14352)
39@@ -1,4 +1,4 @@
40-function flag=waitonlock(md)
41+function ispresent=waitonlock(md)
42 %WAITONLOCK - wait for a file
43 %
44 % This routine will return when a file named 'filename' is written to disk.
45@@ -7,54 +7,56 @@
46 % Usage:
47 % flag=waitonlock(md)
48
49+%Return if waitonlock < 0 (no need to wait)
50+
51 %Get filename (lock file) and options
52-executionpath=md.cluster.executionpath;
53-cluster=md.cluster.name;
54-login=md.cluster.login;
55-if isprop(md.cluster,'port')
56- port=md.cluster.port;
57+executionpath = md.cluster.executionpath;
58+timelimit = md.settings.waitonlock;
59+filename = [executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock'];
60+cluster = md.cluster;
61+
62+%If we are using the generic cluster in interactive mode, job is already complete
63+if isa(cluster,'generic') & cluster.interactive
64+ %We are in interactive mode, no need to check for job completion
65+ ispresent=1;
66+ return;
67 end
68-timelimit=md.settings.waitonlock;
69-filename=[executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock'];
70
71-%waitonlock will work if the lock is on the same machine only:
72+%initialize time and file presence test flag
73+time=0; ispresent=0;
74+disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
75+
76+%prepare command if the job is not running on the local machine
77 if ~strcmpi(oshostname(),cluster),
78-
79- disp('solution launched on remote cluster. log in to detect job completion.');
80- choice=input('Is the job successfully completed? (y/n)','s');
81- if ~strcmp(choice,'y'),
82- disp('Results not loaded... exiting');
83- flag=0;
84+ login = cluster.login;
85+ port = 0;
86+ if isprop(cluster,'port')
87+ port = cluster.port;
88+ end
89+ if port,
90+ command = ['ssh -l ' login ' -p ' num2str(port) ' localhost " [ -f ' filename ' ]" 2>/dev/null'];
91 else
92- flag=1;
93+ command = ['ssh -l ' login ' ' cluster.name ' " [ -f ' filename ' ]" 2>/dev/null'];
94 end
95+end
96
97-%job is running on the same machine
98-else
99-
100- if ismember('interactive',properties(md.cluster)) & md.cluster.interactive
101- %We are in interactive mode, no need to check for job completion
102- flag=1;
103- return;
104- end
105- %initialize time and file presence test flag
106- time=0; ispresent=0;
107- disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
108-
109- %loop till file .lock exist or time is up
110- while (ispresent==0 & time<timelimit)
111+%loop till file .lock exist or time is up
112+while (ispresent==0 & time<timelimit)
113+ if strcmpi(oshostname(),cluster),
114 ispresent=exist(filename,'file');
115 pause(1);
116 time=time+1/60;
117- end
118-
119- %build output
120- if (time>timelimit),
121- disp('Time limit exceeded. Increase md.settings.waitonlock');
122- disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
123- error(['waitonlock error message: time limit exceeded']);
124- flag=0;
125 else
126- flag=1;
127+ pause(10);
128+ fprintf('\rchecking for job completion (time = %3.2f min) ',time);
129+ ispresent=~system(command); if ispresent, fprintf('\n'); end
130+ time=time+10/60;
131 end
132 end
133+
134+%build output
135+if (time>timelimit),
136+ disp('Time limit exceeded. Increase md.settings.waitonlock');
137+ disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
138+ error(['waitonlock error message: time limit exceeded']);
139+end
Note: See TracBrowser for help on using the repository browser.