Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ApplicationLibCode/Application/Tools/RiaCurveMerger.inl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void RiaCurveMerger<XValueType>::computeInterpolatedValues( bool includeValuesFr

if ( !RiaCurveDataTools::isValidValue( interpolValue, false ) )
{
#pragma omp critical
// Each iteration writes to its own element, so no synchronization is required
accumulatedValidValues[valueIndex] = HUGE_VAL;
}

Expand Down
4 changes: 2 additions & 2 deletions ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void RifOpmCommonEclipseSummary::setEnsembleImportState( RifEnsembleImportConfig
void RifOpmCommonEclipseSummary::resetEnhancedSummaryFileCount()
{
// This function can be called from a parallel loop, make it thread safe
#pragma omp critical
#pragma omp critical( critical_section_createdEsmryFileCount )
sm_createdEsmryFileCount = 0;
}

Expand Down Expand Up @@ -405,6 +405,6 @@ std::string RifOpmCommonEclipseSummary::keywordForAddress( const RifEclipseSumma
void RifOpmCommonEclipseSummary::increaseEsmryFileCount()
{
// This function can be called from a parallel loop, make it thread safe
#pragma omp critical
#pragma omp critical( critical_section_createdEsmryFileCount )
sm_createdEsmryFileCount++;
}
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifOpmSummaryTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ std::pair<std::set<RifEclipseSummaryAddress>, std::map<RifEclipseSummaryAddress,
}
}

#pragma omp critical
#pragma omp critical( critical_section_RifOpmSummaryTools_buildAddresses )
{
addresses.insert( threadAddresses.begin(), threadAddresses.end() );
addressToKeywordMap.insert( threadAddressToKeywordMap.begin(), threadAddressToKeywordMap.end() );
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifRoffFileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ bool RifRoffFileTools::openGridFile( const QString& fileName, RigEclipseCaseData
size_t numActiveCells = computeActiveCellMatrixIndex( activeCells );

// Loop over cells and fill them with data
#pragma omp for
#pragma omp parallel for
for ( int gridLocalCellIndex = 0; gridLocalCellIndex < cellCount; ++gridLocalCellIndex )
{
RigCell& cell = mainGrid->cell( cellStartIndex + gridLocalCellIndex );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ size_t RifSummaryReaderInterface::dataObjectCount() const
//--------------------------------------------------------------------------------------------------
void RifSummaryReaderInterface::increaseSerialNumber()
{
#pragma omp critical
#pragma omp critical( critical_section_RifSummaryReaderInterface_serialNumber )
m_serialNumber = m_nextSerialNumber++;
}

Expand Down
95 changes: 57 additions & 38 deletions ApplicationLibCode/ModelVisualization/RivNNCGeometryGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <cmath>

#include "RiaOpenMPTools.h"

#include "RigCell.h"
#include "RigMainGrid.h"
#include "RigNNCData.h"
Expand Down Expand Up @@ -86,63 +88,80 @@ void RivNNCGeometryGenerator::computeArrays()
mainGrid = m_grid->mainGrid();
}

#pragma omp parallel for ordered
for ( long long nIdx = 0; nIdx < numConnections; ++nIdx )
{
size_t conIdx = m_nncIndexes.empty() ? nIdx : m_nncIndexes[nIdx];
int numberOfThreads = RiaOpenMPTools::availableThreadCount();

if ( !m_includeAllanDiagramGeometry && conIdx >= m_nncData->eclipseConnectionCount() )
{
continue;
}
std::vector<std::vector<cvf::Vec3f>> threadVertices( numberOfThreads );
std::vector<std::vector<size_t>> threadTriangleToNNC( numberOfThreads );

const RigConnection& conn = m_nncData->allConnections()[conIdx];
#pragma omp parallel
{
int myThread = RiaOpenMPTools::currentThreadIndex();

if ( !conn.polygon().empty() )
// NB! We are inside a parallel section, do not use "parallel for" here
#pragma omp for
for ( long long nIdx = 0; nIdx < numConnections; ++nIdx )
{
bool isVisible = true;
if ( isVisibilityCalcActive )
size_t conIdx = m_nncIndexes.empty() ? nIdx : m_nncIndexes[nIdx];

if ( !m_includeAllanDiagramGeometry && conIdx >= m_nncData->eclipseConnectionCount() )
{
bool cell1Visible = false;
bool cell2Visible = false;
continue;
}

if ( mainGrid->cell( conn.c1GlobIdx() ).hostGrid() == m_grid.p() )
{
size_t cell1GridLocalIdx = mainGrid->cell( conn.c1GlobIdx() ).gridLocalCellIndex();
cell1Visible = ( *m_cellVisibility )[cell1GridLocalIdx];
}
const RigConnection& conn = m_nncData->allConnections()[conIdx];

if ( mainGrid->cell( conn.c2GlobIdx() ).hostGrid() == m_grid.p() )
if ( !conn.polygon().empty() )
{
bool isVisible = true;
if ( isVisibilityCalcActive )
{
size_t cell2GridLocalIdx = mainGrid->cell( conn.c2GlobIdx() ).gridLocalCellIndex();
cell2Visible = ( *m_cellVisibility )[cell2GridLocalIdx];
}
bool cell1Visible = false;
bool cell2Visible = false;

isVisible = cell1Visible || cell2Visible;
}
if ( mainGrid->cell( conn.c1GlobIdx() ).hostGrid() == m_grid.p() )
{
size_t cell1GridLocalIdx = mainGrid->cell( conn.c1GlobIdx() ).gridLocalCellIndex();
cell1Visible = ( *m_cellVisibility )[cell1GridLocalIdx];
}

if ( isVisible )
{
cvf::Vec3f vx1 = conn.polygon()[0] - offset;
cvf::Vec3f vx2;
cvf::Vec3f vx3 = conn.polygon()[1] - offset;
if ( mainGrid->cell( conn.c2GlobIdx() ).hostGrid() == m_grid.p() )
{
size_t cell2GridLocalIdx = mainGrid->cell( conn.c2GlobIdx() ).gridLocalCellIndex();
cell2Visible = ( *m_cellVisibility )[cell2GridLocalIdx];
}

isVisible = cell1Visible || cell2Visible;
}

for ( size_t vxIdx = 2; vxIdx < conn.polygon().size(); ++vxIdx )
if ( isVisible )
{
vx2 = vx3;
vx3 = conn.polygon()[vxIdx] - offset;
#pragma omp critical( critical_section_RivNNCGeometryGenerator_computeArrays )
cvf::Vec3f vx1 = conn.polygon()[0] - offset;
cvf::Vec3f vx2;
cvf::Vec3f vx3 = conn.polygon()[1] - offset;

for ( size_t vxIdx = 2; vxIdx < conn.polygon().size(); ++vxIdx )
{
vertices.push_back( vx1 );
vertices.push_back( vx2 );
vertices.push_back( vx3 );
triangleToNNC.push_back( conIdx );
vx2 = vx3;
vx3 = conn.polygon()[vxIdx] - offset;

threadVertices[myThread].push_back( vx1 );
threadVertices[myThread].push_back( vx2 );
threadVertices[myThread].push_back( vx3 );
threadTriangleToNNC[myThread].push_back( conIdx );
}
}
}
}
}

// Merge in thread order. The default static schedule assigns contiguous chunks to the threads, so the
// resulting geometry is identical from run to run.
for ( int i = 0; i < numberOfThreads; i++ )
{
vertices.insert( vertices.end(), threadVertices[i].begin(), threadVertices[i].end() );
triangleToNNC.insert( triangleToNNC.end(), threadTriangleToNNC[i].begin(), threadTriangleToNNC[i].end() );
}

m_vertices = new cvf::Vec3fArray;
m_vertices->assign( vertices );
m_triangleIndexToNNCIndex = new cvf::Array<size_t>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void RivSurfaceIntersectionGeometryGenerator::calculateArrays()
std::array<double, 8> cornerWeights2 =
caf::HexInterpolator::vertexWeights( cellCorners, clippedTriangleVxes[triVxIdx + 2] );

#pragma omp critical
#pragma omp critical( critical_section_RivSurfaceIntersectionGeometryGenerator_computeArrays )
{
outputTriangleVertices.emplace_back( point0 );
outputTriangleVertices.emplace_back( point1 );
Expand Down
Loading