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

조회 수: 35(최근 30일)
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
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.

채택된 답변

Edric Ellis
Edric Ellis 2022년 7월 14일
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)

추가 답변(0개)


Find more on File Operations 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!

Translated by