2017-04-23 81 views
-2

可能会导致什么Linux设置在C++程序运行为:Linux,bash脚本中的内存不足,不是交互式的,不是ulimit?

jellyfish count -m 31 -t 40 -C -s 105 -o k_u_hash_0 pe.cor.fa 

时该命令在终端中执行工作正常,但在bash脚本崩溃?在后一种情况下,它会在退出之前立即请求411428571480字节。这很奇怪,因为当交互式运行时,top在开始运行几分钟后显示它仅有10秒的Virt和Res存储器。

ulimit -a 

在两个环境中显示:

core file size   (blocks, -c) 0 
data seg size   (kbytes, -d) unlimited 
scheduling priority    (-e) 0 
file size    (blocks, -f) unlimited 
pending signals     (-i) 2067197 
max locked memory  (kbytes, -l) 64 
max memory size   (kbytes, -m) unlimited 
open files      (-n) 1024 
pipe size   (512 bytes, -p) 8 
POSIX message queues  (bytes, -q) 819200 
real-time priority    (-r) 0 
stack size    (kbytes, -s) 10240 
cpu time    (seconds, -t) unlimited 
max user processes    (-u) 1024 
virtual memory   (kbytes, -v) unlimited 
file locks      (-x) unlimited 

的/ proc/meminfo中显示:

CommitLimit: 615693660 kB 
Committed_AS: 48320500 kB 

,甚至陌生人,小C的测试程序,它只是释放calloc比以往更大的存储器模块在任何环境下运行时,包括水母前立即释放它们:

calloc_test 
Testing 4294967296 
Testing 8589934592 
Testing 17179869184 
Testing 34359738368 
Testing 68719476736 
Testing 137438953472 
Testing 274877906944 
Testing 549755813888 
Testing 1099511627776 
FAILED 

也就是说,它能够分配一个549 Gb块,它比要求的一个水母要大,并且在两种环境下的内存分配都表现相同。

在任何一种情况下都没有设置LD_LIBRARY_PATH

有人可以提出在两种环境中可能会有什么不同,以说明内存分配程序子集的动作差异吗? (在这一点上的一个子集)。

谢谢。

按照要求,这是脚本(只下降到故障点加3​​条额外的线路):

#!/bin/bash 

# assemble.sh generated by masurca 
CONFIG_PATH="/home/mathog/do_masurca/project.cfg" 
CMD_PATH="/home/mathog/MaSuRCA/bin/masurca" 

# Test that we support <() redirection 
(eval "cat <(echo test) >/dev/null" 2>/dev/null) || { 
    echo >&2 "ERROR: The shell used is missing important features." 
    echo >&2 "  Run the assembly script directly as './$0'" 
    exit 1 
} 

# Parse command line switches 
while getopts ":rc" o; do 
    case "${o}" in 
    c) 
    echo "configuration file is '$CONFIG_PATH'" 
    exit 0 
    ;; 
    r) 
    echo "Rerunning configuration" 
    exec perl "$CMD_PATH" "$CONFIG_PATH" 
    echo "Failed to rerun configuration" 
    exit 1 
    ;; 
    *) 
    echo "Usage: $0 [-r] [-c]" 
    exit 1 
    ;; 
    esac 
done 
set +e 
# Set some paths and prime system to save environment variables 
save() { 
    (echo -n "$1=\""; eval "echo -n \"\$$1\""; echo '"') >> environment.sh 
} 
GC= 
RC= 
NC= 
if tty -s < /dev/fd/1 2> /dev/null; then 
    GC='\e[0;32m' 
    RC='\e[0;31m' 
    NC='\e[0m' 
fi 
log() { 
    d=$(date) 
    echo -e "${GC}[$d]${NC} [email protected]" 
} 
fail() { 
    d=$(date) 
    echo -e "${RC}[$d]${NC} [email protected]" 
    exit 1 
} 
signaled() { 
    fail Interrupted 
} 
trap signaled TERM QUIT INT 
rm -f environment.sh; touch environment.sh 

# To run tasks in parallel 
run_bg() { 
    semaphore -j $NUM_THREADS --id masurca_$$ -- "[email protected]" 
} 
run_wait() { 
    semaphore -j $NUM_THREADS --id masurca_$$ --wait 
} 
export PATH="/home/mathog/MaSuRCA/bin:/home/mathog/MaSuRCA/bin/../CA/Linux-amd64/bin:$PATH" 
save PATH 
export PERL5LIB=/home/mathog/MaSuRCA/bin/../lib/perl${PERL5LIB:+:$PERL5LIB} 
save PERL5LIB 
NUM_THREADS=40 
save NUM_THREADS 
log 'Processing pe library reads' 
rm -rf meanAndStdevByPrefix.pe.txt 
echo 'pe 400 20' >> meanAndStdevByPrefix.pe.txt 
run_bg rename_filter_fastq 'pe' <(exec expand_fastq '/home/mathog/SPUR_datasets/pe_400_R1.fastq' | awk '{if(length($0>200)) print substr($0,1,200); else print $0;}') <(exec expand_fastq '/home/mathog/SPUR_datasets/pe_400_R2.fastq' | awk '{if(length($0>200)) print substr($0,1,200); else print $0;}') > 'pe.renamed.fastq' 
run_wait 

head -q -n 40000 pe.renamed.fastq | grep --text -v '^+' | grep --text -v '^@' > pe_data.tmp 
export PE_AVG_READ_LENGTH=`awk '{if(length($1)>31){n+=length($1);m++;}}END{print int(n/m)}' pe_data.tmp` 
save PE_AVG_READ_LENGTH 
echo "Average PE read length $PE_AVG_READ_LENGTH" 
KMER=`for f in pe.renamed.fastq;do head -n 80000 $f |tail -n 40000;done | perl -e 'while($line=<STDIN>){$line=<STDIN>;chomp($line);push(@lines,$line);$line=<STDIN>;$line=<STDIN>}$min_len=100000;$base_count=0;foreach $l(@lines){$base_count+=length($l);push(@lengths,length($l));@f=split("",$l);foreach $base(@f){if(uc($base) eq "G" || uc($base) eq "C"){$gc_count++}}} @lengths =sort {$b <=> $a} @lengths; $min_len=$lengths[int($#lengths*.75)]; $gc_ratio=$gc_count/$base_count;$kmer=0;if($gc_ratio<0.5){$kmer=int($min_len*.7);}elsif($gc_ratio>=0.5 && $gc_ratio<0.6){$kmer=int($min_len*.5);}else{$kmer=int($min_len*.33);} $kmer++ if($kmer%2==0); $kmer=31 if($kmer<31); $kmer=127 if($kmer>127); print $kmer'` 
save KMER 
echo "choosing kmer size of $KMER for the graph" 
KMER_J=$KMER 
MIN_Q_CHAR=`cat pe.renamed.fastq |head -n 50000 | awk 'BEGIN{flag=0}{if($0 ~ /^\+/){flag=1}else if(flag==1){print $0;flag=0}}' | perl -ne 'BEGIN{$q0_char="@";}{chomp;@f=split "";foreach $v(@f){if(ord($v)<ord($q0_char)){$q0_char=$v;}}}END{$ans=ord($q0_char);if($ans<64){print "33\n"}else{print "64\n"}}'` 
save MIN_Q_CHAR 
echo MIN_Q_CHAR: $MIN_Q_CHAR 
JF_SIZE=`ls -l *.fastq | awk '{n+=$5}END{s=int(n/50); if(s>80000000000)printf "%.0f",s;else print "80000000000";}'` 
save JF_SIZE 
perl -e '{if(int('$JF_SIZE')>80000000000){print "WARNING: JF_SIZE set too low, increasing JF_SIZE to at least '$JF_SIZE', this automatic increase may be not enough!\n"}}' 
log Creating mer database for Quorum. 
quorum_create_database -t 40 -s $JF_SIZE -b 7 -m 24 -q $((MIN_Q_CHAR + 5)) -o quorum_mer_db.jf.tmp pe.renamed.fastq && mv quorum_mer_db.jf.tmp quorum_mer_db.jf 
if [ 0 != 0 ]; then 
    fail Increase JF_SIZE in config file, the recommendation is to set this to genome_size*coverage/2 
fi 

log Error correct PE. 

quorum_error_correct_reads -q $((MIN_Q_CHAR + 40)) --contaminant=/home/mathog/MaSuRCA/bin/../share/adapter.jf -m 1 -s 1 -g 1 -a 3 -t 40 -w 10 -e 3 -M quorum_mer_db.jf pe.renamed.fastq --no-discard -o pe.cor --verbose 1>quorum.err 2>&1 || { 
    mv pe.cor.fa pe.cor.fa.failed && fail Error correction of PE reads failed. Check pe.cor.log. 
} 


log Estimating genome size. 
jellyfish count -m 31 -t 40 -C -s $JF_SIZE -o k_u_hash_0 pe.cor.fa 
export ESTIMATED_GENOME_SIZE=`jellyfish histo -t 40 -h 1 k_u_hash_0 | tail -n 1 |awk '{print $2}'` 
save ESTIMATED_GENOME_SIZE 
echo "Estimated genome size: $ESTIMATED_GENOME_SIZE" 
+1

什么是C++程序没用使用猫的?你有多少内存?为什么这个程序会分配10 GB的内存?也能够分配内存的来回并不意味着你也能够写入所有的内存。 – smac89

+0

https://stackoverflow.com/help/mcve – PSkocik

+0

它可能是一个32位的bash实现吗? – didiz

回答

0

这里的(一些)无用的内存和CPU周期脚本浪费:

cat pe.renamed.fastq | head -n 50000 | ... 

而应该避免与

head -n 50000 pe.renamed.fastq | ... 
+0

这些都不是我的代码。我只是想明白为什么该计划的行事方式如此。这一点浪费的资源在这里并不重要 - 在48台CPU机器上运行脚本需要几天时间。我还不知道有多少天... – mathog