ARBB and classes

ARBB and classes

HiIn order to parallelize function in class member i'd like to use this kind of structure :class toto{public : toto() {}; void valuate(arbb::f64 & ret) { ret =0. ; }; void values( arbb::dense & ret ) { arbb::map(toto::valuate)(ret); } void paral_call( arbb::dense & ret) { arbb::call(toto::values)(ret); }}Why is it impossible. Of course no problem if used outside class.Is there a workaround to achieve the parallelizationThank you

publicaciones de 4 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de Zhang Z (Intel)

Let me try to explain what I think about why it's not working. I might be wrong, so I will double check with ArBB engineers later on to confirm. But I do have a workaround, which surely works for this case.

Because you are using arbb::map and arbb::call inside member methods of a class, you are involving the "this" pointer in the calls. That is, your code looks like this from a compiler's point of view:

arbb::map(this->valuate)(ret);
arbb::call(this->values)(ret);

However, "this" pointer is not an ArBB type. It is a regular C++ type (toto*). ArBB mandates that functions to be captured must have all parameters as ArBB types. This means the calling object must also be an ArBB type. Because "this" pointer is not an ArBB type, the member methods toto::valuate() and toto::values() cannot be captured.

The workaround is straightforward. You just declare the two functions as static members of the class:

static void valuate(arbb::f64 & ret) { ... }

static void values(arbb::dense & ret) { ... }

Let me know if this helps. Thanks.

Hi ZhangThank you gor the answer but idon't want to use a static member. I effectively noticed that in the samples with the doc the member were static.I explain what i have in mindclass toto{public :bool buyer ;static void valuate(arbb::f64 & ret){ if (buyer) { } else{ }}}void values(arbb::dense & ret) { ... }}I want to capture the behavior of valuate at the first call to avoid futher " if else". It sounds reasonable because for this function member buyer is global .....It would be very attractive to have the same behavior as with normal function ....Otherwise i would have made an ARBB class.....If you have a way to do it easily...Thank you very muchXavier

Imagen de Stefanus Du Toit (Intel)

I want to capture the behavior of valuate at the first call to avoid futher " if else". It sounds reasonable because for this function member buyer is global .....

Capturing member functions with associated state (a proper "this" variable) is a feature we intend to add to a future release of ArBB. We are also looking at allowing the capture of arbitrary function objects, to allow capture to use some C++ state in defining a closure.Unfortunately the only way to do what you want at the moment is to use a global object (e.g. a singleton) of some kind. We realize this is not a very good C++ idiom, and therefore definitely plan to add the member function version. It will look something along the lines of:

X x; // X has a member function "foo"
capture(&x, X::foo);

Inicie sesión para dejar un comentario.