Пример #1
0
// 'argc' contains the number of program arguments, and
// 'argv' is an array of char pointers, where each
// char pointer points to a null-terminated string.
int main(int argc, char *argv[]){
  if(argc == 2)
    print_primes(atoi(argv[1]));
  else
    printf("Please state an interger number.\n");
  return 0;
}
Пример #2
0
//Serial timing function that has omp only to initilise everything to prime
void serial_timing ( double* serial_time, bool* is_prime, long long n, int thread_count )
{
	double start;
	double finish;
	long long i;
	//Marks everything prime initially in the boolean array
	#   pragma omp parallel for schedule(static) num_threads(thread_count) \
	default(none) private(i) shared(n, is_prime)

	for ( i = 2; i <= n; i++ )
		is_prime[i] = true;

	//Start timing
	start = omp_get_wtime();
	//starts with 2 and marks all even numbers as multiples
	mark_two_multiples ( 2, n, is_prime );

	//Only odd numbers are prime from 3 and onward so increments of two are done instead of 1
	for ( i = 3; i <= n; i += 2 ) {
		if ( is_prime[i] )
			mark_multiples_odd ( i, n, is_prime );
	}

	//End timing
	finish = omp_get_wtime();
	*serial_time = finish - start;
	serial_count = print_primes ( is_prime, "1", n );
}
Пример #3
0
int main(){
    int n;
    printf("Enter the Number n :");
    scanf("%d",&n);
    printf("The primes are :\n");
    print_primes(n);
    return 0;
}
Пример #4
0
// 'argc' contains the number of program arguments, and
// 'argv' is an array of char pointers, where each
// char pointer points to a null-terminated string.
int main(int argc, char *argv[]) {
    clock_t start = clock(), diff;
    if(argc == 2)
        print_primes(atoi(argv[1]));
    else
        printf("Please state an interger number.\n");
    diff = clock() - start;
    int msec = diff * 1000 / CLOCKS_PER_SEC;
    printf("          Execution time: %d ms\n", msec);
    return 0;
}
Пример #5
0
int main()
{
  long int t, n, m, k;
  int *primes = (int*) malloc(PRIMES * sizeof(int));
  e_sieve(primes, MAX_PRIME);

  scanf("%ld", &t);
  for (k=0; k<t; k+=1) {
    scanf("%ld %ld", &n, &m);
    print_primes(primes, n, m);
  }
  
  /* free(primes); */
  return(0);
}
Пример #6
0
int
main(int argc, char* argv[]) {
    if(argc < 2) {
        printf("Please provide a number as a single argument.\n");
        return 1;
    }

    int n = atoi(argv[1]);

    int* primes = (int *)malloc( sizeof(int)*n );
    assert(primes != 0);

    init_array(primes, n);

    int num_prime = prime_sieve(primes, n);

    printf("%ld Primes less than %ld.\n", (long)num_prime, (long)n);
    print_primes(primes, n, num_prime);

    free(primes);
    return 0;
}
Пример #7
0
int main(void){
  
  print_primes(1000000);
  return 0;
}