parallel processing - C++ AMP nested loop -
i'm working on project requires massive parallel computing. however, tricky problem that, project contains nested loop, this:
for(int i=0; i<19; ++i){ for(int j=0; j<57; ++j){ //the computing section } }
to achieve highest gain, need parallelise 2 levels of loops. this:
parallel_for_each{ parallel_for_each{ //computing section } }
i tested , found amp doesn't support nested loops. have idea on problem? thanks
you could, @high performance mark suggest collapse 2 loops one. however, don't need c++ amp because supports 2 , 3 dimensional extent
s on array
s , array_view
s. can use index
multi-dimensional index.
array<float, 2> x(19,57); parallel_for_each(x.extent, [=](index<2> idx) restrict(amp) { x[idx] = func(x[idx]); }); float func(const float v) restrict(amp) { return v * v; }
you can access individual sub-indeces in idx
using:
int row = idx[0]; int col = idx[1];
you should consider amount of work being done computing section
. if relatively small may want have each thread process more 1 element of array, x
.
the following article worth reading cpu if loops not access memory efficiently can have big impact on performance. arrays row major in c++ amp
Comments
Post a Comment