[3175] | 1 | function flag=waitonlock(md,executionpath,login,port)
|
---|
[1] | 2 | %WAITONLOCK - wait for a file
|
---|
| 3 | %
|
---|
| 4 | % This routine will return when a file named 'filename' is written to disk.
|
---|
[2226] | 5 | % If the time limit given in input is exceeded, return 0
|
---|
[1] | 6 | %
|
---|
| 7 | % Usage:
|
---|
[2555] | 8 | % flag=waitonlock(md,executionpath)
|
---|
[1] | 9 |
|
---|
[2555] | 10 | %Get filename (lock file) and options
|
---|
[5954] | 11 | executionpath=md.cluster.executionpath;
|
---|
| 12 | cluster=md.cluster.name;
|
---|
| 13 | login=md.cluster.login;
|
---|
| 14 | port=md.cluster.port;
|
---|
| 15 | timelimit=md.waitonlock;
|
---|
[5546] | 16 | filename=[executionpath '/' md.runtimename '/' md.name '.lock'];
|
---|
[2226] | 17 |
|
---|
[2555] | 18 | %waitonlock will work if the lock is on the same machine only:
|
---|
| 19 | if ~strcmpi(oshostname(),cluster),
|
---|
[3175] | 20 |
|
---|
[6378] | 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;
|
---|
[2555] | 26 | else
|
---|
[6378] | 27 | flag=1;
|
---|
[2555] | 28 | end
|
---|
[2226] | 29 |
|
---|
[2555] | 30 | %job is running on the same machine
|
---|
[2226] | 31 | else
|
---|
[2555] | 32 |
|
---|
| 33 | %initialize time and file presence test flag
|
---|
| 34 | time=0; ispresent=0;
|
---|
| 35 | disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
|
---|
| 36 |
|
---|
| 37 | %loop till file .lock exist or time is up
|
---|
| 38 | while (ispresent==0 & time<timelimit)
|
---|
| 39 | ispresent=exist(filename,'file');
|
---|
| 40 | pause(1);
|
---|
| 41 | time=time+1/60;
|
---|
| 42 | end
|
---|
| 43 |
|
---|
| 44 | %build output
|
---|
| 45 | if (time>timelimit),
|
---|
[2656] | 46 | disp('Time limit exceeded. Increase md.waitonlock');
|
---|
| 47 | disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
|
---|
| 48 | error(['waitonlock error message: time limit exceeded']);
|
---|
[2555] | 49 | flag=0;
|
---|
| 50 | else
|
---|
| 51 | flag=1;
|
---|
| 52 | end
|
---|
[2226] | 53 | end
|
---|