Raytrace difference using for and parfor

조회 수: 4 (최근 30일)
Stavros Tsimpoukis
Stavros Tsimpoukis 2023년 9월 14일
편집: Dheeraj 2023년 10월 31일
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
Pooja Kumari
Pooja Kumari 2023년 9월 25일
Can you share the complete code?
Stavros Tsimpoukis
Stavros Tsimpoukis 2023년 9월 26일
Yes of course, though it doesn't really change a lot as the main difference is just the for/ parfor approach.
I will share just the important parts of the code.
fc = 10e9; % antenna frequency
c = physconst("Lightspeed");
lambda = c/fc;
tx_antenna = horn(...);
tx = txsite("cartesian", ...
"AntennaPosition",tx_pos, ...
"TransmitterFrequency",fc,...
"Antenna",tx_antenna);
rx_pos = ...;
rx = rxsite("cartesian",...,
"AntennaPosition", rx_pos);
pm = propagationModel("raytracing", ...
"CoordinateSystem","cartesian", ...
"Method","sbr", ...
"AngularSeparation","medium",...
"MaxNumReflections",4, ...
"MaxNumDiffractions",1,...
"SurfaceMaterial","perfect-reflector");
numSites = numel(rx);
rays = cell(numSites,1);
parpool();
parfor i=1:numSites
rays{i} = raytrace(tx, rx(i), pm);
end
delete(gcp);

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

답변 (1개)

Dheeraj
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!

카테고리

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