jpayne@68: package kmer; jpayne@68: jpayne@68: import java.util.concurrent.atomic.AtomicInteger; jpayne@68: jpayne@68: import shared.Shared; jpayne@68: import shared.Tools; jpayne@68: import structures.SuperLongList; jpayne@68: jpayne@68: public final class HistogramMaker { jpayne@68: jpayne@68: jpayne@68: public static long[] fillHistogram(final AbstractKmerTable[] tables, final int histMax) { jpayne@68: if(Shared.threads()>2){ jpayne@68: return fillHistogram_MT(tables, histMax); jpayne@68: }else{ jpayne@68: return fillHistogram_ST(tables, histMax); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: private static long[] fillHistogram_ST(final AbstractKmerTable[] tables, final int histMax) { jpayne@68: long[] ca=new long[histMax+1]; jpayne@68: for(AbstractKmerTable set : tables){ jpayne@68: set.fillHistogram(ca, histMax); jpayne@68: } jpayne@68: return ca; jpayne@68: } jpayne@68: jpayne@68: private static long[] fillHistogram_MT(final AbstractKmerTable[] tables, final int histMax) { jpayne@68: boolean errorState=false; jpayne@68: int threads=Shared.threads(); jpayne@68: threads=Tools.min((threads>20 ? threads/2 : threads), (tables.length+1)/2, 32); jpayne@68: if(threads<2){return fillHistogram_ST(tables, histMax);} jpayne@68: jpayne@68: final FillThread[] array=new FillThread[threads]; jpayne@68: final AtomicInteger next=new AtomicInteger(0); jpayne@68: for(int i=0; i