How workers share cores and use threads?

45 views (last 30 days)
Camilo
Camilo on 13 May 2011
Hi, I am using the PCT to run a parfor loop in a "aggregated" memory/cpus machine with 92 cores. I would like to know how the workers in a distributed job, such us parfor, would share these cores. I know that the short answers is "the cpu will be smart and share then in some way," but I would like to know more details. Specially, I am trying to understand how a workers process is set up when it is launched from the Matlab client, and how many threads each workers is set up to use by ''default". Also, I would like to know if it is possible to modify the way workers are launched so that I could define how many threads each worker should use and possibly the set the threads-to-cores affinity.

Answers (3)

Titus Edelhofer
Titus Edelhofer on 13 May 2011
Hi,
per default each worker is started in single thread mode: this is motivated by a rule of thumb, namely, "start one worker per core". Let's say you have a machine with four quad-cores, then starting 16 single threaded workers probably be the best option. Next best I guess would be 8 workers with 2 threads each. Until now you could possibly use maxNumCompThreads on each worker to achieve this, but it is discouraged, because in larger installations multithreaded applications (using more cores then "allowed" by cluster controller) are prohibited anyway.
To make the long answer short: use as many workers as cores (as long as not restricted by number of worker licenses). The distribution of "which worker uses which core" is totally up to the operating system and out of MATLABs control.
Hope this helps,
Titus

Camilo
Camilo on 13 May 2011
Hi Titus, Thanks so much for the prompt response. I see now that by default each worker process is started in single thread mode, and that one can use the maxNumCompThreads to modify the thread limit. My question now is: When do you change the maxNumCompThreads variable? Is it the case that if this variable is change in the client process, then each worker would inherit this maxNumCompThreads variable limit as if it were a "global" variable? I see that in some cases it would be desirable to set 1 thread per worker, as in a parfor loop where the computation in the loop is not so massive. However, if the computation in the loop is a large matrix manipulation that benefits greatly from multithreading (such as matrix product), it would be better to have less workers and more threads available to each worker. So, in you example with the 4 quad-core machine, how do I actually set PCT to use 4 workers, with each worker using 4 thread, and potentially how do I make sure each worker would use 4 distinct cores. Thanks again! --Camilo

Titus Edelhofer
Titus Edelhofer on 13 May 2011
Hi Camilo,
maxNumCompThreads is a function. If you want to give it a try: when you have you matlabpool open, do
pctRunOnAll maxNumCompThreads(4)
to tell all workers (and your Client by the way) to use 4 threads. But keep in mind, this will go away (on purpose). I would be interested to see a result from you like 16 workers singlethreaded = TimeX, 4 workers 4-threaded (what an english) = TimeY.
Titus

Categories

Find more on MATLAB Parallel Server in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!