Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coreComponents/common/MpiWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ int MpiWrapper::scatterv( TS const * const sendbuf,
#else
static_assert( std::is_same< TS, TR >::value,
"MpiWrapper::scatterv() for serial run requires send and receive buffers are of the same type" );
std::size_t const sendBufferSize = sendcounts * sizeof(TS);
std::size_t const sendBufferSize = sendcounts[0] * sizeof(TS);
std::size_t const recvBufferSize = recvcount * sizeof(TR);
GEOS_ERROR_IF_NE_MSG( sendBufferSize, recvBufferSize, "size of send buffer and receive buffer are not equal" );
memcpy( recvbuf, sendbuf, sendBufferSize );
Expand Down
29 changes: 14 additions & 15 deletions src/coreComponents/mesh/graphs/GraphColoringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ namespace geos
namespace graph
{

bool GraphColoringBase::isColoringValid( const std::vector< camp::idx_t > & xadj,
const std::vector< camp::idx_t > & adjncy,
const std::vector< int > & coloring )
bool GraphColoringBase::isColoringValid( const stdVector< size_t > & xadj,
const stdVector< size_t > & adjncy,
const stdVector< int > & coloring )
{
for( size_t node = 0; node < coloring.size(); ++node )
{
int node_color = coloring[node];
std::unordered_set< camp::idx_t > neighbors = getGraphNodeNeighbors( node, xadj, adjncy );

for( camp::idx_t neighbor : neighbors )
std::unordered_set< size_t > neighbors = getGraphNodeNeighbors( node, xadj, adjncy );
for( size_t neighbor : neighbors )
{
if( coloring[neighbor] == node_color )
{
Expand All @@ -48,7 +47,7 @@ bool GraphColoringBase::isColoringValid( const std::vector< camp::idx_t > & xadj
}


size_t GraphColoringBase::getNumberOfColors( const std::vector< int > & colors )
size_t GraphColoringBase::getNumberOfColors( const stdVector< int > & colors )
{
std::unordered_set< int > uniqueColors;
for( int color : colors )
Expand All @@ -63,7 +62,7 @@ size_t GraphColoringBase::getNumberOfColors( const std::vector< int > & colors )


// Assume only one node per rank.
bool GraphColoringBase::isColoringValid( const std::vector< camp::idx_t > & adjncy,
bool GraphColoringBase::isColoringValid( const stdVector< size_t > & adjncy,
const int color,
MPI_Comm comm )
{
Expand All @@ -74,7 +73,7 @@ bool GraphColoringBase::isColoringValid( const std::vector< camp::idx_t > & adjn
// matched by the wrong iRecv, producing false color conflicts.
// Allgather has no tag and is always safe.
int const size = MpiWrapper::commSize( comm );
std::vector< int > allColors( size );
stdVector< int > allColors( size );
MpiWrapper::allgather( &color, 1, allColors.data(), 1, comm );

// Check for color conflicts with each listed neighbor.
Expand All @@ -97,27 +96,27 @@ bool GraphColoringBase::isColoringValid( const std::vector< camp::idx_t > & adjn

size_t GraphColoringBase::getNumberOfColors( const int color, MPI_Comm comm )
{
std::vector< int > colors = {color};
stdVector< int > colors = {color};
return getNumberOfColors( colors, comm );
}


size_t GraphColoringBase::getNumberOfColors( const std::vector< int > & colors, MPI_Comm comm )
size_t GraphColoringBase::getNumberOfColors( const stdVector< int > & colors, MPI_Comm comm )
{
int const rank = MpiWrapper::commRank( comm );
int const size = MpiWrapper::commSize( comm );

std::set< int > localDistinctColors = std::set< int >( colors.begin(), colors.end());
std::vector< int > localDistinctColorsVector( localDistinctColors.begin(), localDistinctColors.end());
stdVector< int > localDistinctColorsVector( localDistinctColors.begin(), localDistinctColors.end());
int const localSize = localDistinctColorsVector.size();

// Gather the sizes of the local color vectors from all ranks
std::vector< int > allSizes( size );
stdVector< int > allSizes( size );
MpiWrapper::gather( &localSize, 1, allSizes.data(), 1, 0, comm );

// Calculate the total number of colors and the displacements for gathering
int totalSize = 0;
std::vector< int > displacements( size, 0 );
stdVector< int > displacements( size, 0 );
if( rank == 0 )
{
for( int i = 0; i < size; ++i )
Expand All @@ -128,7 +127,7 @@ size_t GraphColoringBase::getNumberOfColors( const std::vector< int > & colors,
}

// Gather all colors from all ranks to rank 0
std::vector< int > allColors( totalSize );
stdVector< int > allColors( totalSize );
MpiWrapper::gatherv( localDistinctColorsVector.data(), localSize,
allColors.data(), allSizes.data(), displacements.data(),
0, comm );
Expand Down
19 changes: 9 additions & 10 deletions src/coreComponents/mesh/graphs/GraphColoringBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace graph
* @class GraphColoringBase
* @brief Abstract base class for graph coloring strategies.
*
* Provides a common interface for graph coloring algorithms used in GEOS.
* Derived classes must implement the coloring logic for adjacency graphs.
* Provides a common interface for graph coloring algorithms used in GEOS. Derived classes must implement the coloring logic for adjacency
* graphs.
*/
class GraphColoringBase
{
Expand All @@ -54,14 +54,14 @@ class GraphColoringBase
* @param adjncy Adjacency list containing neighbors of each node.
* @return A vector of colors assigned to each node.
*/
virtual std::vector< int > colorGraph( const std::vector< camp::idx_t > & xadj, const std::vector< camp::idx_t > & adjncy ) = 0;
virtual stdVector< int > colorGraph( const stdVector< size_t > & xadj, const stdVector< size_t > & adjncy ) = 0;

/**
* @brief Pure virtual method to color a graph assuming one node per rank.
* @param adjncy Adjacency list containing neighbors of each node.
* @return Color of the node.
*/
virtual int colorGraph( const std::vector< camp::idx_t > & adjncy ) = 0;
virtual int colorGraph( const stdVector< size_t > & adjncy ) = 0;


/**
Expand All @@ -81,7 +81,7 @@ class GraphColoringBase
* @param coloring A vector where the index represents the node and the value represents the assigned color.*
* @return True if the coloring is valid, false otherwise.
*/
static bool isColoringValid( const std::vector< camp::idx_t > & xadj, const std::vector< camp::idx_t > & adjncy, const std::vector< int > & coloring );
static bool isColoringValid( const stdVector< size_t > & xadj, const stdVector< size_t > & adjncy, const stdVector< int > & coloring );

/**
* @brief Checks the validity of the graph coloring assuming one node per rank.
Expand All @@ -92,26 +92,25 @@ class GraphColoringBase
*
* @return True if the coloring is valid, false otherwise.
*/
static bool isColoringValid( const std::vector< camp::idx_t > & adjncy, const int color, MPI_Comm comm );
static bool isColoringValid( const stdVector< size_t > & adjncy, const int color, MPI_Comm comm );

/**
* @brief Counts the number of distinct colors.
*
* This function takes a vector of integers representing colors
* and returns the number of distinct (positive) colors present in the vector.
* This function takes a vector of integers representing colors and returns the number of distinct (positive) colors present in the vector.
*
* @param colors A vector of integers representing colors.
* @return The number of distinct colors in the vector.
*/
static size_t getNumberOfColors( const std::vector< int > & colors );
static size_t getNumberOfColors( const stdVector< int > & colors );

/**
* @brief Counts the number of distinct colors (parallel version).
* @param colors Vector of color values.
* @param comm MPI communicator.
* @return Number of distinct colors.
*/
static size_t getNumberOfColors( const std::vector< int > & colors, MPI_Comm comm );
static size_t getNumberOfColors( const stdVector< int > & colors, MPI_Comm comm );

/**
* @brief Counts the number of distinct colors assuming one node per rank (parallel version).
Expand Down
64 changes: 32 additions & 32 deletions src/coreComponents/mesh/graphs/GraphTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ namespace geos
namespace graph
{

size_t getGraphNodeDegree( idx_t node, const std::vector< idx_t > & xadj )
size_t getGraphNodeDegree( size_t node, const stdVector< size_t > & xadj )
{
return xadj[node + 1] - xadj[node];
}


std::unordered_set< idx_t > getGraphNodeNeighbors( idx_t node, const std::vector< idx_t > & xadj, const std::vector< idx_t > & adjncy )
std::unordered_set< size_t > getGraphNodeNeighbors( size_t node, const stdVector< size_t > & xadj, const stdVector< size_t > & adjncy )
{
std::unordered_set< idx_t > neighbors;
for( idx_t i = xadj[node]; i < xadj[node + 1]; ++i )
std::unordered_set< size_t > neighbors;
for( size_t i = xadj[node]; i < xadj[node + 1]; ++i )
{
neighbors.insert( adjncy[i] );
}
return neighbors;
}


bool isGraphValid( const std::vector< idx_t > & xadj,
const std::vector< idx_t > & adjncy )
bool isGraphValid( const stdVector< size_t > & xadj,
const stdVector< size_t > & adjncy )
{
idx_t num_nodes = xadj.size() - 1;
size_t num_nodes = xadj.size() - 1;

for( idx_t i = 0; i < num_nodes; ++i )
for( size_t i = 0; i < num_nodes; ++i )
{
std::unordered_set< idx_t > neighbors;
for( idx_t j = xadj[i]; j < xadj[i + 1]; ++j )
std::unordered_set< size_t > neighbors;
for( size_t j = xadj[i]; j < xadj[i + 1]; ++j )
{
idx_t neighbor = adjncy[j];
size_t neighbor = adjncy[j];

// Check for out-of-bounds indices
if( neighbor >= num_nodes )
Expand All @@ -75,7 +75,7 @@ bool isGraphValid( const std::vector< idx_t > & xadj,

// Check for bidirectional connection
bool bidirectional = false;
for( idx_t k = xadj[neighbor]; k < xadj[neighbor + 1]; ++k )
for( size_t k = xadj[neighbor]; k < xadj[neighbor + 1]; ++k )
{
if( adjncy[k] == i )
{
Expand All @@ -95,9 +95,9 @@ bool isGraphValid( const std::vector< idx_t > & xadj,
}


std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphRandom( size_t numVertices, size_t numEdges )
std::tuple< stdVector< size_t >, stdVector< size_t > > generateGraphRandom( size_t numVertices, size_t numEdges )
{
std::vector< std::pair< size_t, size_t > > edges;
stdVector< std::pair< size_t, size_t > > edges;
srand( static_cast< unsigned int >(time( 0 )));

// Generate random edges
Expand All @@ -116,8 +116,8 @@ std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphRandom( si
std::sort( edges.begin(), edges.end());

// Initialize xadj and adjncy
std::vector< idx_t > xadj( numVertices + 1, 0 );
std::vector< idx_t > adjncy;
stdVector< size_t > xadj( numVertices + 1, 0 );
stdVector< size_t > adjncy;
adjncy.reserve( edges.size());

// Fill xadj and adjncy
Expand All @@ -142,25 +142,25 @@ std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphRandom( si
}


std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphCartPartitionning3D( idx_t nx, idx_t ny, idx_t nz, const std::vector< std::array< int, 3 > > & neighbor_offsets )
std::tuple< stdVector< size_t >, stdVector< size_t > > generateGraphCartPartitioning3D( size_t nx, size_t ny, size_t nz, const stdVector< stdArray< int, 3 > > & neighbor_offsets )
{
idx_t num_nodes = nx * ny * nz;
std::vector< idx_t > xadj( num_nodes + 1, 0 );
std::vector< idx_t > adjncy;
size_t num_nodes = nx * ny * nz;
stdVector< size_t > xadj( num_nodes + 1, 0 );
stdVector< size_t > adjncy;

auto getNodeIndex = [nx, ny] ( const idx_t x, const idx_t y, const idx_t z )
auto getNodeIndex = [nx, ny] ( const size_t x, const size_t y, const size_t z )
{
return x + nx * (y + ny * z);
};

idx_t node_counter = 0;
for( idx_t z = 0; z < nz; ++z )
size_t node_counter = 0;
for( size_t z = 0; z < nz; ++z )
{
for( idx_t y = 0; y < ny; ++y )
for( size_t y = 0; y < ny; ++y )
{
for( idx_t x = 0; x < nx; ++x )
for( size_t x = 0; x < nx; ++x )
{
std::vector< idx_t > neighbors;
stdVector< size_t > neighbors;
for( const auto & offset : neighbor_offsets )
{

Expand All @@ -186,17 +186,17 @@ std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphCartPartit
return {xadj, adjncy};
}

std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphCartPartitionning3D6( idx_t nx, idx_t ny, idx_t nz )
std::tuple< stdVector< size_t >, stdVector< size_t > > generateGraphCartPartitioning3D6( size_t nx, size_t ny, size_t nz )
{
std::vector< std::array< int, 3 > > neighbor_offsets = {
stdVector< stdArray< int, 3 > > neighbor_offsets = {
{-1, 0, 0}, {1, 0, 0}, {0, -1, 0}, {0, 1, 0}, {0, 0, -1}, {0, 0, 1}
};
return generateGraphCartPartitionning3D( nx, ny, nz, neighbor_offsets );
return generateGraphCartPartitioning3D( nx, ny, nz, neighbor_offsets );
}

std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphCartPartitionning3D26( idx_t nx, idx_t ny, idx_t nz )
std::tuple< stdVector< size_t >, stdVector< size_t > > generateGraphCartPartitioning3D26( size_t nx, size_t ny, size_t nz )
{
std::vector< std::array< int, 3 > > neighbor_offsets;
stdVector< stdArray< int, 3 > > neighbor_offsets;
for( int dz = -1; dz <= 1; ++dz )
{
for( int dy = -1; dy <= 1; ++dy )
Expand All @@ -210,7 +210,7 @@ std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphCartPartit
}
}
}
return generateGraphCartPartitionning3D( nx, ny, nz, neighbor_offsets );
return generateGraphCartPartitioning3D( nx, ny, nz, neighbor_offsets );
}


Expand Down
14 changes: 6 additions & 8 deletions src/coreComponents/mesh/graphs/GraphTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ namespace geos
namespace graph
{

using camp::idx_t;

/**
* @brief Validates the graph based on the given criteria.
*
Expand All @@ -45,7 +43,7 @@ using camp::idx_t;
* @param adjncy The adjacency list containing the neighbors of each node.
* @return True if the graph meets all criteria, false otherwise.
*/
bool isGraphValid( const std::vector< idx_t > & xadj, const std::vector< idx_t > & adjncy );
bool isGraphValid( const stdVector< size_t > & xadj, const stdVector< size_t > & adjncy );

/**
* @brief Calculates the degree of a node in the graph.
Expand All @@ -56,7 +54,7 @@ bool isGraphValid( const std::vector< idx_t > & xadj, const std::vector< idx_t >
* @param xadj The adjacency list offsets for each node.
* @return The degree of the node.
*/
size_t getGraphNodeDegree( idx_t node, const std::vector< idx_t > & xadj );
size_t getGraphNodeDegree( size_t node, const stdVector< size_t > & xadj );

/**
* @brief Retrieves the neighbors of a node in the graph.
Expand All @@ -68,7 +66,7 @@ size_t getGraphNodeDegree( idx_t node, const std::vector< idx_t > & xadj );
* @param adjncy The adjacency list containing the neighbors of each node.
* @return A set of indices representing the neighbors of the node.
*/
std::unordered_set< idx_t > getGraphNodeNeighbors( idx_t node, const std::vector< idx_t > & xadj, const std::vector< idx_t > & adjncy );
std::unordered_set< size_t > getGraphNodeNeighbors( size_t node, const stdVector< size_t > & xadj, const stdVector< size_t > & adjncy );



Expand All @@ -81,7 +79,7 @@ std::unordered_set< idx_t > getGraphNodeNeighbors( idx_t node, const std::vector
* @param num_edges Number of edges in the graph.
* @return A tuple containing xadj and adjncy.
*/
std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphRandom( size_t num_nodes, size_t num_edges );
std::tuple< stdVector< size_t >, stdVector< size_t > > generateGraphRandom( size_t num_nodes, size_t num_edges );

/**
* @brief Generates the adjacency list representation (xadj and adjncy) for a Cartesian domain decomposition in 3D.
Expand All @@ -94,7 +92,7 @@ std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphRandom( si
* @param nz Number of divisions along the z-axis.
* @return A tuple containing xadj and adjncy.
*/
std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphCartPartitionning3D6( idx_t nx, idx_t ny, idx_t nz );
std::tuple< stdVector< size_t >, stdVector< size_t > > generateGraphCartPartitioning3D6( size_t nx, size_t ny, size_t nz );

/**
* @brief Generates the adjacency list representation (xadj and adjncy) for a Cartesian domain decomposition in 3D.
Expand All @@ -107,7 +105,7 @@ std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphCartPartit
* @param nz Number of divisions along the z-axis.
* @return A tuple containing xadj and adjncy.
*/
std::tuple< std::vector< idx_t >, std::vector< idx_t > > generateGraphCartPartitionning3D26( idx_t nx, idx_t ny, idx_t nz );
std::tuple< stdVector< size_t >, stdVector< size_t > > generateGraphCartPartitioning3D26( size_t nx, size_t ny, size_t nz );


} // namespace geos
Expand Down
Loading
Loading