How do I use objects with inheritance structures in a `parfor` loop in Matlab?
36 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to parallelize a simulation that uses a custom library. Within the 'parfor' loop I am using, I receive the following error:
Error using sensor/readdata
Unrecognized field name "sensorDevice".
The object is an instance of Sensor that inherits its .sensorDevice field from its parent class. The method readdata calls on the inherited field. This works fine in a for loop. The transparency requirements for variable definitions and the corresponding documentation emphasize the ability of all variables to be machine-readable, but I do not follow why the parfor loop cannot trace the pointers to the parent classes' fields and methods. Re-writing the class in a flattened structure is not an option due to the time that would be required to do so.
How do I use methods and fields from a parent class in an instance of a child class in a parfor loop?
4 Kommentare
Jeff Miller
vor etwa 16 Stunden
I have no helpful suggestion but feel that I should comment on this part of your original post: "I do not follow why the parfor loop cannot trace the pointers to the parent classes' fields and methods."
With some pretty simple class/inheritance hierarchies, I use parfor loops like this all the time without any problems. That is, my parfor calls a child's method, and the child's method references its parent's properties and calls its parent's methods. So at least in some situations MATLAB can trace the pointers to the parents as needed.
If you can create a minimal example of a class structure where the tracing fails, it may be possible to spot just what determines whether tracing succeeds or fails.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!