This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [libstdc++-v3 parallel mode] Why is not std::transform executed in parallel by default?
- From: Johannes Singler <singler at ira dot uka dot de>
- To: Kento EMOTO <emoto at ipl dot t dot u-tokyo dot ac dot jp>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Wed, 17 Sep 2008 12:02:45 +0200
- Subject: Re: [libstdc++-v3 parallel mode] Why is not std::transform executed in parallel by default?
- References: <48CE2FC8.5020700@ipl.t.u-tokyo.ac.jp>
Kento EMOTO wrote:
> Hi,
>
> I'm enjoying the novel libstdc++ parallel mode, and I have some
> questions about it:
>
> Does a user need to specify __gnu_parallel::parallel_balanced (or
> other choice in _Parallelism) explicitly to execute std::transform
> (and __gnu_parallel::transform) in parallel?
> Is it an intended (desired) behavior of the parallel mode?
No. This is a bug. Thanks for finding it.
--snipped--
> BTW, when the default parameter value
> __gnu_parallel::parallel_balanced of the last parameter of
> transform1_switch (parallel/algo.h) is put into the prototype
> declaration of transform1_switch (parallel/algorithmfwd.h),
> std::transform is executed in parallel by default (when
> -D_GLIBCXX_PARALLEL is specified).
>
> Why is the default value specified not in the prototype
> declaration but in the definition?
> Since the prototype without the default value is found earlier than
> the definition with the default value, g++ determines that
> transform1_switch does not have the default value. This situation
> occurs also in other 'XXX_switch'es.
Looks like you also found the solution :-)
Fixed accordingly in attached patch for /parallel. Does that solve the
problem so far? I will investigate the problem further.
-- Johannes
Index: iterator.h
===================================================================
--- iterator.h (revision 140275)
+++ iterator.h (working copy)
@@ -131,7 +131,7 @@
public:
typedef IteratorCategory iterator_category;
typedef void value_type;
- typedef typename Iterator1::difference_type difference_type;
+ typedef typename std::iterator_traits<Iterator1>::difference_type difference_type;
typedef type* pointer;
typedef type& reference;
Index: algorithmfwd.h
===================================================================
--- algorithmfwd.h (revision 140275)
+++ algorithmfwd.h (working copy)
@@ -99,7 +99,8 @@
template<typename _RAIter, typename _Tp>
typename iterator_traits<_RAIter>::difference_type
count_switch(_RAIter, _RAIter, const _Tp&, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_unbalanced);
template<typename _IIter, typename _Predicate>
@@ -121,7 +122,8 @@
template<typename _RAIter, typename _Predicate>
typename iterator_traits<_RAIter>::difference_type
count_if_switch(_RAIter, _RAIter, _Predicate, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_unbalanced);
// algobase.h
template<typename _IIter1, typename _IIter2>
@@ -228,7 +230,8 @@
template<typename _RAIter, typename _Function>
_Function
for_each_switch(_RAIter, _RAIter, _Function, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _FIter, typename _Generator>
@@ -250,7 +253,8 @@
template<typename _RAIter, typename _Generator>
void
generate_switch(_RAIter, _RAIter, _Generator, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _OIter, typename _Size, typename _Generator>
_OIter
@@ -272,7 +276,8 @@
template<typename _RAIter, typename _Size, typename _Generator>
_RAIter
generate_n_switch(_RAIter, _Size, _Generator, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2>
bool
@@ -429,7 +434,8 @@
_RAOIter
transform1_switch(_RAIIter, _RAIIter, _RAOIter, UnaryOperation,
random_access_iterator_tag, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2, typename _OIter,
@@ -455,7 +461,8 @@
transform2_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter3, _BiOperation,
random_access_iterator_tag, random_access_iterator_tag,
random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2, typename _OIter,
typename _BiOperation, typename _Tag1,
@@ -546,7 +553,8 @@
template<typename _RAIter, typename _Compare>
_RAIter
max_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2, typename _OIter>
@@ -615,7 +623,8 @@
template<typename _RAIter, typename _Compare>
_RAIter
min_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _RAIter>
void
Index: numericfwd.h
===================================================================
--- numericfwd.h (revision 140275)
+++ numericfwd.h (working copy)
@@ -83,7 +83,8 @@
_Tp
accumulate_switch(_RAIter, _RAIter, _Tp, _BinaryOper,
random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _IIter, typename _OIter>
_OIter
@@ -124,7 +125,8 @@
adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper,
random_access_iterator_tag,
random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2, typename _Tp>
_Tp
@@ -164,7 +166,8 @@
inner_product_switch(_RAIter1, _RAIter1, _RAIter2, _Tp, BinaryFunction1,
BinaryFunction2, random_access_iterator_tag,
random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2, typename _Tp,
typename _BinaryFunction1, typename _BinaryFunction2,