Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mcmapply memory error #9

Open
asifzubair opened this issue May 15, 2016 · 51 comments
Open

mcmapply memory error #9

asifzubair opened this issue May 15, 2016 · 51 comments

Comments

@asifzubair
Copy link
Contributor

When doing the 3vs8 analysis with default settings, getting the following error:

.Quitting from lines 458-473 (atacseeker.Rmd) 
��Error in mcfork() : 
  unable to fork, possible reason: Cannot allocate memory
Calls: <Anonymous> ... eval -> mcmapply -> mclapply -> lapply -> FUN -> mcfork
��
��Execution halted
�=Warning message:
system call failed: Cannot allocate memory 
@ttriche
Copy link
Member

ttriche commented May 16, 2016

probably a nested loop of some sort -- you may need to replace mcmapply
and/or farm the analysis out over multiple instances if the child processes
are eating up too much RAM on one AMI.

--t

On Sun, May 15, 2016 at 3:34 PM, Asif Zubair [email protected]
wrote:

When doing the 3vs8 analysis with default settings, getting the following
error:

.Quitting from lines 458-473 (atacseeker.Rmd)
��Error in mcfork() :
unable to fork, possible reason: Cannot allocate memory
Calls: ... eval -> mcmapply -> mclapply -> lapply -> FUN -> mcfork
��
��Execution halted
�=Warning message:
system call failed: Cannot allocate memory


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#9

@asifzubair
Copy link
Contributor Author

asifzubair commented May 16, 2016

this is the exact invocation:

command = paste("bash bamToBigWig_dedup.sh", bam.files)
tmp <- mcmapply(system, command = command)

I was trying to call a script in parallel for converting bam to BigWigs. However, now i've changed to mapply. Of course, now it takes longer :/

@ttriche
Copy link
Member

ttriche commented May 16, 2016

better to take longer and complete successfully than to quickly fail :-)

--t

On Sun, May 15, 2016 at 10:36 PM, Asif Zubair [email protected]
wrote:

this is the exact invocation:

command = paste("bash bamToBigWig_dedup.sh", bam.files)tmp <- mcmapply(system, command = command)

I was trying to call a script in parallel for converting bam to BigWigs.
However, now i've changed to mapply. However, of course now it takes
longer :/


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@asifzubair
Copy link
Contributor Author

also, this is happening when i have dedup = FALSE. In fact, this is causing PWMEnirch to fail as well. Please see this issue. I think the simpler solution to our problems will be to clear memory once we are done with csaw as indicated in this SO. In any case, once we have got the differentially accessible regions and have exported the SummarizedExperiment produced by csaw, we shouldn't need it for further downstream analysis - LOLA, BigWigs and PWMEnrich

@ttriche
Copy link
Member

ttriche commented May 16, 2016

true. gc(,T) sometimes helps (run it 10 times if you're going to run it
once; R uses a generational garbage collector and this legitimately can
help clear RAM)

--t

On Mon, May 16, 2016 at 1:20 AM, Asif Zubair [email protected]
wrote:

also, this is happening when i have dedup = FALSE. In fact, this is
causing PWMEnirch to fail as well. Please see this issue
#10. I think the
simpler solution to our problems will be to clear memory once we are done
with csaw as indicated in this SO
http://stackoverflow.com/questions/8813753/what-is-the-difference-between-gc-and-rm.
In any case, once we have got the differentially accessible regions and
have exported the SummarizedExperiment produced by csaw, we shouldn't
need it for further downstream analysis - LOLA, BigWigs and PWMEnrich


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@asifzubair
Copy link
Contributor Author

asifzubair commented May 16, 2016

For now, I'm going to do the following:

rm(list=setdiff(ls(),
    c("test", "dump_dir", "output_dir", "dedup", "bam.files", 
    "compute_library_complexity", "generate_BigWigs", "do_motif_analysis", 
    "is.sig", "diffAccRanges")))
gc()

Once the significant regions have been called, I really only need the bed file for motif enrichment analysis. Also, apropos your suggestion on speed up, PWMEnrich does have a parallel processing mode and that might help with speedup.

@ttriche
Copy link
Member

ttriche commented May 16, 2016

re: PWM:

just make sure it's using openMP and not forking a zillion processes :-)

--t

On Mon, May 16, 2016 at 1:14 PM, Asif Zubair [email protected]
wrote:

For now, I'm going to do the following:

rm(list=ls())
gc()diffAccRanges = import(file.path(output_dir, "diffAccRanges.NS.fdrLt005.hg19.bed"), genome="hg19")

Once the significant regions have been called, I really only need the bed
file for motif enrichment analysis. Also, apropos your suggestion on speed
up, PWMEnrich does have a parallel processing mode and that might help
with speedup.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@asifzubair
Copy link
Contributor Author

I think this might be the case:

Motif scanning is the most time consuming operation. Because of this, the package has a support for parallel motif scanning using the R parallel core package.

@ttriche
Copy link
Member

ttriche commented May 17, 2016

gah, might want to skip it. People can wait longer if the bottleneck is on
someone else's computer (e.g. Amazon's or Illumina's) instaed of locally

--t

On Mon, May 16, 2016 at 5:04 PM, Asif Zubair [email protected]
wrote:

I think this might be the case:

Motif scanning is the most time consuming operation. Because of this, the
package has a support for parallel motif scanning using the R parallel
core package.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@asifzubair
Copy link
Contributor Author

this is still failing, despite memory clean up, when dedup = FALSE:

�.Quitting from lines 470-485 (atacseeker.Rmd) 
���Error in mcfork() : 
  unable to fork, possible reason: Cannot allocate memory

@ttriche
Copy link
Member

ttriche commented May 17, 2016

it looks like you are still parallelizing it at process level -- maybe just
use lapply or mapply as needed? It will take longer but it should not seg
fault.

--t

On Tue, May 17, 2016 at 12:39 AM, Asif Zubair [email protected]
wrote:

this is still failing, despite memory clean up, when dedup = FALSE:

�.Quitting from lines 470-485 (atacseeker.Rmd)
���Error in mcfork() :
unable to fork, possible reason: Cannot allocate memory


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@asifzubair
Copy link
Contributor Author

I did try that, but even systems calls are failing:

## Warning in system(cmd5): system call failed: Cannot allocate memory

@ttriche
Copy link
Member

ttriche commented May 17, 2016

You may need to print out memory usage ( gc(TRUE, TRUE) will do it) along
the way in order to debug this. How much RAM is in a standard BaseSpace
EC2 AMI?

--t

On Tue, May 17, 2016 at 9:23 AM, Asif Zubair [email protected]
wrote:

I did try that, but even systems calls are failing:

Warning in system(cmd5): system call failed: Cannot allocate memory


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@asifzubair
Copy link
Contributor Author

asifzubair commented May 17, 2016

60gb. Yes, I read somewhere that it is always advisable to call gc(T,T) before running system. That's what I am testing out. Also, when dedup = TRUE, I don't find any significant regions. However, for completeness, I want this option to be available.

@asifzubair
Copy link
Contributor Author

this is what gc(T,T) spits out

�|Garbage collection 489 = 337+76+76 (level 2) ... 
433.0 Mbytes of cons cells used (17%)
7174.9 Mbytes of vectors used (29%)

@ttriche
Copy link
Member

ttriche commented May 17, 2016

this is bizarre... I'm not sure why an 8GB RAM footprint is segfaulting on
a 60GB machine. Sure, R is a pig, but nothing is that much of a pig...

--t

On Tue, May 17, 2016 at 12:40 PM, Asif Zubair [email protected]
wrote:

this is what gc(T,T) spits out

�|Garbage collection 489 = 337+76+76 (level 2) ...
433.0 Mbytes of cons cells used (17%)
7174.9 Mbytes of vectors used (29%)


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@asifzubair
Copy link
Contributor Author

Personally, I think we should check with Jay about the instance. He told me that it is a cc2.8x large instance. But, I am not sure.

@asifzubair
Copy link
Contributor Author

this is even more weird, R is using 3gb and yet the system command is failing:

�}Garbage collection 547 = 361+101+85 (level 2) ... 
288.0 Mbytes of cons cells used (10%)
2747.9 Mbytes of vectors used (10%)
�}Garbage collection 548 = 361+101+86 (level 2) ... 
288.0 Mbytes of cons cells used (12%)
2747.9 Mbytes of vectors used (12%)
�}Garbage collection 549 = 361+101+87 (level 2) ... 
288.0 Mbytes of cons cells used (15%)
2747.9 Mbytes of vectors used (15%)
�}Garbage collection 550 = 361+101+88 (level 2) ... 
288.0 Mbytes of cons cells used (19%)
2747.9 Mbytes of vectors used (19%)
�}Garbage collection 551 = 361+101+89 (level 2) ... 
288.0 Mbytes of cons cells used (24%)
2747.9 Mbytes of vectors used (24%)
�}Garbage collection 552 = 361+101+90 (level 2) ... 
288.0 Mbytes of cons cells used (30%)
2747.9 Mbytes of vectors used (30%)
�}Garbage collection 553 = 361+101+91 (level 2) ... 
288.0 Mbytes of cons cells used (37%)
2747.9 Mbytes of vectors used (30%)
�}Garbage collection 554 = 361+101+92 (level 2) ... 
288.0 Mbytes of cons cells used (37%)
2747.9 Mbytes of vectors used (30%)
�2Garbage collection 555 = 361+101+93 (level 2) ... �K
288.0 Mbytes of cons cells used (37%)
2747.9 Mbytes of vectors used (30%)
�}Garbage collection 556 = 361+101+94 (level 2) ... 
288.0 Mbytes of cons cells used (37%)
2747.9 Mbytes of vectors used (30%)

