Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

664 missing assertions for threaded execution #284

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions include/graphblas/omp/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ namespace grb {
return ret;
}

/**
* @returns The maximum number of threads reported by OpenMP.
*
* This function can be called from any context.
*/
static size_t maxThreads() {
return omp_get_max_threads();
}

/**
* @returns The number of threads in the current OpenMP parallel section.
*
Expand Down
11 changes: 11 additions & 0 deletions include/graphblas/reference/coordinates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ namespace grb {
/** Per-thread capacity for parallel stack updates. */
size_t _buf;

/** Number of threads for which these coordinates have been initialised. */
#ifdef _H_GRB_REFERENCE_OMP_COORDINATES
const size_t _threads = config::OMP::threads();
#else
const size_t _threads = 1;
#endif

/**
* Increments the number of nonzeroes in the current thread-local stack.
*
Expand Down Expand Up @@ -294,6 +301,10 @@ namespace grb {
// blocks are not managed by this class)
}

size_t requiredThreadsForUpdate() const noexcept {
return _threads;
}

/**
* @returns An empty thread-local stack for new nonzeroes.
*/
Expand Down
8 changes: 8 additions & 0 deletions include/graphblas/reference/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,14 @@ namespace grb {

template< typename D, typename C >
inline C & getCoordinates( Vector< D, reference, C > &x ) noexcept {
#if defined(_H_GRB_REFERENCE_OMP_VECTOR) && !defined(NDEBUG)
if( x._coordinates.requiredThreadsForUpdate() != config::OMP::maxThreads() ) {
#pragma omp critical
std::cerr << " " << x._coordinates.requiredThreadsForUpdate()
<< " != " << config::OMP::maxThreads() << "\n";
}
assert( x._coordinates.requiredThreadsForUpdate() == config::OMP::maxThreads() );
#endif
return x._coordinates;
}

Expand Down
Loading