/* * Circuit Satisfiability, Version 3 * * This enhanced version of the program prints the * total number of solutions and individual timings. */ #include #include int main (int argc, char *argv[]) { int count; /* Solutions found by this proc */ int global_count; /* Total number of solutions */ int i; int id; /* Process rank */ int p; /* Number of processes */ int check_circuit (int, int); double elapsed_time; MPI_Init (&argc, &argv); 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); elapsed_time += MPI_Wtime(); printf ("Process %d is done, elapsed time = %lf\n", id, 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<