|
@@ -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);
|
|
|
+ }
|
|
|
+}
|