Commit a237f8b2 authored by Jonathan Twite's avatar Jonathan Twite

Update prime_divs.c (commented for better readability)

parent d448bb62
......@@ -11,50 +11,39 @@
#include <string.h>
#include "fileFeatures.h"
// int max value: 2 147 483 647
// long max value: 9223372 036 854 775 807
// char *filepath = "/home/jtwite/Desktop/test";
// Remplacez-le contenu par le chemin relatif du fichier que vous souhaitez tester.
int main(int argc, char *argv[])
struct timeval stop, start;
gettimeofday(&start, NULL);
printf("argv[1]: %s\n", argv[1]);
printf("argv[2]: %s\n", argv[2]);
printf("argv[1]: %s\n", argv[1]); // argv[1] = input file path
printf("argv[2]: %s\n", argv[2]); // argv[2] = output file path
//open the file
//open the fileInput
int fileInput = open(argv[1], O_RDONLY);
if (fileInput <= 0)
// get the fileInput size
// get the fileInput size, map it in the virtual &dress space and close fileInput directory
struct stat sb;
fstat(fileInput, &sb);
char *file_in_memory = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fileInput, 0);
// Create a new file struct in which the output is writen
FILE *fileOutput = fopen(argv[2], "w");
FILE *fileOutput = fopen(argv[2], "w"); // Create the file output
if(fileOutput == NULL)
//go through the mapped file to get numbers and write them in fileOutput
//go through the mapped file, read numbers and write them in fileOutput
factorize(file_in_memory, fileOutput);
//close everything
// unmap fileInput and close fileOutput
munmap(file_in_memory, sb.st_size);
// print out the computation performance
gettimeofday(&stop, NULL);
printf("took %lu µs\n", (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec);
printf("%s factorized into %s.\ntook %lu µs\n", argv[1], argv[2], (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec);
return 0;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment