Search code examples
fortranlapackblas

Packed storage with BLAS function


I want to calculate A*x with A lower triangle matrix and x the vector. For example:

     1  0  0
A =  2  4  0
     3  5  6

with packed storage

 A = (/ 1, 2, 3, 4, 5, 6/) 

and

 X = (/1, 1, 1/)

Now I want to do A*x with BLAS function, shoud I tranform A back to be a 3x3 matrix? If not, could you please give me some hint? (I know in memory of fortran array, A is contiguously stored)


Solution

  • solved by checking: http://www.icl.utk.edu/~mgates3/docs/lapack.html

    program main
    
      implicit none
      integer :: n
      real*8, allocatable, dimension(:) :: x
      real*8, allocatable, dimension(:) :: A
    
      n = 3
      allocate(A(n*(n+1)/2))
      allocate(x(n))
      A = 1.0d0
      x = 1.0d0
    
      ! x will be updated as A*x
      call dtpmv('L', 'N', 'N', n, A, x, 1)
    
      deallocate(A)
      deallocate(x)
    
    end program main