Skip to content

Commit 46aefea

Browse files
committed
Fix the assertion to be callable from parallel context
1 parent 7dd3d04 commit 46aefea

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

include/graphblas/omp/config.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ namespace grb {
7979
return ret;
8080
}
8181

82+
/**
83+
* @returns The maximum number of threads reported by OpenMP.
84+
*
85+
* This function can be called from any context.
86+
*/
87+
static size_t maxThreads() {
88+
return omp_get_max_threads();
89+
}
90+
8291
/**
8392
* @returns The number of threads in the current OpenMP parallel section.
8493
*

include/graphblas/reference/vector.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,12 @@ namespace grb {
12751275
template< typename D, typename C >
12761276
inline C & getCoordinates( Vector< D, reference, C > &x ) noexcept {
12771277
#ifdef _H_GRB_REFERENCE_OMP_VECTOR
1278-
assert( x._coordinates.requiredThreadsForUpdate() == config::OMP::threads() );
1278+
if( x._coordinates.requiredThreadsForUpdate() != config::OMP::maxThreads() ) {
1279+
#pragma omp critical
1280+
std::cerr << " " << x._coordinates.requiredThreadsForUpdate()
1281+
<< " != " << config::OMP::maxThreads() << "\n";
1282+
}
1283+
assert( x._coordinates.requiredThreadsForUpdate() == config::OMP::maxThreads() );
12791284
#endif
12801285
return x._coordinates;
12811286
}

0 commit comments

Comments
 (0)