1 | function flag=waitonlock(md,executionpath,login,port)
|
---|
2 | %WAITONLOCK - wait for a file
|
---|
3 | %
|
---|
4 | % This routine will return when a file named 'filename' is written to disk.
|
---|
5 | % If the time limit given in input is exceeded, return 0
|
---|
6 | %
|
---|
7 | % Usage:
|
---|
8 | % flag=waitonlock(md,executionpath)
|
---|
9 |
|
---|
10 | %Get filename (lock file) and options
|
---|
11 | executionpath=md.cluster.executionpath;
|
---|
12 | cluster=md.cluster.name;
|
---|
13 | login=md.cluster.login;
|
---|
14 | port=md.cluster.port;
|
---|
15 | timelimit=md.waitonlock;
|
---|
16 | filename=[executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock'];
|
---|
17 |
|
---|
18 | %waitonlock will work if the lock is on the same machine only:
|
---|
19 | if ~strcmpi(oshostname(),cluster),
|
---|
20 |
|
---|
21 | disp('solution launched on remote cluster. log in to detect job completion.');
|
---|
22 | choice=input('Is the job successfully completed? (y/n)','s');
|
---|
23 | if ~strcmp(choice,'y'),
|
---|
24 | disp('Results not loaded... exiting');
|
---|
25 | flag=0;
|
---|
26 | else
|
---|
27 | flag=1;
|
---|
28 | end
|
---|
29 |
|
---|
30 | %job is running on the same machine
|
---|
31 | else
|
---|
32 |
|
---|
33 | if ismember('interactive',properties(md.cluster)) & md.cluster.interactive
|
---|
34 | %We are in interactive mode, no need to check for job completion
|
---|
35 | flag=1;
|
---|
36 | return;
|
---|
37 | end
|
---|
38 | %initialize time and file presence test flag
|
---|
39 | time=0; ispresent=0;
|
---|
40 | disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
|
---|
41 |
|
---|
42 | %loop till file .lock exist or time is up
|
---|
43 | while (ispresent==0 & time<timelimit)
|
---|
44 | ispresent=exist(filename,'file');
|
---|
45 | pause(1);
|
---|
46 | time=time+1/60;
|
---|
47 | end
|
---|
48 |
|
---|
49 | %build output
|
---|
50 | if (time>timelimit),
|
---|
51 | disp('Time limit exceeded. Increase md.waitonlock');
|
---|
52 | disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
|
---|
53 | error(['waitonlock error message: time limit exceeded']);
|
---|
54 | flag=0;
|
---|
55 | else
|
---|
56 | flag=1;
|
---|
57 | end
|
---|
58 | end
|
---|