sending ImageMagick object in openMPI, C++
I have a severe problem in my project. I need to send an image data to another node in the cluster. I read the images with ImageMagick, as like:
Image testImage;
// read in the file
testImage.read("i开发者_运维问答mage.png");
And i send it as:
MPI_Send( &testImage, sizeof(Image), MPI_BYTE, i , 100, MPI_COMM_WORLD);
the other nodes should receive it as:
Image subimage_toModify;
MPI_Recv( &subimage_toModify, sizeof(Image), MPI_BYTE, 0, 100, MPI_COMM_WORLD, &status);
But i get a Segmentation Fault:
Signal code: Address not mapped (1)
can anyone be of any help? i am almost frustrated !
The Image
class is not a POD type, therefore you can not send it using MPI_Send
The simplest way to do it is to send BLOB data, which you can get from the Image object, but it might not be optimal. So, do it like this :
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);
To receive :
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());
精彩评论