Skip to content
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
11 changes: 5 additions & 6 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,
bool GraphColoringBase::isColoringValid( const std::vector< size_t > & xadj,
const std::vector< size_t > & adjncy,
const std::vector< 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 @@ -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 std::vector< size_t > & adjncy,
const int color,
MPI_Comm comm )
{
Expand Down
8 changes: 4 additions & 4 deletions src/coreComponents/mesh/graphs/GraphColoringBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 std::vector< int > colorGraph( const std::vector< size_t > & xadj, const std::vector< 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 std::vector< 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 std::vector< size_t > & xadj, const std::vector< size_t > & adjncy, const std::vector< int > & coloring );

/**
* @brief Checks the validity of the graph coloring assuming one node per rank.
Expand All @@ -92,7 +92,7 @@ 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 std::vector< size_t > & adjncy, const int color, MPI_Comm comm );

/**
* @brief Counts the number of distinct colors.
Expand Down
58 changes: 29 additions & 29 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 std::vector< 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 std::vector< size_t > & xadj, const std::vector< 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 std::vector< size_t > & xadj,
const std::vector< 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,7 +95,7 @@ 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< std::vector< size_t >, std::vector< size_t > > generateGraphRandom( size_t numVertices, size_t numEdges )
{
std::vector< std::pair< size_t, size_t > > edges;
srand( static_cast< unsigned int >(time( 0 )));
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;
std::vector< size_t > xadj( numVertices + 1, 0 );
std::vector< 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< std::vector< size_t >, std::vector< size_t > > generateGraphCartPartitioning3D( size_t nx, size_t ny, size_t nz, const std::vector< std::array< 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;
std::vector< size_t > xadj( num_nodes + 1, 0 );
std::vector< 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;
std::vector< size_t > neighbors;
for( const auto & offset : neighbor_offsets )
{

Expand All @@ -186,15 +186,15 @@ 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< std::vector< size_t >, std::vector< size_t > > generateGraphCartPartitioning3D6( size_t nx, size_t ny, size_t nz )
{
std::vector< std::array< 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< std::vector< size_t >, std::vector< size_t > > generateGraphCartPartitioning3D26( size_t nx, size_t ny, size_t nz )
{
std::vector< std::array< int, 3 > > neighbor_offsets;
for( int dz = -1; dz <= 1; ++dz )
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 std::vector< size_t > & xadj, const std::vector< 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 std::vector< 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 std::vector< size_t > & xadj, const std::vector< 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< std::vector< size_t >, std::vector< 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< std::vector< size_t >, std::vector< 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< std::vector< size_t >, std::vector< size_t > > generateGraphCartPartitioning3D26( size_t nx, size_t ny, size_t nz );


} // namespace geos
Expand Down
32 changes: 16 additions & 16 deletions src/coreComponents/mesh/graphs/GraphToolsMPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace geos
namespace graph
{

std::pair< std::vector< camp::idx_t >, std::vector< camp::idx_t > >
scatterGraphData( const std::vector< camp::idx_t > & xadj,
const std::vector< camp::idx_t > & adjncy,
std::pair< std::vector< size_t >, std::vector< size_t > >
scatterGraphData( const std::vector< size_t > & xadj,
const std::vector< size_t > & adjncy,
MPI_Comm comm )
{
int const rank = MpiWrapper::commRank( comm );
Expand All @@ -42,7 +42,7 @@ scatterGraphData( const std::vector< camp::idx_t > & xadj,

std::vector< int > sendCounts;
std::vector< int > displacements;
std::vector< camp::idx_t > xadjToScatter;
std::vector< size_t > xadjToScatter;

if( rank == 0 )
{
Expand All @@ -64,23 +64,23 @@ scatterGraphData( const std::vector< camp::idx_t > & xadj,
}
}

std::vector< camp::idx_t > localXadj( 2 ); // Each rank will have two elements in localXadj: xadj[i] and xadj[i+1]
std::vector< size_t > localXadj( 2 ); // Each rank will have two elements in localXadj: xadj[i] and xadj[i+1]
MpiWrapper::scatter( xadjToScatter.data(), 2, localXadj.data(), 2, 0, comm );

int localSize;
MpiWrapper::scatter( sendCounts.data(), 1, &localSize, 1, 0, comm );

std::vector< camp::idx_t > localAdjncy( localSize );
std::vector< size_t > localAdjncy( localSize );
MpiWrapper::scatterv( adjncy.data(), sendCounts.data(), displacements.data(),
localAdjncy.data(), localSize, 0, comm );

return {localXadj, localAdjncy};
}


std::pair< std::vector< camp::idx_t >, std::vector< camp::idx_t > >
gatherGraphData( const std::vector< camp::idx_t > & localXadj,
const std::vector< camp::idx_t > & localAdjncy,
std::pair< std::vector< size_t >, std::vector< size_t > >
gatherGraphData( const std::vector< size_t > & localXadj,
const std::vector< size_t > & localAdjncy,
MPI_Comm comm )
{
int const rank = MpiWrapper::commRank( comm );
Expand All @@ -105,7 +105,7 @@ gatherGraphData( const std::vector< camp::idx_t > & localXadj,
}

// Resize the xadj vector on rank 0 to hold the gathered data
std::vector< camp::idx_t > xadj;
std::vector< size_t > xadj;
if( rank == 0 )
{
int totalSize = std::accumulate( recvCounts.begin(), recvCounts.end(), 0 );
Expand Down Expand Up @@ -133,7 +133,7 @@ gatherGraphData( const std::vector< camp::idx_t > & localXadj,
}

// Resize the adjncy vector on rank 0 to hold the gathered data
std::vector< camp::idx_t > adjncy;
std::vector< size_t > adjncy;
if( rank == 0 )
{
int totalSize = std::accumulate( recvCounts.begin(), recvCounts.end(), 0 );
Expand All @@ -150,7 +150,7 @@ gatherGraphData( const std::vector< camp::idx_t > & localXadj,
}


std::vector< camp::idx_t > createXadjFromAdjncy( const std::vector< camp::idx_t > & localAdjncy, MPI_Comm comm )
std::vector< size_t > createXadjFromAdjncy( const std::vector< size_t > & localAdjncy, MPI_Comm comm )
{
int const size = MpiWrapper::commSize( comm );

Expand All @@ -160,26 +160,26 @@ std::vector< camp::idx_t > createXadjFromAdjncy( const std::vector< camp::idx_t
MpiWrapper::allgather( &localAdjncySize, 1, adjncyCounts.data(), 1, comm );

// Calculate xadj
std::vector< camp::idx_t > xadj( size + 1, 0 );
std::vector< size_t > xadj( size + 1, 0 );
std::partial_sum( adjncyCounts.begin(), adjncyCounts.end(), xadj.begin() + 1 );

// Prepare data to scatter
std::vector< camp::idx_t > xadjToScatter( 2 * size );
std::vector< size_t > xadjToScatter( 2 * size );
for( int i = 0; i < size; ++i )
{
xadjToScatter[2 * i] = xadj[i];
xadjToScatter[2 * i + 1] = xadj[i + 1];
}

// Scatter the xadj data
std::vector< camp::idx_t > localXadj( 2 );
std::vector< size_t > localXadj( 2 );
MpiWrapper::scatter( xadjToScatter.data(), 2, localXadj.data(), 2, 0, comm );

return localXadj;
}


std::vector< int > createVertexGlobalID( const std::vector< camp::idx_t > & localXadj, MPI_Comm comm )
std::vector< int > createVertexGlobalID( const std::vector< size_t > & localXadj, MPI_Comm comm )
{
int const rank = MpiWrapper::commRank( comm );
int const size = MpiWrapper::commSize( comm );
Expand Down
Loading
Loading