Assigning Variables in a parfor loop

  • Follow


Dear all,

I have a simulink model which references another model inside. I have a list of variables for the referenced model. I would like to run the simulation using parfor loop in different workers. I have been trying to assign these variables in different workers using 1.assignin commands, 2.trying to run the M File containing these variables and also 3.trying to load the .mat file, but nothing seems to be working. I receive an error while building the referenced model. I have realized that the variables are not received by the workers. 

I am also using the accelerator mode.
I would really appreciate if anyone could pls help me find a solution on how to assign the variables in different workers for the referenced model ?? 

Thanks in advance

Sumant
0
Reply Sumant 1/22/2010 10:10:23 PM

"Sumant " <stal_yaji2002@yahoo.co.in> wrote in message <hjd7of$hh4$1@fred.mathworks.com>...
> Dear all,
> 
> I have a simulink model which references another model inside. I have a list of variables for the referenced model. I would like to run the simulation using parfor loop in different workers. I have been trying to assign these variables in different workers using 1.assignin commands, 2.trying to run the M File containing these variables and also 3.trying to load the .mat file, but nothing seems to be working. 
========================

Try inserting explicit pre-declarations of the variables before you use assign/load or whatever

var1=[]; var2=[];, var3=[]; etc...

assginin(...)
assignin(...)

Not doing so is a known hazard of assignin,load,evalin, and others... 
0
Reply Matt 1/22/2010 10:35:23 PM


Thanks, But I wanted to know, what if i have say some 100 variables in one reference model and 100 in another... do i have to assign each variable using this assignin command...??
or
I wanted to know if there is any other simpler way of assigning the variables.. say in one single file or..??

Thanks once again

Sumant


"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hjd97b$mad$1@fred.mathworks.com>...
> "Sumant " <stal_yaji2002@yahoo.co.in> wrote in message <hjd7of$hh4$1@fred.mathworks.com>...
> > Dear all,
> > 
> > I have a simulink model which references another model inside. I have a list of variables for the referenced model. I would like to run the simulation using parfor loop in different workers. I have been trying to assign these variables in different workers using 1.assignin commands, 2.trying to run the M File containing these variables and also 3.trying to load the .mat file, but nothing seems to be working. 
> ========================
> 
> Try inserting explicit pre-declarations of the variables before you use assign/load or whatever
> 
> var1=[]; var2=[];, var3=[]; etc...
> 
> assginin(...)
> assignin(...)
> 
> Not doing so is a known hazard of assignin,load,evalin, and others... 
0
Reply Sumant 1/23/2010 12:55:25 AM

"Sumant " <stal_yaji2002@yahoo.co.in> wrote in message <hjdhdt$qgc$1@fred.mathworks.com>...

> Thanks, 
=============

So, that fixed the problem?


>But I wanted to know, what if i have say some 100 variables in one reference model and 100 in another... do i have to assign each variable using this assignin command...??
> or
> I wanted to know if there is any other simpler way of assigning the variables.. say in one single file or..??
=================

Not sure I understand. 

It is always dangerous to introduce a variable into a workspace without an explicit assignment statement (a practice called "poofing" by some).

If you have hundreds of variables, it would probably be helpful for you to hold them all as fields in a structure

S.var1, S.var2, etc...

Note that if you have all the variables stored in a .mat file, you can assign them to structure fields via the syntax

S=load(FileName)

This avoids the poofing problem because S is introduced into the workspace through an explicitly assignment statement, S=..... If you find it  inconvenient to access your variables through dot indexing syntax S.var1, S.var2, etc... you can unpack the structure S using my structvars() tool:

http://www.mathworks.com/matlabcentral/fileexchange/26216-structure-fields-to-variables
0
Reply Matt 1/23/2010 1:14:09 AM

Hi,

The problem is fixed, as you have mentioned we cant assign the variables to the workspace without an explicit assign statement. So what I am working on is saving the variables in a MAT-File and the loading the file in the Workspace with an assign statement. It seems to be working.

Thanks once again for your advice

Regards

Sumant

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hjdih1$386$1@fred.mathworks.com>...
> "Sumant " <stal_yaji2002@yahoo.co.in> wrote in message <hjdhdt$qgc$1@fred.mathworks.com>...
> 
> > Thanks, 
> =============
> 
> So, that fixed the problem?
> 
> 
> >But I wanted to know, what if i have say some 100 variables in one reference model and 100 in another... do i have to assign each variable using this assignin command...??
> > or
> > I wanted to know if there is any other simpler way of assigning the variables.. say in one single file or..??
> =================
> 
> Not sure I understand. 
> 
> It is always dangerous to introduce a variable into a workspace without an explicit assignment statement (a practice called "poofing" by some).
> 
> If you have hundreds of variables, it would probably be helpful for you to hold them all as fields in a structure
> 
> S.var1, S.var2, etc...
> 
> Note that if you have all the variables stored in a .mat file, you can assign them to structure fields via the syntax
> 
> S=load(FileName)
> 
> This avoids the poofing problem because S is introduced into the workspace through an explicitly assignment statement, S=..... If you find it  inconvenient to access your variables through dot indexing syntax S.var1, S.var2, etc... you can unpack the structure S using my structvars() tool:
> 
> http://www.mathworks.com/matlabcentral/fileexchange/26216-structure-fields-to-variables
0
Reply Sumant 1/25/2010 8:54:02 AM

4 Replies
402 Views

(page loaded in 0.044 seconds)

Similiar Articles:













7/21/2012 4:28:09 AM


Reply: