Open keryell opened 3 years ago
The example
class RandomFiller { public: RandomFiller(accessor<int> ptr) : ptr_ { ptr } { std::random_device hwRand; std::uniform_int_distribution<> r { 1, 100 }; randomNum_ = r(hwRand); } void operator()(item<1> item) const { ptr_[item.get_id()] = get_random(); } int get_random() { return randomNum_; } private: accessor<int> ptr_; int randomNum_; }; void workFunction(buffer<int, 1>& b, queue& q, const range<1> r) { myQueue.submit([&](handler& cgh) { accessor ptr { buf, cgh }; RandomFiller filler { ptr }; cgh.parallel_for(r, filler); }); }
is kind of misleading because of the useless call to get_random() instead of returning directly randomNum_, which might suggest with the call operator that a different random number is used for each work-item.
get_random()
randomNum_
simplify with direct member
The example
is kind of misleading because of the useless call to
get_random()
instead of returning directlyrandomNum_
, which might suggest with the call operator that a different random number is used for each work-item.