I'm using magick++ library to manage images. I want to distribute my algorithm using openMPI, is it possible to send objects?
for example in my code I have
Image image(imgName);
int w = image.columns();
int h = image.rows();
PixelPacket *pixels = image.getPixels(0, 0, w, h);
Can I send pixels
with MPI_Send or Scatter of whatever? if yes with which datatype?
I am no C++ programmer, but the following does what you are asking. Basically, I start 8 MPI process (I happen to use
mpich
) and the master reads in an image (Lena of course, from aPNG
file) using Magick++ and then sends her to each of the slaves. The slaves receive Lena and rebuild her from the data they receive and each slave writes out its own local copy as aJPEG
under a different name.I cheated on the sizes because working out the sizes and passing those is easy but not germane to what I am demonstrating.
My
Makefile
looks like this:It runs like this:
And the outputs look like this:
In general, unless you have a special library that's doing packing for you, it's never possible to send a specialized object in MPI. The built-in datatypes are listed in the MPI Standard (MPI 3.0 page 665, Defined Values and Handles has a list), but at a high level, they're:
MPI_CHAR
MPI_INT
MPI_FLOAT
MPI_DOUBLE
MPI_BYTE
There are a lot more than that, but most of them end up being something like that.
You can take those types and put them together to make your own custom datatypes. For instance, if you know that you're going to send a bunch of structs that contain something like:
You can construct a type to hold that, it would be a contiguous type for the name and then a struct type for the overall datatype (which would contain the int, the type you construct for the name, and the double).
All you'd have to do is create a datatype which describes your
PixelPacket
.