# vectorwise parallelization with pararrayfun

3 messages
Open this post in threaded view
|

## 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