|
@@ -39,7 +39,7 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
|
//Attente d'un message de fin
|
|
|
int syncBuff;
|
|
|
- MPI_Request sync;
|
|
|
+ MPI_Request sync, finish;
|
|
|
MPI_Irecv(&syncBuff, 1, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &sync);
|
|
|
|
|
|
//Calcul
|
|
@@ -76,36 +76,35 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
|
//Si on est le processus qui à trouvé
|
|
|
if(end) {
|
|
|
- //Avertit les autres
|
|
|
- for(int i = 0; i < world_size; i++) {
|
|
|
- MPI_Send(&world_rank, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
|
|
|
+ //Reverifie si quelqu'un d'autre a trouver avant
|
|
|
+ int flag;
|
|
|
+ MPI_Test(&sync, &flag, MPI_STATUS_IGNORE);
|
|
|
+ if(flag) {
|
|
|
+ stop = true;
|
|
|
}
|
|
|
- //Attend la fin des autres processus
|
|
|
- for(int i = 0; i < world_size; i++) {
|
|
|
- if(i != world_rank) {
|
|
|
- int buff;
|
|
|
- MPI_Recv(&buff, 1, MPI_INT, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|
|
+ if(!stop) {
|
|
|
+ //Avertit les autres
|
|
|
+ for(int i = 0; i < world_size; i++) {
|
|
|
+ MPI_Isend(&world_rank, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &finish);
|
|
|
}
|
|
|
+ //Attend que tous les processus finissent
|
|
|
+ sleep(1);
|
|
|
+ //Affiche le resultat
|
|
|
+ printf("------------------------------------------------------------------------------------------------------\n");
|
|
|
+ printf(GREEN);
|
|
|
+ printf("s %s\n",end?"SATISFIABLE":"NOT FOUND");
|
|
|
+ printf(YELLOW);
|
|
|
+ printf("c real time : %.4f seconds\n", gsat->realTime() - startTime);
|
|
|
+ printf("c [pid:%6d][process:%2d][iteration:%4d][fill:%d][heuristic:%d]Satisfied clauses (begin: %d)(end:%d)\n",
|
|
|
+ getpid(),
|
|
|
+ world_rank,
|
|
|
+ gsat->getNbIterations(),
|
|
|
+ gsat->getHeuristicFill(),
|
|
|
+ gsat->getHeuristicSolve(),
|
|
|
+ gsat->getNbSatisfiedClausesFill(),
|
|
|
+ gsat->getNbSatisfiedClausesSolve());
|
|
|
+ printf(RESET);
|
|
|
}
|
|
|
- //Affiche le resultat
|
|
|
- printf("------------------------------------------------------------------------------------------------------\n");
|
|
|
- printf(GREEN);
|
|
|
- printf("s %s\n",end?"SATISFIABLE":"NOT FOUND");
|
|
|
- printf(YELLOW);
|
|
|
- printf("c real time : %.4f seconds\n", gsat->realTime() - startTime);
|
|
|
- printf("c [pid:%6d][process:%2d][iteration:%4d][fill:%d][heuristic:%d]Satisfied clauses (begin: %d)(end:%d)\n",
|
|
|
- getpid(),
|
|
|
- world_rank,
|
|
|
- gsat->getNbIterations(),
|
|
|
- gsat->getHeuristicFill(),
|
|
|
- gsat->getHeuristicSolve(),
|
|
|
- gsat->getNbSatisfiedClausesFill(),
|
|
|
- gsat->getNbSatisfiedClausesSolve());
|
|
|
- printf(RESET);
|
|
|
- } else {
|
|
|
- //Indique au processus qui a trouvé que ce processus a finit de travailler
|
|
|
- int buff = 1;
|
|
|
- MPI_Send(&buff, 1, MPI_INT, syncBuff, 0, MPI_COMM_WORLD);
|
|
|
}
|
|
|
|
|
|
MPI_Finalize();
|