Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 6:5e0f3eedaf66
- Parent:
- 5:2b929fbd5c69
- Child:
- 7:931219974070
--- a/main.cpp Tue Jan 03 18:41:10 2017 +0000
+++ b/main.cpp Tue Jan 03 19:59:24 2017 +0000
@@ -48,12 +48,12 @@
pc.baud(115200);
//pc.baud(9600);
- while(1)
- {
+ while(1) {
+
pc.printf("Starting benchmark...\n");
-
+
do_benchmark();
-
+
pc.printf(" kraj \n\n");
}
}
@@ -61,26 +61,27 @@
/******************************************************************************/
int do_benchmark ( void )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- MAIN is the main program for LINPACK_BENCH.
+ MAIN is the main program for LINPACK_BENCH.
- Discussion:
+ Discussion:
- LINPACK_BENCH drives the double precision LINPACK benchmark program.
+ LINPACK_BENCH drives the double precision LINPACK benchmark program.
- Modified:
+ Modified:
- 25 July 2008
+ 25 July 2008
- Parameters:
+ Parameters:
- N is the problem size.
-*/
-{
+ N is the problem size.
+ */
+
# define N 2
# define LDA ( N + 1 )
@@ -119,8 +120,8 @@
pc.printf ( " Matrix order N = %d\n", N );
pc.printf ( " Leading matrix dimension LDA = %d\n", LDA );
- ops = ( double ) (( 2 * N * N * N ) / 3.0 ) + 2.0 * ( N * N )); //c++
- //ops = ( double ) ( 2L * N * N * N ) / 3.0 + 2.0 * ( double ) ( (long)N * N ); // Arduiono C
+ // ops = ( double ) ( 2 * N * N * N ) / 3.0 + 2.0 * ( double ) ( N * N );
+ ops = ( double ) ( 2L * N * N * N ) / 3.0 + 2.0 * ( double ) ( (long)N * N ); // Arduino C
/*
Allocate space for arrays.
@@ -220,7 +221,6 @@
eps = r8_epsilon ( );
residn = resid_max / ( double ) N / a_max / b_max / eps;
-
time[2] = total;
@@ -242,8 +242,8 @@
//pc.printf( " \n\n ");
//pc.printf( "\n Norm. Resid Resid MACHEP X[1] X[N]\n" );
pc.printf( "\n MACHEP X[1] X[N]\n" );
- //pc.printf(" %14f", residn);
- //pc.printf(" %14f", resid_max);
+ pc.printf(" %14f", residn);
+ pc.printf(" %14f", resid_max);
pc.printf(" %14e", eps);
pc.printf(" %14f", b[0]);
pc.printf(" %14f ",b[N-1]);
@@ -251,7 +251,7 @@
//pc.printf( " %14f %14f %14e %14f %14f \n", residn, resid_max, eps, b[0], b[N-1] );
pc.printf( " \n\n ");
- pc.printf( " Factor Solve Total MFLOPS Unit Cray-Ratio \n\n" );
+ pc.printf( " Factor Solve Total MFLOPS Unit Cray-Ratio \n\n" );
for(int ii=0; ii<6; ii++) {
pc.printf(" %9f", time[ii]);
@@ -261,8 +261,9 @@
/*
Terminate.
- free mem
- */
+ Free Mem
+ */
+
free ( a );
free ( b );
free ( ipvt );
@@ -311,54 +312,54 @@
void daxpy ( int n, double da, double dx[], int incx, double dy[], int incy )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- DAXPY computes constant times a vector plus a vector.
+ DAXPY computes constant times a vector plus a vector.
- Discussion:
+ Discussion:
- This routine uses unrolled loops for increments equal to one.
+ This routine uses unrolled loops for increments equal to one.
- Modified:
+ Modified:
- 30 March 2007
+ 30 March 2007
- Author:
+ Author:
- FORTRAN77 original by Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart.
- C version by John Burkardt
+ FORTRAN77 original by Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart.
+ C version by John Burkardt
- Reference:
+ Reference:
- Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
- LINPACK User's Guide,
- SIAM, 1979.
+ Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
+ LINPACK User's Guide,
+ SIAM, 1979.
- Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,
- Basic Linear Algebra Subprograms for Fortran Usage,
- Algorithm 539,
- ACM Transactions on Mathematical Software,
- Volume 5, Number 3, September 1979, pages 308-323.
+ Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,
+ Basic Linear Algebra Subprograms for Fortran Usage,
+ Algorithm 539,
+ ACM Transactions on Mathematical Software,
+ Volume 5, Number 3, September 1979, pages 308-323.
- Parameters:
+ Parameters:
- Input, int N, the number of elements in DX and DY.
+ Input, int N, the number of elements in DX and DY.
- Input, double DA, the multiplier of DX.
+ Input, double DA, the multiplier of DX.
- Input, double DX[*], the first vector.
+ Input, double DX[*], the first vector.
- Input, int INCX, the increment between successive entries of DX.
+ Input, int INCX, the increment between successive entries of DX.
- Input/output, double DY[*], the second vector.
- On output, DY[*] has been replaced by DY[*] + DA * DX[*].
+ Input/output, double DY[*], the second vector.
+ On output, DY[*] has been replaced by DY[*] + DA * DX[*].
- Input, int INCY, the increment between successive entries of DY.
-*/
-{
+ Input, int INCY, the increment between successive entries of DY.
+ */
int i;
int ix;
int iy;
@@ -416,54 +417,55 @@
/******************************************************************************/
double ddot ( int n, double dx[], int incx, double dy[], int incy )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- DDOT forms the dot product of two vectors.
+ DDOT forms the dot product of two vectors.
- Discussion:
+ Discussion:
- This routine uses unrolled loops for increments equal to one.
+ This routine uses unrolled loops for increments equal to one.
- Modified:
+ Modified:
- 30 March 2007
+ 30 March 2007
- Author:
+ Author:
- FORTRAN77 original by Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart.
- C version by John Burkardt
+ FORTRAN77 original by Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart.
+ C version by John Burkardt
- Reference:
+ Reference:
- Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
- LINPACK User's Guide,
- SIAM, 1979.
+ Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
+ LINPACK User's Guide,
+ SIAM, 1979.
- Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,
- Basic Linear Algebra Subprograms for Fortran Usage,
- Algorithm 539,
- ACM Transactions on Mathematical Software,
- Volume 5, Number 3, September 1979, pages 308-323.
+ Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,
+ Basic Linear Algebra Subprograms for Fortran Usage,
+ Algorithm 539,
+ ACM Transactions on Mathematical Software,
+ Volume 5, Number 3, September 1979, pages 308-323.
- Parameters:
+ Parameters:
- Input, int N, the number of entries in the vectors.
+ Input, int N, the number of entries in the vectors.
- Input, double DX[*], the first vector.
+ Input, double DX[*], the first vector.
- Input, int INCX, the increment between successive entries in DX.
+ Input, int INCX, the increment between successive entries in DX.
- Input, double DY[*], the second vector.
+ Input, double DY[*], the second vector.
- Input, int INCY, the increment between successive entries in DY.
+ Input, int INCY, the increment between successive entries in DY.
- Output, double DDOT, the sum of the product of the corresponding
- entries of DX and DY.
-*/
-{
+ Output, double DDOT, the sum of the product of the corresponding
+ entries of DX and DY.
+ */
+
double dtemp;
int i;
int ix;
@@ -521,51 +523,52 @@
/******************************************************************************/
int dgefa ( double a[], int lda, int n, int ipvt[] )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- DGEFA factors a real general matrix.
+ DGEFA factors a real general matrix.
- Modified:
+ Modified:
- 16 May 2005
+ 16 May 2005
- Author:
+ Author:
- C version by John Burkardt.
+ C version by John Burkardt.
- Reference:
+ Reference:
- Jack Dongarra, Cleve Moler, Jim Bunch and Pete Stewart,
- LINPACK User's Guide,
- SIAM, (Society for Industrial and Applied Mathematics),
- 3600 University City Science Center,
- Philadelphia, PA, 19104-2688.
- ISBN 0-89871-172-X
+ Jack Dongarra, Cleve Moler, Jim Bunch and Pete Stewart,
+ LINPACK User's Guide,
+ SIAM, (Society for Industrial and Applied Mathematics),
+ 3600 University City Science Center,
+ Philadelphia, PA, 19104-2688.
+ ISBN 0-89871-172-X
- Parameters:
+ Parameters:
- Input/output, double A[LDA*N].
- On intput, the matrix to be factored.
- On output, an upper triangular matrix and the multipliers used to obtain
- it. The factorization can be written A=L*U, where L is a product of
- permutation and unit lower triangular matrices, and U is upper triangular.
+ Input/output, double A[LDA*N].
+ On intput, the matrix to be factored.
+ On output, an upper triangular matrix and the multipliers used to obtain
+ it. The factorization can be written A=L*U, where L is a product of
+ permutation and unit lower triangular matrices, and U is upper triangular.
- Input, int LDA, the leading dimension of A.
+ Input, int LDA, the leading dimension of A.
- Input, int N, the order of the matrix A.
+ Input, int N, the order of the matrix A.
- Output, int IPVT[N], the pivot indices.
+ Output, int IPVT[N], the pivot indices.
- Output, int DGEFA, singularity indicator.
- 0, normal value.
- K, if U(K,K) == 0. This is not an error condition for this subroutine,
- but it does indicate that DGESL or DGEDI will divide by zero if called.
- Use RCOND in DGECO for a reliable indication of singularity.
-*/
-{
+ Output, int DGEFA, singularity indicator.
+ 0, normal value.
+ K, if U(K,K) == 0. This is not an error condition for this subroutine,
+ but it does indicate that DGESL or DGEDI will divide by zero if called.
+ Use RCOND in DGECO for a reliable indication of singularity.
+ */
+
int info;
int j;
int k;
@@ -628,62 +631,63 @@
/******************************************************************************/
void dgesl ( double a[], int lda, int n, int ipvt[], double b[], int job )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- DGESL solves a real general linear system A * X = B.
+ DGESL solves a real general linear system A * X = B.
- Discussion:
+ Discussion:
- DGESL can solve either of the systems A * X = B or A' * X = B.
+ DGESL can solve either of the systems A * X = B or A' * X = B.
- The system matrix must have been factored by DGECO or DGEFA.
+ The system matrix must have been factored by DGECO or DGEFA.
- A division by zero will occur if the input factor contains a
- zero on the diagonal. Technically this indicates singularity
- but it is often caused by improper arguments or improper
- setting of LDA. It will not occur if the subroutines are
- called correctly and if DGECO has set 0.0 < RCOND
- or DGEFA has set INFO == 0.
+ A division by zero will occur if the input factor contains a
+ zero on the diagonal. Technically this indicates singularity
+ but it is often caused by improper arguments or improper
+ setting of LDA. It will not occur if the subroutines are
+ called correctly and if DGECO has set 0.0 < RCOND
+ or DGEFA has set INFO == 0.
- Modified:
+ Modified:
- 16 May 2005
+ 16 May 2005
- Author:
+ Author:
- C version by John Burkardt.
+ C version by John Burkardt.
- Reference:
+ Reference:
- Jack Dongarra, Cleve Moler, Jim Bunch and Pete Stewart,
- LINPACK User's Guide,
- SIAM, (Society for Industrial and Applied Mathematics),
- 3600 University City Science Center,
- Philadelphia, PA, 19104-2688.
- ISBN 0-89871-172-X
+ Jack Dongarra, Cleve Moler, Jim Bunch and Pete Stewart,
+ LINPACK User's Guide,
+ SIAM, (Society for Industrial and Applied Mathematics),
+ 3600 University City Science Center,
+ Philadelphia, PA, 19104-2688.
+ ISBN 0-89871-172-X
- Parameters:
+ Parameters:
- Input, double A[LDA*N], the output from DGECO or DGEFA.
+ Input, double A[LDA*N], the output from DGECO or DGEFA.
- Input, int LDA, the leading dimension of A.
+ Input, int LDA, the leading dimension of A.
- Input, int N, the order of the matrix A.
+ Input, int N, the order of the matrix A.
- Input, int IPVT[N], the pivot vector from DGECO or DGEFA.
+ Input, int IPVT[N], the pivot vector from DGECO or DGEFA.
- Input/output, double B[N].
- On input, the right hand side vector.
- On output, the solution vector.
+ Input/output, double B[N].
+ On input, the right hand side vector.
+ On output, the solution vector.
- Input, int JOB.
- 0, solve A * X = B;
- nonzero, solve A' * X = B.
-*/
-{
+ Input, int JOB.
+ 0, solve A * X = B;
+ nonzero, solve A' * X = B.
+ */
+
int k;
int l;
double t;
@@ -735,45 +739,46 @@
/******************************************************************************/
void dscal ( int n, double sa, double x[], int incx )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- DSCAL scales a vector by a constant.
+ DSCAL scales a vector by a constant.
- Modified:
+ Modified:
- 30 March 2007
+ 30 March 2007
- Author:
+ Author:
- FORTRAN77 original by Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart.
- C version by John Burkardt
+ FORTRAN77 original by Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart.
+ C version by John Burkardt
- Reference:
+ Reference:
- Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
- LINPACK User's Guide,
- SIAM, 1979.
+ Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
+ LINPACK User's Guide,
+ SIAM, 1979.
- Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,
- Basic Linear Algebra Subprograms for Fortran Usage,
- Algorithm 539,
- ACM Transactions on Mathematical Software,
- Volume 5, Number 3, September 1979, pages 308-323.
+ Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,
+ Basic Linear Algebra Subprograms for Fortran Usage,
+ Algorithm 539,
+ ACM Transactions on Mathematical Software,
+ Volume 5, Number 3, September 1979, pages 308-323.
- Parameters:
+ Parameters:
- Input, int N, the number of entries in the vector.
+ Input, int N, the number of entries in the vector.
- Input, double SA, the multiplier.
+ Input, double SA, the multiplier.
- Input/output, double X[*], the vector to be scaled.
+ Input/output, double X[*], the vector to be scaled.
- Input, int INCX, the increment between successive entries of X.
-*/
-{
+ Input, int INCX, the increment between successive entries of X.
+ */
+
int i;
int ix;
int m;
@@ -810,50 +815,51 @@
/******************************************************************************/
int idamax ( int n, double dx[], int incx )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- IDAMAX finds the index of the vector element of maximum absolute value.
+ IDAMAX finds the index of the vector element of maximum absolute value.
- Discussion:
+ Discussion:
- WARNING: This index is a 1-based index, not a 0-based index!
+ WARNING: This index is a 1-based index, not a 0-based index!
- Modified:
+ Modified:
- 30 March 2007
+ 30 March 2007
- Author:
+ Author:
- FORTRAN77 original by Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart.
- C version by John Burkardt
+ FORTRAN77 original by Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart.
+ C version by John Burkardt
- Reference:
+ Reference:
- Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
- LINPACK User's Guide,
- SIAM, 1979.
+ Jack Dongarra, Cleve Moler, Jim Bunch, Pete Stewart,
+ LINPACK User's Guide,
+ SIAM, 1979.
- Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,
- Basic Linear Algebra Subprograms for Fortran Usage,
- Algorithm 539,
- ACM Transactions on Mathematical Software,
- Volume 5, Number 3, September 1979, pages 308-323.
+ Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,
+ Basic Linear Algebra Subprograms for Fortran Usage,
+ Algorithm 539,
+ ACM Transactions on Mathematical Software,
+ Volume 5, Number 3, September 1979, pages 308-323.
- Parameters:
+ Parameters:
- Input, int N, the number of entries in the vector.
+ Input, int N, the number of entries in the vector.
- Input, double X[*], the vector to be examined.
+ Input, double X[*], the vector to be examined.
- Input, int INCX, the increment between successive entries of SX.
+ Input, int INCX, the increment between successive entries of SX.
- Output, int IDAMAX, the index of the element of maximum
- absolute value.
-*/
-{
+ Output, int IDAMAX, the index of the element of maximum
+ absolute value.
+ */
+
double dmax;
int i;
int ix;
@@ -899,28 +905,29 @@
/******************************************************************************/
double r8_abs ( double x )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- R8_ABS returns the absolute value of a R8.
+ R8_ABS returns the absolute value of a R8.
- Modified:
+ Modified:
- 02 April 2005
+ 02 April 2005
- Author:
+ Author:
- John Burkardt
+ John Burkardt
- Parameters:
+ Parameters:
- Input, double X, the quantity whose absolute value is desired.
+ Input, double X, the quantity whose absolute value is desired.
- Output, double R8_ABS, the absolute value of X.
-*/
-{
+ Output, double R8_ABS, the absolute value of X.
+ */
+
double value;
if ( 0.0 <= x ) {
@@ -933,38 +940,39 @@
/******************************************************************************/
double r8_epsilon ( void )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- R8_EPSILON returns the R8 round off unit.
+ R8_EPSILON returns the R8 round off unit.
- Discussion:
+ Discussion:
- R8_EPSILON is a number R which is a power of 2 with the property that,
- to the precision of the computer's arithmetic,
- 1 < 1 + R
- but
- 1 = ( 1 + R / 2 )
+ R8_EPSILON is a number R which is a power of 2 with the property that,
+ to the precision of the computer's arithmetic,
+ 1 < 1 + R
+ but
+ 1 = ( 1 + R / 2 )
- Licensing:
+ Licensing:
- This code is distributed under the GNU LGPL license.
+ This code is distributed under the GNU LGPL license.
- Modified:
+ Modified:
- 08 May 2006
+ 08 May 2006
- Author:
+ Author:
- John Burkardt
+ John Burkardt
- Parameters:
+ Parameters:
- Output, double R8_EPSILON, the double precision round-off unit.
-*/
-{
+ Output, double R8_EPSILON, the double precision round-off unit.
+ */
+
double r;
r = 1.0;
@@ -979,28 +987,29 @@
/******************************************************************************/
double r8_max ( double x, double y )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- R8_MAX returns the maximum of two R8's.
+ R8_MAX returns the maximum of two R8's.
- Modified:
+ Modified:
- 18 August 2004
+ 18 August 2004
- Author:
+ Author:
- John Burkardt
+ John Burkardt
- Parameters:
+ Parameters:
- Input, double X, Y, the quantities to compare.
+ Input, double X, Y, the quantities to compare.
- Output, double R8_MAX, the maximum of X and Y.
-*/
-{
+ Output, double R8_MAX, the maximum of X and Y.
+ */
+
double value;
if ( y < x ) {
@@ -1013,35 +1022,36 @@
/******************************************************************************/
double r8_random ( int iseed[4] )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- R8_RANDOM returns a uniformly distributed random number between 0 and 1.
+ R8_RANDOM returns a uniformly distributed random number between 0 and 1.
- Discussion:
+ Discussion:
- This routine uses a multiplicative congruential method with modulus
- 2**48 and multiplier 33952834046453 (see G.S.Fishman,
- 'Multiplicative congruential random number generators with modulus
- 2**b: an exhaustive analysis for b = 32 and a partial analysis for
- b = 48', Math. Comp. 189, pp 331-344, 1990).
+ This routine uses a multiplicative congruential method with modulus
+ 2**48 and multiplier 33952834046453 (see G.S.Fishman,
+ 'Multiplicative congruential random number generators with modulus
+ 2**b: an exhaustive analysis for b = 32 and a partial analysis for
+ b = 48', Math. Comp. 189, pp 331-344, 1990).
- 48-bit integers are stored in 4 integer array elements with 12 bits
- per element. Hence the routine is portable across machines with
- integers of 32 bits or more.
+ 48-bit integers are stored in 4 integer array elements with 12 bits
+ per element. Hence the routine is portable across machines with
+ integers of 32 bits or more.
- Parameters:
+ Parameters:
- Input/output, integer ISEED(4).
- On entry, the seed of the random number generator; the array
- elements must be between 0 and 4095, and ISEED(4) must be odd.
- On exit, the seed is updated.
+ Input/output, integer ISEED(4).
+ On entry, the seed of the random number generator; the array
+ elements must be between 0 and 4095, and ISEED(4) must be odd.
+ On exit, the seed is updated.
- Output, double R8_RANDOM, the next pseudorandom number.
-*/
-{
+ Output, double R8_RANDOM, the next pseudorandom number.
+ */
+
int ipw2 = 4096;
int it1;
int it2;
@@ -1088,26 +1098,27 @@
/******************************************************************************/
double *r8mat_gen ( int lda, int n )
+{
/******************************************************************************/
-/*
- Purpose:
+ /*
+ Purpose:
- R8MAT_GEN generates a random R8MAT.
+ R8MAT_GEN generates a random R8MAT.
- Modified:
+ Modified:
- 06 June 2005
+ 06 June 2005
- Parameters:
+ Parameters:
- Input, integer LDA, the leading dimension of the matrix.
+ Input, integer LDA, the leading dimension of the matrix.
- Input, integer N, the order of the matrix.
+ Input, integer N, the order of the matrix.
- Output, double R8MAT_GEN[LDA*N], the N by N matrix.
-*/
-{
+ Output, double R8MAT_GEN[LDA*N], the N by N matrix.
+ */
+
double *ba;
int i;
int init[4] = { 1, 2, 3, 1325 };