public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
       [not found] <bug-61075-4@http.gcc.gnu.org/bugzilla/>
@ 2014-05-06  9:47 ` denes.matetelki at gmail dot com
  2014-05-06 10:55 ` [Bug libstdc++/61075] " denes.matetelki at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: denes.matetelki at gmail dot com @ 2014-05-06  9:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075

Denes Matetelki <denes.matetelki at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
               Host|                            |Linux  3.13.5-gentoo #10
                   |                            |SMP Fri Apr 25 16:12:35
                   |                            |CEST 2014 x86_64 Intel(R)
                   |                            |Xeon(R) CPU W3690 @ 3.47GHz
                   |                            |GenuineIntel GNU/Linux

--- Comment #1 from Denes Matetelki <denes.matetelki at gmail dot com> ---
#include <vector>
#include <numeric>
#include <iostream>

class Custom
{
public:
  Custom(int i) : m_i(i) {}
  int getI() const { return m_i; }

private:
  int m_i;
};

int main (int /*argc*/, char* /*argv*/[])
{
  std::vector<int> v(10, 1);
  const int v_sum = std::accumulate(v.begin(), v.end(), 0,
                                    [](int sum, int i) { return sum + i; } );


  std::vector<Custom> v2(10, Custom(1));
  const int v2_sum = std::accumulate(v2.begin(), v2.end(), 0,
                                    [](int sum, const Custom& c) { return sum +
c.getI(); } );

  return 0;
}

Compiling with parallel mode:

parallel_accumulate.cpp:33:93:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include/g++-v4/parallel/par_loop.h:102:15:
error: cannot convert
'std::__iterator_traits<__gnu_cxx::__normal_iterator<Custom*,
std::vector<Custom> >, true>::value_type {aka Custom}' to 'int' in
initialization
      __reduct = new _Result(__f(__o, __begin + __start));


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
       [not found] <bug-61075-4@http.gcc.gnu.org/bugzilla/>
  2014-05-06  9:47 ` [Bug c++/61075] parallel std::accumulate reduct type cannot be different than the iterated type denes.matetelki at gmail dot com
@ 2014-05-06 10:55 ` denes.matetelki at gmail dot com
  2014-05-06 14:54 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: denes.matetelki at gmail dot com @ 2014-05-06 10:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075

--- Comment #2 from Denes Matetelki <denes.matetelki at gmail dot com> ---
g++ -v

Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.2/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.8.2/work/gcc-4.8.2/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.2
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.2
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.2/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.2/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include/g++-v4
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.8.2/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--enable-checking=release --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.8.2 p1.3r1, pie-0.5.8r1' --enable-libstdcxx-time
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64
--disable-altivec --disable-fixed-point --enable-targets=all --disable-libgcj
--enable-libgomp --disable-libmudflap --disable-libssp --enable-lto
--without-cloog
Thread model: posix
gcc version 4.8.2 (Gentoo 4.8.2 p1.3r1, pie-0.5.8r1)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
       [not found] <bug-61075-4@http.gcc.gnu.org/bugzilla/>
  2014-05-06  9:47 ` [Bug c++/61075] parallel std::accumulate reduct type cannot be different than the iterated type denes.matetelki at gmail dot com
  2014-05-06 10:55 ` [Bug libstdc++/61075] " denes.matetelki at gmail dot com
@ 2014-05-06 14:54 ` redi at gcc dot gnu.org
  2014-05-13  9:07 ` denes.matetelki at gmail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-06 14:54 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-05-06
     Ever confirmed|0                           |1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
       [not found] <bug-61075-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2014-05-06 14:54 ` redi at gcc dot gnu.org
@ 2014-05-13  9:07 ` denes.matetelki at gmail dot com
  2014-05-13  9:24 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: denes.matetelki at gmail dot com @ 2014-05-13  9:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075

--- Comment #4 from Denes Matetelki <denes.matetelki at gmail dot com> ---
Thank you for the reply, Jonathan.

I understand your reasoning and not sure if my desires has much impact in the
future of GCC.

