2011-11-16 12:37:44 +00:00
|
|
|
function [queue] = Add2Queue(queue,func_name, func_args, varargin)
|
|
|
|
% function [queue] = Add2Queue(queue,func_name, func_args, varargin)
|
|
|
|
%
|
2022-03-11 21:17:27 +00:00
|
|
|
% Use this function to add a function to the queue.
|
2011-11-16 12:37:44 +00:00
|
|
|
%
|
|
|
|
% 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;
|
2011-11-16 12:37:44 +00:00
|
|
|
|
|
|
|
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 ...
|
2011-12-19 08:54:11 +00:00
|
|
|
'err=[];' ...
|
|
|
|
'try;' ...
|
2011-11-16 12:37:44 +00:00
|
|
|
'[outargs{1:' num2str(queue.jobs{jobnum}.nargout) '}]=' func_name '(func_args{:});' ...
|
2011-12-19 08:54:11 +00:00
|
|
|
'catch err;outargs=0;end;' ...
|
|
|
|
'save(''-V7'',''' queue.jobs{jobnum}.outargsfile ''',''outargs'',''err'');' ...
|
2011-11-16 12:37:44 +00:00
|
|
|
'exit;"'];
|
|
|
|
|
|
|
|
[queue.jobs{jobnum}.pid, queue.jobs{jobnum}.filenames] = queue_addProcess( queue.jobs{jobnum}.command );
|