Browse Source

Changement gestion boolean end

Loquicom 6 years ago
parent
commit
faf89459c7
2 changed files with 14 additions and 9 deletions
  1. 11 7
      Partie_1/Hybride/GSATThreadMPI.cpp
  2. 3 2
      Partie_1/Hybride/GSATThreadMPI.hpp

+ 11 - 7
Partie_1/Hybride/GSATThreadMPI.cpp

@@ -32,7 +32,7 @@ GSATThreadMPI::~GSATThreadMPI() {
 
 bool GSATThreadMPI::solve() {
 	threads.clear();
-	end = false;
+	this->end(false);
 	find = false;
 	//Lance thread
 	for(int i = 0; i < nbThread; i++) {
@@ -55,8 +55,12 @@ bool GSATThreadMPI::solve() {
   	return find;
 }
 
-void GSATThreadMPI::isEnd() {
-	end = true;
+void GSATThreadMPI::end() {
+	this->end(true);
+}
+
+void GSATThreadMPI::end(bool endOrNot) {
+	bEnd = endOrNot;
 }
 
 void GSATThreadMPI::printResult() {
@@ -84,7 +88,7 @@ void GSATThreadMPI::solverThread(int id) {
 	double startTime = gsat[id]->realTime();
 	bool solve = false;
 	int cpt = 0;
-	while(!end && !solve){
+	while(!bEnd && !solve){
 		//Pour eviter que les processeurs effectue tous les meme calculs
         int fill = rand() % 4 + 2;
         int h = rand() % 7;
@@ -107,9 +111,9 @@ void GSATThreadMPI::solverThread(int id) {
 		cpt++;
 	}
 	//Si 1er arreter
-	if(!end && solve) {
+	if(!bEnd && solve) {
 		this->mpiNotify(world_rank);
-		end = true;
+		this->end(true);
 		find = true;
 		result.threadId = id;
 		result.calcTime = gsat[id]->realTime() - startTime;
@@ -125,7 +129,7 @@ void GSATThreadMPI::mpiWait(GSATThreadMPI* gsat) {
     int buff;
     MPI_Recv(&buff, 1, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
     if(buff != world_rank) {
-        gsat->isEnd();
+        gsat->end();
     }
 }
 

+ 3 - 2
Partie_1/Hybride/GSATThreadMPI.hpp

@@ -25,14 +25,15 @@ class GSATThreadMPI {
 		GSATThreadMPI(int, int, char**);
 		~GSATThreadMPI();
 		bool solve();
-		void isEnd();
+		void end();
+		void end(bool);
 		void printResult();
 		/* --- Getter --- */
 		inline unsigned int getNbVariables() {return gsat[0]->getNbVariables();}
 		inline unsigned int getNbClauses() {return gsat[0]->getNbClauses();}
 
 	private:
-		bool end;
+		bool bEnd;
 		bool find;
 		int nbThread;
 		std::vector<GSAT*> gsat;