Index: ../trunk-jpl/src/m/solve/solve.m =================================================================== --- ../trunk-jpl/src/m/solve/solve.m (revision 14351) +++ ../trunk-jpl/src/m/solve/solve.m (revision 14352) @@ -100,15 +100,22 @@ end %wait on lock -if md.settings.waitonlock>0, - %we wait for the done file - islock=waitonlock(md); - if islock==0, %no results to be loaded - disp('The results must be loaded manually with md=loadresultsfromcluster(md).'); - else %load results - disp('loading results from cluster'); +if isnan(md.settings.waitonlock), + %load when user enters 'y' + disp('solution launched on remote cluster. log in to detect job completion.'); + choice=input('Is the job successfully completed? (y/n)','s'); + if ~strcmp(choice,'y'), + disp('Results not loaded... exiting'); + else md=loadresultsfromcluster(md); end +elseif md.settings.waitonlock>0, + %we wait for the done file + done=waitonlock(md); + disp('loading results from cluster'); + md=loadresultsfromcluster(md); +elseif md.settings.waitonlock==0, + disp('Model results must be loaded manually with md=loadresultsfromcluster(md);'); end %post processes qmu results if necessary Index: ../trunk-jpl/src/m/solve/waitonlock.m =================================================================== --- ../trunk-jpl/src/m/solve/waitonlock.m (revision 14351) +++ ../trunk-jpl/src/m/solve/waitonlock.m (revision 14352) @@ -1,4 +1,4 @@ -function flag=waitonlock(md) +function ispresent=waitonlock(md) %WAITONLOCK - wait for a file % % This routine will return when a file named 'filename' is written to disk. @@ -7,54 +7,56 @@ % Usage: % flag=waitonlock(md) +%Return if waitonlock < 0 (no need to wait) + %Get filename (lock file) and options -executionpath=md.cluster.executionpath; -cluster=md.cluster.name; -login=md.cluster.login; -if isprop(md.cluster,'port') - port=md.cluster.port; +executionpath = md.cluster.executionpath; +timelimit = md.settings.waitonlock; +filename = [executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock']; +cluster = md.cluster; + +%If we are using the generic cluster in interactive mode, job is already complete +if isa(cluster,'generic') & cluster.interactive + %We are in interactive mode, no need to check for job completion + ispresent=1; + return; end -timelimit=md.settings.waitonlock; -filename=[executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock']; -%waitonlock will work if the lock is on the same machine only: +%initialize time and file presence test flag +time=0; ispresent=0; +disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)']) + +%prepare command if the job is not running on the local machine if ~strcmpi(oshostname(),cluster), - - disp('solution launched on remote cluster. log in to detect job completion.'); - choice=input('Is the job successfully completed? (y/n)','s'); - if ~strcmp(choice,'y'), - disp('Results not loaded... exiting'); - flag=0; + login = cluster.login; + port = 0; + if isprop(cluster,'port') + port = cluster.port; + end + if port, + command = ['ssh -l ' login ' -p ' num2str(port) ' localhost " [ -f ' filename ' ]" 2>/dev/null']; else - flag=1; + command = ['ssh -l ' login ' ' cluster.name ' " [ -f ' filename ' ]" 2>/dev/null']; end +end -%job is running on the same machine -else - - if ismember('interactive',properties(md.cluster)) & md.cluster.interactive - %We are in interactive mode, no need to check for job completion - flag=1; - return; - end - %initialize time and file presence test flag - time=0; ispresent=0; - disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)']) - - %loop till file .lock exist or time is up - while (ispresent==0 & timetimelimit), - disp('Time limit exceeded. Increase md.settings.waitonlock'); - disp('The results must be loaded manually with md=loadresultsfromcluster(md).'); - error(['waitonlock error message: time limit exceeded']); - flag=0; else - flag=1; + pause(10); + fprintf('\rchecking for job completion (time = %3.2f min) ',time); + ispresent=~system(command); if ispresent, fprintf('\n'); end + time=time+10/60; end end + +%build output +if (time>timelimit), + disp('Time limit exceeded. Increase md.settings.waitonlock'); + disp('The results must be loaded manually with md=loadresultsfromcluster(md).'); + error(['waitonlock error message: time limit exceeded']); +end