33 #ifndef _GLIBCXX_PARALLEL_SEARCH_H 34 #define _GLIBCXX_PARALLEL_SEARCH_H 1 49 template<
typename _RAIter,
typename _DifferenceTp>
54 typedef _DifferenceTp _DifferenceType;
59 _DifferenceType __k = 0;
60 for (_DifferenceType __j = 2; __j <= __length; __j++)
62 while ((__k >= 0) && !(__elements[__k] == __elements[__j-1]))
77 template<
typename __RAIter1,
82 __RAIter2 __begin2, __RAIter2 __end2,
85 typedef std::iterator_traits<__RAIter1> _TraitsType;
86 typedef typename _TraitsType::difference_type _DifferenceType;
90 _DifferenceType __pattern_length = __end2 - __begin2;
93 if(__pattern_length <= 0)
97 _DifferenceType __input_length = (__end1 - __begin1) - __pattern_length;
100 _DifferenceType __result = (__end1 - __begin1);
101 _DifferenceType *__splitters;
104 if (__input_length < 0)
107 omp_lock_t __result_lock;
108 omp_init_lock(&__result_lock);
111 (1, std::min<_DifferenceType>(__input_length,
112 __get_max_threads()));
114 _DifferenceType __advances[__pattern_length];
117 # pragma omp parallel num_threads(__num_threads) 121 __num_threads = omp_get_num_threads();
122 __splitters =
new _DifferenceType[__num_threads + 1];
128 _DifferenceType __start = __splitters[__iam],
129 __stop = __splitters[__iam + 1];
131 _DifferenceType __pos_in_pattern = 0;
132 bool __found_pattern =
false;
134 while (__start <= __stop && !__found_pattern)
137 #pragma omp flush(__result) 139 if (__result < __start)
141 while (__pred(__begin1[__start + __pos_in_pattern],
142 __begin2[__pos_in_pattern]))
145 if (__pos_in_pattern == __pattern_length)
148 omp_set_lock(&__result_lock);
149 __result =
std::min(__result, __start);
150 omp_unset_lock(&__result_lock);
152 __found_pattern =
true;
157 __start += (__pos_in_pattern - __advances[__pos_in_pattern]);
158 __pos_in_pattern = (__advances[__pos_in_pattern] < 0
159 ? 0 : __advances[__pos_in_pattern]);
163 omp_destroy_lock(&__result_lock);
165 delete[] __splitters;
168 return (__begin1 + __result);
uint16_t _ThreadIndex
Unsigned integer to index a thread number. The maximum thread number (for each processor) must fit in...
__RAIter1 __search_template(__RAIter1 __begin1, __RAIter1 __end1, __RAIter2 __begin2, __RAIter2 __end2, _Pred __pred)
Parallel std::search.
GNU parallel code for public use.
End-user include file. Provides advanced settings and tuning options. This file is a GNU parallel ext...
void __calc_borders(_RAIter __elements, _DifferenceTp __length, _DifferenceTp *__off)
Precalculate __advances for Knuth-Morris-Pratt algorithm.
_OutputIterator __equally_split(_DifferenceType __n, _ThreadIndex __num_threads, _OutputIterator __s)
function to split a sequence into parts of almost equal size.
#define _GLIBCXX_CALL(__n)
Macro to produce log message when entering a function.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.