1

I want to accumulate complex numbers in boost.compute library, but I face compile error when I run the below code.

I am using boost 1.65.0

P.S: the code is incomplete. I just summarize it to show the compile error.

#include <boost/compute/core.hpp>
#include <boost/compute/platform.hpp>
#include <boost/compute/algorithm.hpp>
#include <boost/compute/types/complex.hpp>
#include <complex>

namespace compute = boost::compute;

int main()
{
compute::vector<std::complex<double_t>> v;
compute::accumulate(v.begin(),v.end(),std::complex<double_t>(0,0));
}

and compiler output is:


In file included from ~/boost/compute/memory_object.hpp:16:0,
                from ~/boost/compute/buffer.hpp:17,
                from ~/boost/compute/core.hpp:18,
                from ~/main.cpp:1:
~/boost/compute/kernel.hpp: In instantiation of ‘struct boost::compute::detail::set_kernel_arg<std::complex<double> >’:
~/boost/compute/kernel.hpp:251:17:   required from ‘void boost::compute::kernel::set_arg(size_t, const T&) [with T = std::complex<double>; size_t = long unsigned int]’
~/boost/compute/algorithm/detail/serial_accumulate.hpp:46:5:   required from ‘void boost::compute::detail::serial_accumulate(InputIterator, InputIterator, OutputIterator, T, BinaryFunction, boost::compute::command_queue&) [with InputIterator = boost::compute::buffer_iterator<std::complex<double> >; OutputIterator = boost::compute::buffer_iterator<std::complex<double> >; T = std::complex<double>; BinaryFunction = boost::compute::plus<std::complex<double> >]’
~/boost/compute/algorithm/accumulate.hpp:46:30:   required from ‘T boost::compute::detail::generic_accumulate(InputIterator, InputIterator, T, BinaryFunction, boost::compute::command_queue&) [with InputIterator = boost::compute::buffer_iterator<std::complex<double> >; T = std::complex<double>; BinaryFunction = boost::compute::plus<std::complex<double> >]’
~/boost/compute/algorithm/accumulate.hpp:118:34:   required from ‘T boost::compute::detail::dispatch_accumulate(InputIterator, InputIterator, T, BinaryFunction, boost::compute::command_queue&) [with InputIterator = boost::compute::buffer_iterator<std::complex<double> >; T = std::complex<double>; BinaryFunction = boost::compute::plus<std::complex<double> >]’
~/boost/compute/algorithm/accumulate.hpp:182:39:   required from ‘T boost::compute::accumulate(InputIterator, InputIterator, T, boost::compute::command_queue&) [with InputIterator = boost::compute::buffer_iterator<std::complex<double> >; T = std::complex<double>]’
~/main.cpp:22:70:   required from here
~/boost/compute/kernel.hpp:398:5: error: no type named ‘type’ in ‘struct boost::enable_if<boost::compute::is_fundamental<std::complex<double> >, void>’
    operator()(kernel &kernel_, size_t index, const T &value)
    ^~~~~~~~
In file included from ~/boost/compute/memory_object.hpp:16:0,
                from ~/boost/compute/buffer.hpp:17,
                from ~/boost/compute/core.hpp:18,
                from ~/main.cpp:1:
