瀏覽代碼

Deplacement methode gestion MPI dans GSATThreadMPI

Arthur Brandao 6 年之前
父節點
當前提交
3500fee7b2
共有 4 個文件被更改,包括 21 次插入16 次删除
  1. 18 2
      Partie_1/Hybride/GSATThreadMPI.cpp
  2. 2 0
      Partie_1/Hybride/GSATThreadMPI.hpp
  3. 0 14
      Partie_1/Hybride/Main.cpp
  4. 1 0
      Partie_1/Hybride/Main.hpp

+ 18 - 2
Partie_1/Hybride/GSATThreadMPI.cpp

@@ -2,11 +2,13 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <mpi.h>
 #include "Main.hpp"
 #include "GSATThreadMPI.hpp"
 #include "color.h"
 
 extern int world_rank;
+extern int world_size;
 
 /* --- Public --- */
 
@@ -37,7 +39,7 @@ bool GSATThreadMPI::solve() {
 		threads[i] = std::thread(&GSATThreadMPI::solverThread, this, i);
 	}
 	//Lance thread de synchronisation MPI
-	mpiSync = std::thread(mpiWait, this);
+	mpiSync = std::thread(&GSATThreadMPI::mpiWait, this, this);
 	//Attend resultat
 	for(int i = 0; i < nbThread; i++){
 		threads[i].join();
@@ -106,7 +108,7 @@ void GSATThreadMPI::solverThread(int id) {
 	}
 	//Si 1er arreter
 	if(!end && solve) {
-		mpiNotify(world_rank);
+		this->mpiNotify(world_rank);
 		end = true;
 		find = true;
 		result.threadId = id;
@@ -118,3 +120,17 @@ void GSATThreadMPI::solverThread(int id) {
 		result.nbSatisfiedClausesSolve = gsat[id]->getNbSatisfiedClausesSolve();
 	}
 }
+
+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();
+    }
+}
+
+void GSATThreadMPI::mpiNotify(int rank) {
+    for(int i = 0; i < world_size; i++) {
+        MPI_Send(&rank, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
+    }
+}

+ 2 - 0
Partie_1/Hybride/GSATThreadMPI.hpp

@@ -41,6 +41,8 @@ class GSATThreadMPI {
 		GSATResult result;
 
 		void solverThread(int);
+		void mpiWait(GSATThreadMPI*);
+		void mpiNotify(int);
 };
 
 #endif

+ 0 - 14
Partie_1/Hybride/Main.cpp

@@ -66,18 +66,4 @@ int main(int argc, char* argv[]) {
     
     MPI_Finalize();
 
-}
-
-void 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();
-    }
-}
-
-void mpiNotify(int rank) {
-    for(int i = 0; i < world_size; i++) {
-        MPI_Send(&rank, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
-    }
 }

+ 1 - 0
Partie_1/Hybride/Main.hpp

@@ -4,6 +4,7 @@
 #include "GSATThreadMPI.hpp"
 
 extern int world_rank;
+extern int world_size;
 
 void help(char*);
 void mpiWait(GSATThreadMPI*);