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!