diff --git a/Projet/CODE/apm/src/apm.c b/Projet/CODE/apm/src/apm.c index 8de453a7eae3e1bdc928a2b36ff04d087da8d813..546a1c5a500ccdf42dc93931ad1245c0d357a569 100644 --- a/Projet/CODE/apm/src/apm.c +++ b/Projet/CODE/apm/src/apm.c @@ -9,6 +9,7 @@ #include <fcntl.h> #include <unistd.h> #include <sys/time.h> +#include <sys/stat.h> #define APM_DEBUG 0 @@ -17,6 +18,7 @@ char * read_input_file(char *filename, size_t *size) { char *buf; + struct stat fs; size_t fsize; int fd = 0; size_t read_bytes = 0; @@ -32,9 +34,9 @@ read_input_file(char *filename, size_t *size) } /* Get the number of characters in the textfile */ - fsize = lseek(fd, 0, SEEK_END); - lseek(fd, 0, SEEK_SET); - /* TODO check return of lseek */ + fstat(fd, &fs); + fsize = fs.st_size; + #if APM_DEBUG printf("File length: %ld\n", fsize); #endif diff --git a/Projet/CODE/apm/src/apm_gpu.cu b/Projet/CODE/apm/src/apm_gpu.cu index 4c070a14afd0d2f2cdd2b952b7434b001cea1f5b..54c0a812193cfa03b345ab500d7bc035d68fa5ca 100644 --- a/Projet/CODE/apm/src/apm_gpu.cu +++ b/Projet/CODE/apm/src/apm_gpu.cu @@ -9,6 +9,7 @@ #include <fcntl.h> #include <unistd.h> #include <sys/time.h> +#include <sys/stat.h> #define APM_DEBUG 0 #define NUMBER_THREADS_BY_BLOCK 1024 @@ -32,66 +33,12 @@ __cudaCheckErrors(char const *msg) } } - -char * -read_input_file(char *filename, int *size) -{ - char *buf; - off_t fsize; - int fd = 0; - int n_bytes = 1; - /* Open the text file */ - fd = open(filename, O_RDONLY); - - if (fd == -1) - { - fprintf(stderr, "Unable to open the text file <%s>\n", filename); - return NULL; - } - - /* Get the number of characters in the textfile */ - fsize = lseek(fd, 0, SEEK_END); - lseek(fd, 0, SEEK_SET); - /* TODO check return of lseek */ -#if APM_DEBUG - printf("File length: %lld\n", fsize); -#endif - /* Allocate data to copy the target text */ - buf = (char *)malloc(fsize * sizeof(char)); - - if (buf == NULL) - { - fprintf(stderr, "Unable to allocate %ld byte(s) for main array\n", - fsize); - return NULL; - } - - n_bytes = read(fd, buf, fsize); - - if (n_bytes != fsize) - { - fprintf(stderr, - "Unable to copy %ld byte(s) from text file " - "(%d byte(s) copied)\n", - fsize, n_bytes); - return NULL; - } - -#if APM_DEBUG - printf("Number of read bytes: %d\n", n_bytes); -#endif - *size = n_bytes; - close(fd); - return buf; -} - off_t get_file_size(int fd) { - off_t size; - size = lseek(fd, 0, SEEK_END); - lseek(fd, 0, SEEK_SET); - return size; + struct stat fs; + fstat(fd, &fs); + return fs.st_size; } char * @@ -142,34 +89,6 @@ read_input_file_max(int fd, int *size, off_t offset) #define MIN3(a, b, c) ((a)<(b) ? ((a)<(c) ? (a) : (c)) : ((b)<(c) ? (b) : (c))) #define MIN2(a, b) ((a)<(b) ? (a) : (b)) -int -levenshtein(char *s1, char *s2, int len, int *column, int approx_factor) -{ - int x, y, lastdiag, olddiag; - - for (y = 1; y <= len; y++) - { - column[y] = y; - } - - for (x = 1; x <= len; x++) - { - column[0] = x; - lastdiag = x - 1; - - for (y = 1; y <= len; y++) - { - olddiag = column[y]; - column[y] = MIN3(column[y] + 1, - column[y - 1] + 1, - lastdiag + (s1[y - 1] == s2[x - 1] ? 0 : 1)); - lastdiag = olddiag; - } - } - - return (column[len] <= approx_factor) ? 1 : 0; -} - __global__ void levenshtein_cu(char *find, char *buf, int len, int n_bytes, int approx_factor, int *result) diff --git a/Projet/CODE/apm/src/apm_omp.c b/Projet/CODE/apm/src/apm_omp.c index 14fd2c63fc879726bf432ec841094e4f37abf3c2..09a25befb200bfd2efb197f48e9cedb7894b1723 100644 --- a/Projet/CODE/apm/src/apm_omp.c +++ b/Projet/CODE/apm/src/apm_omp.c @@ -9,6 +9,7 @@ #include <fcntl.h> #include <unistd.h> #include <sys/time.h> +#include <sys/stat.h> #include "omp.h" @@ -18,6 +19,7 @@ char * read_input_file(char *filename, size_t *size) { char *buf; + struct stat fs; size_t fsize; int fd = 0; size_t read_bytes = 0; @@ -33,9 +35,9 @@ read_input_file(char *filename, size_t *size) } /* Get the number of characters in the textfile */ - fsize = lseek(fd, 0, SEEK_END); - lseek(fd, 0, SEEK_SET); - /* TODO check return of lseek */ + fstat(fd, &fs); + fsize = fs.st_size; + #if APM_DEBUG printf("File length: %ld\n", fsize); #endif