Add ifdefs for OpenMP usage.

This commit is contained in:
Kristian Bendiksen 2020-09-11 18:38:39 +02:00
parent 81a93a80fd
commit 02944f4eca
4 changed files with 33 additions and 5 deletions

View File

@ -59,7 +59,10 @@
#include <cmath> // Needed for HUGE_VAL on Linux
#include <iostream>
#include <map>
#ifdef USE_OPENMP
#include <omp.h>
#endif
//--------------------------------------------------------------------------------------------------
/// ECLIPSE cell numbering layout:
@ -138,7 +141,10 @@ bool transferGridCellData( RigMainGrid* mainGrid,
// Loop over cells and fill them with data
#pragma omp parallel
{
int cellCountPerThread = std::max( 1, cellCount / omp_get_num_threads() );
int cellCountPerThread = cellCount;
#ifdef USE_OPENMP
cellCountPerThread = std::max( 1, cellCount / omp_get_num_threads() );
#endif
int computedThreadCellCount = 0;
@ -210,13 +216,18 @@ bool transferGridCellData( RigMainGrid* mainGrid,
// if (!invalid && (cell.isInCoarseCell() || (!cell.isActiveInMatrixModel() &&
// !cell.isActiveInFractureModel()) ) )
cell.setInvalid( cell.isLongPyramidCell() );
#ifdef USE_OPENMP
if ( omp_get_thread_num() == 0 )
{
computedThreadCellCount++;
if ( computedThreadCellCount <= maxProgressCell && computedThreadCellCount % cellsPrProgressTick == 0 )
progInfo.incrementProgress();
}
#else
computedThreadCellCount++;
if ( computedThreadCellCount <= maxProgressCell && computedThreadCellCount % cellsPrProgressTick == 0 )
progInfo.incrementProgress();
#endif
}
}
return true;
@ -1428,7 +1439,7 @@ cvf::Vec3d interpolate3DPosition( const std::vector<SegmentPositionContribution>
// distance = 1.0;
}
distance = 1.0 / distance;
distance = 1.0 / distance;
nominators[i] = distance;
denominator += distance;

View File

@ -44,7 +44,10 @@
#include "cvfStructGridGeometryGenerator.h"
#include <algorithm>
#ifdef USE_OPENMP
#include <omp.h>
#endif
namespace caf
{
@ -857,11 +860,20 @@ void RimContourMapProjection::generateTrianglesWithVertexValues()
}
}
}
#ifdef USE_OPENMP
std::vector<std::vector<std::vector<cvf::Vec4d>>> threadTriangles( omp_get_max_threads() );
#else
std::vector<std::vector<std::vector<cvf::Vec4d>>> threadTriangles( 1 );
#endif
#pragma omp parallel
{
#ifdef USE_OPENMP
int myThread = omp_get_thread_num();
#else
int myThread = 0;
#endif
threadTriangles[myThread].resize( std::max( (size_t)1, m_contourPolygons.size() ) );
#pragma omp for schedule( dynamic )

View File

@ -28,7 +28,9 @@
#include "cvfAssert.h"
#include "cvfBoundingBoxTree.h"
#ifdef USE_OPENMP
#include <omp.h>
#endif
RigMainGrid::RigMainGrid()
: RigGridBase( this )
@ -740,7 +742,10 @@ void RigMainGrid::buildCellSearchTree()
#pragma omp parallel
{
size_t threadCellCount = std::ceil( cellCount / static_cast<double>( omp_get_num_threads() ) );
size_t threadCellCount = cellCount;
#ifdef USE_OPENMP
threadCellCount = std::ceil( cellCount / static_cast<double>( omp_get_num_threads() ) );
#endif
std::vector<size_t> threadIndicesForBoundingBoxes;
std::vector<cvf::BoundingBox> threadBoundingBoxes;

View File

@ -39,7 +39,7 @@ if (RESINSIGHT_USE_OPENMP)
if(OPENMP_FOUND)
message(STATUS "Enabling OpenMP support")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -DUSE_OPENMP")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
else()
message(STATUS "Disabling OpenMP support")