Programmatically check type of parpool

23 visualizaciones (últimos 30 días)
Matthias Wurm
Matthias Wurm el 8 de Ag. de 2025
Comentada: Matthias Wurm el 11 de Ag. de 2025 a las 13:34
How can I check programmatically whether an existing parallel pool is thread-based or process-based?
  2 comentarios
Raymond Norris
Raymond Norris el 11 de Ag. de 2025 a las 12:25
@Matthias Wurm I'm currious why this would matter?
Matthias Wurm
Matthias Wurm el 11 de Ag. de 2025 a las 13:34
Some of my functions use the thread-based pool, others the process-based pool. When running a function and the wrong pool already exists, I would like to end it and create the correct one.

Iniciar sesión para comentar.

Respuesta aceptada

Meg Noah
Meg Noah el 8 de Ag. de 2025 a las 7:58
delete(gcp('nocreate'))
pool = parpool('Threads')
Starting parallel pool (parpool) using the 'Threads' profile ... Connected to parallel pool with 8 workers.
pool =
ThreadPool with properties: NumWorkers: 8 Busy: false FileStore: [1x1 parallel.FileStore] ValueStore: [1x1 parallel.ValueStore]
class(pool)
ans = 'parallel.ThreadPool'
% test of whether or not pool is a thread parallel pool
contains(class(pool), 'parallel.ThreadPool')
ans = logical
1
opts = parforOptions(pool)
opts =
PoolOptions with properties: RangePartitionMethod: 'auto' Pool: [1×1 parallel.ThreadPool] MaxNumWorkers: 8
class(opts.Pool)
ans = 'parallel.ThreadPool'
% test for whether or not pool is a Thread pool
contains(class(opts.Pool), 'parallel.ThreadPool')
ans = logical
1
% check to see if the same methods in pool are inherited from ThreadPool
methods(pool)
Methods for class parallel.ThreadPool: addAttachedFiles parfeval partition tocBytes listAutoAttachedFiles parfevalOnAll ticBytes updateAttachedFiles Call "methods('handle')" for methods of parallel.ThreadPool inherited from handle.
  1 comentario
Matthias Wurm
Matthias Wurm el 8 de Ag. de 2025 a las 8:07
Thank you! I was not aware of the "class()" function.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel Computing Fundamentals en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by