Jovan Ivković / Mbed 2 deprecated Linpack

Dependencies:   mbed

Revision:
3:da1132c65314
Parent:
2:273153e44338
Child:
4:557ad9613c6e
--- a/main.cpp	Tue Jan 03 02:31:38 2017 +0000
+++ b/main.cpp	Tue Jan 03 03:29:16 2017 +0000
@@ -1,4 +1,5 @@
 //********************************************************
+//** BETA---------------
 //**  Nucleo-144 Stm32F746 and Stm32F767 benchmark  ******
 //**  Limpack -port form Arduino IDE                 *****
 //**  Jovan Ivkovic - 2016                          ******
@@ -45,7 +46,8 @@
 int main()
 {
     //pc.baud(115200);
-    pc.baud(19200);
+    //pc.baud(19200);
+    pc.baud(9600);
 
     while(1) {
 
@@ -83,27 +85,29 @@
 # define N 8
 # define LDA ( N + 1 )
 
+    //static double a[90];
     static double *a;
     static double a_max;
+    //static double b[9];
     static double *b;
     static double b_max;
     const double cray = 0.056;
     static double eps;
     int i;
     int info;
-    static int ipvt[N];
+    static int *ipvt;
     int j;
     int job;
     double ops;
-    static double resid[N];
+    static double *resid;
     double resid_max;
     double residn;
-    static double rhs[N];
-    float t1;
-    float t2;
+    static double *rhs;
+    double t1 = 0.0;
+    double t2 = 0.0;
     static double time[6];
     double total;
-    double x[N];
+    double *x;
 
 
     pc.printf ( "\n" );
@@ -116,12 +120,13 @@
     pc.printf ( "  Matrix order N               = %d\n", N );
     pc.printf ( "  Leading matrix dimension LDA = %d\n", LDA );
 
-    ops = ( double ) ( 2L * N * N * N ) / 3.0 + 2.0 * ( double ) ( ( long ) N * N );
+    ops = ( double ) ( 2L * N * N * N ) / 3.0 + 2.0 * ( double ) ( N * N );
 
     /*
       Allocate space for arrays.
     */
     a = r8mat_gen ( LDA, N );
+    //r8mat_gen ( LDA, N, a);
 
     a_max = 0.0;
     for ( j = 0; j < N; j++ ) {
@@ -144,11 +149,11 @@
     timer.start();
     
     //*****************
-    t1 = timer.read();
+    t1 = ( double ) timer.read_us() / 1000000.0;
     
     info = dgefa ( a, LDA, N, ipvt );
 
-    t2 = timer.read();
+    t2 = ( double ) timer.read_us() / 1000000.0;
     
     if ( info != 0 ) {
         pc.printf ( "\n" );
@@ -157,17 +162,20 @@
         pc.printf ( "  Abnormal end of execution.\n" );
         return 1;
     }
-    time[0] = ( double )(t2 - t1);
+    time[0] = ( double ) t2 - t1;
+    
+    timer.stop();
+    timer.reset();
 
     //*********
-    timer.reset();
-    t1 = timer.read;
+    timer.start();
+    t1 = ( double ) timer.read_us() / 1000000.0;
 
     job = 0;
     dgesl ( a, LDA, N, ipvt, b, job );
 
-    t2 = timer.read;
-    time[1] = ( double )(t2 - t1);
+    t2 = ( double ) timer.read_us() / 1000000.0;
+    time[1] = ( double ) t2 - t1;
 
     total = time[0] + time[1];
 
@@ -178,6 +186,7 @@
       Compute a residual to verify results.
     */
     a = r8mat_gen ( LDA, N );
+    //r8mat_gen ( LDA, N, a);
 
     for ( i = 0; i < N; i++ ) {
         x[i] = 1.0;
@@ -213,11 +222,11 @@
 
     time[2] = total;
 
-        if ( total > 0.0 )
+    if ( 0.0 < total)
      {
-           time[3] = ops / ( 1.0E+06 * total );
+           time[3] = ( double ) ops / ( 1000000.0 * total );
      } 
-     else 
+    else 
      {
          time[3] = -1.0;
      }
@@ -226,29 +235,27 @@
     time[5] = total / cray;
 
     pc.printf( "\n" );
-    pc.printf( "     Norm. Resid      Resid           MACHEP         X[1]          X[N] \n\n" );
-    /*   pc.printf(" %14f", residn);
-
-       pc.printf(" %14f", resid_max);
+    pc.printf( "     Norm. Resid      Resid           MACHEP         X[1]          X[N]\n" );
 
-       pc.printf(" %f14", eps);
-
-       pc.printf(" %f14", b[0]);
+    //pc.printf(" %14f", residn);
+    //pc.printf(" %14f", resid_max);
+    //pc.printf(" %14e", eps);
+    //pc.printf(" %14f", b[0]);
+    //pc.printf(" %14f ",b[N-1]);
+    //pc.printf("\n\n");
 
-       pc.printf(" %14f ",b[N-1]);
-       pc.printf("\n\n");
-    */
+    // */
     //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" );
-    // */  
+    /*  
     for(int ii=0; ii<6; ii++) {
         pc.printf("\t %9f", time[ii]);
     }
-    
-    // pc.printf( "  %9f  %9f  %9f  %9f  %9f  %9f\n", time[0], time[1], time[2], time[3], time[4], time[5] );
+    */
+    pc.printf( "  %9f  %9f  %9f  %9f  %9f  %9f\n", time[0], time[1], time[2], time[3], time[4], time[5] );
 
     /*
       Terminate.
@@ -1091,18 +1098,18 @@
     Output, double R8MAT_GEN[LDA*N], the N by N matrix.
 */
 {
-    double *a;
+    double *ba;
     int i;
     int init[4] = { 1, 2, 3, 1325 };
     int j;
 
-    a = ( double * ) malloc ( lda * n * sizeof ( double ) );
+    ba = ( double * ) malloc ( lda * n * sizeof ( double ) );
 
     for ( j = 1; j <= n; j++ ) {
         for ( i = 1; i <= n; i++ ) {
-            a[i-1+(j-1)*lda] = r8_random ( init ) - 0.5;
+            ba[i-1+(j-1)*lda] = r8_random ( init ) - 0.5;
         }
     }
 
-    return a;
+    return ba;
 }
\ No newline at end of file