Skip to content
Snippets Groups Projects
Commit 3117b041 authored by timeo's avatar timeo
Browse files

OpenMP basique sans gestion nb threads

parent b41fd042
Branches
Tags
No related merge requests found
...@@ -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
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment