- What's your definition of large? How many rows and columns?
- How long is it taking for those large matrices? How many seconds or minutes?
- How much speed do you require? What is the max allowable time?
- Do you have the Parallel Processing Toolbox?
Is there any other function faster than sum(A,2) to get the sum of all rows?
    16 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
a=zeros(6750);
h=zeros(6750,1);
tic;k=h-sum(a,2); toc
Is there any faster way than to use sum(A,2) to get the sums of the rows of a matrix? sum(A,2) seems to be slow for large matrices.
4 Commenti
  Image Analyst
      
      
 il 27 Giu 2022
				The Parallel Processing Toolbox is an add-on toolbox.  You can ask for a free trial of it and see if the Parallel Processing Toolbox helps.  I know some functions recognize if you have that toolbox and start parallel processes going on multiple CPU cores on your computer automatically.
  Walter Roberson
      
      
 il 27 Giu 2022
				For sufficiently large matrices, addition is automatically handled by high performance parallel libraries. Using parfor or parfeval() will not improve performance compared to the automatic multi-core work that is done.
Risposte (2)
  Walter Roberson
      
      
 il 26 Giu 2022
        Switching to columns can improve performance as it allows better use of hardware cache.
2 Commenti
  Walter Roberson
      
      
 il 27 Giu 2022
				When I test on my system, the sum(a,1) version is 5 to 6 times faster than the sum(a,2) version
  MJFcoNaN
      
 il 26 Giu 2022
        In general, the native functions are optimized sufficiently.
In certain cases, there may be some better way but in other parts of code. For example,
a=sparse(zeros(6750));
h=sparse(zeros(6750,1));
tic;k=h-sum(a,2); toc
Vedere anche
Categorie
				Scopri di più su Matrix Indexing in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



