# include # include # include int main ( int argc, char *argv[] ); double cpu_time ( void ); /******************************************************************************/ int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for SUM_MILLION. Discussion: SUM_MILLION is a sketch of a program to generate the numbers from 1 to 1,000,000, add them, and print the result. This program is only a sketch. Your job is to finish it, debug it, and get it to run. */ { # define N 1000000 double ctime; double ctime1; double ctime2; double error; double exact = 500000500000.0; int flops; int i; double mflops; double total; double x[N]; printf ( "\n" ); printf ( "SUM_MILLION:\n" ); printf ( " C version\n" ); printf ( "\n" ); printf ( " Task: add the numbers from 1 to %d.\n", N ); /* Step 1: Load the array X with the values. */ for ( i = 0; i < N; i++ ) { x[i] = i + 1; } /* Step 2: Start the clock. Add up the entries in X. Stop the clock. Compute elapsed CPU time; Set the number of FLOPs. Compute the MFLOPS rate. Compute the error. */ MISSING CODE /* Step 3: Print results. */ printf ( "\n" ); printf ( " Total = %f\n", total ); printf ( " Error = %f\n", error ); printf ( " CPU time = %f\n", ctime ); printf ( " MegaFLOPS = %f\n", mflops ); return 0; # undef N } /*******************************************************************************/ double cpu_time ( void ) /*******************************************************************************/ /* Purpose: CPU_TIME reports the total CPU time for a program. Modified: 27 September 2005 Author: John Burkardt Parameters: Output, double CPU_TIME, the current total elapsed CPU time in second. */ { double value; value = ( double ) clock ( ) / ( double ) CLOCKS_PER_SEC; return value; }