#!/usr/bin/env bash
                
DEBUG="no"
FORMAT_TEST="yes"
STOP_TIME="1"
MAX_ITERATIONS="10"
export CUDA_PROFILE=0

PWD=`pwd`
IWD="$PWD"
BASE="ftp://math.nist.gov/pub/MatrixMarket2/Harwell-Boeing/"
SPARSE_MATRIX_BENCHMARK="tnl-sparse-matrix-benchmark"
SPARSE_MATRIX_BENCHMARK_DBG="tnl-sparse-matrix-benchmark-dbg"
#SPARSE_MATRIX_BENCHMARK="tnl-sparse-matrix-benchmark-dbg"

export CUDA_PROFILE_CONFIG="$IWD/cuda-profiler.conf"
PROCESS_CUDA_PROFILE="$IWD/process-cuda-profile.pl"
source matrix-market
source florida-matrix-market

write_header()
{
   echo "<html>" > $1
   echo "   <body>" >> $1
   echo "      <table border=1>" >> $1
   echo "          <tr>" >> $1
   echo "             <td rowspan=4 colspan=4 align=center>Matrix</td>" >> $1
   echo "             <td rowspan=4 colspan=2 align=center>CSR</td>" >> $1
   echo "             <td rowspan=4 colspan=3 align=center>Cusparse</td>" >> $1
   echo "             <td rowspan=4 colspan=3 align=center>Hybrid</td>" >> $1
   echo "             <td colspan=68 align=center>Row-Grouped CSR</td>" >> $1   
   echo "             <td colspan=68 align=center>Row-Grouped CSR with rows sorted decreasingly by the number of the nonzeros</td>" >> $1
   echo "             <td colspan=120 align=center>Adaptive Row-Grouped CSR</td>" >> $1   
   echo "          </tr>" >> $1
   
   echo "          <tr>" >> $1
   echo "             <td colspan=17>Group Size = 16</td>" >> $1       # RgCSR
   echo "             <td colspan=17>Group Size = 32</td>" >> $1
   echo "             <td colspan=17>Group Size = 64</td>" >> $1
   echo "             <td colspan=17>Group Size Variable</td>" >> $1    # RgCSR adaptive group size
   echo "             <td colspan=17>Group Size = 16</td>" >> $1       # RgCSR rows sorted decreasingly
   echo "             <td colspan=17>Group Size = 32</td>" >> $1
   echo "             <td colspan=17>Group Size = 64</td>" >> $1
   echo "             <td colspan=17>Group Size Variable</td>" >> $1      # RgCSR rows sorted decreasingly, adaptive group size
   echo "             <td rowspan=2 colspan=20>Chunk Size = 1</td>" >> $1          # Adaptive RgCSR 
   echo "             <td rowspan=2 colspan=20>Chunk Size = 2</td>" >> $1
   echo "             <td rowspan=2 colspan=20>Chunk Size = 4</td>" >> $1
   echo "             <td rowspan=2 colspan=20>Chunk Size = 8</td>" >> $1
   echo "             <td rowspan=2 colspan=20>Chunk Size = 16</td>" >> $1
   echo "             <td rowspan=2 colspan=20>Chunk Size = 32</td>" >> $1   
   echo "          </tr>" >> $1
   
   echo "          <tr>" >> $1
   echo "             <td rowspan=2 colspan=2></td>" >> $1                         # RgCSR format with the group size = 16
   echo "             <td rowspan=2 colspan=3>CPU</td>" >> $1
   echo "             <td colspan=12>GPU</td>" >> $1
   echo "             <td rowspan=2 colspan=2></td>" >> $1                         # RgCSR format with the group size = 32
   echo "             <td rowspan=2 colspan=3>CPU</td>" >> $1
   echo "             <td colspan=12>GPU</td>" >> $1   
   echo "             <td rowspan=2 colspan=2></td>" >> $1                         # RgCSR format with the group size = 64
   echo "             <td rowspan=2 colspan=3>CPU</td>" >> $1
   echo "             <td colspan=12>GPU</td>" >> $1

   echo "             <td rowspan=2 colspan=2></td>" >> $1                         # RgCSR format with the variable group size 
   echo "             <td rowspan=2 colspan=3>CPU</td>" >> $1
   echo "             <td colspan=12>GPU</td>" >> $1
   
   echo "             <td rowspan=2 colspan=2></td>" >> $1                         # RgCSR (sorted rows) format with the group size = 16
   echo "             <td rowspan=2 colspan=3>CPU</td>" >> $1
   echo "             <td colspan=12>GPU</td>" >> $1
   echo "             <td rowspan=2 colspan=2></td>" >> $1                         # RgCSR (sorted rows) format with the group size = 32
   echo "             <td rowspan=2 colspan=3>CPU</td>" >> $1
   echo "             <td colspan=12>GPU</td>" >> $1   
   echo "             <td rowspan=2 colspan=2></td>" >> $1                         # RgCSR (sorted rows) format with the group size = 64
   echo "             <td rowspan=2 colspan=3>CPU</td>" >> $1
   echo "             <td colspan=12>GPU</td>" >> $1
      
   echo "             <td rowspan=2 colspan=2></td>" >> $1                         # RgCSR (sorted rows) format with variable group size
   echo "             <td rowspan=2 colspan=3>CPU</td>" >> $1
   echo "             <td colspan=12>GPU</td>" >> $1
   
#   echo "             <td colspan=20>GPU</td>" >> $1                     # Adaptive RgCSR format with the chunk size 1
#   echo "             <td colspan=20>GPU</td>" >> $1                     # Adaptive RgCSR format with the chunk size 2
#   echo "             <td colspan=20>GPU</td>" >> $1                     # Adaptive RgCSR format with the chunk size 4
#   echo "             <td colspan=20>GPU</td>" >> $1                     # Adaptive RgCSR format with the chunk size 8
#   echo "             <td colspan=20>GPU</td>" >> $1                     # Adaptive RgCSR format with the chunk size 16
#   echo "             <td colspan=20>GPU</td>" >> $1                     # Adaptive RgCSR format with the chunk size 32
   
   
   
                  
   echo "          </tr>" >> $1
   
   echo "          <tr>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 32</td>" >> $1        # RgCSR format with the group size = 16
   echo "             <td colspan=3>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 256</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 32</td>" >> $1        # RgCSR format with the group size = 32
   echo "             <td colspan=3>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 256</td>" >> $1         
   echo "             <td colspan=3>CUDA Block Size = 32</td>" >> $1        # RgCSR format with the group size = 64
   echo "             <td colspan=3>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 256</td>" >> $1
   
   echo "             <td colspan=3>CUDA Block Size = 32</td>" >> $1        # RgCSR format with the group size cca 16
   echo "             <td colspan=3>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 256</td>" >> $1
   
   
   echo "             <td colspan=3>CUDA Block Size = 32</td>" >> $1        # RgCSR (sorted rows) format with the group size = 16
   echo "             <td colspan=3>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 256</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 32</td>" >> $1        # RgCSR (sorted rows) format with the group size = 32
   echo "             <td colspan=3>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 256</td>" >> $1         
   echo "             <td colspan=3>CUDA Block Size = 32</td>" >> $1        # RgCSR (sorted rows) format with the group size = 64
   echo "             <td colspan=3>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 256</td>" >> $1
   
   echo "             <td colspan=3>CUDA Block Size = 32</td>" >> $1        # RgCSR (sorted rows) format with the group size >= 16
   echo "             <td colspan=3>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=3>CUDA Block Size = 256</td>" >> $1
   
   echo "             <td colspan=5>CUDA Block Size = 32</td>" >> $1        # Adaptive RgCSR format with the chunk size = 1
   echo "             <td colspan=5>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 256</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 32</td>" >> $1        # Adaptive RgCSR format with the chunk size = 2
   echo "             <td colspan=5>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 256</td>" >> $1         
   echo "             <td colspan=5>CUDA Block Size = 32</td>" >> $1        # Adaptive RgCSR format with the chunk size = 4
   echo "             <td colspan=5>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 256</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 32</td>" >> $1        # Adaptive RgCSR format with the chunk size = 8
   echo "             <td colspan=5>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 256</td>" >> $1  
   echo "             <td colspan=5>CUDA Block Size = 32</td>" >> $1        # Adaptive RgCSR format with the chunk size = 16
   echo "             <td colspan=5>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 256</td>" >> $1  
   echo "             <td colspan=5>CUDA Block Size = 32</td>" >> $1        # Adaptive RgCSR format with the chunk size = 32
   echo "             <td colspan=5>CUDA Block Size = 64</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 128</td>" >> $1
   echo "             <td colspan=5>CUDA Block Size = 256</td>" >> $1  
     
            
   echo "          </tr>" >> $1      
         
   echo "          <tr>" >> $1
   echo "             <td>Name</td>" >> $1                      # Matrix description
   echo "             <td>Size</td>" >> $1
   echo "             <td>NonZeros No.</td>" >> $1
   echo "             <td>NonZeros %</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1                 # CSR format on CPU
   echo "             <td>GFlops</td>" >> $1                    

   echo "             <td>Time/sec.</td>" >> $1                 # Cusparse
   echo "             <td>GFlops</td>" >> $1                    
   echo "             <td>Speed-up</td>" >> $1
   
   echo "             <td>Time/sec.</td>" >> $1                 # Hybrid format Bell, Garland on GPU
   echo "             <td>GFlops</td>" >> $1                    
   echo "             <td>Speed-up</td>" >> $1
   
   echo "             <td>Info</td>" >> $1                      # RgCSR format with the group size = 16
   echo "             <td>Artificial Zeros</td>" >> $1    
   echo "             <td>Time/sec.</td>" >> $1  
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1      
   echo "             <td>Info</td>" >> $1                      # RgCSR format with the group size = 32
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1      
   echo "             <td>Info</td>" >> $1                      # RgCSR format with the group size = 64   
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1          
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   
   echo "             <td>Info</td>" >> $1                        # RgCSR format with the group size variable
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1      
   
   echo "             <td>Info</td>" >> $1                        # RgCSR (sorted rows) format with the group size = 16
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1      
   echo "             <td>Info</td>" >> $1                        # RgCSR (sorted rows) format with the group size = 32   
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1      
   echo "             <td>Info</td>" >> $1                         # RgCSR (sorted rows) format with the group size = 64   
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   
   echo "             <td>Info</td>" >> $1                          # RgCSR (sorted rows) format with the group size variable
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1      
   
   echo "             <td>Info</td>" >> $1                         # Adaptive RgCSR format with the chunk size = 1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1                         # Adaptive RgCSR format with the chunk size = 2   
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1                        # Adaptive RgCSR format with the chunk size = 4   
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1                        # Adaptive RgCSR format with the chunk size = 8   
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1                        # Adaptive RgCSR format with the chunk size = 16   
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1                        # Adaptive RgCSR format with the chunk size = 32   
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1
   echo "             <td>Info</td>" >> $1
   echo "             <td>Artificial Zeros</td>" >> $1
   echo "             <td>Time/sec.</td>" >> $1   
   echo "             <td>GFlops</td>" >> $1
   echo "             <td>Speed-up</td>" >> $1   
}

write_closing()
{
   echo "      </table>" >> $1
   echo "   </body>" >> $1
   echo "</html>" >> $1
}

write_header sparse-matrix-benchmark-float.log.html
write_header sparse-matrix-benchmark-double.log.html
write_header sparse-matrix-benchmark-amd-float.log.html
write_header sparse-matrix-benchmark-amd-double.log.html

for link in $MM_MATRICES;
do
   echo "###############################################################################################"
   matrix=matrices`echo $link | sed 's/ftp:\/\/math.nist.gov\/pub//'`
   unzipped_matrix=`echo $matrix | sed 's/.gz//'`
   if test ! -e $matrix;
   then
      echo "Matrix $matrix is missing !!! Run the script 'get-matrices' first."
      #echo "Matrix $matrix is missing !!! Run the script 'get-matrices' first." >> sparse-matrix-benchmark.log            
   else
      gunzip -c ${matrix} > ${unzipped_matrix}      
      echo "Checking with the matrix $unzipped_matrix in single precision ..."
      export CUDA_PROFILE_LOG=$unzipped_matrix.float.log
      if test x$DEBUG = xyes;
      then
         gdb --args ${SPARSE_MATRIX_BENCHMARK_DBG} --input-mtx-file $unzipped_matrix --log-file sparse-matrix-benchmark-float.log.html --stop-time $STOP_TIME --max-iterations $MAX_ITERATIONS --verbose 1
      else
         $SPARSE_MATRIX_BENCHMARK --input-mtx-file $unzipped_matrix --pdf-file $unzipped_matrix.pdf --log-file sparse-matrix-benchmark-float.log.html --stop-time $STOP_TIME --max-iterations $MAX_ITERATIONS --format-test $FORMAT_TEST --verbose 1
      fi
      #perl $PROCESS_CUDA_PROFILE $unzipped_matrix.float.log sparse-matrix-profiling-float.log          
   fi
