Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
PARFOR on system without Parallel Computing Toolbox

Subject: PARFOR on system without Parallel Computing Toolbox

From: Matthew

Date: 29 Oct, 2010 19:26:04

Message: 1 of 3

Is "parfor" understood by MATLAB 2010a even when the Parallel Computing Toolbox (PCT) is not installed (in which case I suppose MATLAB would run it as a for loop instead) or will the syntax generate an error message on any system on which the toolbox is not installed?

I have a code segment that I'd like to run as a parfor loop when the PCT is present, and as a for loop otherwise. I imagine something like this:

A = ver('distcomp');
if isempty(A)
    %Parallel toolbox not installed - execute for loop
    for...
    end
else
    %Parallel toolbox installed - execute parfor loop
    parfor...
    end
end

Will this generate a syntax error on a system without PCT because the keyword "parfor" isn't recognized? (I don't have access to a MATLAB system that doesn't have PCT installed so I can't test this myself).

If the above code is invalid on a non-PCT system then perhaps this would work, by "hiding" the parfor command in another function that is only executed if the PCT is installed:

A = ver('distcomp');
if isempty(A)
    %Parallel toolbox not installed - execute function containing for loop
    notparallelfunction(...)
else
    %Parallel toolbox installed - execute function containing parfor loop
    parallelfunction(...)
end

Any thoughts? Thanks for your advice!!

Subject: PARFOR on system without Parallel Computing Toolbox

From: Sean

Date: 29 Oct, 2010 19:37:04

Message: 2 of 3

"Matthew" <brit_h2o.nospam@hotmail.com> wrote in message <iaf74c$dk9$1@fred.mathworks.com>...
> Is "parfor" understood by MATLAB 2010a even when the Parallel Computing Toolbox (PCT) is not installed (in which case I suppose MATLAB would run it as a for loop instead) or will the syntax generate an error message on any system on which the toolbox is not installed?
>
> I have a code segment that I'd like to run as a parfor loop when the PCT is present, and as a for loop otherwise. I imagine something like this:
>
> A = ver('distcomp');
> if isempty(A)
> %Parallel toolbox not installed - execute for loop
> for...
> end
> else
> %Parallel toolbox installed - execute parfor loop
> parfor...
> end
> end
>
> Will this generate a syntax error on a system without PCT because the keyword "parfor" isn't recognized? (I don't have access to a MATLAB system that doesn't have PCT installed so I can't test this myself).
>
> If the above code is invalid on a non-PCT system then perhaps this would work, by "hiding" the parfor command in another function that is only executed if the PCT is installed:
>
> A = ver('distcomp');
> if isempty(A)
> %Parallel toolbox not installed - execute function containing for loop
> notparallelfunction(...)
> else
> %Parallel toolbox installed - execute function containing parfor loop
> parallelfunction(...)
> end
>
> Any thoughts? Thanks for your advice!!

I also have PCT on all my machines, but here are a things to think about:

You also would have to have the matlabpool workers open before using the parfor loop or it'll be run in serial anyway. Running a parfor loop in serial is much slower due to the extra requirements of parfor.

Personally, I would recommend having an additional logical input to your function that would determine if it should be run with a parfor loop or without.

Subject: PARFOR on system without Parallel Computing Toolbox

From: Eric

Date: 29 Oct, 2010 20:51:03

Message: 3 of 3

I have used parfor in code on a machine without the Parallel Computing Toolbox installed. I just comment out the appropriate matlabpool commands in the code when running on other machines.

-Eric

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us