/*------------------------------------------------------------------ * Function: parallel_dynamic * Purpose: Run tests with schedule(dynamic, 1) * In arg: thread_count */ int parallel_dynamic(int thread_count) { int i; int global_count = 0; int input_maximum = 65536; #pragma omp parallel for num_threads(thread_count) \ shared(global_count) schedule(dynamic, 1) for(i = 0; i < input_maximum; i++) { //If the current number is a solution, increment the count if( check_circuit(omp_get_thread_num(), i) ) { global_count++; } } return global_count; }
int main(int argc, char** argv) { int i; int id; int p; double elapsedTime; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Comm_size(MPI_COMM_WORLD, &p); MPI_Barrier(MPI_COMM_WORLD); elapsedTime = -1 * MPI_Wtime(); int localNumPassed = 0; for(long i = id ; i < 65536 ; i += p) { localNumPassed += check_circuit(id, i); } int globalNumPassed; MPI_Reduce(&localNumPassed, &globalNumPassed, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); elapsedTime += MPI_Wtime(); double globalElapsedTime; MPI_Reduce(&elapsedTime, &globalElapsedTime, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if(id == 0) { printf("Elapsed Time = %f (Aggregate Time Taken: %f)\n", elapsedTime, globalElapsedTime); printf("Global inputs passed (of 65536)= %d\n", globalNumPassed); } MPI_Finalize(); return 0; }