Skip to content

Commit

Permalink
Refactor debugPrint utils function
Browse files Browse the repository at this point in the history
  • Loading branch information
byjtew committed Jul 12, 2023
1 parent b136bd1 commit 59e107d
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions include/graphblas/algorithms/bfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,6 @@ namespace grb {
std::cout << e << " ";
std::cout << "] - "
<< "Vector \"" << name << "\" (" << vector.size() << ")" << std::endl;
#endif
}

void debugPrint( const std::string & msg, std::ostream & os = std::cout ) {
(void)msg;
(void)os;
#ifdef BFS_DEBUG
os << msg;
#endif
}
} // namespace utils
Expand Down Expand Up @@ -274,7 +266,9 @@ namespace grb {

size_t max_iter = max_iterations < 0 ? nvertices : max_iterations;
for( size_t level = 1; level <= max_iter; level++ ) {
utils::debugPrint( "** Level " + std::to_string( level ) + ":\n" );
#ifdef _DEBUG
std::cout << "** Level " << level << ":" << std::endl << std::flush;
#endif
max_level = level;

// Multiply the current frontier by the adjacency matrix
Expand All @@ -287,11 +281,10 @@ namespace grb {
utils::printSparseVector( y, "y" );

// Update not_visited vector
for( const std::pair< size_t, bool > e : y ) {
if( e.second )
setElement( not_visited, false, e.first );
}

rc = rc ? rc : eWiseLambda([&not_visited, y] (const size_t y_i) {
not_visited[y_i] = !y[y_i];
},
y, not_visited);
// Assign the current level to the newly discovered vertices only

rc = rc ? rc : foldl( levels, y, level, min_monoid, Phase::RESIZE );
Expand All @@ -302,18 +295,20 @@ namespace grb {
explored_all = nnz( levels ) == nvertices;
if( explored_all ) {
// If all vertices are discovered, stop
utils::debugPrint( "Explored " + std::to_string( level )
+ " levels to discover all of the "
+ std::to_string( nvertices ) + " vertices.\n" );
#ifdef _DEBUG
std::cout << "Explored " << level << " levels to discover all of the "
<< nvertices << " vertices.\n" << std::flush;
#endif
return rc;
}
bool can_continue = nnz( y ) > 0;
if( ! can_continue ) {
max_level = level - 1;
// If no new vertices are discovered, stop
utils::debugPrint( "Explored " + std::to_string( level )
+ " levels to discover " + std::to_string( nnz( levels ) )
+ " vertices.\n" );
#ifdef _DEBUG
std::cout << "Explored " << level << " levels to discover "
<< nnz( levels ) << " vertices.\n" << std::flush;
#endif
break;
}

Expand All @@ -323,10 +318,11 @@ namespace grb {
}

// Maximum number of iteration passed, not every vertex has been discovered
utils::debugPrint( "A full exploration is not possible on this graph. "
"Some vertices are not reachable from the given root: " +
std::to_string( root ) + "\n" );

#ifdef _DEBUG
std::cout << "A full exploration is not possible on this graph. "
<< "Some vertices are not reachable from the given root: "
<< root << std::endl << std::flush;
#endif
return rc;
}

Expand Down Expand Up @@ -424,16 +420,18 @@ namespace grb {
max_level = 0;
explored_all = false;
for( size_t level = 1; level <= max_iter; level++ ) {
#ifdef _DEBUG
std::cout << "** Level " << level << ":" << std::endl << std::flush;
#endif
max_level = level;
utils::debugPrint( "** Level " + std::to_string( level ) + ":\n" );

rc = rc ? rc : clear( y );
// utils::printSparseVector( x, "x - before indexing" );
rc = rc ? rc :
eWiseLambda(
[ &x ]( const size_t i ) {
x[ i ] = i;
},
x );
rc = rc
? rc
: eWiseLambda( [ &x ]( const size_t i ) {
x[ i ] = i;
}, x );
utils::printSparseVector( x, "x - after indexing" );

rc = rc ? rc : vxm( y, x, A, semiring, Phase::RESIZE );
Expand All @@ -448,9 +446,10 @@ namespace grb {
rc = rc ? rc : foldl( min_parent, parents, min_negative_monoid );
if( min_parent > not_find_value ) {
explored_all = true;
utils::debugPrint( "Explored " + std::to_string( max_level )
+ " levels to discover all of the "
+ std::to_string( nvertices ) + " vertices.\n" );
#ifdef _DEBUG
std::cout << "Explored " << level << " levels to discover all of the "
<< nvertices << " vertices.\n" << std::flush;
#endif
break;
}

Expand Down

0 comments on commit 59e107d

Please sign in to comment.