Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProgrammationParallelle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JACQUIER Timeo
ProgrammationParallelle
Commits
3117b041
Commit
3117b041
authored
2 years ago
by
timeo
Browse files
Options
Downloads
Patches
Plain Diff
OpenMP basique sans gestion nb threads
parent
b41fd042
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ProgrammesEnVrac/main.cpp
+74
-5
74 additions, 5 deletions
src/ProgrammesEnVrac/main.cpp
with
74 additions
and
5 deletions
src/ProgrammesEnVrac/main.cpp
+
74
−
5
View file @
3117b041
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include
<fstream>
#include
<fstream>
#include
<chrono>
#include
<chrono>
#include
<omp.h>
#define CHRONO
#define CHRONO
using
namespace
std
;
using
namespace
std
;
...
@@ -18,7 +20,6 @@ void parseFile(string namefile) // Enregitrement du fichier dans une variable
...
@@ -18,7 +20,6 @@ void parseFile(string namefile) // Enregitrement du fichier dans une variable
myfile
.
open
(
namefile
);
myfile
.
open
(
namefile
);
if
(
myfile
.
is_open
())
if
(
myfile
.
is_open
())
{
{
while
(
getline
(
myfile
,
line
))
while
(
getline
(
myfile
,
line
))
{
{
fichier
=
line
;
fichier
=
line
;
...
@@ -154,23 +155,91 @@ uint64_t nbAdditifWithSomme(){
...
@@ -154,23 +155,91 @@ uint64_t nbAdditifWithSomme(){
return
nbAdditive
;
return
nbAdditive
;
}
}
uint64_t
nbAdditifWithSommeOpenMp
(
int
nb
){
//Max de threads OpenMp = Max de coeurs du processeur (nb threads processeur / 2)
/*if (nb > omp_get_max_threads()/2){
nb = omp_get_max_threads()/2;
}*/
int
nbAdditive
=
0
;
#pragma omp parallel for num_threads(nb)
for
(
int
tailleBloc
=
1
;
tailleBloc
<=
fichier
.
size
()
/
3
;
tailleBloc
++
)
//Test pour chaque taille de bloc possible
{
for
(
int
i
=
0
;
i
<=
fichier
.
size
()
-
tailleBloc
*
3
;
i
++
)
// Permet de créer les 3 blocs succéssifs
{
int
additionbloc1
=
valeurBloc
(
i
+
0
,
i
+
tailleBloc
-
1
);
int
additionbloc2
=
valeurBloc
(
i
+
tailleBloc
,
i
+
2
*
tailleBloc
-
1
);
int
additionbloc3
=
valeurBloc
(
i
+
2
*
tailleBloc
,
i
+
3
*
tailleBloc
-
1
);
#ifdef DEBUG
std
::
cout
<<
"bloc1 "
<<
bloc1
<<
std
::
endl
;
std
::
cout
<<
"bloc2 "
<<
bloc2
<<
std
::
endl
;
std
::
cout
<<
"bloc3 "
<<
bloc3
<<
std
::
endl
;
#endif
#ifdef DEBUG
std
::
cout
<<
"Total bloc1 "
<<
additionbloc1
<<
std
::
endl
;
std
::
cout
<<
"Total bloc2 "
<<
additionbloc2
<<
std
::
endl
;
std
::
cout
<<
"Total bloc3 "
<<
additionbloc3
<<
std
::
endl
;
#endif
if
(
additionbloc1
==
additionbloc2
&&
additionbloc2
==
additionbloc3
)
// Lorsqu'il y a une additivité cubique
{
#ifdef DEBUG
std
::
cout
<<
"Egalité cubique "
<<
" i "
<<
i
<<
std
::
endl
;
std
::
cout
<<
bloc1
<<
std
::
endl
;
std
::
cout
<<
bloc2
<<
std
::
endl
;
std
::
cout
<<
bloc3
<<
std
::
endl
;
#endif
nbAdditive
++
;
}
else
{
#ifdef DEBUG
std
::
cout
<<
"Pas d'égalité cubique "
<<
" i "
<<
i
<<
std
::
endl
;
#endif
}
}
}
#ifdef DEBUG
std
::
cout
<<
nbAdditive
<<
std
::
endl
;
#endif
return
nbAdditive
;
}
int
main
(){
int
main
(){
parseFile
(
"testfiles/5000fromCorrect.txt"
);
parseFile
(
"testfiles/100000_with_erro.txt"
);
sommeAdditive
();
#ifdef CHRONO
#ifdef CHRONO
high_resolution_clock
::
time_point
t1
=
high_resolution_clock
::
now
();
high_resolution_clock
::
time_point
t1
=
high_resolution_clock
::
now
();
#endif
#endif
sommeAdditive
();
//std::cout << std::endl << nbAdditif() << std::endl;
//std::cout << std::endl << nbAdditif() << std::endl;
std
::
cout
<<
std
::
endl
<<
nbAdditifWithSomme
()
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
<<
nbAdditifWithSommeOpenMp
(
8
)
<<
std
::
endl
;
#ifdef CHRONO
#ifdef CHRONO
high_resolution_clock
::
time_point
t2
=
high_resolution_clock
::
now
();
high_resolution_clock
::
time_point
t2
=
high_resolution_clock
::
now
();
duration
<
double
>
time_span
=
duration_cast
<
duration
<
double
>>
(
t2
-
t1
);
duration
<
double
>
time_span
=
duration_cast
<
duration
<
double
>>
(
t2
-
t1
);
std
::
cout
<<
"Durée :"
<<
time_span
.
count
()
<<
" secondes"
<<
std
::
endl
;
std
::
cout
<<
"Durée :"
<<
time_span
.
count
()
<<
" secondes avec OpenMp"
<<
std
::
endl
;
#endif
std
::
cout
<<
std
::
endl
<<
nbAdditifWithSomme
()
<<
std
::
endl
;
#ifdef CHRONO
high_resolution_clock
::
time_point
t3
=
high_resolution_clock
::
now
();
duration
<
double
>
time_span2
=
duration_cast
<
duration
<
double
>>
(
t3
-
t1
);
std
::
cout
<<
"Durée :"
<<
time_span2
.
count
()
<<
" secondes sans OpenMp"
<<
std
::
endl
;
#endif
#endif
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment