Clear persistent variables of function on worker

조회 수: 6 (최근 30일)
Massimiliano Zanoli
Massimiliano Zanoli 2023년 5월 6일
답변: Edric Ellis 2023년 5월 9일
I need to clear the persistent variables of a function on all workers after having called it from a parallelized statement.
parfor n = 1 : N
persistentFunction()
end
spmd
clear persistentFunction
end
The above will not work because clear cannot be called from an spmd statement.
How can I clear persistentFunction ?

채택된 답변

Walter Roberson
Walter Roberson 2023년 5월 6일
parfevalOnAll(@() clear('persistentFunction'), 0)

추가 답변 (1개)

Edric Ellis
Edric Ellis 2023년 5월 9일
Whenever you issue a clear command at the client, the same clear command is issued on the workers. So you can simply do
clear persistentFunction

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by