How to set a background pool to process-based instead of thread-based
43 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Linus Olofsson
el 13 de Jul. de 2022
Respondida: Jixiong Su
el 25 de Nov. de 2023
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.
0 comentarios
Respuesta aceptada
Edric Ellis
el 14 de Jul. de 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)
0 comentarios
Más respuestas (1)
Jixiong Su
el 25 de Nov. de 2023
You can use
pool=parpool('Processes')
f = parfeval(pool, @fetchAndPrepareData,0,filePaths);
0 comentarios
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!