use all cores of CPU - matlab

I want to use parallel computing on matlab, i have i7-960 CPU with 4 cores and 8 threads, when i run feature('numCores') command in matlab, i obtain this
feature('numCores')
MATLAB detected: 3 physical cores.
MATLAB detected: 6 logical cores.
MATLAB was assigned: 6 logical cores by the OS.
MATLAB is using: 3 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
ans =
3
why matlab detect just juste 3 physical cores ! and how can i use all logical and physical cores for parallel computing.
thanks.

To use all logical processes (number of threads) you need to change the NumWorkers in the matlab setting.
in matlab 2018 menu follow this:
Preferences >> Parallel Computing Toolbox>> Cluster Profile Manager >> click "Edit" on the bottom right >> Set "NumWorkers" to the number of logical process, 8 in your case. > Done >> close and apply

Related

How many of the available cores can I take up on a Mac without crashing the computer?

I need to run a parfor loop in Matlab and assign the number of workers to the loop.
Total Number of Cores: 10 (8 performance and 2 efficiency).
What is the maximum number of cores that I can take up, without crashing the computer and still being able to use the computer for browsing and email? Is leaving only 1 core free enough?
Below is an example in which 3 cores are selected.
n = 3 % Select the number of workers that you need and set n to that integer.
parpool(n)
parfor
i=1:n, c(:,i) = eig(rand(100));
end

MATLAB: controlling for number core / threads

Suppose that I have a program that is to be run on a linux machine with 32 cores (64 threads), of which I'm only allowed to use 10 cores (20 threads). So I would like to specify this before I run the program.
I googled and found maxNumCompThreads but it doesn't appear to work when I test it on a machine with MATLAB 2016a, core i5 (2 cores, 4 threads). That is, I get the same output for feature('numCores') when I do any of the following
maxNumCompThreads(1)
maxNumCompThreads(2)
maxNumCompThreads(4)
maxNumCompThreads('Automatic')
Then I tried parpool (each time I closed the current parpool session with delete(gcp('nocreate'))). I got an error when running parpool(4) (I think I understand why: parpool takes in the number of cores and hyper-threading is enabled automatically and the testing machine has just 2 physical cores). So I tested with parpool(1) and parpool(2). Again, the output for feature('numCores') did not change.
Question: so what is a right tool for the job for the situation described in the first paragraph above? And is feature('numCores') the right monitoring tool to see if the appropriate specification is in effect?
The same feature('numCores') output I keep referring to above is:
MATLAB detected: 2 physical cores.
MATLAB detected: 4 logical cores.
MATLAB was assigned: 4 logical cores by the OS.
MATLAB is using: 2 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
Edit: when I run parpool(10) on the linux machine I got the following error
Starting parallel pool (parpool) using the 'local' profile ... Error using parpo ol (line 103)
Couldn't interpret output from psname.sh: ""
Error in parpool_test_2016_10_03 (line 3)
parpool(10);
No, it's not the right monitoring tool. Look at feature('numthreads') instead:
>> feature('numcores')
MATLAB detected: 4 physical cores.
MATLAB detected: 8 logical cores.
MATLAB was assigned: 8 logical cores by the OS.
MATLAB is using: 4 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
ans =
4
>> feature('numthreads')
ans =
4
>> maxNumCompThreads(1)
ans =
4
>> feature('numcores')
MATLAB detected: 4 physical cores.
MATLAB detected: 8 logical cores.
MATLAB was assigned: 8 logical cores by the OS.
MATLAB is using: 4 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
ans =
4
>> feature('numthreads')
ans =
1
In general, be careful using feature as it's undocumented and prone to change without warning. Take a look at this post and this StackOverflow question for more information about feature.

Why does TreeBagger in Matlab 2014a/b only use few workers from a parallel pool?

I'm using the TreeBagger class provided by Matlab (R2014a&b), in conjunction with the distributed computing toolbox. I have a local cluster running, with 30 workers, on a Windows 7 machine with 40 cores.
I call the TreeBagger constructor to generate a regression forest (an ensemble containing 32 trees), passing an options structure with 'UseParallel' set to 'always'.
However, TreeBagger seems to only make use of 8 or so workers, out of the 30 available (judging by CPU usage per process, observed using the Task Manager). When I try to test the pool with a simple parfor loop:
parfor i=1:30
a = fft(rand(20000));
end
Then all 30 workers are engaged.
My question is:
(How) can I force TreeBagger to use all available resources?
Based on the documentation for the TreeBagger class it would appear that the operations required are quite memory intensive. Without knowing more about the internal scheduling system used by Matlab it seems likely that distributing the workload across fewer workers with more memory for each worker is what the scheduler believes will be the most efficient way to solve the problem.
The number of workers used/available may also depend on the number of physical cores on the system(which is different from the number of hyper threaded cores), as well as the resources Matlab is allowed to consume.
Splitting memory intensive tasks across a less than maximum number of workers is a common technique in HPC for some types of problems.

Maximum number of workers in a parallel loop (local cluster) with Matlab R2014a?

I have a Macbook Pro Intel Core I7; which is the maximum number of workers in a parallel loop (local cluster) with Matlab R2014a?
With Matlab R2014a you can have more than 12 local workers, however before creating too many workers you should see how many cores you have on your cpu. This information can be obtained as explained at https://stackoverflow.com/a/1715612/3676517.

maxNumCompThreads with R2014a

maxNumCompThreads is deprecated, but is it still working with R2014a?
I tried to force a script to use a single computational thread, but it uses 2 logical cores:
maxNumCompThreads(1); % limit MATLAB to a single computational thread.
signal = rand(1, 1000000);
for i=1:100
cwt(signal,1:10,'sym2');
i
end
Any idea why?
Setting the -singleCompThread option when starting MATLAB does work fine (the script then uses one core only).
Note that my computer has hyperthreading, so 2 logical cores is actually only 1 physical core but usually Matlab count with logical cores, not physical ones (e.g. when setting the number of cores in a parallel pool).