From: Eoin on
Hey all,

(thanks to anyone who's helped me out here in the last few days)

I'm using a parfor loop. Within the loop I'd like to create and use an array. I'd like each iteration of the loop is to create and use its own array independently, the array is not used outside the parfor loop, and I never use the index of the parfor loop to index elements of the array. In this sense it is, to use the parfor documentation terminology, a 'temporary' varialbe. However as far as I can see MATLAB only expects to see sliced arrays within a parfor loop, and because the way in which I use my array breaks the rules of using sliced arrays MATLAB complains that it can't classify the array. Is there a way around this problem or a way to assure MATLAB that this is not intended to be a sliced array and it's use is independent of all other iterations of the parfor loop so it can treat it as a temporary variable?

Many thanks,

Eoin
From: Edric M Ellis on
"Eoin " <emullan11(a)qub.ac.uk> writes:

> I'm using a parfor loop. Within the loop I'd like to create and use an
> array. I'd like each iteration of the loop is to create and use its
> own array independently, the array is not used outside the parfor
> loop, and I never use the index of the parfor loop to index elements
> of the array. In this sense it is, to use the parfor documentation
> terminology, a 'temporary' varialbe. However as far as I can see
> MATLAB only expects to see sliced arrays within a parfor loop, and
> because the way in which I use my array breaks the rules of using
> sliced arrays MATLAB complains that it can't classify the array. Is
> there a way around this problem or a way to assure MATLAB that this is
> not intended to be a sliced array and it's use is independent of all
> other iterations of the parfor loop so it can treat it as a temporary
> variable?

It's definitely possible to create and use temporary variables within a
PARFOR loop, like so:

parfor ii=1:10
tmp = rand(ii);
x(ii) = sum(tmp(1,:)) + sum(tmp(:,end));
end

Here, "tmp" is considered temporary. Can you post an example of some
code where you are having trouble? (Note that you must not refer to
temporary variables after the end of the PARFOR loop)

Cheers,

Edric.
From: Eoin on
Edric M Ellis <eellis(a)mathworks.com> wrote in message <ytwfx0ze1e9.fsf(a)uk-eellis-deb5-64.mathworks.co.uk>...
> "Eoin " <emullan11(a)qub.ac.uk> writes:
>
> > I'm using a parfor loop. Within the loop I'd like to create and use an
> > array. I'd like each iteration of the loop is to create and use its
> > own array independently, the array is not used outside the parfor
> > loop, and I never use the index of the parfor loop to index elements
> > of the array. In this sense it is, to use the parfor documentation
> > terminology, a 'temporary' varialbe. However as far as I can see
> > MATLAB only expects to see sliced arrays within a parfor loop, and
> > because the way in which I use my array breaks the rules of using
> > sliced arrays MATLAB complains that it can't classify the array. Is
> > there a way around this problem or a way to assure MATLAB that this is
> > not intended to be a sliced array and it's use is independent of all
> > other iterations of the parfor loop so it can treat it as a temporary
> > variable?
>
> It's definitely possible to create and use temporary variables within a
> PARFOR loop, like so:
>
> parfor ii=1:10
> tmp = rand(ii);
> x(ii) = sum(tmp(1,:)) + sum(tmp(:,end));
> end
>
> Here, "tmp" is considered temporary. Can you post an example of some
> code where you are having trouble? (Note that you must not refer to
> temporary variables after the end of the PARFOR loop)
>
> Cheers,
>
> Edric.

Thanks Edric,

I've got it working now, initalising the array as you have fixed the problem This was not necessary when using a simple for loop.

Eoin