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 /kmer_utils.c | |
parent | 1c2ce90501d87db6431a7f29a37876d61347aff7 (diff) |
first commit of openmpopenmp
Diffstat (limited to 'kmer_utils.c')
-rw-r--r-- | kmer_utils.c | 33 |
1 files changed, 24 insertions, 9 deletions
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; |