If you accumulate and discard as you go, you can substantially reduce the memory requirement.
Ie. (Using 10x10 as an example) After reading the first row, and duplicating the 9 elements to the lower triangle you need storage for 19 elements:
+---+---+---+---+---+---+---+---+---+---+ | a | b | c | d | e | f | g | h | i | j | +---+---+---+---+---+---+---+---+---+---+ | b'| +---+ | c'| +---+ | d'| +---+ | e'| +---+ | f'| +---+ | g'| +---+ | h'| +---+ | i'| +---+ | j'| +---+
But then you can print out the first row to the new file and free up that memory leaving only 9 elements in ram.
You then read the second row, duplicate the 8 elements, and print out the second row to the new file and discard it. And you now have 8x2=16 in memory.
The peak memory requirement comes when you have read the 5th row, at which point you will have 5x5 =25 elements in the lower triangle cache, and (breifly) the 10 elements of the 5 row before writing it out and discarding it. So rather than 10x10=100 you have a maximum requirement of (n/2)2 + n = (10/2)2+10 = 35.
Or for your example (460000/2)2 + 460000 = 52,900,460,000 rather than 4600002 = 211,600,000,000 or ~60% less. Still needs a lot of memory, but it might help if your numbers are small enough to allow a C solution.
In reply to Re^3: upper or lower triangular matrix to full
by BrowserUk
in thread upper or lower triangular matrix to full
by savita
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |