# include # include # include # include using namespace std; int main ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // MAIN is the main program for MXM_SERIAL. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 30 October 2011 // // Author: // // John Burkardt // { double a[500][500]; double angle; double b[500][500]; double c[500][500]; int i; int j; int k; int n = 500; double pi = 3.141592653589793; double s; timestamp ( ); cout << "\n"; cout << "MXM_SERIAL:\n"; cout << " C++ version\n"; cout << " Compute matrix product C = A * B.\n"; cout << "\n"; cout << " The matrix order N = " << n << "\n"; // // Loop 1: Evaluate A. // s = 1.0 / sqrt ( ( double ) ( n ) ); for ( i = 0; i < n; i++ ) { for ( j = 0; j < n; j++ ) { angle = 2.0 * pi * i * j / ( double ) n; a[i][j] = s * ( sin ( angle ) + cos ( angle ) ); } } // // Loop 2: Copy A into B. // for ( i = 0; i < n; i++ ) { for ( j = 0; j < n; j++ ) { b[i][j] = a[i][j]; } } // // Loop 3: Compute C = A * B. // for ( i = 0; i < n; i++ ) { for ( j = 0; j < n; j++ ) { c[i][j] = 0.0; for ( k = 0; k < n; k++ ) { c[i][j] = c[i][j] + a[i][k] * b[k][j]; } } } cout << " C(100,100) = C[99][99] = " << c[99][99] << "\n"; // // Terminate. // cout << "\n"; cout << "MXM_SERIAL:\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // TIMESTAMP prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 July 2009 // // Author: // // John Burkardt // // Parameters: // // None // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; size_t len; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); len = std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }