Context
At work I built a GUI to perform image registration on several microscopy images. On the computer I'm using (i.e. at work) the Parallel Processing Toolbox is installed, so I can take advantage of spmd blocks to distribute the work on the computer's cores.
First I create a codistributed array to split my array into smaller chunks:
spmd
DistributedCell = codistributed.cell(NumberFrames)
...
end
All is well until I run the code on my own laptop, on which the Parallel Processing Toolbox is not installed. Obviously I can't use spmd
blocks and codistributed arrays so I wrote non-parallelized code to register the images, which works equally well but takes longer to execute.
The problem
The problem I'm having is that the code in spmd
blocks needs to be commented when I'm using my home laptop, otherwise Matlab complains that:
MATLAB cannot determine whether "codistributed"
refers to a function or variable.
So even if I check whether I have the PP toolbox installed (or not) and use a condition to execute different commands depending on whether it is or not as follows:
%// Check for parallel toolbox installed
if ~isempty(ver('parallel'))
NON-PARALLEL code...
else
PARALLEL code...
spmd
PROBLEM HERE
DistributedCell = codistributed.cell(NumberFrames)
...
end
end
Matlab won't evaluate the condition of the if
statement and will throw the error I mentioned above. This is quite cumbersome since every time I use the code on my laptop I need to comment all the lines generating the error (there are many of them) and vice versa when I'm at work.
Question
Is it possible to avoid commenting the code manually and make Matlab don't bother about codistributed arrays when it is running on a computer on which the PP toolbox is not installed?
Maybe I missed something obvious in the debugging world but I can't get around it.
I'm running on Mac if that can be useful (R2015a at work and R2013a at home).
EDIT
To clarify the situation:
The error pops up before any line of code is executed at all. I guess Matlab parses the whole code before executing any of it, so the only way I can avoid it is to comment it. That does not happen with other functions (in this case the classic undefined function [...]
appears) but I can avoid it with the if/else
statement. It really is the codistributed
term that Matlab does not like.