~/boost/compute/kernel.hpp: In instantiation of ‘void boost::compute::kernel::set_arg(size_t, const T&) [with T = std::complex<double>; size_t = long unsigned int]’:
~/boost/compute/algorithm/detail/serial_accumulate.hpp:46:5:   required from ‘void boost::compute::detail::serial_accumulate(InputIterator, InputIterator, OutputIterator, T, BinaryFunction, boost::compute::command_queue&) [with InputIterator = boost::compute::buffer_iterator<std::complex<double> >; OutputIterator = boost::compute::buffer_iterator<std::complex<double> >; T = std::complex<double>; BinaryFunction = boost::compute::plus<std::complex<double> >]’
~/boost/compute/algorithm/accumulate.hpp:46:30:   required from ‘T boost::compute::detail::generic_accumulate(InputIterator, InputIterator, T, BinaryFunction, boost::compute::command_queue&) [with InputIterator = boost::compute::buffer_iterator<std::complex<double> >; T = std::complex<double>; BinaryFunction = boost::compute::plus<std::complex<double> >]’
~/boost/compute/algorithm/accumulate.hpp:118:34:   required from ‘T boost::compute::detail::dispatch_accumulate(InputIterator, InputIterator, T, BinaryFunction, boost::compute::command_queue&) [with InputIterator = boost::compute::buffer_iterator<std::complex<double> >; T = std::complex<double>; BinaryFunction = boost::compute::plus<std::complex<double> >]’
~/boost/compute/algorithm/accumulate.hpp:182:39:   required from ‘T boost::compute::accumulate(InputIterator, InputIterator, T, boost::compute::command_queue&) [with InputIterator = boost::compute::buffer_iterator<std::complex<double> >; T = std::complex<double>]’
~/main.cpp:22:70:   required from here
~/boost/compute/kernel.hpp:251:36: error: no match for call to ‘(boost::compute::detail::set_kernel_arg<std::complex<double> >) (boost::compute::kernel&, size_t&, const std::complex<double>&)’
        detail::set_kernel_arg<T>()(*this, index, value);
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~



  • 1
    `compute::vector> v();` -- That looks like a function declaration. [Most vexing parse](https://stackoverflow.com/questions/14077608/what-is-the-purpose-of-the-most-vexing-parse)? – PaulMcKenzie Jul 02 '20 at 14:33
  • 1
    *It's not important '()' it will call the default constructor* -- [No it won't](http://coliru.stacked-crooked.com/a/02ec4b0976ae77f7). Those parentheses changed it to a function declaration. So what is the real code? – PaulMcKenzie Jul 02 '20 at 14:40
  • I didn't know that, I just forgot to delete it when I want to make simple the question, thank you, compute::vector> v(fft_size,std::complex(0,0)); it was something like this and I forgot to delete its parentheses. Sorry this is my first question in stack overflow and I'm a little bit noob – Ariyan Sharifi Jul 02 '20 at 14:57
  • Why are you using boost when the same thing is available in standard library? Simple code like this works without boost: https://wandbox.org/permlink/rKTQQmmQjqqnVRIu – brc-dd Jul 02 '20 at 14:58
  • 1
    because boost.compute is a wrapper for OpenCL and it use GPU or intel SSE and AVX to accelerate my code, (and it is quite like STL so it is easy to use) I use it to accelerate my code with heterogeneous computing – Ariyan Sharifi Jul 02 '20 at 15:00
  • I couldn't even get this to compile due to not having OpenCL on my system. At the very least, post `boost` code where a vanilla installation of `boost` is all that's required. – PaulMcKenzie Jul 02 '20 at 15:00
  • 1
    @AriyanSharifi -- What if you changed the type to an `int` instead of `std::complex`? Does it compile? – PaulMcKenzie Jul 02 '20 at 15:04
  • @PaulMcKenzie No same compile error, I just used the instruction of boost comput toturial, [https://www.boost.org/doc/libs/1_65_1/libs/compute/doc/html/boost_compute/advanced_topics.html#boost_compute.advanced_topics.complex_values] – Ariyan Sharifi Jul 02 '20 at 15:08
  • 2
    Well, I have boost 1.73, installed Intel OpenCL, and there is no compiler error if changed to `int`. The error occurs when using `std::complex(0,0)` as the type. `int main() { compute::vector v; compute::accumulate(v.begin(), v.end(), 0);}`. – PaulMcKenzie Jul 02 '20 at 15:14
  • @PaulMcKenzie and it's interesting that all of other function in boost.compute like transform and sort works completly fine with complex number only when I use accumulate I face this errors, I guess this is a problem in their liberary – Ariyan Sharifi Jul 02 '20 at 15:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/217093/discussion-between-paulmckenzie-and-ariyan-sharifi). – PaulMcKenzie Jul 02 '20 at 15:18
  • @PaulMcKenzie yes you are right, I thought you told me to replace `std::complex` with `std::complex` when i replace whole `std::complex` with `int` no error occure Sorry – Ariyan Sharifi Jul 02 '20 at 15:19
  • @PaulMcKenzie It always requires OpenCL, that's standard, and the point of the library. The minimal sample is fine, I wish everyone posted questions like these (modulo the MVP of course) – sehe Jul 02 '20 at 16:13

0 Answers0