54 lines
1.6 KiB
Matlab
54 lines
1.6 KiB
Matlab
function wh = submit_handle(funcHandle, wh, options)
|
|
|
|
arguments
|
|
funcHandle
|
|
wh
|
|
options.parallel = 1;
|
|
options.waitbar = true;
|
|
end
|
|
|
|
fprintf('Requested %d loops\n', wh.getLastLinIndice);
|
|
|
|
jobs = repmat(struct('args', {{}}, 'label', "", 'meta', struct()), 1, wh.getLastLinIndice);
|
|
|
|
for lin_idx = 1:wh.getLastLinIndice
|
|
optionalVars = buildOptionalVars(lin_idx, wh);
|
|
jobs(lin_idx).args = {optionalVars};
|
|
jobs(lin_idx).label = sprintf('Job %d', lin_idx);
|
|
jobs(lin_idx).meta.lin_idx = lin_idx;
|
|
end
|
|
|
|
mode = processingMode.serial;
|
|
if options.parallel
|
|
mode = processingMode.parallel;
|
|
end
|
|
|
|
runBatch(funcHandle, jobs, ...
|
|
"mode", mode, ...
|
|
"waitbar", options.waitbar, ...
|
|
"waitbarMessage", "Processing Simulations...", ...
|
|
"resultHandler", @storeResult, ...
|
|
"errorHandler", @handleError);
|
|
|
|
function optionalVars = buildOptionalVars(lin_idx, dataStorage)
|
|
optionalVars = struct();
|
|
if ~isempty(dataStorage.getDimension)
|
|
[parametervalues, parameternames] = dataStorage.getPhysIndicesByLinIndex(lin_idx);
|
|
for pidx = 1:numel(parameternames)
|
|
optionalVars.(parameternames{pidx}) = parametervalues{pidx};
|
|
end
|
|
end
|
|
end
|
|
|
|
function storeResult(result, job, ~)
|
|
wh.addValueToStorageByLinIdx(result, 'ber', job.meta.lin_idx);
|
|
end
|
|
|
|
function handleError(ME, job, ~)
|
|
fprintf('[%s] ERROR [%s]: %s\n', job.label, ME.identifier, ME.message);
|
|
for st = ME.stack'
|
|
fprintf(' %s:%d (%s)\n', st.file, st.line, st.name);
|
|
end
|
|
end
|
|
end
|