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