# vectorwise parallelization with pararrayfun

3 messages
Open this post in threaded view
|
Report Content as Inappropriate

## vectorwise parallelization with pararrayfun

 Hello People, Suppose I have a function called function1, which processes element-wise computation on a vector of dimensionality (1,n). Where n > 1. For example:   1 # This is a function to test parallel package   2 function        outputs = function1(inputs)   3         if ( rows(inputs) != 1 || columns(inputs) <= 1 )   4                 error("in function1: bad inputs array dimensionality");   5         endif   6         outputs = [];   7         for i = 1:columns(inputs)   8                 if ( i == 1 )   9                         outputs(1,i) = (log(inputs(1,i)) + log(inputs(1,i+1)))/2;  10                 elseif ( i == columns(inputs) )  11                         outputs(1,i) = outputs(1,i-1)*(log(inputs(1,i-1)) + log(inputs(1,i)))/2;  12                 else  13                         outputs(1,i) = outputs(1,i-1)*(log(inputs(1,i-1)) + log(inputs(1,i)) + log(inputs(1,i+1)))/3;  14                 endif  15         endfor  16 endfunction In this function, the iterations must be executed sequentially in order to keep the integrity of the computation. Now, suppose I have a second function called function2, which is a kind of wrapper that uses function1 to process an array of dimensionality (m,n) -where m > 1- vector by vector (i,:). Let's say:    1 # This is a function to test parallel package   2 function        outputs = function2(inputs)   3         if ( rows(inputs) <= 1 || columns(inputs) <= 1 )   4                 error("in function2: bad inputs array dimensionality");   5         endif   6         outputs = [];   7         for i = 1:rows(inputs)   8                 outputs(i,:) = function1(inputs(i,:));   9         endfor  10 endfunction My question is: How can I use pararrayfun to parallelize function2 in a way that just function2 is concurrent but not function1? That is to say: I want concurrency only among different rows of inputs array, but I want no concurrency at all inside of function1. Thanks
Open this post in threaded view
|
Report Content as Inappropriate

## Re: vectorwise parallelization with pararrayfun

 > My question is: How can I use pararrayfun to parallelize function2 in a way > that just function2 is concurrent but not function1? > That is to say: I want concurrency only among different rows of inputs > array, but I want no concurrency at all inside of function1. > Unless I fail to understand your question, the steps are the usual ones: 1. Make a cell out of the (m,n) array (call it X):     input = mat2cell (X, ones(m,1), n); 2. Pass this cell to parcellfun:     output = parcellfun (nproc, @function1, input, 'UniformOutput', false); 3. Reshape Y as you desired, e.g.     Y = cell2mat (output); I think you should also try to vectorize function1 a lot more (if you have memory to spare), or put it down to C++. Cheers _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave