Commit 2b8405bb authored by franjo_j@hotmail.com's avatar franjo_j@hotmail.com
Browse files

Disabled openmp support because it does not work on Windows platform


git-svn-id: https://pl5.projectlocker.com/igui/meshGeneration/svn@9 fdcce57e-7e00-11e2-b579-49867b4cea03
parent d4f6cf5a
#!/bin/sh
# Compile mesh library
cd meshLibrary
wmake libso
cd ..
wmake libso meshLibrary
# Compile cartesianMesh
#cd executables/cartesianMesh
#wmake
#cd ../..
# Compile executables
wmake all executables
# Compile dualMesh
#cd executables/dualMesh
#wmake
#cd ../..
# Compile utilities
wmake all utilities
......@@ -52,11 +52,13 @@ void tetMeshExtractorOctree::createPoints()
const LongList<point>& tetPoints = tetCreator_.tetPoints();
points.setSize ( tetPoints.size() );
points.setSize(tetPoints.size());
# pragma omp parallel for
forAll ( tetPoints, pointI )
points[pointI] = tetPoints[pointI];
# ifdef USE_OMP
# pragma omp parallel for
# endif
forAll(tetPoints, pointI)
points[pointI] = tetPoints[pointI];
}
void tetMeshExtractorOctree::createPolyMesh()
......@@ -71,41 +73,47 @@ void tetMeshExtractorOctree::createPolyMesh()
const LongList<partTet>& tets = tetCreator_.tets();
VRWGraph pTets;
pTets.reverseAddressing ( mesh_.points().size(), tets );
pTets.reverseAddressing(mesh_.points().size(), tets);
//- set the number of cells
cells.setSize ( tets.size() );
cells.setSize(tets.size());
//- all faces of tetrahedral cells
faces.setSize ( 4*tets.size() );
boolList removeFace ( faces.size() );
faces.setSize(4*tets.size());
boolList removeFace(faces.size());
# pragma omp parallel if( tets.size() > 1000 )
# ifdef USE_OMP
# pragma omp parallel if( tets.size() > 1000 )
# endif
{
//- set face labels
# pragma omp for
forAll ( removeFace, faceI )
removeFace[faceI] = false;
# ifdef USE_OMP
# pragma omp for
# endif
forAll(removeFace, faceI)
removeFace[faceI] = false;
//- set sizes of cells and create all faces
# pragma omp for schedule(dynamic, 20)
forAll ( tets, elmtI )
# ifdef USE_OMP
# pragma omp for schedule(dynamic, 20)
# endif
forAll(tets, elmtI)
{
cells[elmtI].setSize ( 4 );
cells[elmtI].setSize(4);
const partTet& elmt = tets[elmtI];
tessellationElement telmt ( elmt[0], elmt[1], elmt[2], elmt[3] );
tessellationElement telmt(elmt[0], elmt[1], elmt[2], elmt[3]);
label faceI = 4 * elmtI;
for ( label i=0;i<4;++i )
for(label i=0;i<4;++i)
{
cells[elmtI][i] = faceI;
face& f = faces[faceI];
f.setSize ( 3 );
const triFace tf = telmt.face ( i );
const triFace tf = telmt.face(i);
f[0] = tf[0];
f[1] = tf[2];
f[2] = tf[1];
......@@ -114,38 +122,42 @@ void tetMeshExtractorOctree::createPolyMesh()
}
}
# pragma omp barrier
# ifdef USE_OMP
# pragma omp barrier
# endif
//- find duplicate faces
# pragma omp for schedule(dynamic, 20)
forAll ( cells, cellI )
# ifdef USE_OMP
# pragma omp for schedule(dynamic, 20)
# endif
forAll(cells, cellI)
{
cell& c = cells[cellI];
forAll ( c, fI )
forAll(c, fI)
{
const face& f = faces[c[fI]];
const label pointI = f[0];
forAllRow ( pTets, pointI, ptI )
forAllRow(pTets, pointI, ptI)
{
//- do not check cells with greater labels
//- they cannot be face owners
if ( pTets ( pointI, ptI ) >= cellI )
if( pTets(pointI, ptI) >= cellI )
continue;
const cell& otherTet = cells[pTets ( pointI, ptI ) ];
const cell& otherTet = cells[pTets(pointI, ptI)];
//- check faces created from a tet
forAll ( otherTet, ofI )
forAll(otherTet, ofI)
{
//- do not compare faces with greater labels
//- they shall not be removed here
if ( otherTet[ofI] >= c[fI] )
if( otherTet[ofI] >= c[fI] )
continue;
//- check if the faces are equal
if ( f == faces[otherTet[ofI]] )
if( f == faces[otherTet[ofI]] )
{
removeFace[c[fI]] = true;
c[fI] = otherTet[ofI];
......@@ -157,15 +169,15 @@ void tetMeshExtractorOctree::createPolyMesh()
}
//- remove duplicate faces
label nFaces ( 0 );
labelListPMG newFaceLabel ( faces.size(), -1 );
label nFaces(0);
labelListPMG newFaceLabel(faces.size(), -1);
forAll ( faces, faceI )
forAll(faces, faceI)
{
if ( !removeFace[faceI] )
if( !removeFace[faceI] )
{
if ( nFaces < faceI )
faces[nFaces].transfer ( faces[faceI] );
if( nFaces < faceI )
faces[nFaces].transfer(faces[faceI]);
newFaceLabel[faceI] = nFaces;
++nFaces;
......@@ -173,24 +185,26 @@ void tetMeshExtractorOctree::createPolyMesh()
}
//- set the size of faces
faces.setSize ( nFaces );
faces.setSize(nFaces);
//- change cells
# pragma omp for schedule(dynamic, 40)
forAll ( cells, cellI )
# ifdef USE_OMP
# pragma omp for schedule(dynamic, 40)
# endif
forAll(cells, cellI)
{
cell& c = cells[cellI];
DynList<label> newC;
forAll ( c, fI )
forAll(c, fI)
{
if ( newFaceLabel[c[fI]] != -1 )
newC.append ( newFaceLabel[c[fI]] );
if( newFaceLabel[c[fI]] != -1 )
newC.append(newFaceLabel[c[fI]]);
}
c.setSize ( newC.size() );
forAll ( c, fI )
c.setSize(newC.size());
forAll(c, fI)
c[fI] = newC[fI];
}
}
......@@ -204,17 +218,15 @@ tetMeshExtractorOctree::tetMeshExtractorOctree
const IOdictionary& meshDict,
polyMeshGen& mesh
)
:
tetCreator_ ( octree, meshDict ),
mesh_ ( mesh )
{
}
:
tetCreator_(octree, meshDict),
mesh_(mesh)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
tetMeshExtractorOctree::~tetMeshExtractorOctree()
{
}
{}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -228,8 +240,8 @@ void tetMeshExtractorOctree::createMesh()
//- create the mesh
createPolyMesh();
polyMeshGenModifier ( mesh_ ).reorderBoundaryFaces();
polyMeshGenModifier ( mesh_ ).removeUnusedVertices();
polyMeshGenModifier(mesh_).reorderBoundaryFaces();
polyMeshGenModifier(mesh_).removeUnusedVertices();
Info << "Mesh has :" << nl
<< mesh_.points().size() << " vertices " << nl
......
......@@ -109,7 +109,9 @@ void extrudeLayer::createDuplicateFrontFaces(const LongList<labelPair>& front)
extrudedFaces_.setSize(counter);
pairOrientation_.setSize(counter);
# ifdef USE_OMP
# pragma omp parallel for if( faceInFront.size() > 100 ) schedule(guided)
# endif
forAll(faceInFront, faceI)
{
if( faceInFront[faceI] < 0 )
......@@ -173,7 +175,9 @@ void extrudeLayer::createDuplicateFrontFaces(const LongList<labelPair>& front)
}
//- renumber the cells
# ifdef USE_OMP
# pragma omp parallel for if( faceInFront.size() > 100 ) schedule(guided)
# endif
forAll(faceInFront, faceI)
{
if( faceInFront[faceI] < 0 )
......@@ -215,7 +219,9 @@ void extrudeLayer::createNewVertices()
//- find the points in the marked front
List<direction> frontPoints(points.size(), NONE);
# ifdef USE_OMP
# pragma omp parallel for if( points.size() > 1000 ) schedule(guided)
# endif
forAll(extrudedFaces_, efI)
{
const face& f = faces[extrudedFaces_[efI].first()];
......@@ -258,8 +264,10 @@ void extrudeLayer::createNewVertices()
LongList<label> receivedData;
help::exchangeMap(exchangeData, receivedData);
# ifdef USE_OMP
# pragma omp parallel for if( receivedData.size() > 1000 ) \
schedule(guided)
# endif
forAll(receivedData, i)
{
frontPoints[globalToLocal[receivedData[i]]] =
......@@ -836,10 +844,14 @@ void extrudeLayer::movePoints()
}
}
# ifdef USE_OMP
# pragma omp parallel if( displacements.size() > 100 )
# endif
{
//- find displacement vectors
# ifdef USE_OMP
# pragma omp for schedule(guided)
# endif
forAll(displacements, pI)
{
if( pointAtProcBnd[pI] )
......@@ -889,9 +901,13 @@ void extrudeLayer::movePoints()
displacements[pI] = normal * thickness;
}
# ifdef USE_OMP
# pragma omp barrier
# endif
# ifdef USE_OMP
# pragma omp for schedule(guided)
# endif
forAll(displacements, pI)
points[nOrigPoints_+pI] += displacements[pI];
}
......
......@@ -27,13 +27,15 @@ License
#include "VRWGraphSMPModifier.H"
#include "labelPair.H"
# ifdef USE_OMP
#include <omp.h>
# endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
VRWGraphSMPModifier::VRWGraphSMPModifier(VRWGraph& graph)
......@@ -43,7 +45,7 @@ VRWGraphSMPModifier::VRWGraphSMPModifier(VRWGraph& graph)
VRWGraphSMPModifier::~VRWGraphSMPModifier()
{}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void VRWGraphSMPModifier::mergeGraphs(const List<VRWGraph>& graphParts)
......@@ -58,25 +60,29 @@ void VRWGraphSMPModifier::mergeGraphs(const List<VRWGraph>& graphParts)
"inline void Foam::VRWGraph::mergeGraphs(const List<VRWGraph>&)"
) << "Cannot merge graphs" << abort(FatalError);
}
//- find the number of elements in each row
labelListPMG nElmtsInRow(nRows);
# ifdef USE_OMP
# pragma omp parallel for schedule(static, 1)
# endif
for(label rowI=0;rowI<nRows;++rowI)
{
label sum(0);
for(label i=0;i<nGraphs;++i)
sum += graphParts[i].sizeOfRow(rowI);
nElmtsInRow[rowI] = sum;
}
//- set the size of graph
setSizeAndRowSize(nElmtsInRow);
//- Finally, assemble the merged graph
# ifdef USE_OMP
# pragma omp parallel for schedule(static, 1)
# endif
for(label rowI=0;rowI<nRows;++rowI)
{
forAll(graphParts, i)
......@@ -87,30 +93,42 @@ void VRWGraphSMPModifier::mergeGraphs(const List<VRWGraph>& graphParts)
}
}
}
void VRWGraphSMPModifier::reverseAddressing(const VRWGraph& origGraph)
{
graph_.setSize(0);
labelListPMG nAppearances;
# ifdef USE_OMP
label nThreads = 3 * omp_get_num_procs();
if( origGraph.size() < 1000 )
nThreads = 1;
# else
const label nThreads(1);
# endif
label minRow(INT_MAX), maxRow(-1);
List<List<LongList<labelPair> > > dataForOtherThreads(nThreads);
# ifdef USE_OMP
# pragma omp parallel num_threads(nThreads)
# endif
{
# ifdef USE_OMP
const label threadI = omp_get_thread_num();
# else
const label threadI(0);
# endif
List<LongList<labelPair> >& dot = dataForOtherThreads[threadI];
dot.setSize(nThreads);
//- find min and max entry in the graph
//- they are used for assigning ranges of values local for each process
label localMinRow(INT_MAX), localMaxRow(-1);
# ifdef USE_OMP
# pragma omp for schedule(static)
# endif
forAll(origGraph, rowI)
{
forAllRow(origGraph, rowI, i)
......@@ -120,40 +138,50 @@ void VRWGraphSMPModifier::reverseAddressing(const VRWGraph& origGraph)
localMinRow = Foam::min(localMinRow, entryI);
}
}
++localMaxRow;
# ifdef USE_OMP
# pragma omp critical
# endif
{
minRow = Foam::min(minRow, localMinRow);
maxRow = Foam::max(maxRow, localMaxRow);
nAppearances.setSize(maxRow);
}
# ifdef USE_OMP
# pragma omp barrier
# endif
//- initialise appearances
# ifdef USE_OMP
# pragma omp for schedule(static)
# endif
for(label i=0;i<maxRow;++i)
nAppearances[i] = 0;
# ifdef USE_OMP
# pragma omp barrier
# endif
const label range = (maxRow - minRow) / nThreads + 1;
const label localMin = minRow + threadI * range;
const label localMax = Foam::min(localMin + range, maxRow);
//- find the number of appearances of each element in the original graph
# ifdef USE_OMP
# pragma omp for schedule(static)
# endif
forAll(origGraph, rowI)
{
forAllRow(origGraph, rowI, j)
{
const label entryI = origGraph(rowI, j);
const label threadNo = (entryI - minRow) / range;
if( threadNo == threadI )
{
++nAppearances[entryI];
......@@ -164,39 +192,47 @@ void VRWGraphSMPModifier::reverseAddressing(const VRWGraph& origGraph)
}
}
}
# ifdef USE_OMP
# pragma omp barrier
# endif
//- count the appearances which are not local to the processor
for(label i=0;i<nThreads;++i)
{
const LongList<labelPair>& data =
dataForOtherThreads[i][threadI];
forAll(data, j)
++nAppearances[data[j].first()];
}
# ifdef USE_OMP
# pragma omp barrier
# endif
//- allocate graph
# ifdef USE_OMP
# pragma omp master
# endif
setSizeAndRowSize(nAppearances);
# ifdef USE_OMP
# pragma omp barrier
# endif
for(label i=localMin;i<localMax;++i)
{
nAppearances[i] = 0;
}
//- start filling reverse addressing graph
//- update data from processors with smaller labels
for(label i=0;i<threadI;++i)
{
const LongList<labelPair>& data =
dataForOtherThreads[i][threadI];
forAll(data, j)
{
const label entryI = data[j].first();
......@@ -205,7 +241,9 @@ void VRWGraphSMPModifier::reverseAddressing(const VRWGraph& origGraph)
}
//- update data local to the processor
# ifdef USE_OMP
# pragma omp for schedule(static)
# endif
forAll(origGraph, rowI)
{
forAllRow(origGraph, rowI, j)
......@@ -216,13 +254,13 @@ void VRWGraphSMPModifier::reverseAddressing(const VRWGraph& origGraph)
graph_(entryI, nAppearances[entryI]++) = rowI;
}
}
//- update data from the processors with higher labels
for(label i=threadI+1;i<nThreads;++i)
{
const LongList<labelPair>& data =
dataForOtherThreads[i][threadI];
forAll(data, j)
{
const label entryI = data[j].first();
......@@ -234,54 +272,70 @@ void VRWGraphSMPModifier::reverseAddressing(const VRWGraph& origGraph)
void VRWGraphSMPModifier::optimizeMemoryUsage()
{
# ifdef USE_OMP
label nThreads = 3 * omp_get_num_procs();
if( graph_.size() < 1000 )
nThreads = 1;
# else
const label nThreads(1);
# endif
DynList<label> nRows, nEntries;
nRows.setSize(nThreads);
nEntries.setSize(nThreads);