Passing class to arbb code

Passing class to arbb code

xavier.warin@gmail.com的头像

Hi Trying to have large arbb function, i face a problem with executing function captured by arbb. Here is the small exemple i took : // a small class
class PayOffSoSimple { public : PayOffSoSimple() {} PayOffSoSimple( const PayOffSoSimple & pay) {} arbb::f64 operator()() const { return 1.; } }; // a first caller with payoff function instanciated inside the caller void caller_( const arbb::usize & N) { PayOffSoSimple pay; arbb::dense Sol(N); _for (arbb::usize i= 0 , i < N , ++i) { Sol[i] = pay(); } _end_for; } // a second one with the pay off as argument void caller( const PayOffSoSimple & pay, const arbb::usize & N) { arbb::dense Sol(N); _for (arbb::usize i= 0 , i < N , ++i) { Sol[i] = pay(); } _end_for; } int main(int argc, char *argv[]) { arbb::usize N_ = 10 ; PayOffSoSimple paySoSimple; // OK arbb::dense sol(N_) ; _for (arbb::usize i= 0 , i < N_ , ++i) { sol[i] = paySoSimple(); } _end_for; // OK arbb::call(caller_)(N_); // exception arbb::call(caller)(paySoSimple,N_); return 0 ; } here is the exception : terminate called after throwing an instance of 'arbb_2::exception' what(): zero types captured Aborted Why is the second caller impossible to use ? Thank you Sincerely yours.

3 帖子 / 0 new
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
Zhang Z (Intel)的头像

The problem here is that the PayoffSoSimple class does not have a member variable. So when ArBB tries to capture this user defined type it has nothing to capture. ArBB documentation says one of the requirements for a user defined type is that member variables of the type must be ArBB types. But it does not say what if the user defined type does not have any data members. This particular case is really a corner case. Thanks for bringing it to our attention. We will investigate how to better address this corner issue and make improvements if necessary.

An easy workaround for this problem is adding a dummy member variable to your class:

class PayOffSoSimple { public : PayOffSoSimple() {} PayOffSoSimple( const PayOffSoSimple & pay) {} arbb::f64 operator()() const { return 1.; }

u8 dummy; };

Thanks.

xavier.warin@gmail.com的头像

Thank you very much !!

登陆并发表评论。