Esempio n. 1
0
// MODIFIED FOR TEST CODE
double MonteCarlo_integrate(int Num_samples, int print)
    {


        Random R = new_Random_seed(SEED);


        int under_curve = 0;
        int count;

        for (count=0; count<Num_samples; count++)
        {
            double x= Random_nextDouble(R);
            double y= Random_nextDouble(R);

            if ( x*x + y*y <= 1.0)
                 under_curve ++;
            
        }

        Random_delete(R);

	// ADDED FOR TEST CODE print results
	if( print )
	  {
	    printf("\n%d\n", under_curve);
	  }

        return ((double) under_curve / Num_samples) * 4.0;
    }
Esempio n. 2
0
/*
 * This is a straightforward copy/adaptation of scimark2.c:main.
 *
 * @note: default to the (small) cache-contained version.
 *
 * @param s_large [logical(1)]
 *   Perform SciMark LARGE, i.e., memory-focused version of the benchmark?
 *   Default is FALSE.
 * @param s_min_time [numeric(1)]
 *   Minimum time to run each of the benchmarks, in seconds.
 * @return [numeric(6)]
 */
SEXP c_rscimark(SEXP s_large, SEXP s_min_time) {
  int large = asLogical(s_large);
  double min_time = asReal(s_min_time);

  int FFT_size = FFT_SIZE;
  int SOR_size =  SOR_SIZE;
  int Sparse_size_M = SPARSE_SIZE_M;
  int Sparse_size_nz = SPARSE_SIZE_nz;
  int LU_size = LU_SIZE;

  Random R = new_Random_seed(RANDOM_SEED);

  if (large) {
    FFT_size = LG_FFT_SIZE;
    SOR_size = LG_SOR_SIZE;
    Sparse_size_M = LG_SPARSE_SIZE_M;
    Sparse_size_nz = LG_SPARSE_SIZE_nz;
    LU_size = LG_LU_SIZE;
  }

  /* allocate memory for return value */
  SEXP s_res = NEW_NUMERIC(6);
  double* res = REAL(s_res);

  /* do the benchmark stuff */
  res[1] = kernel_measureFFT(FFT_size, min_time, R);
  res[2] = kernel_measureSOR(SOR_size, min_time, R);
  res[3] = kernel_measureMonteCarlo(min_time, R);
  res[4] = kernel_measureSparseMatMult(
    Sparse_size_M, Sparse_size_nz, min_time, R);
  res[5] = kernel_measureLU(LU_size, min_time, R);

  /* composite value */
  res[0] = (res[1] + res[2] + res[3] + res[4] + res[5]) / 5;

  Random_delete(R);
  return s_res;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
        /* default to the (small) cache-contained version */

        double min_time = RESOLUTION_DEFAULT;

        int FFT_size = FFT_SIZE;
        int SOR_size =  SOR_SIZE;
        int Sparse_size_M = SPARSE_SIZE_M;
        int Sparse_size_nz = SPARSE_SIZE_nz;
        int LU_size = LU_SIZE;


        /* run the benchmark */

        double res[6] = {0.0};
        Random R = new_Random_seed(RANDOM_SEED);


        if (argc > 1)
        {
			int current_arg = 1;

			if (strcmp(argv[1], "-help")==0  ||
					strcmp(argv[1], "-h") == 0)
			{
				fprintf(stderr, "Usage: [-large] [minimum_time]\n");
				exit(0);
			}

			if (strcmp(argv[1], "-large")==0)
			{
				FFT_size = LG_FFT_SIZE;
				SOR_size = LG_SOR_SIZE;
				Sparse_size_M = LG_SPARSE_SIZE_M;
				Sparse_size_nz = LG_SPARSE_SIZE_nz;
				LU_size = LG_LU_SIZE;

				current_arg++;
			}

			if (current_arg < argc)
			{
				min_time = atof(argv[current_arg]);
			}
			
        }

	
		print_banner();
		printf("Using %10.2f seconds min time per kenel.\n", min_time);

        res[1] = kernel_measureFFT( FFT_size, min_time, R);   
        res[2] = kernel_measureSOR( SOR_size, min_time, R);   
        res[3] = kernel_measureMonteCarlo(min_time, R); 
        res[4] = kernel_measureSparseMatMult( Sparse_size_M, 
                Sparse_size_nz, min_time, R);           
        res[5] = kernel_measureLU( LU_size, min_time, R);  



        res[0] = (res[1] + res[2] + res[3] + res[4] + res[5]) / 5;

        /* print out results  */
        printf("Composite Score:        %8.2f\n" ,res[0]);
        printf("FFT             Mflops: %8.2f    (N=%d)\n", res[1], FFT_size);
        printf("SOR             Mflops: %8.2f    (%d x %d)\n", 		
				res[2], SOR_size, SOR_size);
        printf("MonteCarlo:     Mflops: %8.2f\n", res[3]);
        printf("Sparse matmult  Mflops: %8.2f    (N=%d, nz=%d)\n", res[4], 
					Sparse_size_M, Sparse_size_nz);
        printf("LU              Mflops: %8.2f    (M=%d, N=%d)\n", res[5],
				LU_size, LU_size);


        Random_delete(R);

        return 0;
  
}