首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DPC++ & MPI,缓冲区,共享内存,变量声明

DPC++ & MPI,缓冲区,共享内存,变量声明
EN

Stack Overflow用户
提问于 2022-04-26 14:58:27
回答 1查看 125关注 0票数 0

我是DPC++的新手,我尝试开发一个基于MPI的DPC++泊松求解器。我读了这本书,对缓冲区和指针和共享或主机回忆录感到非常困惑。这两件事的区别是什么,以及我在开发代码时应该使用什么。

现在,我使用由带有const大小的std::数组初始化的缓冲区作为串行代码,并且运行良好。然而,当我将DPC++代码与MPI耦合时,我必须为每个设备声明一个本地长度,但我没有做到这一点。这里我附上我的代码

代码语言:javascript
复制
    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);

我得到了错误

代码语言:javascript
复制
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++中的并行操作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-26 17:14:01

您太急于使用constexpr了。删除这段代码中的所有三处内容,并进行编译。因此,这与DPC++无关。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72016205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档