On 9 February 2016 at 03:52, Arun Das <
arund...@gmail.com> wrote:
> Hello !
>
> I am taking a course on MPI programming and is going to do an image
> processing project very soon. I installed OpenCV and did basic image
> manipulations like opening, viewing, scaling, splitting images. The next
> step for me was to slice the image and send them to different nodes using
> Scatter() and gather them back using Gather(). I have been working on it for
> a couple of days now and I am missing the basic understanding on how the
> image can be scattered properly. Could you guys please guide me ?
>
What kind of image processing algorithms are you planning to use?
Depending on whether you need "ghost cells" (i.e entries from
neighboring processors) to perform the local processing, things go
from trivial to complicated.
The other thing you have to decide is how do you want to distribute
your data: you can use either a easy one-dimensional distribution
(i.e, distribute the rows) or a more complicated two-dimensional
distribution (i.e. distribute both rows and columns). If you are a
beginner, I would start experimenting with 1D distributions. Also be
aware that your image size might not be a multiple of the number of
processes in the run, so you'll likely have to use
Scatterv()/Gatherv() (i.e. in MPI parlance, the "vector" variant of
scatter/gather)
Take a look at this example:
https://bitbucket.org/dalcinl/pasi-2011-mpi4py/src/default/examples/mandelbrot-mpi-block.py
That's a start, you have to do basically the same to gather the
results back to process zero. What is left is the initial Scatterv()
to distribute your image from processes zero.
Line 23 is (one of the) the usual ways to compute the local number of
rows "N" given the global number of rows "h".
Line 25 is a quick way to compute the (global) start row index
corresponding to each local piece, in case you need it in your
computations.
Line 39 is a quick way to get a list of local sizes, you have to use
it to either Scatterv()/Gatterv().
Try to understand what's going on in this example first, add print
statements here and there, change the global sizes, run it with
1,2,3,... processes, and so on. If you still cannot Scatter/Gather you
image, then write us back, I'll write the code for you, but remember
that you learn by doing and making mistakes :-)
--
Lisandro Dalcin
============
Research Scientist
Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
Numerical Porous Media Center (NumPor)
King Abdullah University of Science and Technology (KAUST)
http://numpor.kaust.edu.sa/
4700 King Abdullah University of Science and Technology
al-Khawarizmi Bldg (Bldg 1), Office # 4332
Thuwal 23955-6900, Kingdom of Saudi Arabia
http://www.kaust.edu.sa
Office Phone:
+966 12 808-0459