필터 지우기
필터 지우기

Problem in using parfor for matrix

조회 수: 1 (최근 30일)
Aep
Aep 2019년 5월 6일
댓글: Aep 2019년 5월 6일
Hello everybody,
I have a for loop and I want to use parfor for increasing the speed. The problem is that I cannot modify my parfor code so that the Matlab can run it. Considering we have a vector called "point" and a matrix called "A" so that:
point=[3 4 5 6]
A=sparse(10)
I want to modify some of the arrays of matrix "A" based on the values form vector "point":
parfor j=1:size(point,2)
A(point(j),point(j)+2)=10;
end
The Matlab gives this error: "The variable A in a parfor cannot be classified."
Can anybody help me with this problem?
I have actually seen the Matlab documentation and I have tried to modify my code based on those instructions, but it still doesn't work. Actually, my real "point" vector and "A" matrix are much larger than what I wrote here, but the main problem with my code is what I mentioned here.
Thanking you in anticipation

채택된 답변

Walter Roberson
Walter Roberson 2019년 5월 6일
This cannot be done. The locations modified by a given parfor iteration must be easily calculated by the parfor index. When you look up the index in point() then parfor cannot easily prove that no two iterations will ever want to write to the same place.
Updating a sparse array in parfor is a bit questionable to me due to the way that data is stored in sparse arrays. Perhaps (hypothetically) it might return a partial result that gets updated in the client for consistency, but I do not know. That is a detail that should be checked.
You should perhaps instead create vectors of locations to update and corresponding values and then after the loop use sparse() to do the updates.
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 5월 6일
L1(j) = point(j) ;
L2(j) = point(j) + 2;
V(j) = 10;
Outside the loop
sparse(L1, L2, V)
Aep
Aep 2019년 5월 6일
Thank you very much. Your answer helped me a lot.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by