/* * Circuit Satisfiability, Version 3 * * This version of the program prints the total number of * solutions and the execution time. * * Programmed by Michael J. Quinn * * Last modification: 3 September 2002 */ #include "mpi.h" #include int main (int argc, char *argv[]) { int count; /* Solutions found by this proc */ double elapsed_time; /* Time to find, count solutions */ int global_count; /* Total number of solutions */ int i; int id; /* Process rank */ int p; /* Number of processes */ int check_circuit (int, int); MPI_Init (&argc, &argv); /* Start timer */ MPI_Barrier (MPI_COMM_WORLD); elapsed_time = - MPI_Wtime(); MPI_Comm_rank (MPI_COMM_WORLD, &id); MPI_Comm_size (MPI_COMM_WORLD, &p); count = 0; for (i = id; i < 65536; i += p) count += check_circuit (id, i); MPI_Reduce (&count, &global_count, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); /* Stop timer */ elapsed_time += MPI_Wtime(); if (!id) { printf ("Execution time %8.6f\n", elapsed_time); fflush (stdout); } MPI_Finalize(); if (!id) printf ("There are %d different solutions\n", global_count); return 0; } /* Return 1 if 'i'th bit of 'n' is 1; 0 otherwise */ #define EXTRACT_BIT(n,i) ((n&(1<