Info

This question is closed. Reopen it to edit or answer.

Is there a way to parallelize the function hygepdf?

1 view (last 30 days)
Ewen Chan
Ewen Chan on 17 May 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
So I have a script that uses the hygepdf function in a for loop and the result of i=i+1 does not depend on the result that is calculated when i=i.
(Hopefully that makes sense.)
Given that, is there a way that I can use the parallel computing toolbox and multiple workers so that I will be able to compute each of the hygepdf computations in the for loop in parallel and then assemble the results back together as if it had ran it in the for loop?
i.e. here is the quasi-pseudocode:
original with a for loop
for i=1:16
thiper(i)=hygepdf(D1,linspace(N,N,minValue+1),linspace(D,D,minValue+1),linspace(m,m,minValue+1);
end
and then change is to that it can run each of those 16 loops in parallel:
something like
thiper(1)=hygepdf(D1,linspace(N,N,minValue+1),linspace(D,D,minValue+1),linspace(m,m,minValue+1);
thiper(2)=hygepdf(D1,linspace(N,N,minValue+1),linspace(D,D,minValue+1),linspace(m,m,minValue+1);
thiper(3)=hygepdf(D1,linspace(N,N,minValue+1),linspace(D,D,minValue+1),linspace(m,m,minValue+1);
thiper(...)=hygepdf(D1,linspace(N,N,minValue+1),linspace(D,D,minValue+1),linspace(m,m,minValue+1);
thiper(16)=hygepdf(D1,linspace(N,N,minValue+1),linspace(D,D,minValue+1),linspace(m,m,minValue+1);
thiper=[thiper(1);thiper(2);thiper(3);thiper(...);thiper(16)];
Hopefully I am able to articulate what I am trying to do sufficiently enough that people will understand what I am going for here.
Again, the basic premise in this for loop calculation is that the result of the current index isn't needed by the next index, so I want to see if there is a way to use multiple workers to run the for loop in parallel and then just assemble the results together at the end.
Thank you.
  4 Comments
Paolo
Paolo on 17 May 2018
Edited: Paolo on 17 May 2018
You are welcome, you can use tic toc to get an indication of the performance increase. Let me know if that solves your question and I'll turn that comment into an answer.
Ewen Chan
Ewen Chan on 17 May 2018
Yeah, I'm already using tic/toc.
I see the worker nodes starting up, but then after a while, the extra parallel workers aren't doing anything more and I am not really 100% sure why.
Unfortunately, I am not authorized to release the code, otherwise I would, so I realize and understand that it means the team's ability to help me is severely limited because of this.
Having said that, here is what the structure of it looks like (at a very high level):
while
for
end
end
if
for
for
end
end
end
In the second block, I tried to nest a parfor inside a parfor and it didn't let me. (I did a find/replace all.)
I'm not much a programmer and I have a VERY limited understanding about MATLAB, but are there other commands here that I can try to use to increase the amount or level of parallelization?
If parfor is only resulting in limited returns, are there more explicit ways for me to quote "manually" make it run on the other workers?
(It would be akin to running another instance of MATLAB without actually have to run another instance of MATLAB.)
Again, hopefully I am communicating my question in a manner that makes sense to people besides myself.
If I am not communicating my question in a clear manner, please let me know.
Thanks.

Answers (1)

Bernhard Suhm
Bernhard Suhm on 12 Jun 2018
I am not an expert for the Parallel Computing toolbox, but if the calculation inside the for loop body is fairly simple (as it looks in your case), the loop bodies will actually be executed in groups, so there's no guarantee all workers will remain busy. I've added PCT as keyword so someone there can jump in if they have other suggestions.

Community Treasure Hunt

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

Start Hunting!