spmd and persistent variables
    13 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hi all,
I use 'spmd' to call a function 'fun1' in which some persistent variables are declared. The documentation states that 'The body of an spmd statement cannot contain global or persistent variable declarations.'.
1) But is-it robust to call a function that declares persistent variables inside an 'spmd' statement? I am not interested by the value of these persistent variables at the end of the process in the client.
2) In the future, the called function 'fun1' will be a mex-file. Is-there a difference?
Here is an example with no special meaning
spmd         
   M=fun1(labindex);       
end
function y = fun1(x)
    persistent y1   
    y1 = magic(x);
    y = y1+10;      
end
I think the answer will be the same for a 'parfor' loop.
Thank you.
Nicolas
0 comentarios
Respuestas (1)
  Harsha Medikonda
    
 el 17 de Ag. de 2015
        Hi Nicolas,
I understand that you wish to know
a)If persistent variables can be declared in a function that is called from an spmd block
b)If we are replacing the function with a mex file, can we still use the persistent variables in the same way?
For your first question: You can declare persistent variables in a function that is called by the spmd block. Please make sure that you are attaching the file 'fun1.m' using "addAttachedFiles" so that it is accessible by all the workers. For Example:
poolobj = gcp;
addAttachedFiles(poolobj,{'fun1.m'})
spmd         
 M=fun1(labindex);       
end
For your second question: We require "mxArray" datatype for both input and output parameters for a mexFunction(which is the starting point for a mex file). By default, an mxArray is not persistent. To make an mxArray persistent through multiple invocations of the Mex-function, call the "mexMakeArrayPersistent" function.
Please refer to the following documentation links for more information
Harsha
0 comentarios
Ver también
Categorías
				Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

