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