text: user1194: I am trying to index wheat genome using STAR through following command
  STAR --runMode genomeGenerate --genomeFastaFiles Triticum_aestivum.TGACv1.dna_sm.toplevel.fa --runThreadN 28 
  
  But getting following error,
  terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
  Aborted (core dumped)
  
  The size of the genome is 13.5 GB and the server capacity is 32 cores with 125 GB RAM, how this error can be resolved?
  Memory usage: 
  I have decreased the number of threads to 8 but again getting the same error as shown below:
  > STAR   --runMode genomeGenerate   --runThreadN 8   --genomeDir wheat   --genomeFastaFiles wheat.fa                                                                      
  Jun 04 02:13:31 ..... started STAR run                                                                                                                                                                                           
  Jun 04 02:13:31 ... starting to generate Genome files                                                                                                                                                                            
  terminate called after throwing an instance of 'std::bad_alloc'                                                                                                                                                                  
  what():  std::bad_alloc                                                                                                                                                                                                        
  Aborted (core dumped)                                           
  
  Even I have tried to use STAR without any threads but still the same error:
  > STAR   --runMode genomeGenerate   --genomeDir wheat   --genomeFastaFiles wheat.fa                                                                         
  Jun 04 02:19:44 ..... started STAR run                                                                                                                                                                                           
  Jun 04 02:19:44 ... starting to generate Genome files                                                                                                                                                                            
  terminate called after throwing an instance of 'std::bad_alloc'                                                                                                                                                                  
  what():  std::bad_alloc
  Aborted (core dumped)
  
  May there can be an issue in reference of wheat that I am using, I got this reference from here.
  Here are the first ten lines of the reference using head command:
  > head wheat.fa
  >Pt dna:chromosome chromosome:TGACv1:Pt:1:135835:1 REF                                                                                                                                                                           
  ACAGAAATACCCAATATCTTGTTCTAGCAAGATATTGGGTATTTCTGTCTTTTCTTTCTT                                                                                                                                                                     
  CAAAAATTCTTATATGTTAGCAGAAAAACCTTATCCATTAATAGATGGAACTTCAACAGC                                                                                                                                                                     
  AGCTAAGTCTAGAGGGAAGTTGTGAGCATTACGTTCGTGCATTACTTCCATACCAAGGTT                                                                                                                                                                     
  AGCACGGTTGATGATATCAGCCCAAGTATTAATAACGCGACCTTGACTATCAACTACAGA                                                                                                                                                                     
  TTGGTTGAAATTGAAACCATTTAGGTTGAAAGCCATAGTACTAATACCTAAAGCAGTGAA                                                                                                                                                                     
  CCAGATTCCTACTACAGGCCAAGCAGCCAAGAAGAAGTGTAAAGAACGAGAGTTGTTGAA                                                                                                                                                                     
  ACTAGCATATTGGAAGATTAATCGGCCAAAATAACCATGAGCAGCCACAATATTATAAGT                                                                                                                                                                     
  TTCTTCCTCTTGACCAAATTTGTAACCCTCATTAGCAGATTCATTTTCAGTAGTTTCCCT                                                                                                                                                                     
  GATCAAACTAGAGGTTACCAAGGAACCATGCATAGCACTGAATAGGGAACCGCCGAATAC 
  
  How this problem can be resolved? 
  
  user939: In addition to the other answer (to reduce the number of threads), you might also need to add a --genomeChrBinNbits argument. Your reference has more than 5000 scaffolds, so you need to adjust the --genomeChrBinNbits argument to reduce RAM consumption. Found here.
  They recommend:
  
  --genomeChrBinNbits} = min(18, log2(GenomeLength/NumberOfReferences))
  
  In your case:
  Genome size 17G, number of scaffolds 735945
  So --genomeChrBinNbits should be set to log2(17,000,000,000/735,945) = 14.4955, so let's say 14 or 15.
  
  user29: Try reducing the number of threads.
  When multithreading the index creation (and other memory bound tasks), the memory usage increases linearly with the number of threads. If you required a 10 GiB working space work with a single thread, then the requirement for 10 threads would be at 100 GiB.
  STAR is particularly memory hungry for the index creation to start with, and your genome is exceptionally large. I’ve had STAR require > 32 GiB of memory for the human genome, with a moderate number of threads. I’m not surprised that it fails with a 4× larger genome and many more threads: it would probably require at least 2× as much RAM as your machine has.
  
original_text: 1194: <p>I am trying to index wheat genome using STAR through following command</p>
  
  <pre><code>STAR --runMode genomeGenerate --genomeFastaFiles Triticum_aestivum.TGACv1.dna_sm.toplevel.fa --runThreadN 28 
  </code></pre>
  
  <p>But getting following error,</p>
  
  <pre><code>terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
  Aborted (core dumped)
  </code></pre>
  
  <p>The size of the genome is 13.5 GB and the server capacity is 32 cores with 125 GB RAM, how this error can be resolved?</p>
  
  <p>Memory usage: <a href="https://i.stack.imgur.com/uKcEQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uKcEQ.png" alt="enter image description here"></a></p>
  
  <p>I have decreased the number of threads to 8 but again getting the same error as shown below:</p>
  
  <pre><code>&gt; STAR   --runMode genomeGenerate   --runThreadN 8   --genomeDir wheat   --genomeFastaFiles wheat.fa                                                                      
  Jun 04 02:13:31 ..... started STAR run                                                                                                                                                                                           
  Jun 04 02:13:31 ... starting to generate Genome files                                                                                                                                                                            
  terminate called after throwing an instance of 'std::bad_alloc'                                                                                                                                                                  
  what():  std::bad_alloc                                                                                                                                                                                                        
  Aborted (core dumped)                                           
  </code></pre>
  
  <p>Even I have tried to use STAR without any threads but still the same error:</p>
  
  <pre><code>&gt; STAR   --runMode genomeGenerate   --genomeDir wheat   --genomeFastaFiles wheat.fa                                                                         
  Jun 04 02:19:44 ..... started STAR run                                                                                                                                                                                           
  Jun 04 02:19:44 ... starting to generate Genome files                                                                                                                                                                            
  terminate called after throwing an instance of 'std::bad_alloc'                                                                                                                                                                  
  what():  std::bad_alloc
  Aborted (core dumped)
  </code></pre>
  
  <p>May there can be an issue in reference of wheat that I am using, I got this reference from <a href="ftp://ftp.ensemblgenomes.org/pub/plants/release-39/fasta/triticum_aestivum/dna/Triticum_aestivum.TGACv1.dna.toplevel.fa.gz" rel="nofollow noreferrer">here.</a>
  Here are the first ten lines of the reference using head command:</p>
  
  <pre><code>&gt; head wheat.fa
  &gt;Pt dna:chromosome chromosome:TGACv1:Pt:1:135835:1 REF                                                                                                                                                                           
  ACAGAAATACCCAATATCTTGTTCTAGCAAGATATTGGGTATTTCTGTCTTTTCTTTCTT                                                                                                                                                                     
  CAAAAATTCTTATATGTTAGCAGAAAAACCTTATCCATTAATAGATGGAACTTCAACAGC                                                                                                                                                                     
  AGCTAAGTCTAGAGGGAAGTTGTGAGCATTACGTTCGTGCATTACTTCCATACCAAGGTT                                                                                                                                                                     
  AGCACGGTTGATGATATCAGCCCAAGTATTAATAACGCGACCTTGACTATCAACTACAGA                                                                                                                                                                     
  TTGGTTGAAATTGAAACCATTTAGGTTGAAAGCCATAGTACTAATACCTAAAGCAGTGAA                                                                                                                                                                     
  CCAGATTCCTACTACAGGCCAAGCAGCCAAGAAGAAGTGTAAAGAACGAGAGTTGTTGAA                                                                                                                                                                     
  ACTAGCATATTGGAAGATTAATCGGCCAAAATAACCATGAGCAGCCACAATATTATAAGT                                                                                                                                                                     
  TTCTTCCTCTTGACCAAATTTGTAACCCTCATTAGCAGATTCATTTTCAGTAGTTTCCCT                                                                                                                                                                     
  GATCAAACTAGAGGTTACCAAGGAACCATGCATAGCACTGAATAGGGAACCGCCGAATAC 
  </code></pre>
  
  <p>How this problem can be resolved? </p>
   939: <p>In addition to the other answer (to reduce the number of threads), you might also need to add a <code>--genomeChrBinNbits</code> argument. Your reference has more than 5000 scaffolds, so you need to adjust the <code>--genomeChrBinNbits</code> argument to reduce RAM consumption. Found <a href="https://github.com/alexdobin/STAR/issues/103" rel="nofollow noreferrer">here</a>.</p>
  
  <p>They recommend:</p>
  
  <blockquote>
    <p>--genomeChrBinNbits} = min(18, log2(GenomeLength/NumberOfReferences))</p>
  </blockquote>
  
  <p>In your case:</p>
  
  <p>Genome size 17G, number of scaffolds 735945</p>
  
  <p>So <code>--genomeChrBinNbits</code> should be set to log2(17,000,000,000/735,945) = 14.4955, so let's say 14 or 15.</p>
   29: <p>Try reducing the number of threads.</p>
  
  <p>When multithreading the index creation (and other memory bound tasks), the memory usage increases linearly with the number of threads. If you required a 10 GiB working space work with a single thread, then the requirement for 10 threads would be at 100 GiB.</p>
  
  <p>STAR is particularly memory hungry for the index creation to start with, and your genome is exceptionally large. I’ve had STAR require > 32 GiB of memory for the human genome, with a moderate number of threads. I’m not surprised that it fails with a 4× larger genome and many more threads: it would probably require at least 2× as much RAM as your machine has.</p>
  