If i Set a matrix A = (1, 23, 17; -2, 1, 94)
and if there is a matrix B = (0.5; 1.6; -0.3)
and if i want to multiply A and B then put the result in C( C = A * B).
Does the computing sequence occurs simultaneously or sequentially[(1, 23, 17)*(0.5; 1.6; -0.3) first occurs and then (-2, 1, 94)*(0.5; 1.6; -0.3) occurs so that computting time take 2 times compared to simultaneous computting]?

 채택된 답변

Guillaume
Guillaume 2019년 5월 17일

0 개 추천

matrices operations in matlab are very optimised, so it's likely that they are parallelised as much as possible. However, implementation details are not documented so you can't know for sure. In any case, whether or not the execution at the processor level occurs in parallel is going to depend on the version of matlab, the type of processor you have and probably the load on said processor.
Why do you care anyway?

댓글 수: 2

Jay Chung
Jay Chung 2019년 5월 17일
I wantted to know if there exists an time cost to code my algorithm with for loop. Anyway in some degree you mean if my code is vectorized, i can run it faster than using for loop?
Stephen23
Stephen23 2019년 5월 17일
편집: Stephen23 2019년 5월 17일
"...if my code is vectorized, i can run it faster than using for loop?"
Vectorized operations are generally highly optimized, so in many cases vectorized code may be faster than a loop... in other cases the loop is faster. It depends on the data, the algorithm, how the code was written, the sizes of intermediate arrays, the MATLAB version, etc. etc.
The only way to know for sure is to test it.
But you should be concentrating first on writing clear, simple, and understandable code (which will in turn be easier to check and have fewer bugs). Unless you have written your code very carefully and used the profiler to determine that this particular operation is causing a major bottleneck and your code is going to run millions/billions/trillions/... of iterations, then there is likely little point in premature optimization of your code.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2019년 5월 17일

편집:

2019년 5월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by