How to Run raytrace or siteviewer related program in Parallel Computing Toolbox?
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am attempting to simulate coverage for different 'txsites' across various osm maps, aiming to expedite the process through parallelization. However, it appears that 'siteviewer' is not compatible with the Parallel Computing Toolbox.
1. I tried to create a 'siteviewer' object within a parallel loop:
pm = propagationModel("raytracing", ...
"Method", "sbr", ...
"MaxNumReflections", 5);
osmMaps = ["hongkong.osm","chicago.osm","manhattan.osm"];
lats = [22.27,41.87,40.71];
lons = [114.15,-87.63,-74.00];
parfor i=1:3
viewer = siteviewer('Buildings', osmMaps(i), 'Terrain', "none", 'Basemap', "darkwater");
txs = txsite(Latitude=lats(i),Longitude=lons(i));
pd = coverage(txs, pm, 'Map', viewer);
disp(pd);
close(viewer);
end
The above code resulted in the following error: Error using siteviewer, Timeout waiting for response. Despite adjusting several initialization parameters, the error persisted. When I changed 'parfor' to 'for', the program ran without any errors. My understanding is that 'siteviewer' objects cannot be created within 'parfor'.
2. Consequently, I altered my parallelization strategy by creating the 'siteviewer' object in advance and referencing it within the 'parfor' loop:
viewer = siteviewer('Buildings', 'hongkong.osm', 'Terrain', "none", 'Basemap', "darkwater");
lats = [22.27,22.273,22.275];
lons = [114.15,114.152,114.154];
parfor i = 1:3
txs = txsite(Latitude=lats(i),Longitude=lons(i)); % Each iteration, 'txs' are at different locations.
pd = coverage(txs, pm, 'Map', viewer);
end
close(viewer);
Referencing the 'viewer' object within 'parfor' still led to errors.
Output: Warning: While loading an object of class 'siteviewer':
Variables of this type are not subscriptable using dot indexing.
3. Further,I examined the source code of the 'coverage' function and debugged the parallel code.
viewer = siteviewer('Buildings', 'hongkong', 'Terrain', "none", 'Basemap', "darkwater");
future = parfeval(@()viewer, 1); % Assuming 'viewer' is already created.
[~, thisResult] = fetchNext([future]);
% Output: Warning: While loading an object of class 'siteviewer':
% Variables of this type are not subscriptable using dot indexing.
future = parfeval(@()siteviewer.all, 1); % Assuming existing 'siteviewer' objects.
[~, thisResult] = fetchNext([future]);
% Output: thisResult = 0x0 cell
future = parfeval(@()siteviewer.current, 1); % Assuming existing 'siteviewer' objects.
[~, thisResult] = fetchNext([future]);
%Output: error using siteviewer, Timeout waiting for response.
I am puzzled, as the computation for Ray Tracing is slow, cannot be expedited using GPU acceleration, nor can it utilize the Parallel Computing Toolbox, resulting in low efficiency. Is there any solution to run 'coverage' in parallel?
I have consulted many Q&As, including the following: answer_link
However, this Answer is evidently incorrect; the 1000 rays within a cell are identical, failing to achieve parallel acceleration, and moreover, the rays were computed incorrectly. Based on the issues I've encountered, 'raytrace' in a parallel loop is unable to access previously created 'viewer' objects, and the 'Map' in 'raytrace(tx,rx)' differs from the one I defined, leading to incorrect results.
0 Commenti
Risposte (1)
Alan
il 1 Lug 2024
Hi 伟林 朱,
I’ve faced the same issue with siteviewer while running it inside parfor. There is an undocumented fix for this, which is to provide the name-value pair “Hidden”, and true as follows:
viewer = siteviewer('Buildings', osmMaps(i), 'Terrain', "none", 'Basemap', "darkwater", "Hidden", true);
But the downside is that there will be no visuals. On the other hand, the propagation data obtained with “parfor” do match with that obtained from using “for”.
Regards.
1 Commento
Hasnul
il 20 Ago 2025
Modificato: Hasnul
il 20 Ago 2025
My problem is very similar.
I tried to use this undocumented option but matlab just threw a bunch of errors -- something something C++ serialization and a bunch of other junk I didn't understand. I don't like using undocumented stuff, so without using this undocumented option, I passed the viewer handle from the outer function holding the parfor loop which consists of a single function call to an "inner" function. This worked and my results matched the un-parallelized version BUT it opened a bunch of windows. So what is going on here? Why do I need to open a bunch of windows to pass the map model to the raytrace function? This is a design issue/flaw; the siteviewer window is tightly coupled with the map object that its holding. Is this intentional? Why?. Is there a fundamental reason why the window cannot be decoupled from the data?
For completeness, my system is an AMD 7700 with 8 cores. With parfor using all eight cores, eight siteviewer windows were launched, which is manageable I guess but still ugly. I shudder at the thought of running this on a system with 16+ cores ...
Vedere anche
Categorie
Scopri di più su Propagation and Channel Models in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!