Skip to content

Commit

Permalink
speed up multi-threading
Browse files Browse the repository at this point in the history
  • Loading branch information
Heng Li committed Apr 7, 2011
1 parent 8766494 commit 8d6b859
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
15 changes: 1 addition & 14 deletions bwtaln.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#include "utils.h"

#ifdef HAVE_PTHREAD
#define THREAD_BLOCK_SIZE 1024
#include <pthread.h>
static pthread_mutex_t g_seq_lock = PTHREAD_MUTEX_INITIALIZER;
#endif

gap_opt_t *gap_init_opt()
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 1 addition & 13 deletions bwtsw2_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d6b859

Please sign in to comment.