none
Concurrency::samples::parallel_transform and boost zip iterators RRS feed

  • Question

  • Hi,

    I can use std::transform with boost zip iterators ok but, when I try the PPL parallel_transform, I get all kinds of errors. I am curious if anyone else tried this?

    Thanks,

    GT

     

    Friday, October 28, 2011 3:49 AM

Answers

  • Hi GT,

    Based on your information, there are actually two problems, which make the boost zip iterator does NOT compatible with PPL parallel_transform(Actually it's not fully compatible with STL either).

    The first problem is that the boost iterator did not use the STL iterator category traits (some tag class like std::random_access_iterator_tag, std::input_iterator_tag, etc), which will fail those algorithms depends on them. STL std::transform is lucky because it does not need those tags, but to tailer a fully optimized algorithm, PPL Concurrency::parallel_transform depends on those tags.

    The second problem is that , for non-random access iterators (like forward_iterator), PPL parallel_transform requires iterators have well defined pointer_type,  in other words, if the object be referenced by iterator does not have a stable address (like temporary or proxy  object), PPL parallel_transform does not support it ( but those objects with random_access iterator will be fine).

    I hope these would help.

     

    Hong 

    • Proposed as answer by Rahul V. PatilModerator Monday, October 31, 2011 11:01 PM
    • Marked as answer by GT227 Tuesday, November 1, 2011 7:32 PM
    Monday, October 31, 2011 6:17 PM

All replies

  •  Hi,

    Can you provide more information about the category of iterators you are using, and error messages ?

    Because currently, the parallel_transform does not support any iterator with category weaker than Forward_iterator, so if you're using that, it might be a problem.

    Hong

     


    • Edited by Hong Hong - Saturday, October 29, 2011 12:36 AM
    Saturday, October 29, 2011 12:32 AM
  • here is some basic code showing the issue:

    ...............

    template<typename T>
    class TBoostZip_T
    {
    public:
      TBoostZip_T(T value)
        : value_(value)
      {
      }

      boost::tuple<T, T> operator()(const boost::tuple<T, T>& x) const
      {
        T v1 = fabs(boost::get<0>(x) - value_);
        T v2 = fabs(boost::get<1>(x) - value_);
        return boost::make_tuple(v1, v2);
      }

    private:
      T value_;
    }; // TBoostZip_T


    void TestBoostZipIterators()
    {
      const int sz = 10;

      srand( (unsigned)time( NULL ) );

      vector<float> va1, va2,
                    vc1(sz), vc2(sz);

      for (int i = 0; i< sz; i++)
      {
        va1.push_back( (float)rand() / ((float)RAND_MAX / 20) );
        va2.push_back( (float)rand() / ((float)RAND_MAX / 20) );
      }

      Concurrency::samples::parallel_transform(
      //std::transform(
                      boost::make_zip_iterator(boost::make_tuple( va1.begin(), va2.begin() )),
                      boost::make_zip_iterator(boost::make_tuple( va1.end(), va2.end() )),
                      boost::make_zip_iterator(boost::make_tuple( vc1.begin(), vc2.begin() )),
                      TBoostZip_T<float>(5.0)
                    );

      for (int k = 0; k < sz; k++ )
      {
        cout <<va1[k] << "/" << va2[k] << "/" << vc1[k] << "/" << vc2[k] << endl;
      }
    } // TestBoostZipIterators
    ............

    using std::transform all is ok. Using parallel_transfrom I get these errors:

    ..........

    1>c:\projects\3rdparty\ms\concrtextras\ppl_extras.h(981): error C2512: 'boost::detail::operator_arrow_proxy<T>' : no appropriate default constructor available
    1>          with
    1>          [
    1>              T=boost::tuples::cons<float &,boost::tuples::cons<float &,boost::tuples::null_type>>
    1>          ]
    1>          c:\projects\3rdparty\ms\concrtextras\ppl_extras.h(981) : while compiling class template member function 'Concurrency::samples::_Iterator_helper<_Forward_iterator,_Iterator_kind>::_Iterator_helper(void)'
    1>          with
    1>          [
    1>              _Forward_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              _Iterator_kind=boost::detail::iterator_category_with_traversal<std::input_iterator_tag,boost::random_access_traversal_tag>
    1>          ]
    1>          c:\projects\3rdparty\ms\concrtextras\ppl_extras.h(1152) : see reference to class template instantiation 'Concurrency::samples::_Iterator_helper<_Forward_iterator,_Iterator_kind>' being compiled
    1>          with
    1>          [
    1>              _Forward_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              _Iterator_kind=boost::detail::iterator_category_with_traversal<std::input_iterator_tag,boost::random_access_traversal_tag>
    1>          ]
    1>          c:\projects\3rdparty\ms\concrtextras\ppl_extras.h(1166) : see reference to class template instantiation 'Concurrency::samples::_Parallel_transform_unary_helper<_Input_iterator,_Output_iterator,_Unary_operator>' being compiled
    1>          with
    1>          [
    1>              _Input_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              _Output_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              _Unary_operator=TBoostZip_T<float>
    1>          ]
    1>          c:\projects\3rdparty\ms\concrtextras\ppl_extras.h(914) : see reference to function template instantiation 'void Concurrency::samples::_Parallel_transform_unary_impl2<_Input_iterator,_Output_iterator,_Unary_operator>(_Input_iterator,_Input_iterator,_Output_iterator &,const _Unary_operator &,Concurrency::task_group &)' being compiled
    1>          with
    1>          [
    1>              _Input_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              _Output_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              _Unary_operator=TBoostZip_T<float>
    1>          ]
    1>          c:\projects\3rdparty\ms\concrtextras\ppl_extras.h(1226) : see reference to function template instantiation 'void Concurrency::samples::_Unary_transform_impl_helper<_Any_input_traits,_Any_output_traits>::_Parallel_transform_unary_impl<_Input_iterator,_Output_iterator,_Unary_operator>(_Input_iterator,_Input_iterator,_Output_iterator &,const _Unary_operator &)' being compiled
    1>          with
    1>          [
    1>              _Any_input_traits=_Input_iterator_type,
    1>              _Any_output_traits=_Output_iterator_type,
    1>              _Input_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              _Output_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              _Unary_operator=TBoostZip_T<float>
    1>          ]
    1>          test.cpp(79) : see reference to function template instantiation '_Output_iterator Concurrency::samples::parallel_transform<boost::zip_iterator<IteratorTuple>,boost::zip_iterator<IteratorTuple>,TBoostZip_T<T>>(_Input_iterator,_Input_iterator,_Output_iterator,const _Unary_operator &)' being compiled
    1>          with
    1>          [
    1>              _Output_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              IteratorTuple=boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>,
    1>              T=float,
    1>              _Input_iterator=boost::zip_iterator<boost::tuples::tuple<std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,std::_Vector_iterator<std::_Vector_val<float,std::allocator<float>>>,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>,
    1>              _Unary_operator=TBoostZip_T<float>
    1>          ]
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Saturday, October 29, 2011 8:00 PM
  • Hi GT,

    Based on your information, there are actually two problems, which make the boost zip iterator does NOT compatible with PPL parallel_transform(Actually it's not fully compatible with STL either).

    The first problem is that the boost iterator did not use the STL iterator category traits (some tag class like std::random_access_iterator_tag, std::input_iterator_tag, etc), which will fail those algorithms depends on them. STL std::transform is lucky because it does not need those tags, but to tailer a fully optimized algorithm, PPL Concurrency::parallel_transform depends on those tags.

    The second problem is that , for non-random access iterators (like forward_iterator), PPL parallel_transform requires iterators have well defined pointer_type,  in other words, if the object be referenced by iterator does not have a stable address (like temporary or proxy  object), PPL parallel_transform does not support it ( but those objects with random_access iterator will be fine).

    I hope these would help.

     

    Hong 

    • Proposed as answer by Rahul V. PatilModerator Monday, October 31, 2011 11:01 PM
    • Marked as answer by GT227 Tuesday, November 1, 2011 7:32 PM
    Monday, October 31, 2011 6:17 PM
  • Ok thanks. I marked this thread as answered.

     

    G.

    Tuesday, November 1, 2011 7:55 PM