matlabpool open n; doesn't work.

Hi,
I'd like to open matlabpool with a variable number of cores, to use the maximum number of cores available. So n would equal features('numCores') here.
But matlabpool open n, matlabpool open features('numCores'), matlabpool open maxNumCompThreads don't work here. matlabpool open seems to accept only numbers and not variables.
I could do something stupid like
if features('numCores') == 4
matlabpool open 4;
elseif features('numCores') == 2
matlabpool open 2;
end
but I'd like to know if something more elegant exists.
Thanks!

 採用された回答

Niklas Nylén
Niklas Nylén 2014 年 5 月 7 日
編集済み: Niklas Nylén 2014 年 5 月 7 日

1 投票

This is because writing arguments like this:
matlabpool open 2
is the same as passing the strings 'open' and '2' to the matlabpool function, i.e. the equivalent to
matlabpool('open','2')
What you can do is to call matlabpool like this:
matlabpool('open', num2str(features('numCores')))
Possibly you can also pass the number of cores directly, but since I do not have parallell computing toolbox I can't test it, like so:
matlabpool('open', features('numCores'))

その他の回答 (2 件)

Matt J
Matt J 2014 年 5 月 7 日
編集済み: Matt J 2014 年 5 月 7 日

2 投票

If you have R2013b or later, you shouldn't be using matlabpool . You should be using parpool , which does take a variable as input directly,
parpool(n)

3 件のコメント

Martin
Martin 2014 年 5 月 7 日
Ok, thank you for your answers. I use Matlab 2012, does parpool work too?
Haseeb Hassan
Haseeb Hassan 2018 年 10 月 7 日
Thank you Matt for your useful hint.
Bruno Silva
Bruno Silva 2020 年 1 月 17 日
Thanks!

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

Malshikho
Malshikho 2018 年 5 月 25 日

0 投票

Unfortunately I have Matlab R2010b

1 件のコメント

Steven Lord
Steven Lord 2018 年 5 月 25 日
Then use matlabpool using the syntax described in the accepted answer by Niklas Nylén.

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

カテゴリ

ヘルプ センター および File ExchangeParallel Computing Fundamentals についてさらに検索

質問済み:

2014 年 5 月 7 日

コメント済み:

2020 年 1 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by