Main.lhs 5.02 KB
Newer Older
Simon Marlow's avatar
Simon Marlow committed
1 2

\section{Main}
3

Simon Marlow's avatar
Simon Marlow committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
 =======================================================================
  Test function: Runs the Linear System Solver (Bi-CGSTAB).

  Provides a variety of data sets and evaluation modes to excercise
  the Bi-CGSTAB iterative algorithm employing the Full Factorization
  preconditioning strategy.

  Written by Brian D. Moe (Summer 1990)
  Modified by Kamini Shenoi (Summer 1991)
  Converted to Haskell by Ian R McLelland and Cordelia V Hall (Nov 1992)
 ========================================================================


   Test may be executed by typing in a value of the form:

        test <eval_type> <data_type> <data_set> <convergence_criterion>

   where

      <eval_type> is one of:  none, bilu

                  none : no preconditioning.
                  bilu : use preconditioner.

      <data_type> is one of:   test_data, gcomp_data

        	    test_data  : Artificial and contrived test data.
                  gcomp_data : Linear system generated from actual
                               reservoir simulations.

      <data_set>  an integer.

                    If test_data is used, it indicates the size of the
                  linear system.  If gcomp_data is used, it indicates
                  which data set to use.

      <convergence_criterion> is one of: conv1, conv2

                  conv1 : (r,r) < 0.000001
                  conv2 : sqrt(r,r) < 0.0000004



   Evaluation Strategy

   none : no preconditioning.
   bilu : use the preconditioner.


   Data Type

   test_data  : a diagonally dominant simple system
   gcomp_data : a "real life" GCOMP linear system

   The data set means different things to different data types.

      test_data  :   Data set determines the size of the system.
                     There will be n^2 rows & columns of blocks.
      gcomp_data :   The data set indicates which set of files
                     to read for data.


  Convergence Criterion

  conv1 : (r,r) < 0.000001
  conv2 : sqrt(r,r) < 0.0000004
70

Simon Marlow's avatar
Simon Marlow committed
71 72 73 74
\begin{code}
import Matrix  -- matrix implementation
import Input   -- read gcomp data files
import Misc    -- for timing function and takeuntil
75
import System.Environment
Simon Marlow's avatar
Simon Marlow committed
76 77 78 79 80 81 82 83 84 85
\end{code}

AbsCg imports the actual linear system solver which uses a
simple conjugate gradient method.

Absmatlib imports the preconditioner.

\begin{code}

import AbsCg (solve_iters, Cg_state (..), show_state)
86 87 88
import Absmatlib


Simon Marlow's avatar
Simon Marlow committed
89 90 91 92


conv1 (Cg_stateC x r p q c) =
    (norm r) < 0.000001
93

Simon Marlow's avatar
Simon Marlow committed
94 95 96 97 98 99 100
conv2 (Cg_stateC x r p q c) =
    sqrt (norm r) < 0.0000004

\end{code}



101
main resps
Simon Marlow's avatar
Simon Marlow committed
102 103 104
 = [ReadChan stdin,            -- to get input parameters
    ReadFile ... ,             -- all of the data files
    AppendChan stdout result]  -- the final result
105 106
    where
    result
Simon Marlow's avatar
Simon Marlow committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120
     = case (resps !! 0) of
        (Str str) -> let (process, data, set, conv) = parseInp str
                         file1 = getFile1 set (tail resps)
                         file2a = getFile2a set (tail resps)
                         ...
                         file6 = getFile6 set (tail resps)
                      in
                      test process data set file1 ... file6a conv
        _ -> error "bad read on input"

 ToDo:
 1) write parseInp (give read a signature which does the parse)
 2) write getFile functions
 3) alter test, test' so that instead of propagating set,
121
    the files are passed to the appropriate function. For
Simon Marlow's avatar
Simon Marlow committed
122 123
    example, pass file5 to soln_vect, but just pass set to
    a_easy.
124
 4) change soln_vect, gmat, etc. so that they get the file, not
Simon Marlow's avatar
Simon Marlow committed
125 126 127 128 129 130 131 132 133 134 135 136 137
    set
 5) change readmtx, etc. so that x becomes "file"; no call
    to doread, etc. needed.


\begin{code}
main = do
    m <- getArgs
    let n = read (head m)
    putStr (result n)
          where
          result n = test bilu test_data n conv2

138
test_data = hard_data
Simon Marlow's avatar
Simon Marlow committed
139 140 141 142 143 144 145 146 147 148 149

noscale a b = (a,b)
noprecond a b = b

test process data' set conv =
    run (test' process data' set conv,
         process ++ "/" ++ data' ++ "/" ++ (show set))

test' process data' set conv
   = header ++ output ++ "\n"
     where
150 151
        output =
              concat (map (show_state soln) iterations)
Simon Marlow's avatar
Simon Marlow committed
152 153 154 155 156
        iterations =
            takeuntil conv (take maxiters all_iterations)
        all_iterations =
            solve_iters scale precond a b
        (scale,precond)
157
           = case process of
Simon Marlow's avatar
Simon Marlow committed
158 159 160 161 162 163 164
              "bilu" -> (doscale,doprecond numwells)
              "none" -> (noscale,noprecond)
              _ ->  error usage
        (a,soln,b,numwells)
           = case data' of
              "easy_data" -> (a_easy set, x1 set, mvmult a soln, 0)
              "hard_data" -> (a_hard set, x1 set, mvmult a soln, 0)
165
              "gcomp_data" -> (gmat set, soln_vect set, rhside set, wells set)
Simon Marlow's avatar
Simon Marlow committed
166 167 168 169
              _      -> error usage
        maxiters = 50
        usage =
           "Usage: test (bilu|none) (test_data|gcomp_data)" ++
170
           " num (conv1|conv2)"
Simon Marlow's avatar
Simon Marlow committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191


header :: [Char]
header =
    "\nIteration   norm (x-soln)   norm r  \n" ++
    "=========   =============   ======= \n"



easy_data = "easy_data"
hard_data = "hard_data"
gcomp_data   = "gcomp_data"
bilu      = "bilu"
none      = "none"

\end{code}





192 193


Simon Marlow's avatar
Simon Marlow committed
194