How to 'load' data inside a parfor loop in an effective way?
17 次查看(过去 30 天)
显示 更早的评论
Let suppose the following general code structure.
parfor i = 1:10000
result(i) = myfunc(data(i));
end
or
parfor i = 1:10000
result(i) = myfunc(data(i).relevantpart);
end
I think, in both case all the data are copied into memory within each loop, and not just data(i) for loop i.
Am I right?
So I want to avoid this.
As far as I see, the only way to do this, if I have separate data variables, like data1, data2, data3, ..., data10000.
But this is very ugly, and to automatically genarate them outside the loop and use them inside the loop, you have to use the function 'eval', which is not recommended in general.
So what is the solution for this general data 'loading/using' problem?
1 个评论
Stephen23
2019-9-25
"...you have to use the function 'eval', which is not recommended in general."
Not only is it a bad way to write code, eval doesn't really work inside parfor loops:
回答(1 个)
Matt J
2019-9-25
编辑:Matt J
2019-9-25
Am I right?
No. In the code you have shown, the struct array data will be sliced,
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!