[PATCH][libstdc++-v3 parallel mode] PR 33488 improved

Benjamin Kosnik benjamin.kosnik@gmail.com
Tue Oct 2 00:30:00 GMT 2007

> > http://gcc.gnu.org/viewcvs/branches/libstdcxx_so_7-branch/libstdc%2B%2B-v3/include/bits/predefined_ops.h?view=markup
> Thanks (I was searching for "v7").
> But what you are doing is burying the functors inside nested namespace
> __ops. But mine are buried in __gnu_parallel, which should be kind of
> the same thing, isn't it?


I think Chris was getting back to the uglification issue with the
parallel mode code in general, where some user code like this:

#include <algorithm>

using namespace __gnu_parallel;

class Settings {} ; // error conflicts with __gnu_parallel::Settings

is currently problematic, but should not be. I'd prefer to deal with
this issue all at once, when some of the other parallel code bugzilla
issues have been resolved. 

So, I think it's safe to proceed as you are in this patch.
> http://gcc.gnu.org/onlinedocs/libstdc++/parallel_mode.html
> "Support and infrastructure is in namespace __gnu_parallel."
> > I can't quite remember exactly how those came about now, but I
> > remember we found you needed that many bits to fix all the existing
> > code floating about (I think mainly some strange bits of boost).
> As long these functors are used by "our" code, we probably don't need
> all the variants. Is there a reason to include them nevertheless?

I don't think so. 

However, a couple of things.

Like for __gnu_parallel::less, you'll need two version of operator() if
you have two argument types.

ie, should be:

+  template<typename T1, typename T2>
+  struct equal_to : std::binary_function<T1, T2, bool>
+  {
+    bool operator()(const T1& t1, const T2& t2) const
+    { return t1 == t2; }
+    bool operator()(const T2& t2, const T1& t1) const
+    { return t2 == t1; }
+  };

Similarly for the relevant multiplies and plus code.

In addition:

-    typedef iterator_traits<InputIterator1> traits_type;
-    typedef typename traits_type::value_type value_type;
-    return inner_product(first1, last1, first2, init,
-			 std::multiplies<value_type>(),
+    return inner_product(first1, last1, first2, init,
+                           __gnu_parallel::plus<
+                             T,
+                             typename
+                           >(),
+                           __gnu_parallel::multiplies<
+                             typename
+                             typename
+                           >(),
+                           parallelism_tag);

Don't even think about removing these typedefs for traits_type and

Instead, use them, and consider new typedefs for the multiplies and
plus types. 


More information about the Libstdc++ mailing list