Error when i run a simulink model which contains a matlab function block within a parfor loop
8 views (last 30 days)
Show older comments
I am running an optimization problem which requires the use of parfor loop to speed up the computation. My optimization seeks to find the optimal performance of a simulink model which contains a matlab function block inside it. I am getting an error when i run the model which states: Unable to read MAT-file TRSSOPTPROB/slprj/_sfprj/EMLReport/emlReportAccessInfo.mat. File might be corrupt. I dont know how to fix this issue which is related to the presence of the matlab function block inside my simulink model.
Thanks for your help.
0 Comments
Answers (1)
Walter Roberson
on 20 Jan 2018
If you have multiple workers writing to the same file and you have not taken care to avoid them overlapping in the file, then you could get file corruption. In particular, do not have multiple workers save() to the same file without going through an interlock to ensure that only one worker is writing at a time.
If you do need multiple workers writing to the same file, then sometimes the easiest approach is to use spmd instead of parfor, as spmd can use labBarrier() to synchronize workers. On the other hand, with spmd is its often easier to designate one worker as the worker responsible for the I/O to the common file, with the other workers using labSend() to send it the data to write, and receiving any read results using labReceive()
With parfor and fairly recent releases, a way to avoid having multiple workers write to the same file is to use a data queue or pollable data queue to send results back to the client which becomes responsible for doing the writing.
If the workers need temporary files but the files do not need to overlap between the workers, then the easiest way is tempname() to get a unique file name. If you need a directory of files but they do not need to overlap between workers then use tempname() to get a unique name, and then mkdir() that name, after which you can write into that directory.
0 Comments
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!