Skipping lines of code based on available functions (s) / toolbars

Context

At work, I built a graphical interface for registering images on several microscopy images. The Parallel Processing Toolbox is installed on the computer that I use (i.e. at work), so I can use spmd blocks to distribute work on computer cores.

First I create a codistributed array to split my array into smaller pieces:

spmd

    DistributedCell = codistributed.cell(NumberFrames)
   ...
end

Everything is fine until I run the code on my own laptop on which the Parallel Processing Toolbox is not installed. Obviously, I cannot use blocks spmdand arrays with distributed distribution, so I wrote non-parallel code for registering images, which works equally well, but takes longer.

Problem

The problem I am facing is that the code in the blocks spmdneeds to be commented out when I use my home laptop, otherwise Matlab complains that:

MATLAB cannot determine whether "codistributed"
refers to a function or variable.

So, even if I check whether the PP toolbox is installed (or not), and use the 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 if , . , , , , ( ) , .

Matlab , , ​​ PP?

, - , .

Mac, (R2015a R2013a ).

:

, - . , Matlab , - . ( undefined function [...]), if/else. codistributed, Matlab.

+4
2

ver('distcomp')

if, ver('parallel'). , .

, ver? , matlabroot\toolbox ( matlabroot - ), , . , ver, , - distcomp.

Parallel Computing Toolbox Distributed Computing Toolbox, .

Edit:

, PCT, , ​​ , ver.

license('test', 'Distrib_Computing_Toolbox').

Distrib_Computing_Toolbox ? (, something.lic matlabroot\licenses) , . , ver.

, .

+4

:

>> foo = ver;

>> foo.Name
ans =
MATLAB
ans =
Signal Processing Toolbox

, , "Parallel" foo(j).Name

0

Source: https://habr.com/ru/post/1605952/


All Articles