Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
"matlabFunction" with Parallel Computing

Subject: "matlabFunction" with Parallel Computing

From: Pooya89

Date: 30 Oct, 2012 19:39:08

Message: 1 of 3

Hi everybody,

I was wondering that if I can speed up matlabFunction command using parallel computing toolbox. I'm trying to write some symbolic matrices as functions to use in a simulation afterwards.
Without using parallel computing it takes about 8 hours of computation, to write the functions.
As far as I know matlabFunction does not support parallel computing yet. So the first thing came to my mind was to write each element of the matrix in a separate file by matlabFunction command in a parfor loop.
It's good, just a minor problem; it seems to me that the parfor loop does the hardest computation in the last iterations ! If the most complex symbolic expression is in the first element, parfor goes for it as the last one. Likewise if the last element of the matrix is the most complex one it will be served in the last iteration.

Is there a way that I can set priority to my tasks in a job or to my iterations in a parfor loop ?

If yes, do you know a way to estimate the computation cost of matlabFuntion for an expression ? I think using children command after expanding the expression would give a good idea of the complexity of the expression and therefore the computation cost of matlabFuntion. And then I can prioritize the elements.

I appreciate any help and suggestions !
Thank you !

Subject: "matlabFunction" with Parallel Computing

From: Pooya89

Date: 1 Nov, 2012 13:48:08

Message: 2 of 3

Well here's what I found myself:

First "The MATLAB job scheduler (MJS) runs jobs in the order in which they are submitted, unless any jobs in its queue are promoted, demoted, canceled, or deleted."
(According to: )

Second as I mentioned in my question it's a good approximation to count the number of expression terms, as a measure of its complexity. However NOT with this code :

length( children( expand( M1(k) ) ) ) % number of terms of M1(k) (too slow)

It's better to use "coeffs" command, which is far faster than the above code for large expressions:

length( coeffs( M1(k) ) ) % number of terms of M1(k)

So here's my procedure:
1. Estimating the complexity of each element of all my matrices,
2. Sorting them,
3. (To reduce the number of output mfiles, group them if necessary)
4. Assigning tasks (The task is to write them in a file using "matlabFunction")

Hope this helps someone having the same problem.

Subject: "matlabFunction" with Parallel Computing

From: Martin

Date: 29 Jul, 2014 16:26:11

Message: 3 of 3

Thanks, that helped me a lot. I could easily divide my symbolic equation (29000000 coefficients) in different parts. I am creating several matlabFunctions in different Matlab windows because somehow parallel computing (the parfor loop) doesn't work for anything. Now I have 100% CPU usage on my i7 and 2/3 of memory usage(8GB). I hope that I can eventually combine about 120 Matlabfunctions to one big Matlabfunction. Since the complexity is linear in relation to input size, the division only safes about 2/5 of computing time due to full processor usage. Nevertheless, the big advantage is that I can now run this problem on several PCs or a Cluster. On my computer alone it would take about 13 days to solve the problem. Be smart in division and use matrix characteristics!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us