[Bug c++/61075] New: parallel std::accumulate reduct type cannot be different than the iterated type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075 Bug ID: 61075 Summary: parallel std::accumulate reduct type cannot be different than the iterated type Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: denes.matetelki at gmail dot com
[Bug c++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075 Denes Matetelki 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 --- #include #include #include 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 v(10, 1); const int v_sum = std::accumulate(v.begin(), v.end(), 0, [](int sum, int i) { return sum + i; } ); std::vector 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 >, true>::value_type {aka Custom}' to 'int' in initialization __reduct = new _Result(__f(__o, __begin + __start));
[Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075 --- Comment #2 from Denes Matetelki --- 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)
[Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075 --- Comment #4 from Denes Matetelki --- 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?
[Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075 Denes Matetelki changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #6 from Denes Matetelki --- I see. Thank you for your help, I'll implement the convert operator.
[Bug libstdc++/61075] parallel std::accumulate reduct type cannot be different than the iterated type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61075 --- Comment #8 from Denes Matetelki --- 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 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 c; // ambigous ctor(int)