Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
Projet 3 - Q6
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de conteneur
Registre de modèles
Opération
Environnements
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Giovanna Stefanelli
Projet 3 - Q6
Validations
d6e06450
Valider
d6e06450
rédigé
5 years ago
par
Giovanna Stefanelli
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Update fact.c
parent
9a98f3dc
Aucune branche associée trouvée
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline
#8912
en échec
5 years ago
Étape : external
Modifications
1
Pipelines
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
fact.c
+31
-9
31 ajouts, 9 suppressions
fact.c
avec
31 ajouts
et
9 suppressions
fact.c
+
31
−
9
Voir le fichier @
d6e06450
...
...
@@ -106,17 +106,24 @@ factor* prime_divs (unsigned long numbr) {
void
*
read_write
()
{
factor
*
dividers
;
long
in_number
;
unsigned
long
number
;
long
neg_number
=
0
;
// Read input file line by line till the end of file (eof)
while
(
!
feof
(
f
.
in
))
{
fscanf
(
f
.
in
,
"%l
u
\n
"
,
&
number
);
// Read number to be factored
fscanf
(
f
.
in
,
"%l
d
\n
"
,
&
in_
number
);
// Read number to be factored
/* Check if the number is > 2
* in this case skip the number and
* leave a message in the file
*/
if
(
number
>
2
)
{
if
(
(
in_
number
>
2
)
||
(
in_number
<
-
2
))
{
/* Verify if the number is prime or not, in this case the dividers are calculated */
/* Handle negative number to calculate prime dividers *********NEW***********/
if
(
in_number
<
-
2
)
{
neg_number
=
in_number
;
}
number
=
abs
(
in_number
);
dividers
=
prime_divs
(
number
);
// Core function of the app //
/* MUTEX LOCK - CONTROL OF CRITICAL ACCESS - START */
...
...
@@ -124,14 +131,21 @@ void *read_write() {
printf
(
"
\n
mutex_lock-mutex_readwrite %s
\n
"
,
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
/* Handle negative number to calculate prime dividers *********NEW********** */
if
(
neg_number
!=
0
)
{
in_number
=
neg_number
;
neg_number
=
0
;
}
if
(
dividers
->
cnt
!=
0
)
{
fprintf
(
f
.
out
,
"%lu "
,
dividers
->
number
);
/* fprintf(f.out, "%lu ", dividers->number); ********** OLD *********** */
fprintf
(
f
.
out
,
"%ld"
,
in_number
);
/* ********NEW********** */
int
i
;
for
(
i
=
0
;
i
<
dividers
->
cnt
;
i
++
)
{
fprintf
(
f
.
out
,
" %lu"
,
dividers
->
prime_dividers
[
i
]);
}
}
else
{
// For internal command test
fprintf
(
f
.
out
,
"%lu "
,
dividers
->
number
);
fprintf
(
f
.
out
,
"%ld"
,
in_number
);
/* ********NEW********** */
/* fprintf(f.out, "%lu ", dividers->number); *********** OLD ********** */
}
/* MUTEX UNLOCK - CONTROL OF CRITICAL ACCESS - END */
if
(
pthread_mutex_unlock
(
&
mutex_readwrite
)
!=
0
)
{
...
...
@@ -141,7 +155,7 @@ void *read_write() {
fprintf
(
f
.
out
,
"
\n
"
);
free
(
dividers
);
}
else
{
fprintf
(
f
.
out
,
"
The number %lu is not > 2, discarde
d
\n
"
,
number
);
fprintf
(
f
.
out
,
"
%l
d
\n
"
,
in_
number
);
}
}
pthread_exit
((
void
*
)
0
);
// thread exit: normal termination => 0
...
...
@@ -158,9 +172,10 @@ int main (int argc, char *argv[]) {
char
*
thread_arg
;
//
int
NO_THREADS
=
DEFAULT_NO_THREADS
;
// Define default number of threads
/* WARNING: ONLY NUMBER POSITIVE AND >2 ARE ACCEPTED */
printf
(
"!!! WARNING: ONLY POSITIVE NUMBER AND >2 ARE ACCEPTED !!!
\n
"
);
printf
(
" OTHERWISE THE PROGRAMME CANNOT RUN CORRECTLY
\n\n
"
);
/* WARNING: ONLY NUMBER POSITIVE AND >2 ARE ACCEPTED
*printf("!!! WARNING: ONLY POSITIVE NUMBER AND >2 ARE ACCEPTED !!!\n");
*printf(" OTHERWISE THE PROGRAMME CANNOT RUN CORRECTLY\n\n");
*/
if
(
argc
==
3
)
{
// Check if the number of argument is correct
inputfile
=
argv
[
1
];
...
...
@@ -174,6 +189,13 @@ int main (int argc, char *argv[]) {
exit
(
EXIT_FAILURE
);
}
NO_THREADS
=
atoi
(
argv
[
2
]);
/* If the number of threads is <= 0 ************* VERSION UPDATE ***************
* NO_THREADS is set to DEFAULT_NO_THREADS
*/
if
(
NO_THREADS
<=
0
)
{
NO_THREADS
=
1
;
printf
(
"The threads number cannot be <= 0 - Threads number set to 1
\n
"
);
}
if
(
NO_THREADS
>
MAX_NO_THREADS
)
{
printf
(
"Threads requested > %d
\n
"
,
MAX_NO_THREADS
);
exit
(
EXIT_FAILURE
);
...
...
@@ -232,4 +254,4 @@ int main (int argc, char *argv[]) {
fclose
(
f
.
in
);
fclose
(
f
.
out
);
return
(
EXIT_SUCCESS
);
}
\ No newline at end of file
}
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter