0

I have 4 distinct large files I'd like to load into memory simultaneously. The following example is not exactly what I'm doing -- but it illustrates to problem:

matlabpool open local 4
spmd
    if labindex==1 
        R = rand(9,9);
      else
        R = rand(4,4);
    end
end
size(R)

when I copy and paste this into the command prompt, R pops up in my work space. but if i save this to a *.m file, size(R) doesn't evaluate -- it gives me an error that R doesn't exist. I've tried using gather and initializing R as a global to no avail. Any ideas?

2
  • What do you mean R pops up? You have a semicolon after the lines where R is created. I can't replicate what you describe (Matlab R2012b, OS X 10.8.3). The code above runs normally from the command window, a script M-file, and a function M-file. size(R) prints out every time: a 1-by-4 composite. Did you possibly create a function M-file rather than a script and are trying to access R from the command window after running the file? If it was a function then you're right, it is a scoping issue. Functions have their own scope regardless of if they call spmd or not.
    – horchler
    Commented Jun 7, 2013 at 22:49
  • okay -- I just figured out what was happening. see below
    – yoshi
    Commented Jun 7, 2013 at 23:30

1 Answer 1

0

Okay:

I was saving this script as test.m.

Then I was calling it from the command line as: run test.m

But then I ran it as-is from command line: test

'run' must spawn a subprocess which it kills after running or something. this must have been killing the variables. just calling the script straight correctly shares the scope of the workspace with the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.