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.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.