From 8d6b859bf8cadf5cd8438630f5bfb4fe931ae36d Mon Sep 17 00:00:00 2001 From: Heng Li Date: Thu, 7 Apr 2011 17:26:08 -0400 Subject: [PATCH] speed up multi-threading --- bwtaln.c | 15 +-------------- bwtsw2_aux.c | 14 +------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/bwtaln.c b/bwtaln.c index bd2aad2..66310d3 100644 --- a/bwtaln.c +++ b/bwtaln.c @@ -13,9 +13,7 @@ #include "utils.h" #ifdef HAVE_PTHREAD -#define THREAD_BLOCK_SIZE 1024 #include -static pthread_mutex_t g_seq_lock = PTHREAD_MUTEX_INITIALIZER; #endif gap_opt_t *gap_init_opt() @@ -98,18 +96,7 @@ void bwa_cal_sa_reg_gap(int tid, bwt_t *const bwt[2], int n_seqs, bwa_seq_t *seq for (i = 0; i != n_seqs; ++i) { bwa_seq_t *p = seqs + i; #ifdef HAVE_PTHREAD - if (opt->n_threads > 1) { - pthread_mutex_lock(&g_seq_lock); - if (p->tid < 0) { // unassigned - int j; - for (j = i; j < n_seqs && j < i + THREAD_BLOCK_SIZE; ++j) - seqs[j].tid = tid; - } else if (p->tid != tid) { - pthread_mutex_unlock(&g_seq_lock); - continue; - } - pthread_mutex_unlock(&g_seq_lock); - } + if (i % opt->n_threads != tid) continue; #endif p->sa = 0; p->type = BWA_TYPE_NO_MATCH; p->c1 = p->c2 = 0; p->n_aln = 0; p->aln = 0; seq[0] = p->seq; seq[1] = p->rseq; diff --git a/bwtsw2_aux.c b/bwtsw2_aux.c index 96d0d0a..8ba6455 100644 --- a/bwtsw2_aux.c +++ b/bwtsw2_aux.c @@ -309,10 +309,6 @@ typedef struct { bsw2seq1_t *seq; } bsw2seq_t; -#ifdef HAVE_PTHREAD -static pthread_mutex_t g_dbwtsw_lock = PTHREAD_MUTEX_INITIALIZER; -#endif - static int fix_cigar(const char *qname, const bntseq_t *bns, bsw2hit_t *p, int n_cigar, uint32_t *cigar) { // FIXME: this routine does not work if the query bridge three reference sequences @@ -469,15 +465,7 @@ static void bsw2_aln_core(int tid, bsw2seq_t *_seq, const bsw2opt_t *_opt, const l = p->l; #ifdef HAVE_PTHREAD - if (_opt->n_threads > 1) { - pthread_mutex_lock(&g_dbwtsw_lock); - if (p->tid < 0) p->tid = tid; - else if (p->tid != tid) { - pthread_mutex_unlock(&g_dbwtsw_lock); - continue; - } // in pinciple else should not happen - pthread_mutex_unlock(&g_dbwtsw_lock); - } + if (x % _opt->n_threads != tid) continue; #endif // set opt->t