Esempio n. 1
0
void r8_test ( int logn_max )

/******************************************************************************/
/*
  Purpose:

    R8_TEST estimates the value of PI using double.

  Discussion:

    PI is estimated using N terms.  N is increased from 10^2 to 10^LOGN_MAX.
    The calculation is repeated using both sequential and Open MP enabled code.
    Wall clock time is measured by calling SYSTEM_CLOCK.

  Licensing:

    This code is distributed under the GNU LGPL license. 

  Modified:

    13 November 2007

  Author:

    John Burkardt
*/
{
  double error;
  double estimate;
  int logn;
  char mode[4];
  int n;
  double r8_pi = 3.141592653589793;
  double wtime;

  printf ( "\n" );
  printf ( "R8_TEST:\n" );
  printf ( "  Estimate the value of PI,\n" );
  printf ( "  using double arithmetic.\n" );
  printf ( "\n" );
  printf ( "  N = number of terms computed and added;\n" );
  printf ( "\n" );
  printf ( "  MODE = SEQ for sequential code;\n" );
  printf ( "  MODE = OMP for Open MP enabled code;\n" );
  printf ( "  (performance depends on whether Open MP is used,\n" );
  printf ( "  and how many processes are available)\n" );
  printf ( "\n" );
  printf ( "  ESTIMATE = the computed estimate of PI;\n" );
  printf ( "\n" );
  printf ( "  ERROR = ( the computed estimate - PI );\n" );
  printf ( "\n" );
  printf ( "  TIME = elapsed wall clock time;\n" );
  printf ( "\n" );
  printf ( "  Note that you can''t increase N forever, because:\n" );
  printf ( "  A) ROUNDOFF starts to be a problem, and\n" );
  printf ( "  B) maximum integer size is a problem.\n" );
  printf ( "\n" );
  printf ( "             N Mode    Estimate        Error           Time\n" );
  printf ( "\n" );

  n = 1;

  for ( logn = 1; logn <= logn_max; logn++ )
  {
/*
  Note that when I set N = 10**LOGN directly, rather than using
  recursion, I got inaccurate values of N when LOGN was "large",
  that is, for LOGN = 10, despite the fact that N itself was
  a KIND = 8 integer!  
 
  Sequential calculation.
*/
    strcpy ( mode, "SEQ" );

    wtime = omp_get_wtime ( );

    estimate = r8_pi_est_seq ( n );

    wtime = omp_get_wtime ( ) - wtime;

    error = r8_abs ( estimate - r8_pi );

    printf ( "%14d  %s  %14f  %14g  %14f\n", n, mode, estimate, error, wtime );
/*
  Open MP enabled calculation.
*/
    strcpy ( mode, "OMP" );

    wtime = omp_get_wtime ( );

    estimate = r8_pi_est_omp ( n );

    wtime = omp_get_wtime ( ) - wtime;

    error = r8_abs ( estimate - r8_pi );

    printf ( "%14d  %s  %14f  %14g  %14f\n", n, mode, estimate, error, wtime );

    n = n * 10;
  }

  return;
}
Esempio n. 2
0
void r8_test ( int logn_max )
{
  double error;
  double estimate;
  int logn;
  char mode[4];
  int n;
  double r8_pi = 3.141592653589793;
  double wtime;
 
  printf ( "\n" );
  printf ( "R8_TEST:\n" );
  printf ( "  Estimate the value of PI,\n" );
  printf ( "  using double arithmetic.\n" );
  printf ( "\n" );
  printf ( "  N = number of terms computed and added;\n" );
  printf ( "\n" );
  printf ( "  MODE = SEQ for sequential code;\n" );
  printf ( "  MODE = OMP for Open MP enabled code;\n" );
  printf ( "  (performance depends on whether Open MP is used,\n" );
  printf ( "  and how many processes are available)\n" );
  printf ( "\n" );
  printf ( "  ESTIMATE = the computed estimate of PI;\n" );
  printf ( "\n" );
  printf ( "  ERROR = ( the computed estimate - PI );\n" );
  printf ( "\n" );
  printf ( "  TIME = elapsed wall clock time;\n" );
  printf ( "\n" );
  printf ( "  Note that you can''t increase N forever, because:\n" );
  printf ( "  A) ROUNDOFF starts to be a problem, and\n" );
  printf ( "  B) maximum integer size is a problem.\n" );
  printf ( "\n" );
  printf ( "             N Mode    Estimate        Error           Time\n" );
  printf ( "\n" );
 
  n = 1;
 
  for ( logn = 1; logn <= logn_max; logn++ )
  {
 
  strcpy ( mode, "SEQ" );
 
    wtime = omp_get_wtime ( );
 
    estimate = r8_pi_est_seq ( n );
 
    wtime = omp_get_wtime ( ) - wtime;
 
    error = r8_abs ( estimate - r8_pi );
 
    printf ( "%14d  %s  %14f  %14g  %14f\n", n, mode, estimate, error, wtime );
/*
 Open MP enabled calculation.
*/
    strcpy ( mode, "OMP" );
 
    wtime = omp_get_wtime ( );
 
    estimate = r8_pi_est_omp ( n );
 
    wtime = omp_get_wtime ( ) - wtime;
 
    error = r8_abs ( estimate - r8_pi );
 
    printf ( "%14d  %s  %14f  %14g  %14f\n", n, mode, estimate, error, wtime );
 
    n = n * 10;
  }
 
  return;
}