12#ifndef BELFEM_GRAPHTOOLS_HPP
13#define BELFEM_GRAPHTOOLS_HPP
31 template<
typename T >
39 for(
Vertex * tVertex : aGraph )
41 tVertex->set_index(
static_cast< index_t> ( aPermutation( tCount++ ) ) );
50 for (
Vertex * tVertex : aGraph )
53 for (
uint k=0; k<tVertex->number_of_vertices(); ++k )
55 tBitset.
set( tVertex->vertex( k )->index() );
57 if ( tVertex->is_flagged() )
59 tBitset.
set( tVertex->index() );
61 tBitset.
where( tIndices );
62 tVertex->reset_vertex_container();
63 tVertex->init_vertex_container( tIndices.
size() );
66 tVertex->insert_vertex( aGraph( k ) );
73 template<
typename T >
80 T tNumVertices =
static_cast< T
>( aGraph.
size() );
85 for(
Vertex * tVertex : aGraph )
87 tVertex->set_index( tCount++ );
98 for(
Vertex * tVertex : aGraph )
100 for(
uint k = 0; k < tVertex->number_of_vertices(); ++k )
102 if( tVertex->vertex( k ) != tVertex )
110 aVertices.
set_size( tNumVertices + 1, 0 );
124 for(
Vertex * tVertex : aGraph )
126 aVertices( tVertex->index() ) = tCount;
128 for(
uint k = 0; k < tVertex->number_of_vertices(); ++k )
130 if( tVertex->vertex( k ) != tVertex )
132 aEdges( tCount++ ) =
static_cast< T
>( tVertex->vertex( k )->index() );
136 aVertices( tNumVertices ) = tCount;
151 BELFEM_ASSERT( aCommSize > 0,
"block_distribution: comm size %d", (
int ) aCommSize );
156 const index_t tSplit = tP - ( tN % tP );
159 for (
index_t p = 0; p < tSplit; ++p )
161 for (
index_t k = 0; k < tDiv; ++k )
163 aGraph( tCount++ )->set_owner(
static_cast< proc_t >( p ) );
166 for (
index_t p = tSplit; p < tP; ++p )
168 for (
index_t k = 0; k < tDiv + 1; ++k )
170 aGraph( tCount++ )->set_owner(
static_cast< proc_t >( p ) );
173 BELFEM_ASSERT( tCount == tN,
"block_distribution: assigned %lu of %lu vertices",
174 (
long unsigned int ) tCount, (
long unsigned int ) tN );
177 template <
typename T >
190 for (
Vertex * tVertex : aGraph )
196 proc_t tOwner = tVertex->owner();
197 if ( tOwner == tCommSize || tOwner ==
gNoOwner )
200 tVertex->set_owner( tOwner );
203 "Vertex %lu has owner %d outside [0, %d)",
204 (
long unsigned int ) tVertex->id(), (
int ) tOwner, (
int ) tCommSize );
212 aDistribution( p+1 ) = aDistribution( p ) + tCount( p );
218 for (
Vertex * tVertex : aGraph )
220 tGraph( aDistribution( tVertex->owner() ) + tCount( tVertex->owner() )++ ) = tVertex;
222 aGraph = std::move( tGraph );
225 for (
Vertex * tVertex : aGraph )
227 for (
uint k = 0; k < tVertex->number_of_vertices(); ++k )
229 tVertex->vertex( k )->set_index(
gNoIndex );
237 for (
Vertex * tVertex : aGraph )
239 tVertex->set_index( tIndex++ );
243 for (
Vertex * tVertex : aGraph )
245 for (
uint k = 0; k < tVertex->number_of_vertices(); ++k )
248 "Vertex index of %lu (owner %u) is not set",
249 (
long unsigned int ) tVertex->vertex( k )->id() ,
250 (
uint ) tVertex->vertex( k)->owner() );
258 for (
Vertex * tVertex : aGraph )
260 for (
uint k = 0; k < tVertex->number_of_vertices(); ++k )
262 if ( tVertex->vertex( k ) != tVertex )
264 ++tNNZ( tVertex->owner() );
269 aVertices.set_size( tCommSize, {} );
270 aEdges.set_size( tCommSize, {} );
272 for (
proc_t p = 0; p < tCommSize; ++p )
274 aVertices( p ).set_size( tCount( p ) + 1 );
282 aEdges( p ).set_size( tNNZ( p ) );
286 aEdges( p ).set_size( 1, 0 );
293 for(
Vertex * tVertex : aGraph )
295 proc_t tOwner = tVertex->owner();
296 aVertices( tOwner )( tXcount( tOwner )++ ) = tAcount( tOwner );
298 for (
uint k=0; k<tVertex->number_of_vertices(); ++k )
300 if ( tVertex->vertex( k ) != tVertex )
302 aEdges( tOwner )( tAcount( tOwner )++ ) =
static_cast< T
>( tVertex->vertex( k )->index() );
307 BELFEM_ASSERT( tAcount == tNNZ,
"The number of non-zeros in the adjacency matrix is not correct" );
309 for (
proc_t p = 0; p < tCommSize; ++p )
311 aVertices( p )( tCount( p ) ) = tNNZ( p );
#define BELFEM_ERROR(aCheck,...)
Definition assert.hpp:264
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
size_t size() const
return the size of the Cell
Definition cl_Cell.hpp:181
void clear()
clear the memory
Definition cl_Cell.hpp:240
Runtime-sized bitset; one bit per flag, packed into 64-bit words.
Definition cl_DynamicBitset.hpp:33
void where(Cell< index_t > &aBits, const bool aAssumeSparse=true) const
Definition cl_DynamicBitset.hpp:704
void reset(const index_t aPos)
Resets (clears) the bit at the given position.
Definition cl_DynamicBitset.hpp:546
void set(const index_t aPos)
Sets the bit at the given position to 1.
Definition cl_DynamicBitset.hpp:524
Column vector.
Definition cl_BZ_Vector.hpp:41
void fill(const T &aValue)
write value into all entries of the vector
Definition cl_AR_Vector.hpp:226
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_AR_Vector.hpp:237
Graph node with an adjacency list; the vertex type the graph algorithms operate on.
Definition cl_Graph_Vertex.hpp:32
Definition cl_Graph_Vertex.cpp:21
void apply_graph_permutation(Graph &aGraph, const Vector< T > &aPermutation)
Definition graphtools.hpp:33
void block_distribution(Graph &aGraph, const proc_t aCommSize)
assign owners to an ownerless graph in contiguous blocks of graph order: the first aCommSize - ( N mo...
Definition graphtools.hpp:149
void build_graph_adjacency(Graph &aGraph, Vector< T > &aVertices, Vector< T > &aEdges)
Definition graphtools.hpp:75
void build_pargraph_adjacency(Graph &aGraph, Vector< T > &aDistribution, Cell< Vector< T > > &aVertices, Cell< Vector< T > > &aEdges)
Definition graphtools.hpp:179
void sort(Graph &aGraph)
Definition fn_Graph_sort.cpp:19
USER GUIDES:
Definition cl_Capacitor.cpp:16
proc_t comm_rank()
Returns the rank of the current process in the communicator.
Definition commtools.cpp:30
Cell< graph::Vertex * > Graph
Definition cl_Graph_Vertex.hpp:329
unsigned int uint
Definition typedefs.hpp:30
int proc_t
Definition commtypes.hpp:29
constexpr index_t gNoIndex
Definition typedefs.hpp:57
struct belfem::OpVertexIndex opVertexIndex
constexpr proc_t gNoOwner
Definition typedefs.hpp:59
uint32_t index_t
Definition typedefs.hpp:52
proc_t comm_size()
Returns the number of processes in the communicator.
Definition commtools.cpp:22