Commit 7f047e0e authored by Li's avatar Li
Browse files

Improve memory usage of cache.

parent 9ecc860e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -511,6 +511,14 @@ void Chromap<MappingRecord>::MapPairedEndReads() {
				mm_history1[pair_index].negative_candidates) ;
    	mm_to_candidates_cache.Update(mm_history2[pair_index].minimizers, mm_history2[pair_index].positive_candidates,
				mm_history2[pair_index].negative_candidates) ;
	if (mm_history1[pair_index].positive_candidates.size() < mm_history1[pair_index].positive_candidates.capacity() / 2)
		std::vector<struct _candidate>().swap(mm_history1[pair_index].positive_candidates) ;
	if (mm_history1[pair_index].negative_candidates.size() < mm_history1[pair_index].negative_candidates.capacity() / 2)
		std::vector<struct _candidate>().swap(mm_history1[pair_index].negative_candidates) ;
	if (mm_history2[pair_index].positive_candidates.size() < mm_history2[pair_index].positive_candidates.capacity() / 2)
		std::vector<struct _candidate>().swap(mm_history2[pair_index].positive_candidates) ;
	if (mm_history2[pair_index].negative_candidates.size() < mm_history2[pair_index].negative_candidates.capacity() / 2)
		std::vector<struct _candidate>().swap(mm_history2[pair_index].negative_candidates) ;
    }

#pragma omp taskwait
@@ -1037,7 +1045,12 @@ void Chromap<MappingRecord>::MapSingleEndReads() {
    for (uint32_t read_index = 0; read_index < num_loaded_reads; ++read_index) {
    	mm_to_candidates_cache.Update(mm_history[read_index].minimizers, mm_history[read_index].positive_candidates,
				mm_history[read_index].negative_candidates) ;
	if (mm_history[read_index].positive_candidates.size() < mm_history[read_index].positive_candidates.capacity() / 2)
		std::vector<struct _candidate>().swap(mm_history[read_index].positive_candidates) ;
	if (mm_history[read_index].negative_candidates.size() < mm_history[read_index].negative_candidates.capacity() / 2)
		std::vector<struct _candidate>().swap(mm_history[read_index].negative_candidates) ;
    }
    std::cerr<<"cache memusage: " << mm_to_candidates_cache.GetMemoryBytes() <<"\n" ;
#pragma omp taskwait
    num_loaded_reads = num_loaded_reads_for_loading;
    read_batch_for_loading.SwapSequenceBatch(read_batch);
+1 −1
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ class Chromap {
  bool output_mapping_in_BED_;
  bool output_mapping_in_TagAlign_;
  bool output_mapping_in_PAF_;
  uint32_t read_batch_size_ = 100000; // default batch size, # reads for single-end reads, # read pairs for paired-end reads
  uint32_t read_batch_size_ = 1000000; // default batch size, # reads for single-end reads, # read pairs for paired-end reads
  std::string reference_file_path_;
  std::string index_file_path_;
  std::string read_file1_path_;
+16 −2
Original line number Diff line number Diff line
@@ -152,12 +152,15 @@ public:
		else
			--cache[hidx].weight ;
		// Renew the cache
		if (cache[hidx].weight <= 0)
		if (cache[hidx].weight < 0)
		{
			cache[hidx].weight = 1 ;
			cache[hidx].minimizers.resize(msize) ;
			if (msize == 0)
			{
				cache[hidx].offsets.resize(0) ;
				return ;
			}

			cache[hidx].offsets.resize(msize - 1) ;
			for (i = 0 ; i < msize ; ++i)
@@ -181,7 +184,18 @@ public:
		}
	}
	
		
	int GetMemoryBytes()
	{
		int i, ret = 0 ;
		for (i = 0 ; i < cache_size ; ++i)
		{
			ret += sizeof(cache[i]) + cache[i].minimizers.capacity() * sizeof(uint64_t) 
				+ cache[i].offsets.capacity() * sizeof(int)
				+ cache[i].positive_candidates.capacity() * sizeof(struct _candidate) 
				+ cache[i].negative_candidates.capacity() * sizeof(struct _candidate) ;
		}
		return ret ;
	}
} ;

}