Azzera filtri
Azzera filtri

Batch command on parallel pool with single cell array input argument

3 visualizzazioni (ultimi 30 giorni)
I want to run a function on a worker in a parallel pool. I use the batch command for that. Let's say I have the function
function out = some_function(in)
for i = 1:numel(in)
out{i} = 2*in{i};
end
Now, I want to run this function on a worker. I read the documentation on the batch command and it says to do the following
job = batch(@some_function, 1, { {1, 2, 3} });
However, when I run this command, the job shows the error
"Too many input arguments"
If I instead change the example function to
function out = some_function2(in, in2)
for i = 1:numel(in)
out{i} = 2*in{i};
end
and run
job = batch(@some_function2, 1, { {1, 2, 3}, [] });
it works correctly.
Why does the first example not work and how can I make it accept the single cell array as input? I expect the problem to be with the nested cell array, but I don't understand why.

Risposta accettata

Jori Selen
Jori Selen il 11 Giu 2021
For anyone with this question in the future: I found out that the syntax for batch changes when you only have cell arrays as inputs. There is some explanation of this in the documentation of batch and of createTask. So, if all inputs arguments are cell arrays, then we should use
job = batch(@function_handle, N, {{ C1, C2, ..., Cn }})
where C1, C2, ..., Cn are all cell arrays. For my specific example above, the correct syntax is then
job = batch(@some_function, 1, {{{1, 2, 3}}})

Più risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by