��2: In system(cmd5) : system call failed: Cannot allocate memory
3: In system(cmd6) : system call failed: Cannot allocate memory
4: In system(cmd7) : system call failed: Cannot allocate memory
5: In system(cmd8) : system call failed: Cannot allocate memory

@ttriche
Copy link
Member

ttriche commented May 18, 2016

agreed; you could also use system("free") to find out.

--t

On Tue, May 17, 2016 at 5:15 PM, Asif Zubair [email protected]
wrote:

Personally, I think we should check with Jay about the instance. He told
me that it is a cc2.8x large instance. But, I am not sure.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@ttriche
Copy link
Member

ttriche commented May 18, 2016

memory leak somewhere?

try system("free") before and after running motif enrichment analysis

--t

On Tue, May 17, 2016 at 9:15 PM, Asif Zubair [email protected]
wrote:

this is even more weird, R is using 3gb and yet the system command is
failing:

�}Garbage collection 547 = 361+101+85 (level 2) ...
288.0 Mbytes of cons cells used (10%)
2747.9 Mbytes of vectors used (10%)
�}Garbage collection 548 = 361+101+86 (level 2) ...
288.0 Mbytes of cons cells used (12%)
2747.9 Mbytes of vectors used (12%)
�}Garbage collection 549 = 361+101+87 (level 2) ...
288.0 Mbytes of cons cells used (15%)
2747.9 Mbytes of vectors used (15%)
�}Garbage collection 550 = 361+101+88 (level 2) ...
288.0 Mbytes of cons cells used (19%)
2747.9 Mbytes of vectors used (19%)
�}Garbage collection 551 = 361+101+89 (level 2) ...
288.0 Mbytes of cons cells used (24%)
2747.9 Mbytes of vectors used (24%)
�}Garbage collection 552 = 361+101+90 (level 2) ...
288.0 Mbytes of cons cells used (30%)
2747.9 Mbytes of vectors used (30%)
�}Garbage collection 553 = 361+101+91 (level 2) ...
288.0 Mbytes of cons cells used (37%)
2747.9 Mbytes of vectors used (30%)
�}Garbage collection 554 = 361+101+92 (level 2) ...
288.0 Mbytes of cons cells used (37%)
2747.9 Mbytes of vectors used (30%)
�2Garbage collection 555 = 361+101+93 (level 2) ... �K
288.0 Mbytes of cons cells used (37%)
2747.9 Mbytes of vectors used (30%)
�}Garbage collection 556 = 361+101+94 (level 2) ...
288.0 Mbytes of cons cells used (37%)
2747.9 Mbytes of vectors used (30%)

��2: In system(cmd5) : system call failed: Cannot allocate memory
3: In system(cmd6) : system call failed: Cannot allocate memory
4: In system(cmd7) : system call failed: Cannot allocate memory
5: In system(cmd8) : system call failed: Cannot allocate memory


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@asifzubair
Copy link
Contributor Author

I'm not calling system anymore. I just append the mv commands into the calling script and run them after. For now, it seems to be working.

@ttriche
Copy link
Member

ttriche commented May 18, 2016

probably better anyways... test if the file exists && mv it

--t

On Wed, May 18, 2016 at 11:29 AM, Asif Zubair [email protected]
wrote:

I'm not calling system anymore. I just append the mv commands into the
calling script and run them after. For now, it seems to be working.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#9 (comment)

@asifzubair
Copy link
Contributor Author

@ttriche what do you think about using the collectGarbage function from WGCNA ?

# ===================================================
# This function collects garbage

collectGarbage=function(){while (gc()[2,4] != gc()[2,4] | gc()[1,4] != gc()[1,4]){}}

@ttriche
Copy link
Member

ttriche commented Jul 19, 2016

handy! It's not "supposed" to be needed for the GC but I do this by hand
now and then.

--t

On Tue, Jul 19, 2016 at 1:27 PM, Asif Zubair [email protected]
wrote:

@ttriche https://github.com/ttriche what do you think about using the
collectGarbage function from WGCNA ?

===================================================# This function collects garbage

collectGarbage=function(){while (gc()[2,4] != gc()[2,4] | gc()[1,4] != gc()[1,4]){}}


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARIkutfNeQ4YblDKjQ1aD3gdqIddy5ks5qXTNJgaJpZM4Ie8PR
.

@arcolombo
Copy link

you might want to consider the software SnakeMake which can actively
control how many fork processes and how much memory to allocate
specifically for each process. lapply and mcLapply does not directly
control memory dispatch ( i don't think) . google snakeMake, or even
bioConda (which is a docker version control flow).

On Tue, Jul 19, 2016 at 2:07 PM, Tim Triche, Jr. [email protected]
wrote:

handy! It's not "supposed" to be needed for the GC but I do this by hand
now and then.

--t

On Tue, Jul 19, 2016 at 1:27 PM, Asif Zubair [email protected]
wrote:

@ttriche https://github.com/ttriche what do you think about using the
collectGarbage function from WGCNA ?

===================================================# This function

collects garbage
collectGarbage=function(){while (gc()[2,4] != gc()[2,4] | gc()[1,4] !=
gc()[1,4]){}}


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<
#9 (comment)
,
or mute the thread
<
https://github.com/notifications/unsubscribe-auth/AAARIkutfNeQ4YblDKjQ1aD3gdqIddy5ks5qXTNJgaJpZM4Ie8PR

.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFODS0Ul_auHtvdShdsFcPs3LXFVBPYPks5qXTyhgaJpZM4Ie8PR
.

@ttriche
Copy link
Member

ttriche commented Jul 19, 2016

not clear how this solves the problem of running out of RAM -- if a forked
child dies, it's going to have to be re-run or the analysis from that child
won't be produced. "parallel" (in R) can be instructed how many cores to
use with options("mc.cores") although that really just tells it how many
children to fork at a time.

On the other hand, for (e.g.) reassembling mt genomes, snakeMake could
really help: say you wanted to reassemble 800 samples, 8 per node across
100 nodes. If a process dies you want to hear about it and respawn, but
you also don't want to kill any other processes on the same node. In that
case I could see SnakeMake being super helpful.

--t

On Tue, Jul 19, 2016 at 3:00 PM, Anthony R. Colombo <
[email protected]> wrote:

you might want to consider the software SnakeMake which can actively
control how many fork processes and how much memory to allocate
specifically for each process. lapply and mcLapply does not directly
control memory dispatch ( i don't think) . google snakeMake, or even
bioConda (which is a docker version control flow).

On Tue, Jul 19, 2016 at 2:07 PM, Tim Triche, Jr. <[email protected]

wrote:

handy! It's not "supposed" to be needed for the GC but I do this by hand
now and then.

--t

On Tue, Jul 19, 2016 at 1:27 PM, Asif Zubair [email protected]
wrote:

@ttriche https://github.com/ttriche what do you think about using
the
collectGarbage function from WGCNA ?

===================================================# This function

collects garbage
collectGarbage=function(){while (gc()[2,4] != gc()[2,4] | gc()[1,4] !=
gc()[1,4]){}}


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<

#9 (comment)

,
or mute the thread
<

https://github.com/notifications/unsubscribe-auth/AAARIkutfNeQ4YblDKjQ1aD3gdqIddy5ks5qXTNJgaJpZM4Ie8PR

.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<
#9 (comment)
,
or mute the thread
<
https://github.com/notifications/unsubscribe-auth/AFODS0Ul_auHtvdShdsFcPs3LXFVBPYPks5qXTyhgaJpZM4Ie8PR

.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARIlIsGsZFnNEVLKL5jGAjqj6ao1O-ks5qXUj2gaJpZM4Ie8PR
.

@arcolombo
Copy link

is this caused by / when / during sliding window calculation. from reading these messages, I'm not sure if this is caused by the window calculation, what exactly is the system() calling, more specifically what process is being computed in the algorithm

if it is the sliding window, one cause may that in order for the downstream analysis to begin, one must wait for all the sliding windows to complete their calculations, storing a genome wide set of windows with computations. if this is true, then one solution may be to calculate the first k windows, push into a result(k), then calculate the k+1 windows and calculate result(k2) = result(k) + results(k+1), etc. then you can clear the memory from windows at the first k at each iteration. oooh this probably makes no sense.

AC

@arcolombo
Copy link

arcolombo commented Jul 22, 2016

the other idea, assuming it is during a sliding window calculation, is that if the sliding_window at position k computations = alpha. then move to sliding_window computation result at position k+beta = gamma. if alpha is somewhat equivalent to gamma, then do not store gamma, but skip it.

@asifzubair
Copy link
Contributor Author

I call all my commands from inside the Rmarkdown, so I don't think I need SnakeMake. I eliminated all system() calls and minimized using mcmapply() because the app would crash everytime a fork failed. I'm now using mappl().

However, the App still crashes in the 8vs8 analysis and I am sort of running out of ideas.

It needs to allocate a 8gb vector (when dedup = F) to find the filter threshold and this fails. However, I am not sure why this would be a problem because Jay said that the machine had 40gb of memory. I am doing memory clean up and garbage collection as well.

Could it be possible that R is not using all the memory ? I could possibly increase it by using memory.limit().

A last question is. Do you folks know how to interpret this output of gc():

286.4 Mbytes of cons cells used (35%)
�289.6 Mbytes of vectors used (26%)

Doesn't this mean that R is using 600Mb of memory ?

Thanks!

@arcolombo
Copy link

It looks like this is due from Rsam
Tools and not a window calculation. Is this true?

Sent from my iPhone

On Jul 28, 2016, at 12:40 AM, Asif Zubair [email protected] wrote:

I call all my commands from inside the Rmarkdown, so I don't think I need SnakeMake. I eliminated all system() calls and minimized using mcmapply() because the app would crash everytime a fork failed. I'm now using mappl().

However, the App still crashes in the 8vs8 analysis and I am sort of running out of ideas.

It needs to allocate a 8gb vector (when dedup = F) to find the filter threshold and this fails. However, I am not sure why this would be a problem because Jay said that the machine had 40gb of memory. I am doing memory clean up and garbage collection as well.

Could it be possible that R is not using all the memory ? I could possibly increase it by using memory.limit().

A last question is. Do you folks know how to interpret this output of gc():

286.4 Mbytes of cons cells used (35%)
�289.6 Mbytes of vectors used (26%)
Doesn't this mean that R is using 600Mb of memory ?

Thanks!


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@asifzubair
Copy link
Contributor Author

The place it breaks is during csaw's global filter computation and not the windowCounts function.

@ttriche
Copy link
Member

ttriche commented Jul 28, 2016

One possibility (something that has happened in the past on HPC) is that
preallocation is used on these nodes. If a process is forking off threads
or LWPs, preallocation will treat anything that exceeds the hypothetical
maximum usage (i.e., assuming all children use the maximum image of the
parent, even though shared memory means they never should) as their actual
footprint and treat violation of that maximum as a segfault. This makes no
sense whatsoever on a machine image, since it should be virtualized and
thrash just like a regular machine, therefore I have no idea why it would
be set up this way. But it's one of the reasons I stopped running parallel
jobs on HPC, at least from R. (Sysadmin decisions of that sort are a
reason that the entire world is moving away from understaffed HPC systems
and onto cloud or predictably cloud-like systems).

It may be time to ask Aaron (csaw) and/or Martin (Rsamtools) about this
behavior on the Bioconductor support site. I don't immediately know the
answer, and I don't really have time to trace it through the code, less so
when the authors of the packages in question are obligated to support them
for a while longer ;-). They may not have the answers, but they'll have
better questions than I do at this point. I'd suggest proceeding in that
direction.

As a bonus, Dan Tenenbaum sets up and runs AMIs and Docker images all the
time, so if it's related to one of those, you may find out quicker by
asking through the support site.

--t

On Thu, Jul 28, 2016 at 3:40 AM, Asif Zubair [email protected]
wrote:

I call all my commands from inside the Rmarkdown, so I don't think I need
SnakeMake. I eliminated all system() calls and minimized using mcmapply()
because the app would crash everytime a fork failed. I'm now using mappl()
.

However, the App still crashes in the 8vs8 analysis and I am sort of
running out of ideas.

It needs to allocate a 8gb vector (when dedup = F) to find the filter
threshold and this fails. However, I am not sure why this would be a
problem because Jay said that the machine had 40gb of memory. I am doing
memory clean up and garbage collection as well.

Could it be possible that R is not using all the memory ? I could possibly
increase it by using memory.limit().

A last question is. Do you folks know how to interpret this output of gc()
:

286.4 Mbytes of cons cells used (35%)
�289.6 Mbytes of vectors used (26%)

Doesn't this mean that R is using 600Mb of memory ?

Thanks!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARIh3KsyivN7IJRbKYEJxPutRkINNFks5qaF0JgaJpZM4Ie8PR
.

@ttriche
Copy link
Member

ttriche commented Jul 28, 2016

also -- yes, it looks like R has allocated under 2GB (1932.132MB to be
exact) in this situation.

Try two things:

  1. system("ulimit")

unlimited, for me

  1. system("free")

will verify what sort of image you really have

Last but not least, make sure you're using a 64-bit R image.

--t

On Thu, Jul 28, 2016 at 3:40 AM, Asif Zubair [email protected]
wrote:

I call all my commands from inside the Rmarkdown, so I don't think I need
SnakeMake. I eliminated all system() calls and minimized using mcmapply()
because the app would crash everytime a fork failed. I'm now using mappl()
.

However, the App still crashes in the 8vs8 analysis and I am sort of
running out of ideas.

It needs to allocate a 8gb vector (when dedup = F) to find the filter
threshold and this fails. However, I am not sure why this would be a
problem because Jay said that the machine had 40gb of memory. I am doing
memory clean up and garbage collection as well.

Could it be possible that R is not using all the memory ? I could possibly
increase it by using memory.limit().

A last question is. Do you folks know how to interpret this output of gc()
:

286.4 Mbytes of cons cells used (35%)
�289.6 Mbytes of vectors used (26%)

Doesn't this mean that R is using 600Mb of memory ?

Thanks!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARIh3KsyivN7IJRbKYEJxPutRkINNFks5qaF0JgaJpZM4Ie8PR
.

@arcolombo
Copy link

You might be able to use the mean value theorem. Instead of looking at a global filter you look at intervals along the global position. Now if you assume you have a continuous function, for every interval there exists a A Beta and a. Mu such that f(beta) = mu. Where mu is the meanover this interval. Then the property of means are additive. This can reduce a global filter into a segmented filter over smaller regions. I'm not sure if this helps at all

Sent from my iPho

On Jul 28, 2016, at 9:30 AM, Asif Zubair [email protected] wrote:

The place it breaks is during csaw's global filter computation and not the windowCounts function.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@asifzubair
Copy link
Contributor Author

thank you, Anthony, but the function has been implemented in csaw and at this point i am not inclined to change it. I am still trying to see how I could play around with R specs.

thank you, Tim. I checked that I am using 64-bit R. I'll also chat with Aaron about it.

@arcolombo
Copy link

no prob. interesting for me to see what you've had problems with
implementing. will probably have to read csaw code much more closely.
tyvm

On Thu, Jul 28, 2016 at 11:42 AM, Asif Zubair [email protected]
wrote:

thank you, Anthony, but the function has been implemented in csaw and at
this point i am not inclined to change it. I am still trying to see how I
could play around with R specs.

thank you, Tim. I checked that I am using 64-bit R. I'll also chat with
Aaron about it.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFODS1OhibXh5HlwweB_2MobVGUbb7QGks5qaPgFgaJpZM4Ie8PR
.

@asifzubair
Copy link
Contributor Author

This is the output from the following commands:

system("free -h")
gc(T)
system("free -h")

output:

label: mem_clean_up_zero
             total       used       free     shared    buffers     cached
Mem:           59G        44G        15G        16M       2.2M        30G
-/+ buffers/cache:        14G        45G
Swap:           0B         0B         0B
Garbage collection 356 = 233+64+59 (level 2) ... 
284.8 Mbytes of cons cells used (64%)
36.9 Mbytes of vectors used (3%)
             total       used       free     shared    buffers     cached
Mem:           59G        40G        19G        16M       2.2M        30G
-/+ buffers/cache:         9G        49G
Swap:           0B         0B         0B

any ideas why is the total memory used 40G when gc() says R is using a lot less ? Thank you.

Also, I am going to switch default behaviour to dedup = TRUE as the App doesn't crash in that case and it seems more appropriate.

@ttriche
Copy link
Member

ttriche commented Jul 29, 2016

Seems like a plan... I can't quite figure out what's using 40GB baseline,
but if you can find it (with e.g. ls() and object.size()) you could rm()
it, or just deduplicate (which seems reasonable anyhow).

--t

On Thu, Jul 28, 2016 at 6:22 PM, Asif Zubair [email protected]
wrote:

This is the output from the following commands:

system("free -h")
gc(T)
system("free -h")

output:

label: mem_clean_up_zero
total used free shared buffers cached
Mem: 59G 44G 15G 16M 2.2M 30G
-/+ buffers/cache: 14G 45G
Swap: 0B 0B 0B
Garbage collection 356 = 233+64+59 (level 2) ...
284.8 Mbytes of cons cells used (64%)
36.9 Mbytes of vectors used (3%)
total used free shared buffers cached
Mem: 59G 40G 19G 16M 2.2M 30G
-/+ buffers/cache: 9G 49G
Swap: 0B 0B 0B

any ideas why is the total memory used 40G when gc() says R is using a
lot less ? Thank you.

Also, I am going to switch default behaviour to dedup = TRUE as the App
doesn't crash in that case and it seems more appropriate.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARIhb8wzhcQfrpEtACGiRhaZPbF7qVks5qaVXdgaJpZM4Ie8PR
.

@asifzubair
Copy link
Contributor Author

but the R gc() shows that it is not using all that much memory, is it ? I don't think there are any large objects which are taking up memory. Do you think this is because I am running the script through Rmarkdown ?

@asifzubair
Copy link
Contributor Author

should I run a profiler ? does R have one ?

@ttriche
Copy link
Member

ttriche commented Jul 29, 2016

R does have a profiler (several, actually;
https://github.com/rstudio/profvis is a particularly nice one) and perhaps
that can answer your question. I really don't understand where 40GB of
memory is going in this instance. It seems like either a horrific bug or a
misallocation by the kernel.

--t

On Thu, Jul 28, 2016 at 8:48 PM, Asif Zubair [email protected]
wrote:

should I run a profiler ? does R have one ?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARInxi25jH9E16r4oYZMtVK6FBWIDmks5qaXf8gaJpZM4Ie8PR
.

@asifzubair
Copy link
Contributor Author

Hi Folks,

I might have this wrong but is it suspicious that the file.copy command causes increase in used memory ? Please see the following:

## Running this inside R environment
> system("free -h")
             total       used       free     shared    buffers     cached
Mem:          7.8G       283M       7.5G       123M        21M       148M
-/+ buffers/cache:       113M       7.7G
Swap:         2.8G         0B       2.8G
> cleanMem <- function(n=10) { for (i in 1:n) gc(T,T) }
> bams = c("071114-3-N_S1.bam", "100214-1-S_S1.bam")
> mapply(file.copy, bams, "/tmp", overwrite = T)
071114-3-N_S1.bam 100214-1-S_S1.bam 
             TRUE              TRUE 
> cleanMem()
Garbage collection 14 = 2+0+12 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
Garbage collection 15 = 2+0+13 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
Garbage collection 16 = 2+0+14 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
Garbage collection 17 = 2+0+15 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
Garbage collection 18 = 2+0+16 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
Garbage collection 19 = 2+0+17 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
Garbage collection 20 = 2+0+18 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
Garbage collection 21 = 2+0+19 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
Garbage collection 22 = 2+0+20 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
Garbage collection 23 = 2+0+21 (level 2) ... 
11.9 Mbytes of cons cells used (48%)
3.2 Mbytes of vectors used (40%)
> system("free -h")
             total       used       free     shared    buffers     cached
Mem:          7.8G       1.5G       6.3G       123M        21M       1.3G
-/+ buffers/cache:       148M       7.6G
Swap:         2.8G         0B       2.8G

This also happens when I do a copy inside the docker container at the commandline:

## this is from the shell
root@0e7fd7a515be:/data# free -h
             total       used       free     shared    buffers     cached
Mem:          7.8G       256M       7.5G       123M        21M       148M
-/+ buffers/cache:        86M       7.7G
Swap:         2.8G         0B       2.8G
root@0e7fd7a515be:/data# cp *.bam /tmp
root@0e7fd7a515be:/data# free -h
             total       used       free     shared    buffers     cached
Mem:          7.8G       1.5G       6.3G       123M        21M       1.4G
-/+ buffers/cache:       122M       7.7G
Swap:         2.8G         0B       2.8G

Is this behaviour expected ?

These are the file sizes:

root@0e7fd7a515be:/data# ll -h *.bam
-rw-r----- 1 1000 staff 602M Jan 30 06:25 071114-3-N_S1.bam
-rw-r----- 1 1000 staff 627M Jan 30 06:25 100214-1-S_S1.bam

Thanks!

@asifzubair
Copy link
Contributor Author

asifzubair commented Jul 29, 2016

Also, is it suspicious that the Amazon EC2 instance has 0 swap ? @arcolombo , do you have this problem when you copy files to the scratch directory ?

@ttriche
Copy link
Member

ttriche commented Jul 29, 2016

no an EC2 instance isn't going to have swap because it's pointless --
memory on a cloud node is like disk and disk is like tape. So think
"swapping to tape" and you'll see why there isn't much demand for that

file.copy can eat up a tremendous amount of memory DURING the copy (run top
sometime on your local machine while copying huge files) but afterwards it
should free it. If not, that's a bug. Where the bug is, I'm less sure.
If you can avoid copying files, that would probably be a good idea.

--t

On Fri, Jul 29, 2016 at 3:29 PM, Asif Zubair [email protected]
wrote:

Also, is it suspicious that on the Amazon EC2 instance has 0 swap ?
@arcolombo https://github.com/arcolombo , do you have this problem when
you copy files to the scratch directory ?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARIlmegRBsxGVVbDMeLwIjre5ymMxZks5qan7WgaJpZM4Ie8PR
.

@asifzubair
Copy link
Contributor Author

Thank you, Tim. That clears things up.

The reason we did the copy is that we wanted to re-index the bam files. The ones generated by ILMN's bwa aligner were not working for some reason.

I think copying large files is tricky. After the copy operation i don't see RAM usage go down. :/

@ttriche
Copy link
Member

ttriche commented Jul 29, 2016

oh crap, that's right. I wonder -- can you simply index them from wherever
they live, and use a symlink or something to pair them with their indices?
Then copying would not be so brutal.

--t

On Fri, Jul 29, 2016 at 4:07 PM, Asif Zubair [email protected]
wrote:

Thank you, Tim. That clears things up.

The reason we did the copy is that we wanted to re-index the bam files.
The ones generated by ILMN's bwa aligner were not working for some reason.

I think copying large files is tricky. After the copy operation i don't
see RAM usage go down. :/


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARIsYLRJbfggT4J0p4JDoXWkbhKg1Hks5qaoe9gaJpZM4Ie8PR
.

@asifzubair
Copy link
Contributor Author

Yes, that's brilliant. Simply link the bam files and then index!!! Thank you, Tim. Will try it out.

@asifzubair
Copy link
Contributor Author

asifzubair commented Jul 30, 2016

Hmm, it doesn't seem to work. This from free -h calls before and after link creation:

label: setup_var_input
             total       used       free     shared    buffers     cached
Mem:           59G       6.5G        53G       8.8M        47M       5.5G
-/+ buffers/cache:       1.0G        58G
Swap:           0B         0B         0B
             total       used       free     shared    buffers     cached
Mem:           59G        59G       368M       8.8M       9.8M        57G
-/+ buffers/cache:       1.7G        57G
Swap:           0B         0B         0B

this seems pretty weird.

@ttriche
Copy link
Member

ttriche commented Jul 30, 2016

This is bizarre. Seems like it has to be some sort of an FS issue -- is
the filesystem mapping into shared memory somehow?!? Truly bizarre

--t

On Fri, Jul 29, 2016 at 7:41 PM, Asif Zubair [email protected]
wrote:

Hmm, it doesn't seem to work. This from free -h calls before and after
link creation:

��label: setup_var_input��
�? total used free shared buffers cached
Mem: 59G 6.5G 53G 8.8M 47M 5.5G
-/+ buffers/cache: 1.0G 58G
Swap: 0B 0B 0B
�? total used free shared buffers cached
Mem: 59G 59G 368M 8.8M 9.8M 57G
-/+ buffers/cache: 1.7G 57G
Swap: 0B 0B 0B

this seems pretty weird.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARIqhloSkATZn9HvKHLa8W7-gsf1rFks5qarnogaJpZM4Ie8PR
.

@asifzubair
Copy link
Contributor Author

Sorry, the linking wasn't causing the memory usage, it was the indexing. However, I checked that the indexs from the Aligner App are also working. I'll rejig the App so that those are now used directly and we don't have to copy/link bams.

Also, it seems that other people have run into R memory issues. Please see this SO. I think the solution is to divide the Rmarkdown into different R files. But I think that will have to wait. I want to work on the App Note for now.

@ttriche
Copy link
Member

ttriche commented Jul 31, 2016

Good plan. FWIW I'm submitting a separate app note today. If there are
any gotchas in review, I'll pass them along :-)

--t

On Sat, Jul 30, 2016 at 9:24 PM, Asif Zubair [email protected]
wrote:

Sorry, the linking wasn't causing the memory usage, it was the indexing.
However, I checked that the indexs from the Aligner App are also working.
I'll rejig the App so that those are now used directly and we don't have to
copy/link bams.

Also, it seems that other people have run into R memory issues. Please see
this SO
http://stackoverflow.com/questions/12322959/r-cannot-allocate-memory-though-memory-seems-to-be-available.
I think the solution is to divide the Rmarkdown into different R files. But
I think that will have to wait. I want to work on the App Note for now.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAARIkvhzmtb9_1sFpktFoG00gsjh3Y0ks5qbCNkgaJpZM4Ie8PR
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants