26
edits
m (show "introduction" header) |
(→Usage) |
||
Line 12: | Line 12: | ||
== Usage == | == Usage == | ||
To load the package, {{codeline|pkg load ndpar}} | To load the package, {{codeline|pkg load ndpar}} | ||
=== setting CatDimensions and IdxDimensions - vectorized === | |||
Suppose we have a function that works along different dimensions of its input arguments, and returns arrays of different shapes like | |||
<code> | |||
<pre> | |||
function [x, y] = f(u, v) | |||
x = u + v.'; | |||
y = x.'; | |||
endfunction | |||
</pre> | |||
</code> | |||
This function is used only to illustrate the syntax, not the usefulness of the extension. | |||
Admittedly such a simple case could be handled easily either by changing the function or making a small wrapper to it. But it becomes really interesting when we are dealing with arrays of many and different dimensions (not shown here yet). | |||
Applying this function to arrays u and v can be straightforwardly parallelized : | |||
{{code|setting CatDimensions and IdxDimensions - vectorized| | |||
<pre> | |||
u = [1:10; 2:11]; | |||
v = u.'; | |||
[x, y] = ndpar_arrayfun(2, @f, u, v, "Vectorized", true, "ChunksPerProc", 2, "VerboseLevel", 1, "CatDimensions", [2 1],"IdxDimensions", [2 1] ); | |||
</pre> | |||
}} | |||
Here is the meaning of the options | |||
* {{codeline|"IdxDimensions", [2 1]}} The parallelization (or slicing, or indexing) should be done along the 2nd dimension of {{codeline|u}} and 1st dimension of {{codeline|v}}. A value of 0 means no indexing (no slicing), so the argument would be passed "as is". | |||
* {{codeline|"CatDimensions", [2 1]}} The outputs from each slice should be concatenated along the 2nd dimension of the first output and 1st dimension of the second output | |||
* {{codeline|"Vectorized", true}} Use only if the function is vectorized along the "indexing" dimensions. | |||
* {{codeline|"ChunksPerProc", 2}} It means that each process should make 2 chunks (2 calls to {{codeline|f}} with {{codeline|"Vectorized", true}}). Increase this number to minimize memory usage for instance. Increasing this number is also useful if function executions can have very different durations. If a process is finished, it can take over jobs from another process that is still busy. |
edits