I'm suprised that the same source code cannot be compiled with parallel mode.
It would be ugly to branch with #ifdef _GLIBCXX_PARALLEL. 
Also, I feel it should be allowed for the user to create a custom labda to add
up custom types, just like in the single threaded mode.
The std::experimental::reduce is experimental, how shall I solve the problem
now? The world accumulate shows the intention, shall I use my own
implementation of reduce till that time: a parallel for_each then a single
threaded for to sum up?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
       [not found] <bug-61075-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2014-05-13  9:07 ` denes.matetelki at gmail dot com
@ 2014-05-13  9:24 ` redi at gcc dot gnu.org
  2014-05-13 10:45 ` denes.matetelki at gmail dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-13  9:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Denes Matetelki from comment #4)
> I'm suprised that the same source code cannot be compiled with parallel
> mode. It would be ugly to branch with #ifdef _GLIBCXX_PARALLEL. 
> Also, I feel it should be allowed for the user to create a custom labda to
> add up custom types, just like in the single threaded mode.

It is allowed, you just need to meet the additional requirement that Custom is
convertible to int, for example add this member function:

  explicit operator int() const { return m_i; }


N.B. the parallel mode is unlikely to see any new work or improvements. Instead
we are more likely to focus on implementing the Paralellism TS (of which N3850
is the current draft).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
       [not found] <bug-61075-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2014-05-13  9:24 ` redi at gcc dot gnu.org
@ 2014-05-13 10:45 ` denes.matetelki at gmail dot com
  2014-05-13 10:48 ` redi at gcc dot gnu.org
  2014-05-16 14:53 ` denes.matetelki at gmail dot com
  7 siblings, 0 replies; 8+ messages in thread
From: denes.matetelki at gmail dot com @ 2014-05-13 10:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075

Denes Matetelki <denes.matetelki at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #6 from Denes Matetelki <denes.matetelki at gmail dot com> ---
I see. Thank you for your help, 

I'll implement the convert operator.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
       [not found] <bug-61075-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2014-05-13 10:45 ` denes.matetelki at gmail dot com
@ 2014-05-13 10:48 ` redi at gcc dot gnu.org
  2014-05-16 14:53 ` denes.matetelki at gmail dot com
  7 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-13 10:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |WONTFIX

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I'm going to set this to WONTFIX instead.

It is a real bug in the parallel mode, but we're not going to fix it because
doing so isn't really possible, and the parallel mode is not being actively
developed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
       [not found] <bug-61075-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2014-05-13 10:48 ` redi at gcc dot gnu.org
@ 2014-05-16 14:53 ` denes.matetelki at gmail dot com
  7 siblings, 0 replies; 8+ messages in thread
From: denes.matetelki at gmail dot com @ 2014-05-16 14:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075

--- Comment #8 from Denes Matetelki <denes.matetelki at gmail dot com> ---
Just an observation:

The contained type also need to declare and define ctor(int).

Which can be tricky, if it is a template class and:

template <typename T>
class Custom
{
public:
  Custom(T t) : m_t(t) {}
  Custom(int i) : m_t() {}
  explicit operator int() const { return convertToInt(m_t); }

private:
  T m_t;
};

Custom<int> c; // ambigous ctor(int)


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-05-16 14:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-61075-4@http.gcc.gnu.org/bugzilla/>
2014-05-06  9:47 ` [Bug c++/61075] parallel std::accumulate reduct type cannot be different than the iterated type denes.matetelki at gmail dot com
2014-05-06 10:55 ` [Bug libstdc++/61075] " denes.matetelki at gmail dot com
2014-05-06 14:54 ` redi at gcc dot gnu.org
2014-05-13  9:07 ` denes.matetelki at gmail dot com
2014-05-13  9:24 ` redi at gcc dot gnu.org
2014-05-13 10:45 ` denes.matetelki at gmail dot com
2014-05-13 10:48 ` redi at gcc dot gnu.org
2014-05-16 14:53 ` denes.matetelki at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).