How do I optionally disable code for a missing toolbox?

I am writing code to share with other researchers. I want to use the parallel processing toolbox for speed savings. Other researchers don't have the parallel processing toolbox.
Is there a way for everyone to use the same function? That is, skip or disable the parallel processing functions, if that toolbox is not available? Right now, my only option is to have two versions of every function, which encourages programming errors. When I was programming in C or C++, I would have solved this problem with compile flags. I tried an input flag, but this fails. MATLAB won't run a function that includes parfor if the parallel processing toolbox is missing.

4 件のコメント

Adam
Adam 2019 年 6 月 10 日
I'm not sure about other aspects of the toolbox, but I know parfor loops will work fine for people without the toolbox and will just be interpreted as a regular for loop.
I can't remember off-hand how you ask if a certain toolbox is installed though
doc ver
can be used to see what is installed. You can pass an argument to it for a specific product, but I can't see off-hand where you get the string from for any given toolbox. There are various 'See also' links from that page though which may help.
Walter Roberson
Walter Roberson 2019 年 6 月 10 日
license() with 'test'
One of my Questions lists all of the codes that I could find.
the cyclist
the cyclist 2019 年 6 月 10 日
Here is the link to Walter's question that addresses this.
Edric Ellis
Edric Ellis 2019 年 6 月 11 日
parfor loops should work correctly whether or not Parallel Computing Toolbox is installed. (Other things such as spmd and parfeval do not, unfortunately...). Of course, if PCT is not installed, a parfor loop will run in serial mode.

サインインしてコメントする。

回答 (1 件)

the cyclist
the cyclist 2019 年 6 月 10 日

0 投票

All credit to Walter, but I believe you'll want to do this test:
license('test','Distrib_Computing_Toolbox')

2 件のコメント

Walter Roberson
Walter Roberson 2019 年 6 月 10 日
Exactly.
Note though that this approach has the weakness that it tests whether the user is licensed for something, not whether the thing is installed. There are other approaches that can test whether software is installed, but not whether it is licensed. If you look at the chart I posted, you can use
ver('distcomp')
to probe whether Parallel Computing is installed.
Edric Ellis
Edric Ellis 2019 年 6 月 11 日
Internally, we tend to use something more like:
isPCTInstalled = exist('gcp', 'file') == 2;
to check whether Parallel Computing Toolbox is installed.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

リリース

R2019a

質問済み:

2019 年 6 月 10 日

コメント済み:

2019 年 6 月 11 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by