source: issm/trunk/src/m/model/waitonlock.m@ 5954

Last change on this file since 5954 was 5954, checked in by Eric.Larour, 14 years ago

New framework for launching a job on different clusters, based on the use of classes for each cluster.

File size: 2.4 KB
Line 
1function 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
11executionpath=md.cluster.executionpath;
12cluster=md.cluster.name;
13login=md.cluster.login;
14port=md.cluster.port;
15timelimit=md.waitonlock;
16filename=[executionpath '/' md.runtimename '/' md.name '.lock'];
17
18%waitonlock will work if the lock is on the same machine only:
19if ~strcmpi(oshostname(),cluster),
20
21 if port,
22 %there is a tunnel, so we have a short at looking for the lock file.
23
24 disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
25 time=0; ispresent=0;
26 while (ispresent==0 & time<timelimit)
27 [status, result]=system(['ssh -q -p ' num2str(port) ' ' login '@localhost "if ( -e ' executionpath '/' md.runtimename '/' md.name '.lock ) echo 1"']);
28 if ~isempty(result),
29 if ismember('1',result),
30 ispresent=1;
31 else
32 ispresent=0;
33 end
34 else
35 ispresent=0;
36 end
37 pause(10); %tunnel can be unstable, let's not use it too much
38 time=time+1/60;
39 end
40 disp(['waitonlock: lock detected, with value of result:|' result '|']);
41
42 %build output
43 if (time>timelimit),
44 disp('Time limit exceeded. Increase md.waitonlock');
45 disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
46 error(['waitonlock error message: time limit exceeded']);
47 flag=0;
48 else
49 flag=1;
50 end
51 else
52 disp('solution launched on remote cluster. log in to detect job completion.');
53 choice=input('Is the job successfully completed? (y/n)','s');
54 if ~strcmp(choice,'y'),
55 disp('Results not loaded... exiting');
56 flag=0;
57 else
58 flag=1;
59 end
60 end
61
62%job is running on the same machine
63else
64
65 %initialize time and file presence test flag
66 time=0; ispresent=0;
67 disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
68
69 %loop till file .lock exist or time is up
70 while (ispresent==0 & time<timelimit)
71 ispresent=exist(filename,'file');
72 pause(1);
73 time=time+1/60;
74 end
75
76 %build output
77 if (time>timelimit),
78 disp('Time limit exceeded. Increase md.waitonlock');
79 disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
80 error(['waitonlock error message: time limit exceeded']);
81 flag=0;
82 else
83 flag=1;
84 end
85end
Note: See TracBrowser for help on using the repository browser.