|
From: Kukanov, A. <Ale...@in...> - 2008-03-06 22:32:14
|
Hi everyone, There was a problem reported recently in the TBB forum (see that post below). The user wanted to change the data item in Body::operator(), but passing the item by reference caused compilation errors. The user was misled by an error in TBB documentation that said Body::operator() takes items to process by reference. That post made me thinking if such usage model is something TBB should be able to handle, and if so, what the best way is to handle it. For example, should parallel_do be extended or reworked for it, or should it better be implemented in a special algorithm? What do you think? Regards, - Alexey Kukanov TBB developer @ Intel ________________________________ Original forum post: Posted By: devbisme in Intel(r) Threading Building Blocks Subject: problems using parallel_do View the complete topic at: http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/302 50244.aspx I'm trying to use parallel_do (using tbb20_20080226oss), but I'm getting an error from the compiler (MS VC++ 2005). I am trying to process some data in a simple structure maintained in a list: typedef struct { double v1, v2, v3; } my_item_t; typedef list<my_item_t> vec_list; class Body{ public: typedef my_item_t argument_type; Body() {}; // overload () so it does a vector multiply void operator() (argument_type& it) const { it.v3 = it.v1 * it.v2; } }; The () operator takes a reference to the simple structure as shown in the documentation for parallel_do. However, the compiler cannot find a () operator that matches the prototype it wants. If I change the operator by removing the reference, then it compiles with no errors: void operator() (argument_type it) const { it.v3 = it.v1 * it.v2; } But this doesn't work because any changes made by the operator only occur in the local copy and don't get passed back into the main list. I can get around this problem by making a list of pointers that point to the data structures, but it seems like the code shown above should work and I want to understand where I'm making my mistake. Thanks for any enlightenment anyone can give. -------------------------------------------------------------------- Closed Joint Stock Company Intel A/O Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russia Federation This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. |