Skip to content

Commit

Permalink
Merge pull request #380 from favreau/master
Browse files Browse the repository at this point in the history
Reviewd OpenMP code
  • Loading branch information
favreau authored Jul 9, 2024
2 parents 2ed4d80 + fb447c3 commit e28af86
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 47 deletions.
31 changes: 19 additions & 12 deletions bioexplorer/backend/science/atlas/Atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -95,7 +95,9 @@ void Atlas::_buildModel(const LoaderProgress& callback)
catch (...)
{
#pragma omp critical
flag = true;
{
flag = true;
}
}
}
ThreadSafeContainer container(*model, _alignToGrid, _position, _rotation);
Expand All @@ -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)
Expand All @@ -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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -93,7 +93,9 @@ void WhiteMatter::_buildModel(const LoaderProgress& callback)
catch (...)
{
#pragma omp critical
flag = true;
{
flag = true;
}
}
}
ThreadSafeContainer container(*model, _alignToGrid, _position, _rotation);
Expand All @@ -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)
Expand Down
21 changes: 13 additions & 8 deletions bioexplorer/backend/science/morphologies/Astrocytes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
25 changes: 15 additions & 10 deletions bioexplorer/backend/science/morphologies/Neurons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
22 changes: 14 additions & 8 deletions bioexplorer/backend/science/vasculature/Vasculature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ void Vasculature::_buildModel(const LoaderProgress& callback, const doubles& rad
catch (...)
{
#pragma omp critical
flag = true;
{
flag = true;
}
}
}

Expand Down Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit e28af86

Please sign in to comment.