how can i distribute a large matrix?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a matrix of (20*2^20) and I can not deal with it . I want to distribute the matrix. How can I use ( distribute) and (gather) . please, the steps that can I write in the m-file.
11 Commenti
Risposte (2)
Image Analyst
il 4 Gen 2015
If a lot of it is empty/zero/unassigned, then try making it sparse. Otherwise, use it in bite-sized chunks.
0 Commenti
Stephen23
il 10 Gen 2015
The code that you uploaded is full of poor coding practice. Some examples of this are:
- using i and j as the names of variables (there are the names of the inbuilt imaginary unit ).
- over-complicated data structure: use a cell array instead of a structure.
- no vectorization : total reliance on loops.
- no array preallocation within those loops.
Using distributed arrays will not solve the slowness of this calculation, because it is the code itself that it poorly written. The last two points particularly need to be addresses to speed up your calculation.
If you tried to use the MATLAB debugger , then you would quickly find that the script does not even progress past the first set of nested loops. When I investigated why this is so slow, I found that the variable a is being enlarged on every loop iteration:
a = [0,1]
a = [0,1,0,1]
a = [0,1,0,1,0,1]
..
a = [0,1,0,1,0,1,0,1,.. ???]
given the rather obfuscated nature of how this vector is being generated I did not waste my time trying to figure out how large it might become (when I stopped it was 1x115444). Every time that you extend any variable in MATLAB it has to check the available memory, and move the variable if required. Suffice to say this can be a slow process.
Note also that you could generate this vector all in one go using the much simpler command
a(2:2:N) = 1;
for some scalar N. Try it and you will see how much faster MATLAB can be.
Until this code is vectorized where appropriate and plenty of array preallocation where not, then this code will always be slow, regardless of what computer you run it on.
1 Commento
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!