How to implement the "tsearchn" algorithm 2 in a parfor loop?

조회 수: 1 (최근 30일)
DroneDoctor
DroneDoctor 2018년 4월 12일
댓글: James Cairns 2019년 10월 24일
Hi!
I have been trying to implement the following for loop in the "tsearchn" function using a parfor.
t = nan(npt,1); % Simplex containing corresponding input point
p = nan(npt,ndim+1); % Barycentric coordinates for corresponding input point
X = [ones(size(x,1),1) x]; % Append 1s to vertex matrix
b = [ones(npt,1) xi]; % Append 1s to point matrix
parfor i = 1:ntri % Return the largest simplex index
% For each triangle
q = b / X(tri(i,:),:); % Compute barycentric coordinate of each point
I = all(q > myeps,2); % Find simplex where all coordinates are positive
t(I) = i; % Set simplex
p(I,:) = q(I,:); % Set barycentric coordinates
end
MATLAB gives me the following errors:
"The variable t in a parfor cannot be classified."
then in editor I get:
"Valid indices for t are restricted in PARFOR loops."
The same is true for the variable p.
Following the suggested links did not elucidate the matter for me.
Does anybody know how to convert it into a PARFOR loop?
Thanks!

답변 (2개)

Edric Ellis
Edric Ellis 2018년 4월 17일

The problem here is that the loop iterations are order-dependent. parfor can only operate when the iterations are independent - and the restrictions on indexing into t and p simply reflect that. Outputs from a parfor loop typically need to be sliced, as described in the documentation. Basically, this means that you must assign elements corresponding to the loop index only.


DroneDoctor
DroneDoctor 2018년 4월 17일
Thanks for the answer. The Parallel Toolbox staff explained the issue in more detail in my service request. I was able to parallelize it and do some vectorizations. Thanks for your answer though. Highly appreciate it!
  댓글 수: 1
James Cairns
James Cairns 2019년 10월 24일
Is there any change someone could explain how this was achieved? I realise this is an old thread but I'm trying to achieve exactly the same as above.

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

카테고리

Help CenterFile Exchange에서 Delaunay Triangulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by