How can I run a function in parallel and return the compiled output of the function?

2 ビュー (過去 30 日間)
Anthony
Anthony 2016 年 6 月 16 日
編集済み: Anthony 2016 年 7 月 1 日
I have a long cell array (thousands) of full file paths, and a function that has been written to pull data from each file path. Normally, I would just send the cell array of file paths to this function, and it would return the data. Because the size of my cell array is so large, this can take a long time, sometimes a couple hours or more. I was wondering if there is any way to have MATLAB call this function in parallel with the file paths sent in groups, and return the results in the same way as without the parallel function processing?
I'll try to give an example to better explain what I want to do.
Current method:
filepaths = {'filepath1','filepath2','filepath3',.....}
results = datapullfunction(filepaths)
Desired method:
filepaths = {'filepath1','filepath2','filepath3',.....}
--send 1/12th of filepaths to datapullfunction 12 times in parallel (I have a 12 core processor) and have it return the same results as the current method--
_____________
Currently I'm trying to use batch:
c = parcluster();
j = batch(c,'datapullfunction',1,filepaths);
results = fetchOutputs(j)
but results returns an error saying my input to datapullfunction "is not a recognized option." I know that it is a recognized option because if I send datapullfunction(filepaths) it works just fine.
Thanks!

採用された回答

sam0037
sam0037 2016 年 6 月 24 日
Hi,
One way to achieve this would be to create a set of jobs and submit to your parallel cluster for execution. Refer to the link below to know more about running independent jobs on a cluster:
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 7 月 1 日
{inputargs} A row cell array specifying the input arguments to be passed to the function F. Each element in the cell array will be passed as a separate input argument. If this is a cell array of cell arrays, a task is created for each cell array.
Anthony
Anthony 2016 年 7 月 1 日
編集済み: Anthony 2016 年 7 月 1 日
Success! Thank you both! Using this parallel method sped up my code over 4 times the original speed, using a 6 physical core processor.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 6 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by