Skip to content
Extraits de code Groupes Projets
Valider 13d779ff rédigé par Andy Laurez's avatar Andy Laurez
Parcourir les fichiers

verbose in Main

parent 3608df93
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
int main(int argc, char** argv){ int main(int argc, char** argv){
Args.nThreads = 8; //default number of threads Args.nThreads = 8; //default number of threads
//getOpt
const char* strOpts = "hvN:"; const char* strOpts = "hvN:";
const struct option longOpts[] = { const struct option longOpts[] = {
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
...@@ -31,6 +33,11 @@ int main(int argc, char** argv){ ...@@ -31,6 +33,11 @@ int main(int argc, char** argv){
Args.input_file = argv[argc-2]; Args.input_file = argv[argc-2];
Args.output_file = argv[argc-1]; Args.output_file = argv[argc-1];
if (Args.verbose == 1){
printf("Number of Threads : %d\n", Args.nThreads );
}
//count number of Line
FILE* LineCounter = fopen(Args.input_file,"r"); FILE* LineCounter = fopen(Args.input_file,"r");
if(LineCounter == NULL){ if(LineCounter == NULL){
printf("Open Error in main for fd LineCounter\n"); printf("Open Error in main for fd LineCounter\n");
...@@ -45,7 +52,9 @@ int main(int argc, char** argv){ ...@@ -45,7 +52,9 @@ int main(int argc, char** argv){
fclose(LineCounter); fclose(LineCounter);
free(line); free(line);
printf("counter BEFORE : %d\n",counter ); if (Args.verbose == 1){
printf("counter BEFORE : %d\n",counter );
}
if (counter < Args.nThreads){ if (counter < Args.nThreads){
Args.nThreads = counter; Args.nThreads = counter;
} }
...@@ -78,14 +87,18 @@ int main(int argc, char** argv){ ...@@ -78,14 +87,18 @@ int main(int argc, char** argv){
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// coumpute fonction
for(int i =0; i<Args.nThreads; i++){ for(int i =0; i<Args.nThreads; i++){
if(pthread_create(&threads[i], NULL, &compute, NULL) != 0){ //TODO: compute function if(pthread_create(&threads[i], NULL, &compute, NULL) != 0){
printf("Error while creating one of the computing threads\n"); printf("Error while creating one of the computing threads\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
//consume fonction
if (pthread_create(&writer, NULL, &consume, NULL) != 0){ if (pthread_create(&writer, NULL, &consume, NULL) != 0){
printf("Error while creating the writer thread\n"); printf("Error while creating the writer thread\n");
return EXIT_FAILURE; return EXIT_FAILURE;
...@@ -110,16 +123,22 @@ int main(int argc, char** argv){ ...@@ -110,16 +123,22 @@ int main(int argc, char** argv){
*/ */
printf("------------ joined reader ---------------\n"); if (Args.verbose == 1){
printf("------------ joined reader ---------------\n");
}
for(int i =0; i < Args.nThreads; i++){ for(int i =0; i < Args.nThreads; i++){
if(pthread_join(threads[i], (void**) &error) != 0){ if(pthread_join(threads[i], (void**) &error) != 0){
printf("Error while joining one of the computing threads\n"); printf("Error while joining one of the computing threads\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf("---------------------------------one thread finished\n"); if (Args.verbose == 1){
printf("---------------------------------one thread finished\n");
}
finished++; finished++;
} }
/* /*
sem_post(&full2); sem_post(&full2);
sem_post(&full2); sem_post(&full2);
...@@ -130,15 +149,20 @@ int main(int argc, char** argv){ ...@@ -130,15 +149,20 @@ int main(int argc, char** argv){
sem_post(&full2); sem_post(&full2);
*/ */
done2=0; done2=0;
printf("------------- joined compute ------------\n");
if (Args.verbose == 1){
printf("------------- joined compute ------------\n");
}
if(pthread_join(writer, (void**) &error) != 0){ if(pthread_join(writer, (void**) &error) != 0){
printf("Error while joining the writer thread"); printf("Error while joining the writer thread");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf("---------------- join consume ---------------------\n");
if (Args.verbose == 1){
printf("---------------- join consume ---------------------\n");
}
sem_destroy(&full); sem_destroy(&full);
...@@ -153,5 +177,9 @@ int main(int argc, char** argv){ ...@@ -153,5 +177,9 @@ int main(int argc, char** argv){
pthread_mutex_destroy(&mutex2); pthread_mutex_destroy(&mutex2);
div_free_queue(buffer2); div_free_queue(buffer2);
if (Args.verbose == 1){
printf("Success end");
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter