annotate userProgramsASRforDummies/worker.m @ 38:c2204b18f4a2 tip

End nov big change
author Ray Meddis <rmeddis@essex.ac.uk>
date Mon, 28 Nov 2011 13:34:28 +0000
parents
children
rev   line source
rmeddis@38 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rmeddis@38 2 % This program is free software; you can redistribute it and/or modify
rmeddis@38 3 % it under the terms of the GNU General Public License as published by
rmeddis@38 4 % the Free Software Foundation; either version 2 of the License, or
rmeddis@38 5 % (at your option) any later version.
rmeddis@38 6 %
rmeddis@38 7 % This program is distributed in the hope that it will be useful,
rmeddis@38 8 % but WITHOUT ANY WARRANTY; without even the implied warranty of
rmeddis@38 9 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
rmeddis@38 10 % GNU General Public License for more details.
rmeddis@38 11 %
rmeddis@38 12 % You can obtain a copy of the GNU General Public License from
rmeddis@38 13 % http://www.gnu.org/copyleft/gpl.html or by writing to
rmeddis@38 14 % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
rmeddis@38 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rmeddis@38 16
rmeddis@38 17 % This is a function the makes sure all of the jobs get completed in an
rmeddis@38 18 % orderly fashion. It is responsible for keeping unruly nodes in line.
rmeddis@38 19 % NC 2010/1011
rmeddis@38 20
rmeddis@38 21 function worker(workFolder)
rmeddis@38 22
rmeddis@38 23 %unit testing
rmeddis@38 24 % close all; clear all; clc
rmeddis@38 25 % workFolder = 'D:\exps\_bar';
rmeddis@38 26
rmeddis@38 27
rmeddis@38 28 %main script
rmeddis@38 29 isloaded = 0;
rmeddis@38 30 while ~isloaded
rmeddis@38 31 if numel(dir(fullfile(workFolder,'jobLock.txt'))) %Check to see if lock already in place
rmeddis@38 32 pTime = randi(30);
rmeddis@38 33 disp(['Worker function locked out -> waiting for ' num2str(pTime) ' seconds until next retry']);
rmeddis@38 34 pause(pTime);
rmeddis@38 35 else
rmeddis@38 36 load(fullfile(workFolder,'jobObject.mat'))
rmeddis@38 37 isloaded = 1;
rmeddis@38 38 end
rmeddis@38 39 end
rmeddis@38 40
rmeddis@38 41
rmeddis@38 42
rmeddis@38 43 x=obj;
rmeddis@38 44 clear obj;
rmeddis@38 45 x.initMAP; %Need to alert it to the path
rmeddis@38 46
rmeddis@38 47 personalWork = 0;
rmeddis@38 48 while(any(x.todoStatus==0))
rmeddis@38 49 x.lockJobList;
rmeddis@38 50 x = x.loadSelf; %Reload incase changed
rmeddis@38 51 rJobs = 8+randi(8);%Grab 1st 9-16 open jobs
rmeddis@38 52 todoNow = find(~x.todoStatus,rJobs,'first');
rmeddis@38 53 x.todoStatus(todoNow) = 1; %Flag it (them) as pending
rmeddis@38 54 x.storeSelf; %store pending flag as quickly as possible to minimise race condition impact
rmeddis@38 55 x.unlockJobList;
rmeddis@38 56 disp(['Grabbed ' num2str(numel(todoNow)) ' sound files for current job.'])
rmeddis@38 57
rmeddis@38 58 % --- DO WORK ---
rmeddis@38 59 for tt=1:numel(todoNow)
rmeddis@38 60 if ~numel(dir(fullfile(x.opFolder,strrep(x.wavList(todoNow(tt)).name, '.wav','.map'))));
rmeddis@38 61 x.genFeat(x.wavList(todoNow(tt)).name);
rmeddis@38 62 else
rmeddis@38 63 disp(['File ' x.wavList(todoNow(tt)).name ' already processed'])
rmeddis@38 64 end
rmeddis@38 65
rmeddis@38 66 end
rmeddis@38 67 % --- END OF WORK ---
rmeddis@38 68
rmeddis@38 69
rmeddis@38 70 x.lockJobList;
rmeddis@38 71 x = x.loadSelf; %Reload incase changed while processing (probably has)
rmeddis@38 72 x.todoStatus(todoNow) = 2; %Flag as complete
rmeddis@38 73 x.storeSelf; %Update as done immediately
rmeddis@38 74 x.unlockJobList;
rmeddis@38 75
rmeddis@38 76 clc
rmeddis@38 77 personalWork = personalWork+1;
rmeddis@38 78 disp( ['This process has completed ' num2str(personalWork) ' lists'] )
rmeddis@38 79 x.checkStatus
rmeddis@38 80 end
rmeddis@38 81
rmeddis@38 82 disp('-*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*-')
rmeddis@38 83 disp( ' > COMPLETED CURRENT JOB' )
rmeddis@38 84 disp( [' In the folder ' workFolder ' .....'] )
rmeddis@38 85 disp( [' This process completed ' num2str(personalWork) ' lists'] )
rmeddis@38 86 disp('-*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*-')
rmeddis@38 87
rmeddis@38 88