How to run 3 programs simultaneously?

5 次查看(过去 30 天)
I have to run three functions or programs on a quad core processor such that function1 is run on core1 of the processor and function2 on core2 and function3 on core3, all simultaneously in one matlab session. Can any one help??

采纳的回答

Thomas
Thomas 2012-3-14
I do not think there is a way to control which matlab processes run on a particular core. Matlab has a lot of inbuilt function that inherently now use multi-threading.
Though you could instantiate three MATLAB instances ( hopefully they run on different cores. haven't tried it) with the
-maxNumCompThreads
set to 1 so that each instance uses only 1 core and then run your function in each instance.
href=""<http://www.mathworks.com/help/techdoc/ref/maxnumcompthreads.html</a>>
  5 个评论
Thomas
Thomas 2012-3-14
Make sure your functions putting the output.. try
doc function
Sampath reddy
Sampath reddy 2012-3-14
in the help it says we cannot get returned values from parfor sessions, is there a way to store the variable data on pc in text or some other format and calling back in the matlab?? Or any other way to return the values to workspace???

请先登录,再进行评论。

更多回答(1 个)

Jason Ross
Jason Ross 2012-3-14
Short answer:
There is no way to control processor affinity. The tasks are handed off to the operating system, which places them as they see fit.
If you wish to control what goes on in each lab, use the spmd construct and labIndex. There is an example of how to do this under "Defining an spmd Statement" on this page:
Long answer:
There are various utilities that are very OS-specific that will let you set processor affinity for a given process. It would be somehow possible to place things if you really wanted to, but the effort would likely be in vain, as modern operating systems are quite good at doing this already, and you'd end up with code that was very tightly coupled with your specific hardware and operating system -- for what could actually be a performance loss.
  2 个评论
Sampath reddy
Sampath reddy 2012-3-14
It is not necessary that function1 is to be run on core1 or anything like that but, the three functions are to be run on three different cores simultaneously.
If u know how to do so please mention the code how to do so.
Jason Ross
Jason Ross 2012-3-14
There is an example in the documentation link I provided that shows how to do this.
To be entirely pedantic and boring, I'm making an assumption that the operating system will choose to place each lab on one core -- hopefully it will. But it's not an ironclad guarantee. The only thing that can be guaranteed is that the tasks for lab1 will go to lab1, the tasks for lab2 will go to lab2 and so on.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by