How I can Make this code GPU parallel compatible

2 次查看(过去 30 天)
HI,
I have this code that i want to make it gpu compatiable, I wonder if anyone can tell what should i do , changing the A to gpu arry didnt help . I only want to make parfor loop to run on gpu .
A=permn([0:1:6],3)
N=4
D={}
parfor ii=1:size(A,1);
D{1,ii}=[]
for jj=1:size(A,1);
for kk=1:size(A,1);
C=DirectSumL(A(ii,:),A(jj,:),A(kk,:)) ;
if sum(C)==N
D{1,ii}=[D{1,ii} ; C];
else
D{1,ii}=D{1,ii};
end
end
end
ii
end
  1 个评论
Walter Roberson
Walter Roberson 2020-6-3
What is DirectSumL ?
Which permn are you using? There are multiple permn in the File Exchange.

请先登录,再进行评论。

回答(1 个)

shahabeddin Mostafanazhad aslmarand
lets just imagin A is a n by m matrix,
the direct sum is this
function A=DirectSumL(A,varargin)
% DIRECTSUM computes the direct sum of matrices
% A=DirectSum(A1,A2,...,An) computes the direct sum of matrices of
% arbitrary size (Peter Arbenz, May 30, 1997)
for k=1:length(varargin)
[n,m]=size(A);
[o,p]=size(varargin{k});
A=[A , varargin{k}];
end
  1 个评论
Walter Roberson
Walter Roberson 2020-6-3
编辑:Walter Roberson 2020-6-3
That appears to be a corrupted definition of Peter Arbenz's DirectSum, which is shown at https://www.unige.ch/~gander/Book/Eigen/Matlab/DirectSum.m and which appears to be equivalent to
blkdiag(A, varargin{:})
The version you show pastes rows, and would be equivalent of
horzcat(A, varargin{:})
The result either way is going to be a 2D matrix, and sum() of that would be a vector. Your if would be comparing that vector to the scalar N. Is it correct that you only want the if to succeed in the case where all of the columns each add up to N? If so then that can be made more efficient, as you could eliminate from consideration any column of A that did not add up to N.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by