# include # include # include # include # include using namespace std; int main ( void ); void test01 ( void ); void test02 ( void ); extern "C" { int idamax_ ( int *n, double *x, int *incx ); double dasum_ ( int *n, double *x, int *incx ); } void timestamp ( void ); //**************************************************************************** int main ( void ) //***************************************************************************** // // Purpose: // // BLAS1_D_PRB_ALPHA tests the BLAS double precision routines on the Alpha. // // Modified: // // 29 March 2007 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "BLAS1_D_PRB_ALPHA:\n"; cout << " C++ version\n"; cout << " Tests for Level 1 BLAS,\n"; cout << " the Double Precision basic linear algebra subprograms.\n"; test01 ( ); test02 ( ); cout << "\n"; cout << "BLAS1_D_PRB_ALPHAB:\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //**************************************************************************** void test01 ( void ) //**************************************************************************** // // Purpose: // // TEST01 tests IDAMAX. // { # define N 11 int i; int incx; int n; double x[N]; cout << "\n"; cout << "TEST01\n"; cout << " IDAMAX returns the index of maximum absolute magnitude;\n"; for ( i = 0; i < N; i++ ) { x[i] = ( double ) ( ( 7 * ( i + 1 ) ) % 11 ) - ( double ) ( N / 2 ); } cout << "\n"; cout << " The vector X:\n"; cout << "\n"; for ( i = 0; i < N; i++ ) { cout << " " << setw(6) << i << " " << setw(12) << x[i] << "\n"; } incx = 1; n = N; i = idamax_ ( &n, x, &incx ); cout << "\n"; cout << " The index of maximum absolute magnitude = " << i << "\n"; return; # undef N } //**************************************************************************** void test02 ( void ) //**************************************************************************** // // Purpose: // // TEST02 tests DASUM. // { # define LDA 6 # define MA 5 # define NA 4 # define NX 10 double a[LDA*NA]; int i; int incx; int j; int lda; int ma; int na; int nx; double s; double x[NX]; lda = LDA; ma = MA; na = NA; nx = NX; s = 1.0; for ( i = 0; i < nx; i++ ) { s = -s; x[i] = s * ( double ) ( 2 * ( i + 1 ) ); } cout << "\n"; cout << "TEST02\n"; cout << " Demonstrate the use of DASUM\n"; cout << " which adds the absolute values of elements of a vector.\n"; cout << "\n"; cout << " X =\n"; cout << "\n"; for ( i = 0; i < NX; i++ ) { printf ( " %4d %10f\n", i, x[i] ); } nx = NX; incx = 1; cout << "\n"; cout << " DASUM_ ( " << nx << ", X, " << incx << " ) = " << dasum_ ( &nx, x, &incx ) << "\n"; nx = NX / 2; incx = 2; cout << " DASUM_ ( " << nx << ", X, " << incx << " ) = " << dasum_ ( &nx, x, &incx ) << "\n"; nx = 2; incx = nx / 2; cout << " DASUM_ ( " << nx << ", X, " << incx << " ) = " << dasum_ ( &nx, x, &incx ) << "\n"; for ( j = 0; j < na; j++ ) { for ( i = 0; i < ma; i++ ) { a[i+j*LDA] = ( double ) ( 10 * ( i + 1 ) + ( j + 1 ) ); } } cout << "\n"; cout << " Demonstrate with a matrix A:\n"; cout << "\n"; for ( i = 0; i < ma; i++ ) { for ( j = 0; j < na; j++ ) { cout << " " << setw(10) << a[i+j*LDA]; } cout << "\n"; } nx = ma; incx = 1; cout << "\n"; cout << " DASUM_ ( " << nx << ", A+" << lda << ", " << incx << " ) = " << dasum_ ( &nx, a+lda, &incx ) << "\n"; nx = na; incx = lda; cout << " DASUM_ ( " << nx << ", A+" << 1 << ", " << incx << " ) = " << dasum_ ( &nx, a+1, &incx ) << "\n"; return; # undef LDA # undef MA # undef NA # undef NX } //****************************************************************************** void timestamp ( void ) //****************************************************************************** // // Purpose: // // TIMESTAMP prints the current YMDHMS date as a time stamp. // // Example: // // May 31 2001 09:45:54 AM // // Modified: // // 24 September 2003 // // Author: // // John Burkardt // // Parameters: // // None // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; size_t len; time_t now; now = time ( NULL ); tm = localtime ( &now ); len = strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); cout << time_buffer << "\n"; return; # undef TIME_SIZE }