Tuesday, January 28, 2014

Things to remember when using parfor

This website from matlab:
http://www.mathworks.com/help/distcomp/programming-considerations.html

-- cannot use clear inside the loop


specifically:

=========
Similarly, you cannot clear variables from a worker's workspace by executing clear inside a parfor statement:
parfor ii= 1:4
    <statements...>
    clear('X')  % cannot clear: transparency violation
    <statements...>
end
As a workaround, you can free up most of the memory used by a variable by setting its value to empty, presumably when it is no longer needed in your parfor statement:
parfor ii= 1:4
    <statements...>
    X = [];
    <statements...>
end
 =============