dpc++ 使用 parallel_for 范围从 1 到 n-2 开始 do 循环

dpc++ start the do loop from 1 to n-2 using parallel_for range

是否可以使用 dpc++ 启动 do 循环并且索引从 1 到 n-2 parallel_for?

h.parallel_for(range{lx , ly }, [=](id<2> idx

这将给出一个从 0 到 lx-1 的 do 循环,我必须这样做

idx[0]>0 && idx[1]>0 && idx[0]<lx-1 && idx[1]<ly-1

然后我可以完成循环吗?

还有,dpc++支持4D吗parallel_for?

在 SYCL 1.2.1 中,parallel_for 支持偏移量,因此您可以使用 h.parallel_for(range{lx-2, ly-2}, id{1, 1}, [=](id<2> idx){ ... });

但是,这个重载 has been deprecated in SYCL 2020:

Offsets to parallel_for, nd_range, nd_item and item classes have been deprecated. As such, the parallel iteration spaces all begin at (0,0,0) and developers are now required to handle any offset arithmetic themselves. The behavior of nd_item.get_global_linear_id() and nd_item.get_local_linear_id() has been clarified accordingly.

所以,如果你想符合最新的标准,你应该手动应用偏移量:

h.parallel_for(range{lx-2, ly-2}, [=](id<2> idx0) { id<2> idx = idx0 + 1; ... });

也就是说,根据您的数据布局,您原来使用“空”线程的方法可能会更快。

Also, does dpc++ support like 4D parallel_for?

没有。您将不得不使用 1D 范围并手动计算 4D 索引。