Posted by on 2017年3月22日

摘要

Today I fixed the license problem of Parallel Computing Toolbox in MATLAB. By the way, the commands of parfor and spmd are really powerful. However, there is a new problem about my global variables. I use the global variable for the transmission of my parameters of model among different functions. (so many parameters in different functions and I need to adjust them time to time, so it is more convenient to use the global variable.) But the paforr-loop doesn't accept the globle variables. Because at the beginning of every parfor-loop, the variables in the workspace will be cleared. Moreover, the data among different workers of the parallel computing can not be shared and transferred. This is really a big trouble for me at present.

Today I fixed the license problem of Parallel Computing Toolbox in MATLAB. By the way, the commands of parfor and spmd are really powerful. However, there is a new problem about my global variables. I use the global variable for the transmission of my parameters of model among different functions. (so many parameters in different functions and I need to adjust them time to time, so it is more convenient to use the global variable.) But the paforr-loop doesn't accept the globle variables. Because at the beginning of every parfor-loop, the variables in the workspace will be cleared. Moreover, the data among different workers of the parallel computing can not be shared and transferred. This is really a big trouble for me at present.

There are only five types of variables in parfor-loops (see the documents here):

1. loop variables: Loop indices
2. sliced variables:Arrays whose segments are operated on by different iterations of the loop
3. broadcast variables:Variables defined before the loop whose value is required inside the loop, but never assigned inside the loop
4. reduction variables:Variables that accumulates a value across iterations of the loop, regardless of iteration order
5. temporary variables: Variables created inside the loop, and not accessed outside the loop

If I really want to take use of this toolbox to reduce the time of computation, I have to obey the rule.

Now I have 3 options as follow and I don't know which on works:
1. make the global variables as input variables and modify my each m file;
For example, if I use the global variable to store the model parameters as follow

then it would be really convenient to manipulate the model parameters a,b,c,d in the main file. However, if I can't use the global variables, I have to revise the functions into thses:

when there are too many parameters, the input variables of function file would be too long. Is there any more easy way to achieve this goal without global variables? Any tricks here?
2. save my parameters every time I adjust them and load the data file every time I call them;
3. use the symbolic substitution (reference here)

Is there any better solution? I'll figure it out tomorrow and hope I can solve this problem soon.

Is there anyone who has better idea, please write your comments here or send me an email please.

2 views
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Comments

Be the first to comment.

Leave a Reply

返回顶部