home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CMLN1285.ZIP / CROSSTH3.LTG next >
Encoding:
Text File  |  1986-02-27  |  2.4 KB  |  75 lines

  1.  
  2.                            Listing 3.  
  3.          PPL code for concurrent matrix LU decomposition
  4.  
  5.  
  6. FUNCTION LU_Decomposition(VAR A : array[1..MAX,1..MAX] of real;
  7.                            N : integer) return boolean
  8.  
  9. è-- Matrix A is converted into a L\U matrix
  10.  
  11. BEGIN
  12.    Priority = 1
  13.    INITIALIZE: Set first colum of L\U matrix = first column of matrix A
  14.    LOOP <Complete first row>
  15.    BEGIN For i = 2 to N
  16.       L\U[1,i] = A[1,i] / A[1,1]
  17.    END LOOP <Complete first row> 
  18.    TERMINATE: None
  19.  
  20.    INITIALIZE: i = 2; Found_Error = FASLE
  21.    LOOP <Set Column>
  22.    BEGIN IF (i > N) OR  Found_Error THEN EXIT <Set Column> END IF
  23.       L\U[i,i] = A[i,i] - (vector of all elements to the left of L\U[i,i]) 
  24.                         * (vector of all elements above L\U[i,i])
  25.       INITIALIZE: First = i
  26.       LOOP <Find Zero Diagonals>
  27.       BEGIN IF (L\U[First,i] <> 0) AND (NOT Found_Error)
  28.                THEN EXIT <Find Zero Diagonals> END IF
  29.                First += 1
  30.                IF First <= N THEN Calculate L\U[First,i] 
  31.                              ELSE Found_Error = TRUE
  32.       END LOOP <Find Zero Diagonals>  
  33.  
  34.       IF Found_Error THEN EXIT <Set column> END IF
  35.  
  36.       IF First <> i 
  37.          THEN Swap rows First and 'i' in matrices A & L\U END IF
  38.    
  39.       IF First < N 
  40.           THEN StartProcedure(Do_Column(i),Priority, ColSignal) END IF
  41.  
  42.       StartProcedure(Do_Row(i), Priority, RowSignal)
  43.       Wait_Signal(ColSignal); Wait_Signal(Row_Signal)
  44.    END LOOP 
  45.    TERMINATE: None
  46.    return ( Found_Errors )
  47. END LU_Decomposition
  48.  
  49.  
  50. PROCEDURE Do_Column(i : integer)
  51. -- procedure to calculate L\U column elements in the 'i'th column
  52.  
  53. BEGIN
  54.    INITIALIZE: 
  55.    LOOP 
  56.    BEGIN For j = i+1 to N
  57.       L\U[i,j] = A[i,j] - (vector of members L\U[1,i] to L\U[i-1,i]) 
  58.                         * (vector of members L\U[j,1] to L\U[j,i-1)
  59.    END LOOP 
  60.    TERMINATE: 
  61. END Do_Column
  62.  
  63.  
  64. èPROCEDURE Do_Row(i : integer)
  65. -- procedure to calculate L\U row elements in the 'i'th row
  66.  
  67. BEGIN
  68.    INITIALIZE: 
  69.    LOOP 
  70.    BEGIN For j = i+1 to N
  71.       L\U[j,i] = A[j,i] - (vector of members L\U[1,i] to L\U[i-1,i]) 
  72.                         * (vector of members L\U[j,1] to L\U[j,i-1)
  73.       L\U[j,i] /= L\U[i,i] -- divide by diagonal element
  74.    END LOOP 
  75.    TERMINATE: 
  76. END Do_Row
  77.