c++ - 在 openMPI、C++ 中发送 ImageMagick 对象

标签 c++ imagemagick mpi openmpi

我的项目有一个严重的问题。我需要将图像数据发送到集群中的另一个节点。我用 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 对象中获取该数据,但这可能不是最佳方法。所以,这样做:

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());

关于c++ - 在 openMPI、C++ 中发送 ImageMagick 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6795424/

相关文章:

c++ - 我们可以将参数传递给 C++ 中的复制构造函数吗

使用 erase() 时出现 C++ std::vector 段错误,在 g++ 中使用 pop_back() 时正常

c++ - Mingw 和 libraw 导致 undefined reference

php - 在 linux/freebsd/macosx 上使用 PHP 查找实用程序的安装路径

ImageMagick 命令行 : converting PDF to high definition images

linux - 将多页 PDF 转换为单个图像

c++ - 将 vector 分散到变量 MPI 中

c - MPI_Allgather 的负缩放

c++ - 每个处理器具有不同计数值的 MPI_File_write_all

c++ - 如何分发我的 C++ Allegro 5 程序,以便它们在未安装 Allegro 的计算机上运行?