How to efficiently update a matrix in Parallel?
Mostra commenti meno recenti
I am looking to update a large sparse matrix (of size N^2 by M^2, currently about 9mil by 9mil, and looking to go larger).
What's the best way to leverage parallel computing to do this? (I'm trying to implement it using parallel cpu cores first, and eventually push it onto the GPU if possible). The matrix elements are defined by a smaller matrix of size NxM. Some of the elements of the NxM matrix will randomly change as i step through time, and when that happens, I want to update only the elements of the N^2xM^2 elements that change.
It seems like the most common ways of doing this involve breaking the matrix into blocks, or by column. However that seems like a lot of overhead, and because the matrix is so big i'm worried about memory issues, or wasting time on elements that don't need to be updated.
edit: Copied code below, and attached m file for ease of reading (formatting went wonky when i copy/pasted)
Risposte (1)
James Tursa
il 6 Set 2016
0 voti
In general, anytime you change elements in a sparse matrix to/from zero to non-zero, the entire matrix must be copied in memory. This is due to how the matrix elements are stored in memory. So your goal should be to limit the number of times this is done, which is going to depend on exactly how you are updating the elements. Not having seen your code for this, I can only offer the suggestion to gather all of your updates off to the side somewhere (e.g., save the row & column & value data in separate variables), and then apply all of these updates at once to your sparse matrix just prior to needing to use it. I.e., try to do the updates entirely in one function call so that (hopefully) only one data copy will take place.
3 Commenti
Joshua L.
il 6 Set 2016
Modificato: James Tursa
il 6 Set 2016
James Tursa
il 6 Set 2016
Modificato: James Tursa
il 6 Set 2016
I can't find "Trying to parallelize here" anywhere in your code so I do not know where to look.
Also, MATLAB does not have a sparse single type. It only has sparse double and sparse logical types. So this code probably doesn't do what you think it does:
A=ones(X*Y+2,5); % <-- A is double
A(:,1)=-single(cond_ins); % <-- A is still double
:
G=spdiags(A,d,X*Y+2,X*Y+2); % <-- G is sparse double, not sparse single
All of those assignments to A elements with single(etc) stuff on the rhs of the assignment do nothing to affect the type of A. All of those single(etc) values on the rhs simply get converted to double as they are assigned to elements of A, which is still double. (Same comment applies to element assignments to G and I).
You could do this to make A single:
A=ones(X*Y+2,5,'single'); % <-- A is single
But then you would run into problems converting it directly to sparse. E.g.,
>> sparse(ones(2,3,'single'))
Undefined function 'sparse' for input arguments of type 'single'.
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!