필터 지우기
필터 지우기

What is the fastest way to do repeated element wise matrix multiplication?

조회 수: 7 (최근 30일)
Given a matrix `A`, I need to multiply with another constant vector `B`, N times (N > 1 million). The size of `A` is `9000x1` and `B` is `9000x1000`.
The code is currently evaluated in the following way (random values taken for example):
B = rand(9000,1000); % B is fixed, does not depend on i
N = 1000000;
for i=1:N
rand('seed',i);
A = rand(9000,1); % A is 9000x1 matrix which varies with i
% prod = A.*B; % prod is 9000 x 1000 matrix
% sum_temp = sum(product); % sum_temp is 1 x 1000 matrix
% Edit
sum_temp = A.' * B;
% do multiple pperations with sum_temp
% result(i) = some_constant;
end
I used Profiler to see which line is taking the most time and it is the 2nd line (prod = A.*R;). The problem is that N is very large and the code is taking over several days to complete.
I am about to try the parallel computing toolbox (GPU computing), but are there any suggestions on what I can do in the basic version?
How can I reduce the run-time of such codes in MATLAB?

채택된 답변

Stephen23
Stephen23 2024년 2월 19일
이동: Stephen23 2024년 2월 19일
Reduce the number of operations inside the loop by replacing TIMES and SUM with MTIMES (of course adjusting the matrix/vector orientations to suit).
  댓글 수: 5
Stephen23
Stephen23 2024년 2월 19일
편집: Stephen23 2024년 2월 19일
@Aravind Varma Dantuluri: did that make enough difference to the speed?
Another possibilty would be to look at some kind of parallel processing:
Aravind Varma Dantuluri
Aravind Varma Dantuluri 2024년 2월 19일
@Stephen23, using MTIMES definitely helped. Now I am checking out pagemtimes and then will check parallel computing capabilities. Thanks for your help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by