Thread Subject: Shared memory in parfor

Subject: Shared memory in parfor

From: Sebastiaan

Date: 14 Apr, 2008 09:34:02

Message: 1 of 4

Dear list,

Is there a way to declare that a variable is shared and not
changed during a parfor loop? A variable containing problem
data can be pretty large. When the data is read-only, there
is no need to copy the data to all of the workers on a
shared memory system.

Example code:

data = rand(N, N); % generate some (static) problem data
parfor j=1:N
  res = do_something(data, j);
  output(j) = res;
end

% data is unchanged

Sincerely,
Sebastiaan

Subject: Shared memory in parfor

From: Narfi

Date: 15 Apr, 2008 16:31:02

Message: 2 of 4

Sebastiaan,

Unfortunately, there is currently no way of achieving this
with parfor. Out of curiosity, how many MB is the problem
data that you have?

Thanks,

Narfi

"Sebastiaan " <s.breedveld@erasmusmc.REMOVE.BOO.BOO.nl>
wrote in message <ftv8ea$19m$1@fred.mathworks.com>...
> Dear list,
>
> Is there a way to declare that a variable is shared and not
> changed during a parfor loop? A variable containing problem
> data can be pretty large. When the data is read-only, there
> is no need to copy the data to all of the workers on a
> shared memory system.
>
> Example code:
>
> data = rand(N, N); % generate some (static) problem data
> parfor j=1:N
> res = do_something(data, j);
> output(j) = res;
> end
>
> % data is unchanged
>
> Sincerely,
> Sebastiaan

Subject: Shared memory in parfor

From: Sebastiaan

Date: 15 Apr, 2008 18:48:01

Message: 3 of 4

Dear Narfi,

the problem data is currently ~400MB, but could grow to a
few GBs in the feature. Currently, it takes longer to
transfer the data to 4 threads than a single thread execution.

The only alternative I can think of is to split the data a
priori, and then submit the jobs to the scheduler.

However, this still doubles the memory usage (assumed that
the data is not copied as well), and assumes that the data
can be split.

Sincerely,
Sebastiaan

Subject: Shared memory in parfor

From: Joshua Dillon

Date: 27 Aug, 2010 19:21:09

Message: 4 of 4

Hi all. I have also had this problem and wrote a mex program to handle this situation. It requires a POSIX compliant system, such as Linux.
http://smlv.cc.gatech.edu/2010/08/27/shared-memory-in-matlab/

Cheers,

Josh


"Sebastiaan " <s.breedveld@erasmusmc.REMOVE.BOO.BOO.nl> wrote in message <fu2t91$l6v$1@fred.mathworks.com>...
> Dear Narfi,
>
> the problem data is currently ~400MB, but could grow to a
> few GBs in the feature. Currently, it takes longer to
> transfer the data to 4 threads than a single thread execution.
>
> The only alternative I can think of is to split the data a
> priori, and then submit the jobs to the scheduler.
>
> However, this still doubles the memory usage (assumed that
> the data is not copied as well), and assumes that the data
> can be split.
>
> Sincerely,
> Sebastiaan
>
>

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com