openEMS/matlab/Add2Queue.m

46 lines
1.3 KiB
Matlab
Raw Normal View History

function [queue] = Add2Queue(queue,func_name, func_args, varargin)
% function [queue] = Add2Queue(queue,func_name, func_args, varargin)
%
% Use this function to add a funtion to the queue.
%
% For more details see: InitQueue
%
% See also: InitQueue, FinishQueue, ResultsQueue, RunOpenEMS
%
% openEMS matlab interface
% -----------------------
% author: Thorsten Liebig
if isfield(queue,'jobs')
jobnum = numel(queue.jobs)+1;
else
jobnum = 1;
end
2011-11-28 13:09:14 +00:00
running = numel(queue.jobs_finished) - sum(queue.jobs_finished);
while (running>=queue.maxThreads)
[queue running] = CheckQueue(queue);
end
if (queue.verbose>=1)
disp(['Add2Queue: Job #' num2str(jobnum) ' starting...']);
end
queue.jobs_finished(jobnum) = 0;
queue.jobs{jobnum}.argsfile = [tempname '.mat'];
save(queue.jobs{jobnum}.argsfile,'func_args');
queue.jobs{jobnum}.nargout = nargout(func_name);
queue.jobs{jobnum}.outargsfile = [tempname '.mat'];
queue.jobs{jobnum}.command = [queue.bin queue.bin_options ' "load(''' queue.jobs{jobnum}.argsfile ''');' ...
queue.DependPath ...
'[outargs{1:' num2str(queue.jobs{jobnum}.nargout) '}]=' func_name '(func_args{:});' ...
'save(''-V7'',''' queue.jobs{jobnum}.outargsfile ''',''outargs'');' ...
'exit;"'];
[queue.jobs{jobnum}.pid, queue.jobs{jobnum}.filenames] = queue_addProcess( queue.jobs{jobnum}.command );