From fb447c3224c598af6b39f37715fac3520e4c073f Mon Sep 17 00:00:00 2001 From: Cyrille Pierre Henri Favreau Date: Tue, 25 Jun 2024 17:53:19 +0200 Subject: [PATCH] Reviewd OpenMP code --- bioexplorer/backend/science/atlas/Atlas.cpp | 31 ++++++++++++------- .../connectomics/whitematter/WhiteMatter.cpp | 24 ++++++++------ .../science/morphologies/Astrocytes.cpp | 21 ++++++++----- .../backend/science/morphologies/Neurons.cpp | 25 +++++++++------ .../science/vasculature/Vasculature.cpp | 22 ++++++++----- 5 files changed, 76 insertions(+), 47 deletions(-) diff --git a/bioexplorer/backend/science/atlas/Atlas.cpp b/bioexplorer/backend/science/atlas/Atlas.cpp index 0b50556b5..dc823a310 100644 --- a/bioexplorer/backend/science/atlas/Atlas.cpp +++ b/bioexplorer/backend/science/atlas/Atlas.cpp @@ -76,7 +76,7 @@ void Atlas::_buildModel(const LoaderProgress& callback) uint64_t index; volatile bool flag = false; std::string flagMessage; -#pragma omp parallel for num_threads(nbDBConnections) +#pragma omp parallel for shared(flag, flagMessage) num_threads(nbDBConnections) for (index = 0; index < regions.size(); ++index) { try @@ -95,7 +95,9 @@ void Atlas::_buildModel(const LoaderProgress& callback) catch (...) { #pragma omp critical - flag = true; + { + flag = true; + } } } ThreadSafeContainer container(*model, _alignToGrid, _position, _rotation); @@ -107,7 +109,9 @@ void Atlas::_buildModel(const LoaderProgress& callback) for (const auto& cell : cells) container.addSphere(cell.second.position, _details.cellRadius, cell.second.region, useSdf); #pragma omp critical - nbCells += cells.size(); + { + nbCells += cells.size(); + } } if (_details.loadMeshes) @@ -126,24 +130,27 @@ void Atlas::_buildModel(const LoaderProgress& callback) } #pragma omp critical - ++counter; + { + ++counter; -#pragma omp critical - containers.push_back(container); + containers.push_back(container); + } } catch (const std::runtime_error& e) { #pragma omp critical - flagMessage = e.what(); -#pragma omp critical - flag = true; + { + flagMessage = e.what(); + flag = true; + } } catch (...) { #pragma omp critical - flagMessage = "Loading was canceled"; -#pragma omp critical - flag = true; + { + flagMessage = "Loading was canceled"; + flag = true; + } } } diff --git a/bioexplorer/backend/science/connectomics/whitematter/WhiteMatter.cpp b/bioexplorer/backend/science/connectomics/whitematter/WhiteMatter.cpp index d115637a8..df40ed6e0 100644 --- a/bioexplorer/backend/science/connectomics/whitematter/WhiteMatter.cpp +++ b/bioexplorer/backend/science/connectomics/whitematter/WhiteMatter.cpp @@ -74,7 +74,7 @@ void WhiteMatter::_buildModel(const LoaderProgress& callback) uint64_t index; volatile bool flag = false; std::string flagMessage; -#pragma omp parallel for num_threads(nbDBConnections) +#pragma omp parallel for shared(flag, flagMessage) num_threads(nbDBConnections) for (index = 0; index < nbStreamlines; ++index) { try @@ -93,7 +93,9 @@ void WhiteMatter::_buildModel(const LoaderProgress& callback) catch (...) { #pragma omp critical - flag = true; + { + flag = true; + } } } ThreadSafeContainer container(*model, _alignToGrid, _position, _rotation); @@ -116,21 +118,25 @@ void WhiteMatter::_buildModel(const LoaderProgress& callback) container.addStreamline(materialId, streamline); #pragma omp critical - containers.push_back(container); + { + containers.push_back(container); + } } catch (const std::runtime_error& e) { #pragma omp critical - flagMessage = e.what(); -#pragma omp critical - flag = true; + { + flagMessage = e.what(); + flag = true; + } } catch (...) { #pragma omp critical - flagMessage = "Loading was canceled"; -#pragma omp critical - flag = true; + { + flagMessage = "Loading was canceled"; + flag = true; + } } } for (uint64_t i = 0; i < containers.size(); ++i) diff --git a/bioexplorer/backend/science/morphologies/Astrocytes.cpp b/bioexplorer/backend/science/morphologies/Astrocytes.cpp index 78c3634f6..6898f0bf8 100644 --- a/bioexplorer/backend/science/morphologies/Astrocytes.cpp +++ b/bioexplorer/backend/science/morphologies/Astrocytes.cpp @@ -170,7 +170,8 @@ void Astrocytes::_buildModel(const LoaderProgress& callback, const doubles& radi // End feet EndFootMap endFeet; if (loadEndFeet) - endFeet = connector.getAstrocyteEndFeet(_details.vasculaturePopulationName, _details.connectomePopulationName, somaId); + endFeet = connector.getAstrocyteEndFeet(_details.vasculaturePopulationName, + _details.connectomePopulationName, somaId); // Soma radius uint64_t count = 1; @@ -358,21 +359,25 @@ void Astrocytes::_buildModel(const LoaderProgress& callback, const doubles& radi } } #pragma omp critical - containers.push_back(container); + { + containers.push_back(container); + } } catch (const std::runtime_error& e) { #pragma omp critical - flagMessage = e.what(); -#pragma omp critical - flag = true; + { + flagMessage = e.what(); + flag = true; + } } catch (...) { #pragma omp critical - flagMessage = "Loading was canceled"; -#pragma omp critical - flag = true; + { + flagMessage = "Loading was canceled"; + flag = true; + } } } diff --git a/bioexplorer/backend/science/morphologies/Neurons.cpp b/bioexplorer/backend/science/morphologies/Neurons.cpp index 74880c0b0..c25089f9d 100644 --- a/bioexplorer/backend/science/morphologies/Neurons.cpp +++ b/bioexplorer/backend/science/morphologies/Neurons.cpp @@ -294,32 +294,37 @@ void Neurons::_buildModel(const LoaderProgress& callback) catch (...) { #pragma omp critical - flag = true; + { + flag = true; + } } } - auto it = somas.begin(); - std::advance(it, neuronIndex); + auto it = std::next(somas.begin(), neuronIndex); const auto& soma = it->second; ThreadSafeContainer container(*model, _alignToGrid, _position, _rotation, _scale); _buildMorphology(container, it->first, soma, neuronIndex, voltages); #pragma omp critical - containers.push_back(container); + { + containers.push_back(container); + } } catch (const std::runtime_error& e) { #pragma omp critical - flagMessage = e.what(); -#pragma omp critical - flag = true; + { + flagMessage = e.what(); + flag = true; + } } catch (...) { #pragma omp critical - flagMessage = "Loading was canceled"; -#pragma omp critical - flag = true; + { + flagMessage = "Loading was canceled"; + flag = true; + } } } } diff --git a/bioexplorer/backend/science/vasculature/Vasculature.cpp b/bioexplorer/backend/science/vasculature/Vasculature.cpp index 87f8d3755..48df94663 100644 --- a/bioexplorer/backend/science/vasculature/Vasculature.cpp +++ b/bioexplorer/backend/science/vasculature/Vasculature.cpp @@ -302,7 +302,9 @@ void Vasculature::_buildModel(const LoaderProgress& callback, const doubles& rad catch (...) { #pragma omp critical - flag = true; + { + flag = true; + } } } @@ -384,21 +386,25 @@ void Vasculature::_buildModel(const LoaderProgress& callback, const doubles& rad } while (iter != nodes.end()); #pragma omp critical - containers.push_back(container); + { + containers.push_back(container); + } } catch (const std::runtime_error& e) { #pragma omp critical - flagMessage = e.what(); -#pragma omp critical - flag = true; + { + flagMessage = e.what(); + flag = true; + } } catch (...) { #pragma omp critical - flagMessage = "Loading was canceled"; -#pragma omp critical - flag = true; + { + flagMessage = "Loading was canceled"; + flag = true; + } } }