From 6a0952948dd30bdc8151d4950ec51f5740c3cdbe Mon Sep 17 00:00:00 2001 From: Heng Li Date: Wed, 15 Oct 2014 14:44:08 -0400 Subject: [PATCH] shared memory --- Makefile | 2 +- bwa.c | 4 ++-- bwa.h | 8 ++++++-- main.c | 3 +++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 9bccbf6..8a10df6 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CFLAGS= -g -Wall -Wno-unused-function -O2 WRAP_MALLOC=-DUSE_MALLOC_WRAPPERS AR= ar DFLAGS= -DHAVE_PTHREAD $(WRAP_MALLOC) -LOBJS= utils.o kthread.o kstring.o ksw.o bwt.o bntseq.o bwa.o bwamem.o bwamem_pair.o bwamem_extra.o malloc_wrap.o +LOBJS= utils.o kthread.o kstring.o ksw.o bwt.o bntseq.o bwa.o bwashm.o bwamem.o bwamem_pair.o bwamem_extra.o malloc_wrap.o AOBJS= QSufSort.o bwt_gen.o bwase.o bwaseqio.o bwtgap.o bwtaln.o bamlite.o \ is.o bwtindex.o bwape.o kopen.o pemerge.o \ bwtsw2_core.o bwtsw2_main.o bwtsw2_aux.o bwt_lite.o \ diff --git a/bwa.c b/bwa.c index e2e1376..65e3c16 100644 --- a/bwa.c +++ b/bwa.c @@ -263,11 +263,11 @@ void bwa_idx_destroy(bwaidx_t *idx) if (idx->bwt) bwt_destroy(idx->bwt); if (idx->bns) bns_destroy(idx->bns); if (idx->pac) free(idx->pac); - } else free((uint8_t*)idx->mem); + } else if (!idx->is_shm) free(idx->mem); free(idx); } -int bwa_mem2idx(int64_t l_mem, const uint8_t *mem, bwaidx_t *idx) +int bwa_mem2idx(int64_t l_mem, uint8_t *mem, bwaidx_t *idx) { int64_t k = 0, x; int i; diff --git a/bwa.h b/bwa.h index 7e2c153..094d79b 100644 --- a/bwa.h +++ b/bwa.h @@ -10,13 +10,17 @@ #define BWA_IDX_PAC 0x4 #define BWA_IDX_ALL 0x7 +#define BWA_SHM_KEY 5291 +#define BWA_SHM_SIZE 0x10000 + typedef struct { bwt_t *bwt; // FM-index bntseq_t *bns; // information on the reference sequences uint8_t *pac; // the actual 2-bit encoded reference sequences with 'N' converted to a random base + int is_shm; int64_t l_mem; - const uint8_t *mem; + uint8_t *mem; } bwaidx_t; typedef struct { @@ -43,7 +47,7 @@ extern "C" { bwaidx_t *bwa_idx_load(const char *hint, int which); void bwa_idx_destroy(bwaidx_t *idx); int bwa_idx2mem(bwaidx_t *idx); - int bwa_mem2idx(int64_t l_mem, const uint8_t *mem, bwaidx_t *idx); + int bwa_mem2idx(int64_t l_mem, uint8_t *mem, bwaidx_t *idx); void bwa_print_sam_hdr(const bntseq_t *bns, const char *rg_line); char *bwa_set_rg(const char *s); diff --git a/main.c b/main.c index 9108c49..30ac54d 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ int bwa_bwtsw2(int argc, char *argv[]); int main_fastmap(int argc, char *argv[]); int main_mem(int argc, char *argv[]); +int main_shm(int argc, char *argv[]); int main_pemerge(int argc, char *argv[]); @@ -43,6 +44,7 @@ static int usage() fprintf(stderr, " sampe generate alignment (paired ended)\n"); fprintf(stderr, " bwasw BWA-SW for long queries\n"); fprintf(stderr, "\n"); + fprintf(stderr, " shm manage indices in shared memory\n"); fprintf(stderr, " fa2pac convert FASTA to PAC format\n"); fprintf(stderr, " pac2bwt generate BWT from PAC\n"); fprintf(stderr, " pac2bwtgen alternative algorithm for generating BWT\n"); @@ -81,6 +83,7 @@ int main(int argc, char *argv[]) else if (strcmp(argv[1], "bwasw") == 0) ret = bwa_bwtsw2(argc-1, argv+1); else if (strcmp(argv[1], "fastmap") == 0) ret = main_fastmap(argc-1, argv+1); else if (strcmp(argv[1], "mem") == 0) ret = main_mem(argc-1, argv+1); + else if (strcmp(argv[1], "shm") == 0) ret = main_shm(argc-1, argv+1); else if (strcmp(argv[1], "pemerge") == 0) ret = main_pemerge(argc-1, argv+1); else { fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]);