我是DPC++的新手,我尝试开发一个基于MPI的DPC++泊松求解器。我读了这本书,对缓冲区和指针和共享或主机回忆录感到非常困惑。这两件事的区别是什么,以及我在开发代码时应该使用什么。
现在,我使用由带有const大小的std::数组初始化的缓冲区作为串行代码,并且运行良好。然而,当我将DPC++代码与MPI耦合时,我必须为每个设备声明一个本地长度,但我没有做到这一点。这里我附上我的代码
define nx 359
define ny 359
constexpr int local_len[2];
global_len[0] = nx + 1;
global_len[1] = ny + 1;
for (int i = 1; i < process; i++)
{
if (process % i == 0)
{
px = i;
py = process / i;
config_e = 1. / (2. * (global_len[1] * (px - 1) / py + global_len[0] * (py - 1) / px));
}
if (config_e >= cmax)
{
cmax = config_e;
cart_num_proc[0] = px;
cart_num_proc[1] = py;
}
}
local_len[0] = global_len[0] / cart_num_proc[0];
local_len[1] = global_len[1] / cart_num_proc[1];
constexpr int lx = local_len[0];
constexpr int ly = local_len[1];
queue Q{};
double *m_cellValue = malloc_shared<double>(size, Q);我得到了错误
error: default initialization of an object of const type 'const int[2]'
error: cannot assign to variable 'local_len' with const-qualified type 'const int[2]'
main.cpp:52:18: error: cannot assign to variable 'local_len' with const-qualified type 'const int[2]'有没有任何方法只定义一个可变大小的数组来执行DPC++中的并行操作?
发布于 2022-04-26 17:14:01
您太急于使用constexpr了。删除这段代码中的所有三处内容,并进行编译。因此,这与DPC++无关。
https://stackoverflow.com/questions/72016205
复制相似问题