XP is just a number PerlMonks

### Re: Out of Memory when generating large matrix

by BrowserUk (Pope)
 on Mar 05, 2018 at 04:56 UTC ( #1210337=note: print w/replies, xml ) Need Help??

in reply to Out of Memory when generating large matrix

4**21 = 4,398,046,511,104. If each of those array elements took just 1 byte that would need 4000GB (or 4TB) of ram.

But each element of a Perl array requires a minimum of 32bytes on a 64-bit system, so that increases the programs memory requirement to at least 32,000GB.

And that's before you multiply by 197!

Even today, very few computers can access Terabytes of memory -- the latest greatest SkyLake will only address 128GB.

The bottom line is that you are going to have to tackle your problem a different way.

If you can describe what you are trying to do -- in computer terms, with a minimum of bio-lingo -- there is probably an approach that will allow you to achieve it without needing £432,000 worth of memory and a processor that can address it; if such an animal currently exists, it would be in the \$millions price range.

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
• Comment on Re: Out of Memory when generating large matrix

Replies are listed 'Best First'.
Re^2: Out of Memory when generating large matrix
by cathyyihao (Novice) on Mar 05, 2018 at 16:27 UTC

Hi! Thank you so much for your reply! So the goal I try to achieve here is that as for the 21mer I'm working on, it is a sequence of 21 letters, each position can have 4 variable "AGCT". Therefore, in total, it should have 4**21 combination. I have total 197 kmer files, each of them contains around 8000 of these 21mers, and I'm trying to count how many time each 21mers has shown among these 197 files. That's why I need a matrix to do so.

Therefore, in total, it should have 4**21 combination.

Yes. But not all of them -- in fact a very small percentage -- will appear; so rather than reserving space for trillions of counts that will 99% never be used, you can choose to only count those that do appear. That will save huge amounts of space and speed up your processing.

With 197 files * 8000 lines, there are at most 1.5 million 21kmers -- if they are all unique -- so there in no need to reserve space for all 4.3 trillion possibilities. 197*8000 / 4.3e12 * 100 = 0.0000358%

I'm trying to count how many time each 21mers has shown among these 197 files.That's why I need a matrix to do so.

Fair enough, but you don't need to count them all in one huge matrix. You can process the 197 files one by one and only store the nonzero counts across files.

Could you post a small sample (say 20 lines) of what is in your kmer files?

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

197 * 8000 = 1576000. If you only have 1.5e6 data points why are you trying to match them against 4**21 possible combinations when all bar an infinitessimal fraction of those won't be present?

Just compare your 1.5e6 against themselves and mark everything else as zero. No matrices required.

For fun, see The 10**21 Problem (Part I) and the subsequent parts.

(Edit: BrowserUk managed to construct a fuller and therefore better response in the time it took me to deduce and type this. Still, great minds and all that ;-)

Create A New User
Node Status?
node history
Node Type: note [id://1210337]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2018-06-18 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (111 votes). Check out past polls.

Notices?