首页 > 解决方案 > 部分填充的 MPI 笛卡尔网格

问题描述

是否可以创建仅“部分”填充节点的 MPI 笛卡尔网格?下面的一段代码总结了这个问题。我正在创建一个 4x4 网格,并且仅使用 15 个处理器运行程序,这会引发“MPI_ERR_DIMS:无效拓扑维度”错误。

下面是重现错误的代码(当使用少于 4x4=16 的处理器运行时):

MPI_Comm
create_topology(int size)
{
    MPI_Comm grid;
    int dims[2] = {4,4};
    int periods[2] = {0,0};

    MPI_Dims_create(size, 2, dims);
    printf("dims = {%d,%d}", dims[0], dims[1]);
    MPI_Cart_create(MPI_COMM_WORLD, 2, dims,
        periods, 0, &grid);

    return grid;
}

int
main(int argc, char** argv)
{
    MPI_Comm topo;
    int rank, size;

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    /* Initializing the grid */
    topo = create_topology(size);

    /* Printing coordinates */
    int coords[2];
    MPI_Cart_coords(topo, rank, 2, coords);

    if(rank == 0) {
        printf("Root:    [%d] -> [%d,%d]\n",
            rank, coords[0], coords[1]);
    } else {
        printf("Process: [%d] -> [%d,%d]\n",
            rank, coords[0], coords[1]);
    }

    MPI_Finalize();
    return 0;
}

我还尝试直接传递一个 dims[]{4,4} 数组,而不使用 MPI_Dims_create 函数,该函数从 MPI_Cart_create 引发了一个 MPI_ERR_ARG。

有没有办法做到这一点?

标签: algorithmparallel-processingopenmpitopology

解决方案


推荐阅读