parallel processing - MATLAB: Copying Global variable for all Workers -


i want pass "a" global variable function "tsfn", say

function [ out ] = tsfn(  )     global a;    out=a+1;  end 

when run following expected result:

>> global a; a=1  out=[]; i=1:4    out =[out tsfn()]; end  out  =      1 out =      2     2     2     2 

however if run parfor instead of end blank vector. leads me believe "a" not being passed function. i'm wondering if there way pass variable global variable workers.

thanks

works fine on platform. try restarting computer or matlab. generally, "parfor" loop accomplishes same task "for" loop--each loop computed in parallel. declaring "global" in 1 or more functions and/or base workspace allows each of them access contents of global variable, usage correct.

here code:

function[ out ] = tsfn()       global a;      out = + 1;  end  edu>> global a; edu>> = 1; edu>> out = []; edu>> parfor = 1 : 4           out = [ out tsfn() ];       end edu>>  =       1  edu>> out  out =       2     2     2     2 

aside, simple way test contents of variable inside function remove semicolon, prints editor.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -