From d6c4a9934943b12caf19fd0024b66a0c889a3bbe Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Thu, 6 Feb 2014 16:45:46 -0500 Subject: first commit of openmp --- Makefile | 4 ++-- kmer_utils.c | 33 ++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index c929cfd..0fe4d17 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION=\"0.0.2\" CC = gcc -CFLAGS = -O3 -s -mtune=native -Wall -DVERSION=$(VERSION) -Wextra +CFLAGS = -O3 -s -mtune=native -Wall -DVERSION=$(VERSION) -Wextra -fopenmp DESTDIR = /usr/local/ @@ -18,7 +18,7 @@ kmer_counts_per_sequence: libkmer.o kmer_counts_per_sequence.c kmer_utils.h clean: rm -vf kmer_total_count kmer_counts_per_sequence libkmer.so libkmer.o -debug: CFLAGS = -ggdb -Wall -Wextra -DVERSION=$(VERSION)\"-debug\" +debug: CFLAGS = -ggdb -Wall -Wextra -DVERSION=$(VERSION)\"-debug\" -fopenmp debug: all install: all diff --git a/kmer_utils.c b/kmer_utils.c index 060e311..36993a4 100644 --- a/kmer_utils.c +++ b/kmer_utils.c @@ -3,6 +3,7 @@ #include #include #include +#include const unsigned char alpha[256] = @@ -158,13 +159,6 @@ size_t strnstrip(char *s, int c, size_t len) { unsigned long long * get_kmer_counts_from_file(FILE *fh, const unsigned int kmer) { - char *line = NULL; - size_t len = 0; - ssize_t read; - - long long i = 0; - long long position = 0; - // width is 4^kmer // there's a sneaky bitshift to avoid pow dependency const unsigned long width = pow_four(kmer); @@ -176,7 +170,25 @@ unsigned long long * get_kmer_counts_from_file(FILE *fh, const unsigned int kmer exit(EXIT_FAILURE); } - while ((read = getdelim(&line, &len, '>', fh)) != -1) { + int test = 1; + #pragma omp parallel + while (test) { + char *line = NULL; + size_t len = 0; + ssize_t read; + + + #pragma omp critical + { + read = getdelim(&line, &len, '>', fh); + } + if(read == -1) { + test = 0; + continue; + } + + long long i = 0; + long long position = 0; size_t k; char *seq; size_t seq_length; @@ -220,11 +232,14 @@ unsigned long long * get_kmer_counts_from_file(FILE *fh, const unsigned int kmer // use this point to get mer of our loop next: // bump up the mer value in the counts array + #pragma omp atomic counts[mer]++; } + #pragma omp critical + free(line); + } - free(line); fclose(fh); return counts; -- cgit v1.2.3