2016-07-13 Jonathan Wakely <jwakely@redhat.com>
+ PR libstdc++/71856
+ * include/bits/c++config (_GLIBCXX_ASSERTIONS): Define to 1 not empty.
+ * include/parallel/compiletime_settings.h (_GLIBCXX_ASSERTIONS):
+ Rename to _GLIBCXX_PARALLEL_ASSERTIONS and make default value depend
+ on _GLIBCXX_ASSERTIONS.
+ * include/parallel/balanced_quicksort.h: Rename _GLIBCXX_ASSERTIONS.
+ Include <unistd.h> for sleep.
+ * include/parallel/losertree.h: Rename _GLIBCXX_ASSERTIONS.
+ * include/parallel/merge.h: Likewise.
+ * include/parallel/multiway_merge.h: Likewise.
+ * include/parallel/partition.h: Likewise.
+ * include/parallel/queue.h: Likewise.
+ * include/parallel/sort.h: Likewise.
+ * testsuite/25_algorithms/headers/algorithm/
+ parallel_algorithm_assert.cc: New.
+
* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI]
(replace(__const_iterator, __const_iterator, initializer_list<C>)):
Forward to different overload.
// Debug Mode implies checking assertions.
#ifdef _GLIBCXX_DEBUG
-# define _GLIBCXX_ASSERTIONS
+# define _GLIBCXX_ASSERTIONS 1
#endif
// Disable std::string explicit instantiation declarations in order to assert.
#include <parallel/random_number.h>
#include <parallel/queue.h>
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
#include <parallel/checkers.h>
+#ifdef _GLIBCXX_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#endif
namespace __gnu_parallel
__median_of_three_iterators(__begin, __begin + (__end - __begin) / 2,
__end - 1, __comp);
-#if defined(_GLIBCXX_ASSERTIONS)
+#if defined(_GLIBCXX_PARALLEL_ASSERTIONS)
// Must be in between somewhere.
_DifferenceType __n = __end - __begin;
std::iter_swap(__begin + __split_pos, __pivot_pos);
__pivot_pos = __begin + __split_pos;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_RAIter __r;
for (__r = __begin; __r != __pivot_pos; ++__r)
_GLIBCXX_PARALLEL_ASSERT(__comp(*__r, *__pivot_pos));
_DifferenceType __split_pos =
__qsb_divide(__begin, __end, __comp, __num_threads);
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(0 <= __split_pos &&
__split_pos < (__end - __begin));
#endif
_Piece __current = __tl._M_initial;
_DifferenceType __elements_done = 0;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_DifferenceType __total_elements_done = 0;
#endif
__pred);
// Left side: < __pivot_pos; __right side: >= __pivot_pos.
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(__begin <= __split_pos1
&& __split_pos1 < __end);
#endif
// Elements equal to pivot are done.
__elements_done += (__split_pos2 - __split_pos1);
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
__total_elements_done += (__split_pos2 - __split_pos1);
#endif
// Always push larger part onto stack.
{
__gnu_sequential::sort(__begin, __end, __comp);
__elements_done += __n;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
__total_elements_done += __n;
#endif
__elements_done = 0;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
double __search_start = omp_get_wtime();
#endif
bool __successfully_stolen = false;
while (__wait && *__tl._M_elements_leftover > 0
&& !__successfully_stolen
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// Possible dead-lock.
&& (omp_get_wtime() < (__search_start + 1.0))
#endif
#endif
}
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
if (omp_get_wtime() >= (__search_start + 1.0))
{
sleep(1);
#endif
if (!__successfully_stolen)
{
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(*__tl._M_elements_leftover == 0);
#endif
return;
__qsb_conquer(__tls, __begin, __begin + __n, __comp, 0,
__num_threads, true);
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// All stack must be empty.
_Piece __dummy;
for (_ThreadIndex __i = 1; __i < __num_threads; ++__i)
#define _GLIBCXX_SCALE_DOWN_FPU 0
#endif
-#ifndef _GLIBCXX_ASSERTIONS
+#ifndef _GLIBCXX_PARALLEL_ASSERTIONS
/** @brief Switch on many _GLIBCXX_PARALLEL_ASSERTions in parallel code.
* Should be switched on only locally. */
-#define _GLIBCXX_ASSERTIONS 0
+#define _GLIBCXX_PARALLEL_ASSERTIONS (_GLIBCXX_ASSERTIONS+0)
#endif
#ifndef _GLIBCXX_RANDOM_SHUFFLE_CONSIDER_L1
__delete_min_insert(_Tp __key, bool __sup)
{
using std::swap;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
__delete_min_insert(_Tp __key, bool __sup)
{
using std::swap;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
void __delete_min_insert(const _Tp& __key, bool __sup)
{
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
void __delete_min_insert(const _Tp& __key, bool __sup)
{
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
int
__get_min_source()
{
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
{
_M_losers[0] = _M_losers[__init_winner(1)];
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top at the beginning
// (0 sequences!)
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
__delete_min_insert(_Tp __key, bool)
{
using std::swap;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
unsigned int __left = __init_winner(2 * __root);
unsigned int __right = __init_winner(2 * __root + 1);
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// If __left one is sentinel then __right one must be, too.
if (_M_losers[__left]._M_source == -1)
_GLIBCXX_PARALLEL_ASSERT(_M_losers[__right]._M_source == -1);
{
_M_losers[0] = _M_losers[__init_winner(1)];
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top at the beginning
// (0 sequences!)
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
__delete_min_insert(_Tp __key, bool)
{
using std::swap;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
int
__get_min_source()
{
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
{
_M_losers[0] = _M_losers[__init_winner(1)];
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top at the beginning
// (0 sequences!)
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
void
__delete_min_insert(const _Tp& __key, bool __sup)
{
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
unsigned int __left = __init_winner(2 * __root);
unsigned int __right = __init_winner(2 * __root + 1);
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// If __left one is sentinel then __right one must be, too.
if (_M_losers[__left]._M_source == -1)
_GLIBCXX_PARALLEL_ASSERT(_M_losers[__right]._M_source == -1);
{
_M_losers[0] = _M_losers[__init_winner(1)];
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top at the beginning
// (0 sequences!)
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
void
__delete_min_insert(const _Tp& __key, bool __sup)
{
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// no dummy sequence can ever be at the top!
_GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
typedef typename std::iterator_traits<_RAIter2>::value_type
_ValueType2;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(__max_length >= 0);
#endif
#include <parallel/parallel.h>
#include <parallel/losertree.h>
#include <parallel/multiseq_selection.h>
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
#include <parallel/checkers.h>
#endif
if (__length == 0)
return __target;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_DifferenceTp __orig_length = __length;
#endif
__finish:
;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(
((_RAIter1)__seq0 - __seqs_begin[0].first) +
((_RAIter1)__seq1 - __seqs_begin[1].first) +
for (_SeqNumber __t = 0; __t < __k; ++__t)
{
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(__seqs_begin[__t].first
!= __seqs_begin[__t].second);
#endif
_SeqNumber __source;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_DifferenceType __i = 0;
#endif
// Take out.
__source = __lt.__get_min_source();
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(0 <= __source && __source < __k);
_GLIBCXX_PARALLEL_ASSERT(__i == 0
|| !__comp(*(__seqs_begin[__source].first), *(__target - 1)));
// Feed.
*(__target++) = *(__seqs_begin[__source].first++);
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
++__i;
#endif
// Replace from same __source.
__target_end = multiway_merge_loser_tree_unguarded<UnguardedLoserTree>
(__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp);
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(__target_end == __target + __length);
_GLIBCXX_PARALLEL_ASSERT(__is_sorted(__target, __target_end, __comp));
#endif
typedef typename std::iterator_traits<_RAIter1>::value_type
_ValueType;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
for (_RAIterIterator __s = __seqs_begin; __s != __seqs_end; ++__s)
{
_GLIBCXX_PARALLEL_ASSERT(__is_sorted((*__s).first,
(__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp);
break;
}
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(
__is_sorted(__target, __target + __length, __comp));
#endif
_Compare __comp,
_ThreadIndex __num_threads)
{
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(__seqs_end - __seqs_begin > 1);
#endif
delete[] __chunks;
} // parallel
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(
__is_sorted(__target, __target + __length, __comp));
#endif
break;
}
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(__swapstart != -1);
#endif
break;
}
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(__swapstart != -1);
#endif
__begin + __thread_right_border
+ __chunk_size, __begin + __swapstart);
}
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
# pragma omp barrier
# pragma omp single
int __former_front, __former_back;
__decode2(__former_borders, __former_front, __former_back);
*(_M_base + __former_front % _M_max_size) = __t;
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
// Otherwise: front - back > _M_max_size eventually.
_GLIBCXX_PARALLEL_ASSERT(((__former_front + 1) - __former_back)
<= _M_max_size);
#include <parallel/features.h>
#include <parallel/parallel.h>
-#if _GLIBCXX_ASSERTIONS
+#if _GLIBCXX_PARALLEL_ASSERTIONS
#include <parallel/checkers.h>
#endif
--- /dev/null
+// { dg-do compile }
+// { dg-require-parallel-mode "" }
+// { dg-options "-fopenmp" { target *-*-* } }
+
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef _GLIBCXX_ASSERTIONS
+# define _GLIBCXX_ASSERTIONS 1
+#endif
+#include <parallel/algorithm>
+#ifndef _GLIBCXX_PARALLEL_ASSERTIONS
+# error "_GLIBCXX_ASSERTIONS does not enable _GLIBCXX_PARALLEL_ASSERTIONS"
+#endif