在openMPI, c++中发送ImageMagick对象

sending ImageMagick object in openMPI, C++

本文关键字:ImageMagick 对象 openMPI c++      更新时间:2023-10-16

我的项目遇到了一个严重的问题。我需要将图像数据发送到集群中的另一个节点。我用ImageMagick读取图像,如:

Image testImage;
// read in the file
testImage.read("image.png");

我发送它为:

MPI_Send( &testImage, sizeof(Image), MPI_BYTE, i , 100, MPI_COMM_WORLD);

其他节点应该接收它为:

Image subimage_toModify;
MPI_Recv( &subimage_toModify, sizeof(Image), MPI_BYTE, 0, 100, MPI_COMM_WORLD, &status);

但是我得到一个分割错误:

Signal code: Address not mapped (1)

有谁能帮忙吗?我几乎要沮丧了!

Image类不是POD类型,因此不能使用MPI_Send发送

最简单的方法是发送BLOB数据,您可以从Image对象获得BLOB数据,但这可能不是最佳方法。所以,像这样做:
Image testImage;
// read in the file
testImage.read("image.png");
Blob blob;
testImage.write( & blob );
int size = blob.length();
MPI_Send( &size, sizeof( size ), MPI_BYTE, i , 100, MPI_COMM_WORLD);
MPI_Send( blob.data(), blob.length(), MPI_BYTE, i , 100, MPI_COMM_WORLD);

接收:

int size = 0;
MPI_Recv( &size, sizeof( size ), MPI_BYTE, 0, 100, MPI_COMM_WORLD, &status);
std::vector< unsigned char > tempBuffer( size, 0 );
MPI_Recv( &tempBuffer[0], tempBuffer.size(), MPI_BYTE, 0, 100, MPI_COMM_WORLD, &status);
Blob blob( &tempBuffer[0], tempBuffer.size());