Error Found an interactive session. You cannot have multiple interactive sessions open simultaneously. To terminate the existing session, use 'delete(gc​p('nocreat​e'))'

조회 수: 20 (최근 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

채택된 답변

Javier Naranjo
Javier Naranjo 2017년 11월 7일
I am going to answer my own question if this helps to someone else.
It is not possible to open a pool with gcp and the open again with parpool.
That was the problem

추가 답변 (1개)

Hernan
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.

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by