Пример #1
0
/**
 * Program entry point
 */
int main(int argc, char ** argv)
{
  //Initilize Variables
  uint128 start = alphaTou128(argv[1]);
  uint128 end = alphaTou128(argv[2]);
  uint128 n;
  int error;

  //Main Body
  if(argc != 3) {
    printUsage();
    return 0;
  }
  for (n = start;n <= end;n+=1)
    {
      char * n_str = u128ToString(n);
      char * str_n_threads = u128ToString(sqrtuint128(n));
      error = PrimeFinder(n_str, str_n_threads);
      free(str_n_threads);
      if (error == EXIT_FAILURE)
	{
	  return EXIT_FAILURE;
	}
    }
  return EXIT_SUCCESS;
}
Пример #2
0
int main(int argc, char * * argv)
{
    const char * str = "340282366920938463463374607431768211455";
    uint128 w = alphaTou128(str);
    char * w_str = u128ToString(w);
    printf("Biiigggg number: %s\n", w_str);
    if(strcmp(str, w_str) != 0)
       printf("ERROR!, expected %s\n", str);
    free(w_str);
    return EXIT_SUCCESS;
}
Пример #3
0
Файл: pa06.c Проект: kuos/ECE264
/**
 * Program entry point
 */
int main(int argc, char * * argv)
{
    if(argc != 3) {
    	printUsage();
    	return 0;
    }

    // What was the input number?
    uint128 n = alphaTou128(argv[1]);
    char * n_str = u128ToString(n); 

    // How many concurrent threads?
    errno = 0; // so we know if strtol fails
    int n_threads = strtol(argv[2], NULL, 10);

    // Was there an error in the input arguments?
        int error = FALSE;
    if(errno != 0 || n_threads <= 0) {
	fprintf(stderr, "2nd argument must be a valid integer >= 1, aborting.\n");
	error = TRUE;
    }
    if(n_str && strcmp(n_str, argv[1]) != 0) {
	fprintf(stderr, "1st argument must be a valid 128-bit integer: '%s' != '%s', aborting.\n", n_str, argv[1]);
	error = TRUE;
    }

    if(error) {
	free(n_str);
	exit(1);
    }
    free(n_str);
   
  
    struct timeval time1;
    struct timeval time2;
    gettimeofday(&time1, NULL);
    printf("Testing if '%s' is prime with %d threads: ", argv[1], n_threads);
    fflush(stdout);
    int is_prime = primalityTestParallel(n, n_threads);
    gettimeofday(&time2, NULL);
    if(is_prime) {
	printf("TRUE");
    } else {
	printf("FALSE");
    }
    printf(", %8.4fs\n", timeDiff(time1, time2));

    return EXIT_SUCCESS;
}
Пример #4
0
int PrimeFinder(char * n_str, char * str_n_threads)
{
  //Initilize Variables
  FILE * fprime;
  char * fprime_str = "PrimeList";
  uint128 n;
  int n_threads;

  //Main Body
  fprime = fopen(fprime_str,"r+");
  if (fprime == NULL)
    {
      printf("File %s failed to open",fprime_str);
      return EXIT_FAILURE;
    }
  n = alphaTou128(n_str);

    // How many concurrent threads?
  errno = 0; // so we know if strtol fails
  n_threads = strtol(str_n_threads, NULL, 10);
  if (n_threads > 10)
    {
      n_threads = 10;
    }

  // Was there an error in the input arguments?
  int error = FALSE;
  if(errno != 0 || n_threads <= 0) {
    fprintf(stderr, "2nd argument must be a valid integer >= 1, aborting.\n");
	error = TRUE;
    }

  /*
    if(n_str && strcmp(n_str, argv[1]) != 0) {
	fprintf(stderr, "1st argument must be a valid 128-bit integer: '%s' != '%s', aborting.\n", n_str, argv[1]);
	error = TRUE;
    }
  */
  if(error) {
    free(n_str);
    fclose(fprime);
    exit(1);
  }
    
  struct timeval time1;
  struct timeval time2;
  gettimeofday(&time1, NULL);
  printf("Testing if '%s' is prime with %d threads: ", n_str, n_threads);
  fflush(stdout);
  int is_prime = primalityTestParallel(n, n_threads, fprime);
  gettimeofday(&time2, NULL);
  if(is_prime) {
    printf("TRUE");
    fprintf(fprime,"\n%s",n_str);
  } else {
    printf("FALSE");
  }
  printf(", %8.4fs\n", timeDiff(time1, time2));

  fclose(fprime);
  free(n_str);
  return EXIT_SUCCESS;
}