Error Found an interactive session. You cannot have multiple interactive sessions open simultaneously. To terminate the existing session, use 'delete(gcp('nocreate'))'
12 ビュー (過去 30 日間)
古いコメントを表示
Hello everybody,
I want to create a pool but Matlab returns that I have a pool opened. I make sure that if a pool is open close it before open the new one. I mean:
delete(gcp('nocreate')); %delete the current pool
poolobj = gcp;
if isempty(poolobj)
poolsize = 1;
else
poolsize = poolobj.NumWorkers;
end
parpool(poolsize,'IdleTimeout',Inf);
This is my code. I check if a pool is opened and then open a new one.
What is wrong? It always shows that issue.
Thanks!
Javi
1 件のコメント
採用された回答
その他の回答 (1 件)
Hernan
2022 年 10 月 14 日
編集済み: Hernan
2022 年 10 月 14 日
Hello Javier,
I arrived here looking for something else, but I think maybe what you wanted to do is something like this:
poolobj = gcp('nocreate'); % get the pool object, and do it avoiding creating a new one.
if isempty(poolobj) % check if there is not a pool.
poolsize = 1;
else
poolsize = poolobj.NumWorkers;
delete( gcp('nocreate')); % delete the current pool object.
end
parpool( poolsize, 'IdleTimeout',Inf); % create a new pool with the previous poolsize and new specs.
In that way your code works.
And what I was looking for was just to delete in case the current number of workers is different that the amount of workers that I want.
So, to replace a parpool( workers, 'IdleTimeout', idletimeout) at the begining of my code, that would drop the error here in subject, I defined the following function:
function [ poolobj ] = check_my_parpool( workers, idletimeout)
if nargin < 1
workers = 4; % default number of workers that I want.
end
if nargin < 2
idletimeout = 20; % default time in minutes of being idle before shut itself down.
end
poolobj = gcp('nocreate'); % get the pool object.
if ~isempty(poolobj) % check if there IS actually a pool:
if poolobj.NumWorkers ~= workers % it has a different number of workers???:
delete( poolobj); % delete the current pool object.
end
end
if isempty( gcp('nocreate')) % finally, if there is not a pool:
poolobj = parpool( workers, 'IdleTimeout', idletimeout); % create a new pool.
end
end
So, as example, add that function to your workspace, and then just replace:
parpool( 4);
with:
check_my_parpool( 4);
I hope this helps you,
Best,
Hernán.
0 件のコメント
参考
カテゴリ
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!