How to set a background pool to process-based instead of thread-based

35 views (last 30 days)
I'm trying to read and write files in the background of my matlab app. However, when I run the function that I want executed in the background
pool = backgroundPool;
f = parfevalOnAll(pool, @fetchAndPrepareData,0,filePaths);
I get the error message
f(1).Error{1}
ans =
ParallelException with properties:
identifier: 'parallel:threadpool:DisallowedBuiltin'
message: 'Use of function fopen is not supported on a thread-based worker.'
cause: {}
remotecause: {[1×1 MException]}
stack: [3×1 struct]
Correction: []
I've done some small work previously using parpool where you can use parpool('threads') or parpool('local') to switch, but I can't seem to find a similar way of achieving this using a backgorund pool.
If people know of a different way to read/write files in the background I am also open for other ideas, but I really want it done in the background since the files takes a very long time to load and the user needs to work on each file for qutie some time so I want the reduce wait time for the user to a minimum by reading the next file while the user is performing the work.

Accepted Answer

Edric Ellis
Edric Ellis on 14 Jul 2022
Unfortunately, as you have seen fopen is not yet supported on thread-based pools such as backgroundPool. There is no way to configure which type of pool is used for backgroundPool, so for now, you must continue to use parpool("local") to create a process-based pool. You can use this just like backgroundPool.
(Of course, one advantage backgroundPool has over parpool("local") is that it is available with MATLAB without requiring Parallel Computing Toolbox. Unfortunately, for now, if you wish to allow things to work without PCT, you'll need to do a little extra work to avoid using parfeval here)

More Answers (1)

Jixiong Su
Jixiong Su on 25 Nov 2023
You can use
pool=parpool('Processes')
f = parfeval(pool, @fetchAndPrepareData,0,filePaths);

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!