Question

I was parallelizing a for loop (that iterates through a stl list) using parallel_for_each, but I got a compile time error saying that there's no matching function call.

//TBB headers
#include "tbb/parallel_for_each.h"

class FUNCTOR
{
public:
    FUNCTOR(    
        CLASS_A& tree,
        CLASS_B *groups,
        const CLASS_C** default_dominator,
        const CLASS_D& filter
    ):
        tree(tree),
        groups(groups),
        default_dominator(default_dominator),
        filter(filter)
    {}
            // Iterator dereferences to a pointer
    void operator()(const ELEMENT_OF_LIST_A*& keeper) const
    {
        /*something*/
    }

private:
    CLASS_A& tree;
    CLASS_B *groups;
    const CLASS_C** default_dominator;
    const CLASS_D& filter;
};


void some_function
(
    CLASS_A& tree,
    CLASS_B *groups,
    const CLASS_C** default_dominator,
    const LIST_A& keepers,
    const CLASS_D& filter
)
{
    // Some code that claims processors

    //LIST_A_ITER begin = keepers.begin();
    //LIST_A_ITER end = keepers.end();
    //const ELEMENT_OF_LIST_A* keeper = *begin

    tbb::parallel_for_each
    (
        keepers.begin(), keepers.end(),
        FUNCTOR(    
            tree,
            groups,
            default_dominator,
            filter
        )
    );

}

Error I got was:

error: no matching function for call to 'tbb::internal::parallel_do_operator_selector<tbb::internal::parallel_for_each_body<FUNCTOR, LIST_A_ITER>, ELEMENT_OF_LIST_A*>::call(const tbb::internal::parallel_for_each_body<FUNCTOR, LIST_A_ITER>&, ELEMENT_OF_LIST_A*, tbb::internal::do_iteration_task_iter<LIST_A_ITER, tbb::internal::parallel_for_each_body<FUNCTOR, LIST_A_ITER>, ELEMENT_OF_LIST_A*>::feeder_type&)'


note: candidate is: static void tbb::internal::parallel_do_operator_selector<Body, Item>::call(const Body&, A1&, A2&) [with A1 = ELEMENT_OF_LIST_A*, A2 = tbb::internal::parallel_do_feeder_impl<tbb::internal::parallel_for_each_body<FUNCTOR, LIST_A_ITER>, ELEMENT_OF_LIST_A*>, Body = tbb::internal::parallel_for_each_body<FUNCTOR, LIST_A_ITER>, Item = ELEMENT_OF_LIST_A*]

What went wrong?

Thanks!

Was it helpful?

Solution

The operator() for FUNCTOR has an extraneous extra level of indirection. Declare it without the *, e.g.:

const ELEMENT_OF_LIST_A& keeper
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top