To scan a 1k dimensional matrix, parallel for is faster than simple for loop?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Zahra Yousefi Darani
el 14 de Mzo. de 2023
Comentada: Zahra Yousefi Darani
el 30 de Mzo. de 2023
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 comentarios
Stephen23
el 14 de Mzo. de 2023
"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.
Zahra Yousefi Darani
el 14 de Mzo. de 2023
Editada: Jan
el 14 de Mzo. de 2023
Respuesta aceptada
Suraj
el 30 de Mzo. de 2023
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.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!