Is it possible to create multiple parallel pools simultaneously

25 views (last 30 days)
Hi all,
I have been trying to speed up some code on a HPC I have access to. The PC has 96 cores and 2 GPUs
To do this, I have wrote an application to make it easier for myself and others
I have been implementing parallelisation in order to get the speed increases I am seeking.
I would therefore like to have two parallel pools. One for the CPU cores and the other for the GPUs. Ideally I would have these parallel pools live at the same time and call each of them when I want something to be evaluated on the CPU or GPU.
Right now I need to close the CPU pool, open a GPU pool, evaluate a GPU function, then close the GPU and reopen the CPU pool. While this is faster than doing nothing, the closing and opening of pools is a little slow!
Is this possible? If so can someone please provide some example code or even pseudocode of the overall framework.

Accepted Answer

Edric Ellis
Edric Ellis on 9 Feb 2023
There's no direct way to do what you're after here. (As @Walter Roberson points out, you can have a backgroundPool and a parpool pool simultaneously, but that probably doesn't help you here).
Here's one potential workaround, which may or may not suit your needs. Basically, the idea is this:
  1. Create a pool of size 96 which you use for everything
  2. For CPU work, just use the pool as normal
  3. For GPU work, use a restricted-size spmd block for those things.
Your client code might look like this:
% Some CPU stuff
parfor i = 1:1000
out(i) = doStuff(i);
% Some GPU stuff
gpuDevice(spmdIndex); % Make sure we're using the correct GPU
outGpu = doStuffOnTheGPU(spmdIndex);
You can also use a restricted-size parfor loop in a similar manner, but there are complexities ensuring you have workers with distinct GPUs that mean it might not be efficient.
  1 Comment
EUAN FOSTER on 9 Feb 2023
I tried this out today and it worked well - Thanks :)
I also tried a restrict-size parfor loop and found that to be slightly easier to implement.
In the end for this specific section of code optimisation, I thought of and tried a totally different method for the problem I was trying to solve. This new approach was the solution in achieving the computational efficiency I wanted.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 8 Feb 2023
Edited: Walter Roberson on 8 Feb 2023
You can have only one parallel pool at a time from a MATLAB client session.
Pools created using parpool('threads') and backgroundPool are both thread-based pools which utilize the same resources. It is possible that activity on one pool may block activity on the other and vice versa. Additionally, persistent data and random number generation stream state are shared in between these pools.
This implies that you might possibly (still) only be able to have one process parpool at a time, but that possibly you could have a process pool at the same time as a background pool, and that definitely you can have a parpool thread pool at the same time as a background pool.
At the moment I do not know whether it is possible to have a cluster pool at the same time as a local pool. I seem to recall there have been a couple of posts implying it was possible, but don't count on it.
I guess your question is really whether you can have more than one cluster pool. The line I quoted first implies not, but I would not rule out the possibility that the line turns out to really only be talking about local pools.


Find more on Parallel Computing Fundamentals 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!