diff --git a/pstl/include/pstl/internal/algorithm_impl.h b/pstl/include/pstl/internal/algorithm_impl.h --- a/pstl/include/pstl/internal/algorithm_impl.h +++ b/pstl/include/pstl/internal/algorithm_impl.h @@ -2804,8 +2804,8 @@ return !__internal::__parallel_or( std::forward<_ExecutionPolicy>(__exec), __first2, __last2, [__first1, __last1, __first2, __last2, &__comp](_ForwardIterator2 __i, _ForwardIterator2 __j) { - assert(__j > __i); - //assert(__j - __i > 1); + __PSTL_ASSERT(__j > __i); + //__PSTL_ASSERT(__j - __i > 1); //1. moving boundaries to "consume" subsequence of equal elements auto __is_equal = [&__comp](_ForwardIterator2 __a, _ForwardIterator2 __b) -> bool { @@ -2829,8 +2829,8 @@ //2. testing is __a subsequence of the second range included into the first range auto __b = std::lower_bound(__first1, __last1, *__i, __comp); - assert(!__comp(*(__last1 - 1), *__b)); - assert(!__comp(*(__j - 1), *__i)); + __PSTL_ASSERT(!__comp(*(__last1 - 1), *__b)); + __PSTL_ASSERT(!__comp(*(__j - 1), *__i)); return !std::includes(__b, __last1, __i, __j, __comp); }); }); @@ -3021,7 +3021,7 @@ } const auto __m2 = __left_bound_seq_2 - __first2; - assert(__m1 == 0 || __m2 == 0); + __PSTL_ASSERT(__m1 == 0 || __m2 == 0); if (__m2 > __set_algo_cut_off) { auto __res_or = __result; diff --git a/pstl/include/pstl/internal/numeric_impl.h b/pstl/include/pstl/internal/numeric_impl.h --- a/pstl/include/pstl/internal/numeric_impl.h +++ b/pstl/include/pstl/internal/numeric_impl.h @@ -316,7 +316,7 @@ __brick_adjacent_difference(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first, BinaryOperation __op, /*is_vector=*/std::true_type) noexcept { - assert(__first != __last); + __PSTL_ASSERT(__first != __last); typedef typename std::iterator_traits<_ForwardIterator1>::reference _ReferenceType1; typedef typename std::iterator_traits<_ForwardIterator2>::reference _ReferenceType2; @@ -346,7 +346,7 @@ _ForwardIterator2 __d_first, _BinaryOperation __op, _IsVector __is_vector, /*is_parallel=*/std::true_type) { - assert(__first != __last); + __PSTL_ASSERT(__first != __last); typedef typename std::iterator_traits<_ForwardIterator1>::reference _ReferenceType1; typedef typename std::iterator_traits<_ForwardIterator2>::reference _ReferenceType2; diff --git a/pstl/include/pstl/internal/parallel_backend_tbb.h b/pstl/include/pstl/internal/parallel_backend_tbb.h --- a/pstl/include/pstl/internal/parallel_backend_tbb.h +++ b/pstl/include/pstl/internal/parallel_backend_tbb.h @@ -139,7 +139,7 @@ _Tp& sum() { - __TBB_ASSERT(_M_has_sum, "sum expected"); + __PSTL_ASSERT_MSG(_M_has_sum, "sum expected"); return *(_Tp*)_M_sum_storage; } __par_trans_red_body(_Up __u, _Tp __init, _Cp __c, _Rp __r) @@ -173,7 +173,7 @@ _Index __j = __range.end(); if (!_M_has_sum) { - __TBB_ASSERT(__range.size() > 1, "there should be at least 2 elements"); + __PSTL_ASSERT_MSG(__range.size() > 1, "there should be at least 2 elements"); new (&_M_sum_storage) _Tp(_M_combine(_M_u(__i), _M_u(__i + 1))); // The condition i+1 < j is provided by the grain size of 3 _M_has_sum = true; @@ -233,7 +233,7 @@ _Tp& sum() const { - __TBB_ASSERT(_M_has_sum, "sum expected"); + __PSTL_ASSERT_MSG(_M_has_sum, "sum expected"); return *const_cast<_Tp*>(reinterpret_cast<_Tp const*>(_M_sum_storage)); } @@ -598,7 +598,7 @@ const _DifferenceType __sort_cut_off = __PSTL_STABLE_SORT_CUT_OFF; if (__n > __sort_cut_off) { - assert(__nsort > 0 && __nsort <= __n); + __PSTL_ASSERT(__nsort > 0 && __nsort <= __n); __buffer<_ValueType> __buf(__n); using tbb::task; task::spawn_root_and_wait(*new (task::allocate_root()) diff --git a/pstl/include/pstl/internal/parallel_backend_utils.h b/pstl/include/pstl/internal/parallel_backend_utils.h --- a/pstl/include/pstl/internal/parallel_backend_utils.h +++ b/pstl/include/pstl/internal/parallel_backend_utils.h @@ -12,7 +12,6 @@ #include #include -#include #include "utils.h" namespace __pstl @@ -54,7 +53,7 @@ _RandomAccessIterator2 __ye, _RandomAccessIterator3 __zs, _Compare __comp) { auto __n = _M_nmerge; - assert(__n > 0); + __PSTL_ASSERT(__n > 0); if (__xs != __xe) { if (__ys != __ye) @@ -146,7 +145,7 @@ ~__stack() { - assert(size() <= _M_maxsize); + __PSTL_ASSERT(size() <= _M_maxsize); while (!empty()) pop(); } @@ -159,20 +158,20 @@ size_t size() const { - assert(_M_ptr - _M_buf.get() <= _M_maxsize); - assert(_M_ptr - _M_buf.get() >= 0); + __PSTL_ASSERT(_M_ptr - _M_buf.get() <= _M_maxsize); + __PSTL_ASSERT(_M_ptr - _M_buf.get() >= 0); return _M_ptr - _M_buf.get(); } bool empty() const { - assert(_M_ptr >= _M_buf.get()); + __PSTL_ASSERT(_M_ptr >= _M_buf.get()); return _M_ptr == _M_buf.get(); } void push(const _ValueType& __v) { - assert(size() < _M_maxsize); + __PSTL_ASSERT(size() < _M_maxsize); new (_M_ptr) _ValueType(__v); ++_M_ptr; } @@ -184,7 +183,7 @@ void pop() { - assert(_M_ptr > _M_buf.get()); + __PSTL_ASSERT(_M_ptr > _M_buf.get()); --_M_ptr; (*_M_ptr).~_ValueType(); } diff --git a/pstl/include/pstl/internal/pstl_config.h b/pstl/include/pstl/internal/pstl_config.h --- a/pstl/include/pstl/internal/pstl_config.h +++ b/pstl/include/pstl/internal/pstl_config.h @@ -14,6 +14,19 @@ #define PSTL_VERSION_MAJOR (PSTL_VERSION / 100) #define PSTL_VERSION_MINOR (PSTL_VERSION - PSTL_VERSION_MAJOR * 100) +#if defined(PSTL_USE_ASSERT) +# undef __PSTL_USE_ASSERT +# define __PSTL_USE_ASSERT PSTL_USE_ASSERT +# include +# define __PSTL_ASSERT(pred) (assert((pred))) +// TODO make this smarter +# define __PSTL_ASSERT_MSG(pred, msg) (assert((pred))) +#else +# undef __PSTL_USE_ASSERT +# define __PSTL_ASSERT(pred) ((void)0) +# define __PSTL_ASSERT_MSG(pred, msg) ((void)0) +#endif + // Check the user-defined macro for parallel policies #if defined(PSTL_USE_PARALLEL_POLICIES) # undef __PSTL_USE_PAR_POLICIES diff --git a/pstl/test/CMakeLists.txt b/pstl/test/CMakeLists.txt --- a/pstl/test/CMakeLists.txt +++ b/pstl/test/CMakeLists.txt @@ -28,7 +28,7 @@ add_executable(${_target} EXCLUDE_FROM_ALL "${_file}") target_include_directories(${_target} PRIVATE "${CMAKE_CURRENT_LIST_DIR}") target_link_libraries(${_target} PRIVATE pstl::ParallelSTL) - target_compile_definitions(${_target} PRIVATE -DPSTL_STANDALONE_TESTS) + target_compile_definitions(${_target} PRIVATE -DPSTL_STANDALONE_TESTS -DPSTL_USE_ASSERT) set_target_properties(${_target} PROPERTIES CXX_EXTENSIONS NO RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") add_test(${_target} "${CMAKE_CURRENT_BINARY_DIR}/${_target}")