Multi-Threading

hello. I would like to implement multi-threading in matlab. There is any easy way to do so? For example, I have 4 processors and want to run an independent MCMC on each of them. I just need how can I tell matlab torun the 4 chains in parallel, one on each processor. Usually, I achieve this using the task manager: I open 4 matlab, and assing to each 1 processor, however i was wondering if there is a way to write a batch file that automatically tells matlab to do so. Thanks Andrea

Respuestas (1)

Jason Ross
Jason Ross el 11 de Mayo de 2012

1 voto

Have you looked at the Parallel Computing Toolbox?
There is a command in the toolbox called "batch" that can farm the work out.
There are also other constructs (parfor, job/task, spmd) that you can employ, as well.
NOTE: The syntax we are both using is a bit inexact. I believe what you are calling "multi-threading" is more "parallel processing" or "distributed processing". Threading is a different animal, to some extent -- and is already implemented for some things in MATLAB.

4 comentarios

Andrea
Andrea el 11 de Mayo de 2012
Movida: Steven Lord el 21 de Dic. de 2022
Thank you Jason. Yes I am not really aware of the difference. But maybe this is exactly to the point. Maybe after all is multi-threading what I want. I am migrating from Gauss, and there the multi-threading is defined as follows. Say I want to draw 1000 draws using an MCMC algorithm . Then I tell the program to create 4 threads, each of them giving an output of 250 draws. When the algorithm gets there, each processor computes 250 draws, then stops waiting for the other threads to end. When all threads are finished, the algorithm moves on. I have tried in the past to look at the parallel toolbox, but it looks a bit too complicated for me for the moment. Can you point me towards a mickey mouse example that I can just download and run on my pc? Thanks PS. Given the speed of your response i assumed you work for mathworks, so this is why I am asking all these things. If i am wrong, no worries, and thank you for being so knd best A
Jason Ross
Jason Ross el 11 de Mayo de 2012
Movida: Steven Lord el 21 de Dic. de 2022
I do indeed work for MathWorks, as a QE in Development. To use PCT, you need to have the software installed, and that means you would need a trial license, which is something I don't have any control over.
To answer your immediate question, though, using PCT you would tell MATLAB you wanted a local cluster with 4 workers, and then you could use parfor to run them in parallel. MATLAB would handle the actual scheduling of the workers for you, you don't need to say what goes where.
I am not familiar with the MCMC algorithm, but from what you say it sounds like each "draw" seems to be independent. If that's correct, it can likely be handled by parfor. A simple example is here:
http://www.mathworks.com/help/toolbox/distcomp/exampleindex.html
There are also a number of webinars and demos here:
http://www.mathworks.com/products/parallel-computing/demos.html
And as for the speed of my response, that was coincidence. Anyone who answers on here is essentially volunteering their time. I had a few moments between tasks and checked the board, and it coincided with your post.
Kurt
Kurt el 21 de Dic. de 2022
Movida: Steven Lord el 21 de Dic. de 2022
The example link just leads to "Call Matlab from C", which is really no help.
Steven Lord
Steven Lord el 21 de Dic. de 2022
I'm not sure which link you followed that led you to "Call MATLAB from C", as none of the ones in Jason's posts did.
But there is another approach that was introduced in release R2021b (I believe) that may be of interest to others with the same type of question as the original poster: running MATLAB functions in a thread-based environment.

Iniciar sesión para comentar.

Categorías

Más información sobre Parallel Computing Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 11 de Mayo de 2012

Comentada:

el 21 de Dic. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by