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