how can i distribute a large matrix?

4 visualizzazioni (ultimi 30 giorni)
esraa
esraa il 4 Gen 2015
Modificato: per isakson il 11 Gen 2015
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
esraa
esraa il 5 Gen 2015
Modificato: Image Analyst il 5 Gen 2015
matrix:
no of rows = 20
no of column = 2^20
May the problem be in my computer? if so, can I send the m-files to be run on another computer?
Image Analyst
Image Analyst il 5 Gen 2015
Of course you can run your code on another computer. Go ahead.

Accedi per commentare.

Risposte (2)

Image Analyst
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.

Stephen23
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
esraa
esraa il 10 Gen 2015
Modificato: per isakson il 11 Gen 2015
thank you very much, how can I construct the matrix b, b: no. of column=20 and no. of rows=2^20=1048576.
the first column=[0 1 0 1 0 1 ........]
the second column=[0 0 1 1 0 0 1 1 0 0 1 1 ........]
the third column=[0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 ..........]
the fourth column=[0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1..................]
and so on. instead of the following command
for j=1:20
for k=0:(2^(ns-j))-1
a((2^(j-1))+1+k*(2^j):(2^j)+k*(2^j))=1;
end
b(j,:)=a;
clear a
end
b=b';
to take less time compared with the commands I use

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by