Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Parallelise matlab using MPI (C or C++)
Posted:
Apr 6, 2014 2:01 AM


"Leo Kay" <anousleshommes@hotmail.com> wrote in message <lhmihf$l6o$1@newscl01ah.mathworks.com>... > Hello, > I guess this question is more for the initiated, but I don't really know where to look so here goes. > I'd like to run the simple matlab piece of code below on a supercomputer using C to lanuch mpi and then entering parameters in C which would then be taken as parameter attributes by a matlab piece of code. The parameter attributes entered into matlab would designate which core performs which computation and in that sense should speed up the operation. > Example C initiates MPI and asks for say 4 workers on a single core. For each worker, see sends the worker parameter to a matlab script and the script thus runs up to a set number n where n = N/4 , so for a FOR LOOP you only solve the loop up to n for the worker. > Then you need to return results and aggregate. > > Apparently this is doable with system function for C > > Can someone enlighten me of how I should go about implement this please? > > Here is a piece of code for which I would very much like this to work > > > if matlabpool('size') == 0 % checking to see if my pool is already open > matlabpool open 2 > end > parfor kay = 1:size(eige,1) > % normalise eigenvector > eige(kay,:) = eige(kay,:)./norm(eige(kay,:)); > entrop(kay) = (1/log(QG.numB))*sum((abs(eige(kay,:)).^2).*log(abs(eige(kay,:)).^2)) ; > end > > > > where eige is a matrix and entrop a vector. > Things to note: The node on the supercomputer has 16 cores and 8 workers per core. I am unsure if the code I use to open the matlabpool is valid and whether I should actually open more than 2 (this is just a safe but obviously low choice). Other thing to note is that code above will run as slowly as a for look because the time consuming sum is actually for each index 'kay'. It is possible I might want to have the parfor inside the for loop to compute the sum, but isn't that illegal? > > So can someone help as to use the simple piece of code above into a c script for mpi? > > Thanks in advance
I think you'll find Jeremy Kepner's pMatlab and his "Parallel Matlab for Multicore and Multinode Computers" book (SIAM 2009, ISBN 089871673X) helpful.
Yair Altman http://UndocumentedMatlab.com



