필터 지우기
필터 지우기

Can an object with a `Transient` property be used in a parfor loop?

조회 수: 2 (최근 30일)
In a class I am using a private property A, an NxN matrix, to store data that is expensive to compute and may be used many times during the lifetime of the object. I was excited to learn about the Transient attribute which seems perfect for this type of property:
...a Transient property useful for cases where data needs to be stored
in the object temporarily as an intermediate computation step, or for
faster retrieval
Easy and elegant solution but a method fails with a "array out of bounds" error when a parallel pool is available. I think the reason is clear enough: MATLAB calls save/load behind the scenes to send my object to workers in the parpool.
My questions:
  1. Am I right about the cause and is this a documented limitation of the Transient attribute?
  2. Is there a workaround that doesn't require the property A to be recomputed by each worker?
thanks

채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 19일
편집: Walter Roberson 2017년 3월 20일
The documentation https://www.mathworks.com/help/matlab/matlab_oop/property-attributes.html describes transient in terms of saving to file, but parfor effectively saves objects to file and reconstructs them on the worker. (it probably serializes into memory and transmits that by message passing, but the effect is the same.)
If you have only a small number of objects entering the parfor loop at any one time then possibly extract the property and transmit it to the workers as a parpool constant.
  댓글 수: 1
Naor Movshovitz
Naor Movshovitz 2017년 3월 20일
Here is the link to the useful and not easily discoverable parallel.pool.Constant function.
I also think there should be mention of this behavior in the documentation of the Transient attribute!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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