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

Last change on this file since 9702 was 9702, checked in by Mathieu Morlighem, 14 years ago

Added autofiff.m class and moved some other fields to settings

File size: 1.6 KB
RevLine 
[3175]1function 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]11executionpath=md.cluster.executionpath;
12cluster=md.cluster.name;
13login=md.cluster.login;
14port=md.cluster.port;
[9702]15timelimit=md.settings.waitonlock;
[9625]16filename=[executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock'];
[2226]17
[2555]18%waitonlock will work if the lock is on the same machine only:
19if ~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]31else
[2555]32
[7984]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
[2555]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),
[9702]51 disp('Time limit exceeded. Increase md.settings.waitonlock');
[2656]52 disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
53 error(['waitonlock error message: time limit exceeded']);
[2555]54 flag=0;
55 else
56 flag=1;
57 end
[2226]58end
Note: See TracBrowser for help on using the repository browser.