To scan a 1k dimensional matrix, parallel for is faster than simple for loop?
조회 수: 1 (최근 30일)
이전 댓글 표시
I need to scan a very huge matrix 15k x 10 x 1k
do you think parrallel-for is faster than simple for in this case? in a smaller matrix tic-toc says they are more or less the same.
Is there any fast way to go through a huge matrix elment by element?
댓글 수: 2
Stephen23
2023년 3월 14일
"I need to scan a very huge matrix 15k x 10 x 1k"
What does "scan" mean? Such an array requires around 1.2 GB, which is not so large these days.
"do you think parrallel-for is faster than simple for in this case?"
I would not expect that, given the extra overhead in setting up a parallel loop, transferrring the data, etc. Whether there is a benefit to using parallel execution depends on many factors:
"Is there any fast way to go through a huge matrix elment by element?"
That depends mostly on what is happening inside the loop, which you have not told us.
채택된 답변
Suraj
2023년 3월 30일
Hey Zahra
For a matrix of size 15k x 10 x 1k, using parallel computing with "parfor" can potentially speed up the iteration process by utilizing multiple CPU cores to perform the computation in parallel. However, the actual speedup depends on the specific operations being performed within the loop, the available resources, and the memory usage.
In general, if the operations within the loop involve heavy computations, such as matrix multiplications, then using parallel computing can provide significant speedup. On the other hand, if the operations are simple, such as accessing individual elements of the matrix, then the overhead of parallelization may outweigh the benefits. You can read more about this here: https://www.mathworks.com/help/parallel-computing/decide-when-to-use-parfor.html .
To further optimize the iteration process, you can consider vectorizing the loop or using built-in functions that operate on the entire matrix at once. Vectorization and built-in functions are generally faster than using loops, especially for large matrices.If you need to perform a more complex operation that cannot be easily vectorized, you can try to optimize the loop using techniques such as preallocating arrays, minimizing memory usage, and avoiding unnecessary operations.
Hope this information helps.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!