Raytrace difference using for and parfor
8 次查看(过去 30 天)
显示 更早的评论
Hello, I try to run the raytrace function of matlab to compute the rays among a transmitter site tx and multiple receiver sites rx ( an aray of RXs ). When I use the following code:
for i=1:numSites
rays{i} = raytrace(tx, rx(i), pm);
end
The rays cell array contains the true comm.Ray array concerning every TX-RX link.
On the contrary when I run the same code, with the exception that the for loop becomes a parfor one, the result changes. This time the rays cell array contains a comm.Ray array with a single propagation path (the line-of-sight) as it is running just once an then stops.
Is there a problem in the parallelization scope ?
Does anyone have a clue on that problem ?
Thank you in advance!
2 个评论
回答(1 个)
Dheeraj
2023-10-27
编辑:Dheeraj
2023-10-31
Hi,
As per my understanding you are trying to compute the rays among a transmitter site “tx” and multiple receiver sites “rx" using “parfor” but it is creating a ray array with single propagation path. Reason for single propagation path in rays cell array with “parfor” loop is because MATLAB parallelizes “parfor” loops by creating a separate worker process for each iteration of the loop. Each worker process has its own memory space and cannot communicate with other worker processes directly.
This means that the rays cell array is not updated with the computed propagation paths from other worker processes. As a result, only the propagation path between the transmitter and receiver that was computed by the last worker process is stored in the “rays” cell array.
To avoid this, use a “parfeval” function instead of a “parfor” loop. The “parfeval” function allows you to evaluate a function asynchronously on multiple workers and collect the results as they become available. You could use the link below to the MATLAB documentation to know more about “parfeval” from parallel computing toolbox.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!