How to declare a vector or array of reducer objects in Cilk++?

How to declare a vector or array of reducer objects in Cilk++?

Hi All,

I found that I can't declare a vector of reducer
objects (maybe I used it in a wrong way):

typedef cilk::reducer_opadd T_reducer;
vector bitmiss_vec;

for (int i = 0; i < 24; ++i) {
T_reducer r;
bitmiss_vec.push_back;
}

However, when I compile the code with Cilk++, it complains at the
push_back() line:

cilk++ geneAttack.cilk -O1 -g -lcilkutil -o geneAttack
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/cilk++/reducer_opadd.h: In member function void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp = cilk::reducer_opadd]:
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_vector.h:601: instantiated from void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cilk::reducer_opadd, _Alloc = std::allocator >]
geneAttack.cilk:667: instantiated from here
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/cilk++/reducer_opadd.h:229: error: cilk::reducer_opadd::reducer_opadd(const cilk::reducer_opadd&) [with Type = int] is private
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/ext/new_allocator.h:107: error: within this context
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/cilk++/reducer_opadd.h: In member function void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = cilk::reducer_opadd, _Alloc = std::allocator >]:
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_vector.h:605: instantiated from void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cilk::reducer_opadd, _Alloc = std::allocator >]
geneAttack.cilk:667: instantiated from here
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/cilk++/reducer_opadd.h:229: error: cilk::reducer_opadd::reducer_opadd(const cilk::reducer_opadd&) [with Type = int] is private
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/vector.tcc:252: error: within this context
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_vector.h:605: instantiated from void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cilk::reducer_opadd, _Alloc = std::allocator >]
geneAttack.cilk:667: instantiated from here
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/cilk++/reducer_opadd.h:230: error: cilk::reducer_opadd& cilk::reducer_opadd::operator=(const cilk::reducer_opadd&) [with Type = int] is private
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/vector.tcc:256: error: within this context
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/cilk++/reducer_opadd.h: In static member function static _BI2 std::__copy_backward<_BoolType, std::random_access_iterator_tag>::__copy_b(_BI1, _BI1, _BI2) [with _BI1 = cilk::reducer_opadd*, _BI2 = cilk::reducer_opadd*, bool _BoolType = false]:
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:465: instantiated from _BI2 std::__copy_backward_aux(_BI1, _BI1, _BI2) [with _BI1 = cilk::reducer_opadd*, _BI2 = cilk::reducer_opadd*]
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:474: instantiated from static _BI2 std::__copy_backward_normal<, >::__copy_b_n(_BI1, _BI1, _BI2) [with _BI1 = cilk::reducer_opadd*, _BI2 = cilk::reducer_opadd*, bool = false, bool = false]
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:540: instantiated from _BI2 std::copy_backward(_BI1, _BI1, _BI2) [with _BI1 = cilk::reducer_opadd*, _BI2 = cilk::reducer_opadd*]
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/vector.tcc:253: instantiated from void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = cilk::reducer_opadd, _Alloc = std::allocator >]
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_vector.h:605: instantiated from void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cilk::reducer_opadd, _Alloc = std::allocator >]
geneAttack.cilk:667: instantiated from here
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/cilk++/reducer_opadd.h:230: error: cilk::reducer_opadd& cilk::reducer_opadd::operator=(const cilk::reducer_opadd&) [with Type = int] is private
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:433: error: within this context
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/cilk++/reducer_opadd.h: In function void std::_Construct(_T1*, const _T2&) [with _T1 = cilk::reducer_opadd, _T2 = cilk::reducer_opadd]:
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_uninitialized.h:87: instantiated from _ForwardIterator std::__uninitialized_copy_aux(_InputIterator, _InputIterator, _ForwardIterator, std::__false_type) [with _InputIterator = cilk::reducer_opadd*, _ForwardIterator = cilk::reducer_opadd*]
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_uninitialized.h:114: instantiated from _ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = cilk::reducer_opadd*, _ForwardIterator = cilk::reducer_opadd*]
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_uninitialized.h:254: instantiated from _ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>) [with _InputIterator = cilk::reducer_opadd*, _ForwardIterator = cilk::reducer_opadd*, _Tp = cilk::reducer_opadd]
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/vector.tcc:275: instantiated from void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = cilk::reducer_opadd, _Alloc = std::allocator >]
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_vector.h:605: instantiated from void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = cilk::reducer_opadd, _Alloc = std::allocator >]
geneAttack.cilk:667: instantiated from here
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/cilk++/reducer_opadd.h:229: error: cilk::reducer_opadd::reducer_opadd(const cilk::reducer_opadd&) [with Type = int] is private
/usr/local/cilk/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../include/c++/4.2.4/bits/stl_construct.h:81: error: within this context
make: *** [geneAttack] Error 1
jinchen@galactica:~/workspace/biometrics/genAttack$ make
cilk++ geneAttack.cilk -O1 -g -lcilkutil -o geneAttack
geneAttack.cilk: In function int cilk cilk_main(int, char**):
geneAttack.cilk:670: error: expected primary-expression before , token
geneAttack.cilk:670: error: expected primary-expression before } token
geneAttack.cilk:674: error: bitmiss_vec was not declared in this scope
make: *** [geneAttack] Error 1

The Cilk++ manule says it supports array/vector of reducers, although
there are performance issues to consider:

"If you create a large number of reducers (for example, an array or
vector of reducers) you must
be aware that there is an overhead at steal and reduce that is
proportional to the number of
reducers in the program.
"

I was using Ubuntu 10.04 on a 64-bit machine. Anyone knows what is going on? How should I declare/use vector of
reducers?
Thank you!

-Jin

publicaciones de 2 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

Hi Jin,

Sorry about the delayed response. The documentation is misleading, thank you for pointing it out. You cannot have a vector of reducers because vectors require element types that are copy-constructible and assignable. Reducers are neither (what would it mean to copy a reducer). You can, however, create an array of reducers:

T_reducer *bitmiss_vec = new T_reducer[24];

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya