diff --git a/include/graphblas/omp/config.hpp b/include/graphblas/omp/config.hpp index 5c5cdb076..106528d68 100644 --- a/include/graphblas/omp/config.hpp +++ b/include/graphblas/omp/config.hpp @@ -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. * diff --git a/include/graphblas/reference/coordinates.hpp b/include/graphblas/reference/coordinates.hpp index 59ea0326f..60253723b 100644 --- a/include/graphblas/reference/coordinates.hpp +++ b/include/graphblas/reference/coordinates.hpp @@ -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. * @@ -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. */ diff --git a/include/graphblas/reference/vector.hpp b/include/graphblas/reference/vector.hpp index f0db908b2..ac6284330 100644 --- a/include/graphblas/reference/vector.hpp +++ b/include/graphblas/reference/vector.hpp @@ -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; }