How do I turn off the warning message in the "parfor" loop?

20 views (last 30 days)
I got a warning message from each "parfor" loop.
For example:
parfor i = 1:5
  warning(['i = ' num2str(i)])
end 
I want to turn off the warning message and therefore use:
warning('off','all')
parfor i = 1:5
  warning(['i = ' num2str(i)])
end
However, the warning message still shows up.
I notice I don't get this issue if I use "for" loop instead of "parfor".
My questions are:
1. How do I turn off the warning message in the "parfor" loop?
2. Why do I still get the warning message even warning('off') is applied.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Jun 2021
MATLAB local parallel workers are separate copies of MATLAB on the machine.
If you want to affect their state, you need to execute the state-changing code on them (typically inside a parallel language construct like parfor, parfeval or spmd).
When you execute:
warning('off','all')
parfor i = 1:5
warning(['i = ' num2str(i)])
end
This only tells the client to disable the warning (the MATLAB you are interacting with).
When you execute:
  parfor i = 1:5
    warning('off','all')
    warning(['i = ' num2str(i)])
  end
Since the warning off call is inside a "parfor" loop, it is executed on the worker MATLABs.
However, if you have a large loop, you don't really want to be executing this every time you go around the loop.
It is recommended typically setting something like this using parfevalOnAll which would execute on all of the workers in the pool once.
For example:
parfevalOnAll(@warning,0,'off','all')
parfor i = 1:5
  warning(['i = ' num2str(i)])
end

More Answers (0)

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!