aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--kmer_utils.c33
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 <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;