done

for link in $FLORIDA_MM_MATRICES;
do
   matrix=matrices`echo $link | sed 's/http:\/\/www.cise.ufl.edu\/research\/sparse//'`
   if test ! -e $matrix;
   then      
      echo "Matrix $matrix is missing !!! Run the script 'get-matrices' first."
      #echo "Matrix $matrix is missing !!! Run the script 'get-matrices' first." >> sparse-matrix-benchmark.log
   else
     DIRNAME=`dirname $matrix`
     FILENAME=`basename $matrix`
     cd $DIRNAME
     tar zxvf $FILENAME
     cd $IWD
     SUBDIRNAME=`echo $FILENAME | sed 's/.tar.gz//'`
     rm -f $DIRNAME/$SUBDIRNAME/*_b.mtx # these are usualy in array format
     for file in $DIRNAME/$SUBDIRNAME/*.mtx;
     do
         echo "###############################################################################################"
         echo "Checking with the matrix $file ..."
         $SPARSE_MATRIX_BENCHMARK --input-file $file.float.bin.bz2 --input-mtx-file $file --pdf-file $file.pdf --log-file sparse-matrix-benchmark-float.log.html --stop-time $STOP_TIME --max-iterations $MAX_ITERATIONS --format-test $FORMAT_TEST --verbose 1                        
     done
   fi
done

write_closing sparse-matrix-benchmark-float.log.html
write_closing sparse-matrix-benchmark-double.log.html
write_closing sparse-matrix-benchmark-amd-float.log.html
write_closing sparse-matrix-benchmark-amd-double.log.html   

