【问题标题】:Sending column through MPI_Bcast通过 MPI_Bcast 发送列
【发布时间】:2013-10-14 22:18:52
【问题描述】:

我正在解决一个问题,其中一个进程对列进行一些计算,我将该列保存在一个临时数组中,并使用 MPI_Bcast 将其广播到所有其他进程,但最终总是在数组中得到全零在接收端。

下面是我正在使用的代码:

//nProc = no of processors;
//helperA = 2D Array i.e. helperA[size][size]
// colK = 1D Array i.e. colK[size]

for (int k = 0; k < size; ++k) {
    if (k % nProc == rank) {
                    // One of the process will do this calculation
        int temp = 0;
        for (int j = k + 1; j < size; ++j) {
            helperA[j][k] = helperA[j][k]/helperA[k][k];
            colK[temp++] = helperA[j][k];
        }
    }

    MPI_Bcast(colK, size - k - 1, MPI_DOUBLE, rank, MPI_COMM_WORLD);    
    // After this other process should get the colK updated with the calculation

    for (int i = k + 1; i < size; ++i) {
        if (i % nProc == rank) {
            int temp = 0;
            for (int j = k + 1; j < size; ++j) {
                                    // Here colK is always zero
                printf("%d %f \n", rank, colK[temp]);
                helperA[j][i] = helperA[j][i] - (colK[temp++] * helperA[k][i]);
            }
        }
    }
}

我不确定我在这里做错了什么。请提供任何帮助/建议。

【问题讨论】:

    标签: c mpi broadcast


    【解决方案1】:

    (我真的不喜欢通过文本框调试代码,所以我假设您已经完成了基本检查,以确保在发送之前colK 中确实有数据并且size-k-1 是所有等级的正确值。)

    您传递给MPI_BCAST 调用的等级值应该是“根”进程的等级。也就是拥有所有要广播的数据的进程。对于所有调用进程,此参数必须相同。您的代码似乎通过了每个调用进程的等级,因此每个人都将尝试与不同的根进程进行通信。

    【讨论】:

    • 谢谢。是的,我已经完成了错误检查并且数据是他们的,但你的观点是有效的,如果是这种情况,我会检查一下并更新你。
    • 就是这样 :) 非常感谢您的帮助!!
    猜你喜欢
    • 2012-06-06
    • 2012-08-06
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多