MPI发送& recv不工作,程序继续运行

时间:2015-12-22 10:22:14

标签: c++ mpi

我正在尝试将图像发送到另一个进程,但我写的代码不会起作用。代码只是永远运行。

MPI_Init(NULL, NULL);

MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Status status;


int imgWidth = 0, imgHeight = 0, kernelWidth = 0, kernelHeight = 0, newImgWidth = 0, newImgHeight = 0, amountOfPixels = 0, verticalPixels = 0, horizontalPixels = 0, lines = 0, rest = 0;

float* image = NULL;
float* kernel = NULL;
float* newImage = NULL;
float* recvBuffer = NULL;

在根中我写了这段代码:

if(rank == root) {
    double offset = atof(argv[3]);
    double scale = atof(argv[4]);

    image = getImageData(argv[1], &imgWidth, &imgHeight);
    kernel = getImageData(argv[2], &kernelWidth, &kernelHeight);

    newImgHeight = imgHeight + kernelHeight - 1;
    newImgWidth = imgWidth + kernelWidth - 1;

    newImage = new float[newImgWidth*newImgHeight];

    zeroPadding(newImage, image, newImgWidth, newImgHeight, imgWidth, imgHeight);
    saveImageData(newImage, newImgWidth, newImgHeight, "testOutput.png");

    amountOfPixels = newImgWidth * newImgHeight;
    cout << "send AOP" << amountOfPixels << endl;

    MPI_Ssend(newImage, amountOfPixels, MPI_FLOAT, i, 0, MPI_COMM_WORLD);
}

这是剩下的

MPI_Bcast(&kernelWidth, 1, MPI_INT, root, MPI_COMM_WORLD); // Broadcast the kernelWidth
MPI_Bcast(&kernelHeight, 1, MPI_INT, root, MPI_COMM_WORLD); // Broadcast the kernelHeight
MPI_Bcast(&imgWidth, 1, MPI_INT, root, MPI_COMM_WORLD); // Broadcast the imageWidth
MPI_Bcast(&imgHeight, 1, MPI_INT, root, MPI_COMM_WORLD); // Broadcast the imageHeight



if(rank == 1){
    cout << "HELLO FROM 1" << endl;
    newImgHeight = imgHeight + kernelHeight - 1;
    newImgWidth = imgWidth + kernelWidth - 1;


    amountOfPixels = newImgWidth * newImgHeight;
    recvBuffer = new float[amountOfPixels];

    cout << rank << "receive AOP" << amountOfPixels << endl;
    MPI_Recv(recvBuffer, amountOfPixels, MPI_FLOAT, root, 0, MPI_COMM_WORLD, &status);
}

MPI_Finalize();
// ------------------ END MPI CODE --------------------------------------

return 0;
}

newImage是一个浮点*,recvBuffer也是如此。

我想在正确的地方做所有事情我猜是因为当我只发送1个int时它停止运行,但是没有检查int值。代码的问题在于它一直在运行。我无法使用scatterv,因为我的最终解决方案中会有重叠的数据。

谢谢!

0 个答案:

没有答案