what is the difference between running backgroundPool and parpool ('Threads') using a parfeval?
31 ビュー (過去 30 日間)
古いコメントを表示
parpool('Threads')
delete(gcp('nocreate'))
pool=parpool('Threads')
f(1:8) = parallel.FevalFuture;
for i = 1:8
f(i) = parfeval(pool, @task, 1, i, 'parpool');
end
afterEach(f, @disp, 0);
function output = task(taskID,poolType)
pause(5);
output = sprintf('Task %d is done in %s at %s', taskID, poolType,datetime('now'));
end
backgroundPool
b(1:8) = parallel.FevalFuture;
for i = 1:8
b(i) = parfeval(backgroundPool, @task, 1, i, 'backgroundPool');
end
afterEach(b, @disp, 0);
function output = task(taskID,poolType)
pause(5);
output = sprintf('Task %d is done in %s at %s', taskID, poolType,datetime('now'));
end
I don't think there's any difference between them
0 件のコメント
回答 (1 件)
Walter Roberson
2023 年 11 月 25 日
"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."
Unfortunately that talks more about the similarities than the differences. The differences are more difficult to find documentation on.
Background pools only support parfeval and parfevalOnAll but do not need the Parallel Computing Toolbox
Thread pools support additional constructs including parfor, but requires the Parallel Computing Toolbox
I do not know if there are any MATLAB functions that support one but not the other
3 件のコメント
Edric Ellis
2023 年 11 月 27 日
Basically, although the pools share resources, they each have some exclusive resources to ensure that progress is never completely blocked by activity on the other pool.
参考
カテゴリ
Help Center および File Exchange で Parallel Computing Fundamentals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!