I am trying to execute the code below using POSIX Threads instead of OpenMp. Any ideas. I am newbee. I have tried several times and it is not working.
#include <stdio.h> #include <math.h> #include <omp.h> main(int argc, char *argv[]) { int i, j, limit; int start, end; /* range of numbers to search */ int number_of_primes = 0; /* number of primes found */ int number_of_41primes = 0;/* number of 4n+1 primes found */ int number_of_43primes = 0;/* number of 4n-1 primes found */ int prime; /* is the number prime? */ int print_primes = 0; /* should each prime be printed? */ start = atoi(argv[1]); end = atoi(argv[2]); if (!(start % 2)) start++; if (argc == 4 && atoi(argv[3]) != 0) print_primes = 1; printf("Range to check for Primes: %d - %d ",start, end); #pragma omp parallel for private (limit, j, prime) for(i = start; i <= end; i += 2) { limit = (int) sqrt((float)i) + 1; prime = 1; /* assume number is prime */ j = 3; while (prime && (j <= limit)) { if (i%j == 0) prime = 0; j += 2; } if (prime) { if (print_primes) printf("%5d is prime",i); #pragma critical { number_of_primes++; if (i%4 == 1) number_of_41primes++; if (i%4 == 3) number_of_43primes++; } } } printf("\n Program Done.\n %d primes found \n",number_of_primes); printf("\nNumber of 4n+1 primes found: %d \n",number_of_41primes); printf("\nNumber of 4n-1 primes found: %d \n",number_of_43primes); }