Skip to content
Snippets Groups Projects
Commit 31900f16 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

Optimized conditional OpenMP traversing in 2D and 3D grid traversers - cells only.

parent a5d90a72
No related branches found
No related tags found
1 merge request!20Traversers optimizations
...@@ -58,30 +58,35 @@ processEntities( ...@@ -58,30 +58,35 @@ processEntities(
if( Devices::Host::isOMPEnabled() && end.x() - begin.x() > 512 ) if( Devices::Host::isOMPEnabled() && end.x() - begin.x() > 512 )
{ {
#pragma omp parallel firstprivate( begin, end ) #pragma omp parallel firstprivate( begin, end )
GridEntity entity( *gridPointer );
#pragma omp for
for( IndexType x = begin.x(); x <= end.x(); x ++ )
{ {
entity.getCoordinates().x() = x; GridEntity entity( *gridPointer );
entity.refresh(); #pragma omp for
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity ); // TODO: g++ 5.5 crashes when coding this loop without auxiliary x as bellow
for( IndexType x = begin.x(); x <= end.x(); x++ )
{
entity.getCoordinates().x() = x;
entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
}
} }
} }
else else
{ {
GridEntity entity( *gridPointer ); GridEntity entity( *gridPointer );
for( IndexType x = begin.x(); x <= end.x(); x ++ ) for( entity.getCoordinates().x() = begin.x();
entity.getCoordinates().x() <= end.x();
entity.getCoordinates().x() ++ )
{ {
entity.getCoordinates().x() = x;
entity.refresh(); entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity ); EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
} }
} }
#else #else
GridEntity entity( *gridPointer ); GridEntity entity( *gridPointer );
for( IndexType x = begin.x(); x <= end.x(); x ++ ) for( entity.getCoordinates().x() = begin.x();
entity.getCoordinates().x() <= end.x();
entity.getCoordinates().x() ++ )
{ {
entity.getCoordinates().x() = x;
entity.refresh(); entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity ); EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
} }
...@@ -332,35 +337,51 @@ processEntities( ...@@ -332,35 +337,51 @@ processEntities(
} }
else else
{ {
//TODO: This does not work with gcc-5.4 and older, should work at gcc 6.x
/*#pragma omp parallel for firstprivate( entity, begin, end ) if( Devices::Host::isOMPEnabled() )
for( entity.getCoordinates().y() = begin.y();
entity.getCoordinates().y() <= end.y();
entity.getCoordinates().y() ++ )
for( entity.getCoordinates().x() = begin.x();
entity.getCoordinates().x() <= end.x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
}*/
#ifdef HAVE_OPENMP #ifdef HAVE_OPENMP
#pragma omp parallel firstprivate( begin, end ) if( Devices::Host::isOMPEnabled() ) if( Devices::Host::isOMPEnabled() )
#endif
{ {
GridEntity entity( *gridPointer, begin, gridEntityParameters... ); #pragma omp parallel firstprivate( begin, end )
#ifdef HAVE_OPENMP {
#pragma omp for GridEntity entity( *gridPointer );
#endif #pragma omp for
for( IndexType y = begin.y(); y <= end.y(); y ++ ) // TODO: g++ 5.5 crashes when coding this loop without auxiliary x and y as bellow
for( IndexType x = begin.x(); x <= end.x(); x ++ ) for( IndexType y = begin.y(); y <= end.y(); y ++ )
{ for( IndexType x = begin.x(); x <= end.x(); x ++ )
entity.getCoordinates().x() = x; {
entity.getCoordinates().y() = y; entity.getCoordinates().x() = x;
entity.refresh(); entity.getCoordinates().y() = y;
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity ); entity.refresh();
} EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
}
}
}
else
{
GridEntity entity( *gridPointer );
for( entity.getCoordinates().y() = begin.y();
entity.getCoordinates().y() <= end.y();
entity.getCoordinates().y() ++ )
for( entity.getCoordinates().x() = begin.x();
entity.getCoordinates().x() <= end.x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
}
} }
#else
GridEntity entity( *gridPointer );
for( entity.getCoordinates().y() = begin.y();
entity.getCoordinates().y() <= end.y();
entity.getCoordinates().y() ++ )
for( entity.getCoordinates().x() = begin.x();
entity.getCoordinates().x() <= end.x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
}
#endif
} }
} }
...@@ -426,7 +447,7 @@ GridTraverser2DBoundaryAlongX( ...@@ -426,7 +447,7 @@ GridTraverser2DBoundaryAlongX(
typename GridType::CoordinatesType coordinates; typename GridType::CoordinatesType coordinates;
coordinates.x() = beginX + Devices::Cuda::getGlobalThreadIdx_x( gridIdx ); coordinates.x() = beginX + Devices::Cuda::getGlobalThreadIdx_x( gridIdx );
coordinates.y() = fixedY; coordinates.y() = fixedY;
if( coordinates.x() <= endX ) if( coordinates.x() <= endX )
{ {
...@@ -436,7 +457,7 @@ GridTraverser2DBoundaryAlongX( ...@@ -436,7 +457,7 @@ GridTraverser2DBoundaryAlongX(
( *grid, ( *grid,
userData, userData,
entity ); entity );
} }
} }
// Boundary traverser using streams // Boundary traverser using streams
...@@ -648,7 +669,7 @@ processEntities( ...@@ -648,7 +669,7 @@ processEntities(
if( processOnlyBoundaryEntities && if( processOnlyBoundaryEntities &&
( GridEntity::getEntityDimension() == 2 || GridEntity::getEntityDimension() == 0 ) ) ( GridEntity::getEntityDimension() == 2 || GridEntity::getEntityDimension() == 0 ) )
{ {
#ifdef GRID_TRAVERSER_USE_STREAMS #ifdef GRID_TRAVERSER_USE_STREAMS
dim3 cudaBlockSize( 256 ); dim3 cudaBlockSize( 256 );
dim3 cudaBlocksCountAlongX, cudaGridsCountAlongX, dim3 cudaBlocksCountAlongX, cudaGridsCountAlongX,
cudaBlocksCountAlongY, cudaGridsCountAlongY; cudaBlocksCountAlongY, cudaGridsCountAlongY;
...@@ -960,8 +981,45 @@ processEntities( ...@@ -960,8 +981,45 @@ processEntities(
} }
else else
{ {
// TODO: this does not work with gcc-5.4 and older, should work at gcc 6.x #ifdef HAVE_OPENMP
/*#pragma omp parallel for firstprivate( entity, begin, end ) if( Devices::Host::isOMPEnabled() ) if( Devices::Host::isOMPEnabled() )
{
#pragma omp parallel firstprivate( begin, end )
{
GridEntity entity( *gridPointer );
#pragma omp for
// TODO: g++ 5.5 crashes when coding this loop without auxiliary x and y as bellow
for( IndexType z = begin.z(); z <= end.z(); z ++ )
for( IndexType y = begin.y(); y <= end.y(); y ++ )
for( IndexType x = begin.x(); x <= end.x(); x ++ )
{
entity.getCoordinates().x() = x;
entity.getCoordinates().y() = y;
entity.getCoordinates().z() = z;
entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
}
}
}
else
{
GridEntity entity( *gridPointer );
for( entity.getCoordinates().z() = begin.z();
entity.getCoordinates().z() <= end.z();
entity.getCoordinates().z() ++ )
for( entity.getCoordinates().y() = begin.y();
entity.getCoordinates().y() <= end.y();
entity.getCoordinates().y() ++ )
for( entity.getCoordinates().x() = begin.x();
entity.getCoordinates().x() <= end.x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
}
}
#else
GridEntity entity( *gridPointer );
for( entity.getCoordinates().z() = begin.z(); for( entity.getCoordinates().z() = begin.z();
entity.getCoordinates().z() <= end.z(); entity.getCoordinates().z() <= end.z();
entity.getCoordinates().z() ++ ) entity.getCoordinates().z() ++ )
...@@ -971,29 +1029,11 @@ processEntities( ...@@ -971,29 +1029,11 @@ processEntities(
for( entity.getCoordinates().x() = begin.x(); for( entity.getCoordinates().x() = begin.x();
entity.getCoordinates().x() <= end.x(); entity.getCoordinates().x() <= end.x();
entity.getCoordinates().x() ++ ) entity.getCoordinates().x() ++ )
{
entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
}*/
#ifdef HAVE_OPENMP
#pragma omp parallel firstprivate( begin, end ) if( Devices::Host::isOMPEnabled() )
#endif
{
GridEntity entity( *gridPointer, begin, gridEntityParameters... );
#ifdef HAVE_OPENMP
#pragma omp for
#endif
for( IndexType z = begin.z(); z <= end.z(); z ++ )
for( IndexType y = begin.y(); y <= end.y(); y ++ )
for( IndexType x = begin.x(); x <= end.x(); x ++ )
{ {
entity.getCoordinates().x() = x;
entity.getCoordinates().y() = y;
entity.getCoordinates().z() = z;
entity.refresh(); entity.refresh();
EntitiesProcessor::processEntity( entity.getMesh(), userData, entity ); EntitiesProcessor::processEntity( entity.getMesh(), userData, entity );
} }
} #endif
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment