parallel computing-- sharing viable between threads

조회 수: 5 (최근 30일)
yu liu
yu liu 2017년 3월 16일
댓글: Walter Roberson 2017년 3월 16일
Hi, recently, I am working on a project that needs parallel computing. I already know things like parfor. However, the difficulty in this project is that, it requires sharing a global variable between threads. For example, if there are two threads both computing "a=a+1;"in a for loop, than the parfor results should be "lab1 : 1,2,3,4,5,6...; lab2 : 1,2,3,4,5,6...", what I expect is probably like this:"lab1: 1,3,6,7,9... lab2: 2,4,5,8,10...." which two threads are both changing the same variable (It doesn't care the sequence of which thread does the add, as long as all threads are adding the number together) Can anybody help me with that?

답변 (1개)

Walter Roberson
Walter Roberson 2017년 3월 16일
It is not possible to have a global shared between workers.
You can use spmd to labSend and labReceive
As of the newly released r2017a there is the ability to send between workers. I would need to check the details.
You might be able to benefit from the sharedmatrix file exchange contribution
  댓글 수: 2
yu liu
yu liu 2017년 3월 16일
Hi, Roberson. Thanks for reply, I'll check that
Walter Roberson
Walter Roberson 2017년 3월 16일
The new facilities in R2017a are send(), poll(), and afterEach(). However, these facilities are to transfer data back and forth between the client and the workers, and are not for transferring data between workers: to transfer between workers, spmd with labSend() and labReceive() is still the mechanism.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by