Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using "save" inside a parfor loop

146 views
Skip to first unread message

John Ramshur

unread,
Apr 7, 2009, 10:48:01 PM4/7/09
to
I need to save an arrays to Matlab v7 binary files (.mat), but I'm getting a transparency error at the save command. I get no error using the load command.

Matlab states: "Examples of some other functions that violate transparency are evalc, evalin, and assignin with the workspace argument specified as 'caller'; save and load, unless the output of load is assigned." But they do not explicitly say that I "can't" use the save function.

Is there a way or is there an alternative to save compressed v7 matlab binary files?

Edric M Ellis

unread,
Apr 8, 2009, 3:27:07 AM4/8/09
to
"John Ramshur" <jram...@gmail.com> writes:

> I need to save an arrays to Matlab v7 binary files (.mat), but I'm getting a
> transparency error at the save command. I get no error using the load command.

If you're using the "struc = load( fname )" form, then as per the doc that you
quote below, that is allowed.

> Matlab states: "Examples of some other functions that violate transparency are
> evalc, evalin, and assignin with the workspace argument specified as 'caller';
> save and load, unless the output of load is assigned." But they do not
> explicitly say that I "can't" use the save function.

No functions which violate workspace transparency can be used directly within
the body of a PARFOR (or SPMD) block. (The reason for this is that we must be
able to analyze the code, and deduce which variables are accessed/created within
such a block).

> Is there a way or is there an alternative to save compressed v7 matlab binary
> files?

You could call a function with the data that you wish to save - it's possible to
call transparency-violating functions in functions called from the body of
PARFOR, like so:

parfor ii=1:10
x = magic(ii);
fname = sprintf( 'file_%d', ii );
iSaveX( fname, x );
end

function iSaveX( fname, x )
save( fname, 'x' );
end

In that case, it's clear from the body of the PARFOR loop that the variables "x"
and "fname" are to be sent to "iSaveX".

Cheers,

Edric.

0 new messages