Commit 49a84143 authored by Franjo's avatar Franjo
Browse files

Modified VRWGraph

parent 78b851c0
......@@ -47,41 +47,44 @@ SourceFiles
namespace Foam
{
class VRWGraphModifier;
class rowElement
{
// Private data
label start_;
//- starting element of the row
long long start_;
//- number of elements in the row
label size_;
public:
inline rowElement()
:
start_(),
size_()
{}
inline rowElement(const label i, const label j)
inline rowElement(const long long i, const label j)
:
start_(i),
size_(j)
{}
inline ~rowElement()
{}
inline label start() const
inline long long start() const
{
return start_;
}
inline label& start()
inline long long& start()
{
return start_;
}
inline label size() const
{
return size_;
......@@ -99,9 +102,9 @@ class rowElement
class VRWGraph
{
// Private data
//- list containing the data
//- list containing data
labelLongList data_;
//- number of rows
LongList<rowElement> rows_;
......@@ -117,9 +120,9 @@ class VRWGraph
FREEENTRY=-11,
FREESTART=-12
};
public:
// Friend classes
friend class VRWGraphSMPModifier;
......@@ -131,7 +134,7 @@ public:
//- Construct given number of rows
explicit inline VRWGraph(const label size);
//- Construct given number of rows and row size
explicit inline VRWGraph
(
......@@ -160,7 +163,7 @@ public:
//- Returns the number of rows
inline label size() const;
//- Returns the number of elements in the given row
inline label sizeOfRow(const label rowI) const;
......@@ -168,7 +171,7 @@ public:
//- Reset the number of rows
inline void setSize(const label);
//- Reset the number of rows. The second argument specifies
//- the reserved column width
inline void setSizeAndColumnWidth
......@@ -176,11 +179,11 @@ public:
const label newNumRows,
const label rcWidth
);
//- Set the number of rows and the size of each row
template<class ListType>
inline void setSizeAndRowSize(const ListType&);
//- Reset the size of the given row
inline void setRowSize(const label rowI, const label newSize);
......@@ -192,21 +195,21 @@ public:
//- Append a list as a row at the end of the graph
template<class ListType>
inline void appendList(const ListType& l);
//- Append an element to the given row
inline void append(const label rowI, const label);
//- Append an element to the given row if it does not exist there
inline void appendIfNotIn(const label rowI, const label);
//- Set row with the list
template<class ListType>
inline void setRow(const label rowI, const ListType& l);
//- merge graphs with the identical number of rows
//- into a single one. Use for SMP parallelisation
inline void mergeGraphs(const List<VRWGraph>& graphParts);
//- set the graph to the reverse of the original graph.
//- the rows of such graph store the rows which contain the elements
//- of the original graph
......@@ -216,33 +219,33 @@ public:
const label nRows,
const GraphType& origGraph
);
template<class GraphType>
inline void reverseAddressing(const GraphType& origGraph);
inline void reverseAddressing
(
const label nRows,
const VRWGraph& origGraph
);
inline void reverseAddressing(const VRWGraph& origGraph);
//- optimize memory usage
// this should be used once the graph will not be resized any more
void optimizeMemoryUsage();
//- check if the element is in the given row (takes linear time)
inline bool contains(const label rowI, const label e) const;
inline label containsAtPosition(const label rowI, const label e) const;
//- get and set operators
inline label operator()(const label i, const label j) const;
inline label& operator()(const label i, const label j);
inline constRow operator[](const label i) const;
inline row operator[](const label i);
//- Assignment operator
inline void operator=(const VRWGraph&);
......
......@@ -31,18 +31,18 @@ inline void Foam::VRWGraph::checkIndex(const label i, const label j) const
(
"void Foam::VRWGraph<T,width>::"
"checkIndex(const label i, const label j) const"
) << "Row index " << Foam::label(i)
<< " is not in range " << Foam::label(0)
) << "Row index " << i
<< " is not in range " << 0
<< " and " << rows_.size() << abort(FatalError);
}
if( (j < 0) || (j >= rows_[i].size()) )
FatalErrorIn
(
"void Foam::VRWGraph<T,width>::"
"checkIndex(label const i) const"
) << "Column index " << Foam::label(j)
<< " is not in range " << Foam::label(0)
"checkIndex(label const, const label) const"
) << "Column index " << j
<< " is not in range " << 0
<< " and " << rows_[i].size() << abort(FatalError);
}
......@@ -53,8 +53,7 @@ inline Foam::VRWGraph::VRWGraph()
:
data_(),
rows_()
{
}
{}
//- Construct given size
inline Foam::VRWGraph::VRWGraph
......@@ -78,12 +77,12 @@ inline Foam::VRWGraph::VRWGraph
const label nColumnsInRow
)
:
data_(nRows * nColumnsInRow),
data_(static_cast<long long>(nRows) * nColumnsInRow),
rows_(nRows)
{
for(label rowI=0;rowI<nRows;++rowI)
{
rows_[rowI].start() = rowI*nColumnsInRow;
rows_[rowI].start() = static_cast<long long>(rowI) * nColumnsInRow;
rows_[rowI].size() = nColumnsInRow;
}
}
......@@ -95,12 +94,12 @@ inline Foam::VRWGraph::VRWGraph
const label t
)
:
data_(nRows * nColumnsInRow, t),
data_(static_cast<long long>(nRows) * nColumnsInRow, t),
rows_(nRows)
{
for(label rowI=0;rowI<nRows;++rowI)
{
rows_[rowI].start() = rowI*nColumnsInRow;
rows_[rowI].start() = static_cast<long long>(rowI) * nColumnsInRow;
rows_[rowI].size() = nColumnsInRow;
}
}
......@@ -112,12 +111,10 @@ inline Foam::VRWGraph::VRWGraph
:
data_(ol.data_),
rows_(ol.rows_)
{
}
{}
inline Foam::VRWGraph::~VRWGraph()
{
}
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -137,7 +134,7 @@ inline void Foam::VRWGraph::setSize(const label size)
if( size > rows_.size() )
{
rowElement rowInfo(INVALIDROW, NONE);
for(label i=rows_.size();i<size;++i)
rows_.append(rowInfo);
}
......@@ -161,18 +158,18 @@ void Foam::VRWGraph::setSizeAndColumnWidth
) << "This function should be used for empty graphs, only!"
<< exit(FatalError);
data_.setSize(newNumRows * rcWidth);
data_.setSize(static_cast<long long>(newNumRows) * rcWidth);
data_ = FREEENTRY;
rows_.setSize(newNumRows);
label start(0);
long long start(0);
for(label i=0;i<newNumRows;++i)
{
rows_[i].start() = start;
rows_[i].size() = 0;
data_[start] = FREESTART;
start += rcWidth;
}
}
......@@ -183,12 +180,12 @@ inline void Foam::VRWGraph::setSizeAndRowSize(const ListType& l)
//- set the size of graph rows
const label nRows = l.size();
rows_.setSize(nRows);
label start(0);
long long start(0);
for(label rowI=0;rowI<nRows;++rowI)
{
rows_[rowI].size() = l[rowI];
if( rows_[rowI].size() != NONE )
{
rows_[rowI].start() = start;
......@@ -197,10 +194,10 @@ inline void Foam::VRWGraph::setSizeAndRowSize(const ListType& l)
{
rows_[rowI].start() = INVALIDROW;
}
start += rows_[rowI].size();
}
data_.setSize(start);
}
......@@ -216,8 +213,8 @@ inline void Foam::VRWGraph::setRowSize(const label rowI, const label newSize)
<< " is not in range " << Foam::label(0)
<< " and " << rows_.size() << abort(FatalError);
# endif
const label start = rows_[rowI].start();
const long long start = rows_[rowI].start();
if( start == INVALIDROW )
{
if( newSize > 0 )
......@@ -232,10 +229,10 @@ inline void Foam::VRWGraph::setRowSize(const label rowI, const label newSize)
{
//- check if there is some unused space after the last element
bool foundUnused(true);
for(label i=rows_[rowI].size();i<newSize;++i)
{
const label j = start + i;
const long long j = start + i;
if(
(j >= data_.size()) ||
(data_[j] != FREEENTRY) ||
......@@ -246,7 +243,7 @@ inline void Foam::VRWGraph::setRowSize(const label rowI, const label newSize)
break;
}
}
if( foundUnused )
{
//- row can be extended without copying
......@@ -265,7 +262,7 @@ inline void Foam::VRWGraph::setRowSize(const label rowI, const label newSize)
for(label i=rows_[rowI].size();i<newSize;++i)
data_.append(NONE);
}
rows_[rowI].size() = newSize;
}
else if( newSize < rows_[rowI].size() )
......@@ -295,7 +292,7 @@ inline void Foam::VRWGraph::appendList
rows_.append(rowElement(INVALIDROW, 0));
return;
}
rowElement rowInfo(data_.size(), l.size());
const label size = l.size();
for(label elI=0;elI<size;++elI)
......@@ -315,10 +312,10 @@ inline void Foam::VRWGraph::append(const label rowI, const label el)
}
else
{
const label oldStart = re.start();
const long long oldStart = re.start();
const label oldSize = re.size();
++re.size();
if( oldStart + oldSize < data_.size() )
{
if(
......@@ -360,7 +357,7 @@ inline void Foam::VRWGraph::setRow
)
{
this->setRowSize(rowI, l.size());
const label start = rows_[rowI].start();
const long long start = rows_[rowI].start();
const label size = l.size();
for(label elI=0;elI<size;++elI)
data_[start+elI] = l[elI];
......@@ -378,7 +375,7 @@ inline void Foam::VRWGraph::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
labelLongList nElmtsInRow(nRows);
for(label rowI=0;rowI<nRows;++rowI)
......@@ -386,12 +383,12 @@ inline void Foam::VRWGraph::mergeGraphs(const List<VRWGraph>& graphParts)
label sum(0);
for(label i=0;i<nGraphs;++i)
sum += graphParts[i].sizeOfRow(rowI);
nElmtsInRow[rowI] = sum;
}
setSizeAndRowSize(nElmtsInRow);
//- Finally, assemble the merged graph
for(label rowI=0;rowI<nRows;++rowI)
{
......@@ -413,26 +410,26 @@ inline void Foam::VRWGraph::reverseAddressing
{
const label origSize = origGraph.size();
labelLongList nElmtsInRow(nRows);
for(label rowI=0;rowI<nRows;++rowI)
nElmtsInRow[rowI] = 0;
for(label rowI=0;rowI<origSize;++rowI)
{
const label rowSize = origGraph[rowI].size();
for(label i=0;i<rowSize;++i)
++nElmtsInRow[origGraph[rowI][i]];
}
setSizeAndRowSize(nElmtsInRow);
nElmtsInRow = 0;
//- finally fill in the data
for(label rowI=0;rowI<origSize;++rowI)
{
const label rowSize = origGraph[rowI].size();
for(label i=0;i<rowSize;++i)
{
const label el = origGraph[rowI][i];
......@@ -446,14 +443,14 @@ inline void Foam::VRWGraph::reverseAddressing(const GraphType& origGraph)
{
const label size = origGraph.size();
label maxValue(-1);
for(label rowI=0;rowI<size;++rowI)
{
const label rowSize = origGraph[rowI].size();
for(label i=0;i<rowSize;++i)
maxValue = Foam::max(maxValue, origGraph[rowI][i]);
}
++maxValue;
reverseAddressing(maxValue, origGraph);
}
......@@ -466,26 +463,26 @@ inline void Foam::VRWGraph::reverseAddressing
{
const label origSize = origGraph.size();
labelLongList nElmtsInRow(nRows);
for(label rowI=0;rowI<nRows;++rowI)
nElmtsInRow[rowI] = 0;
for(label rowI=0;rowI<origSize;++rowI)
{
const label rowSize = origGraph.sizeOfRow(rowI);
for(label i=0;i<rowSize;++i)
++nElmtsInRow[origGraph(rowI, i)];
}
setSizeAndRowSize(nElmtsInRow);
nElmtsInRow = 0;
//- finally fill in the data
for(label rowI=0;rowI<origSize;++rowI)
{
const label rowSize = origGraph.sizeOfRow(rowI);
for(label i=0;i<rowSize;++i)
{
const label el = origGraph(rowI, i);
......@@ -498,14 +495,14 @@ inline void Foam::VRWGraph::reverseAddressing(const VRWGraph& origGraph)
{
const label size = origGraph.size();
label maxValue(-1);
for(label rowI=0;rowI<size;++rowI)
{
const label rowSize = origGraph.sizeOfRow(rowI);
for(label i=0;i<rowSize;++i)
maxValue = Foam::max(maxValue, origGraph(rowI, i));
}
++maxValue;
reverseAddressing(maxValue, origGraph);
}
......@@ -516,15 +513,15 @@ inline bool Foam::VRWGraph::contains
const label e
) const
{
const label start = rows_[rowI].start();
const long long start = rows_[rowI].start();
if( start == INVALIDROW )
return false;
const label size = rows_[rowI].size();
for(register label i=0;i<size;++i)
if( data_[start+i] == e )
return true;
return false;
}
......@@ -534,15 +531,15 @@ inline Foam::label Foam::VRWGraph::containsAtPosition
const label e
) const
{
const label start = rows_[rowI].start();
const long long start = rows_[rowI].start();
if( start == INVALIDROW )
return -1;
const label size = rows_[rowI].size();
for(register label i=0;i<size;++i)
if( data_[start+i] == e )
return i;
return -1;
}
......@@ -557,7 +554,7 @@ inline Foam::label Foam::VRWGraph::operator()
#ifdef FULLDEBUG
checkIndex(i, j);
#endif
return data_[rows_[i].start() + j];
}
......@@ -570,7 +567,7 @@ inline Foam::label& Foam::VRWGraph::operator()
#ifdef FULLDEBUG
checkIndex(i, j);
#endif
return data_[rows_[i].start() + j];
}
......
......@@ -336,7 +336,7 @@ void VRWGraphSMPModifier::optimizeMemoryUsage()
# endif
//- find the starting position for each thread
label rowStart(0), entryStart(0);
long long rowStart(0), entryStart(0);
for(label i=0;i<threadI;++i)
{
rowStart += nRows[i];
......
......@@ -89,7 +89,7 @@ void VRWGraphSMPModifier::setSizeAndRowSize(const ListType& s)
# pragma omp barrier
# endif
label start(0);
long long start(0);
# ifdef USE_OMP
for(label i=0;i<omp_get_thread_num();++i)
start += procEntries[i];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment