|
"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.
|