diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2014-02-06 16:45:46 -0500 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2014-02-06 16:45:46 -0500 |
commit | d6c4a9934943b12caf19fd0024b66a0c889a3bbe (patch) | |
tree | 0c719c296a25ccf8189521342470812a890f926b | |
parent | 1c2ce90501d87db6431a7f29a37876d61347aff7 (diff) |
first commit of openmpopenmp
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | kmer_utils.c | 33 |
2 files changed, 26 insertions, 11 deletions
@@ -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 <stdio.h> #include <stdlib.h> #include <string.h> +#include <omp.h> 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; |