title: Question regarding the syntax of SGESV in Fortran
body: <p>I am a bit confused on this subroutine. I have read the documentation but I am a bit confused what exactly the IPIV vector does and how exactly I set my leading dimension. I read that the leading dimension helps to find the starting point for the matrix elements in each successive column of the array. For example lets say we want to solve</p>
  <pre><code>Ax = B
  </code></pre>
  <p>where</p>
  <pre><code>integer, parameter :: sp = selected_real_kind(6,37)
  real(kind=sp),dimension(:,:),intent(inout) :: A
  real(kind=sp),dimension(:),intent(inout) :: B
  integer, dimension(10) :: IPIV
  </code></pre>
  <p>where sp is for single precision which I have set in my main program
  and the dimensions are</p>
  <pre><code>A(10,10)
  B(10)
  </code></pre>
  <p>which are set in my main program and passed to this subroutine
  Should I set my subroutine as</p>
  <pre><code>integer :: n,INFO
  n = size(A,1)
  
  
  IPIV = 0
  call SGESV(n,n,A,2*n,IPIV,B,2*n,INFO)
  </code></pre>
  <p>or</p>
  <pre><code>call SGESV(n,n,A,n,IPIV,B,n,INFO)
  </code></pre>
  <p>and for IPIV I should just create a vector of size 10 and initialize it with zeros?</p>
  <hr />
  <p>edit : I have used</p>
  <pre><code>call sgesv(n, n, A, n, ipiv, B, n, INFO)
  </code></pre>
  <p>as proposed as well but I get a segmentation error Program received signal SIGSEGV: Segmentation fault - invalid memory reference.</p>
  <p>I have printed the matrix sizes and they are correct which are the size of the matrix A is 100 and the size of the vector is 10</p>
  <p>Edit2 : So in my main I have a loop which inside my loop it calculates a matrix of A (10,10) and a vector B(10) at each iteration. Then I call my subroutine to solve the system</p>
  <pre><code>call solver(A,B)
  
  </code></pre>
  <p>However I get the segmentation error which I do not understand since the dimensions are correct. (To check it I printed the size of the matrix and the vector and commented out the call to my subroutine and they are 100 and 10)</p>
  <p>Perhaps I should make my matrices allocatable? But I do not see a problem with that since at each iteration I calculate the matrix and the vector though a series of calculations and overwrite them.</p>
  <p>Basically I declare the matrix and the vector as follows</p>
  <pre><code>   real(sp) , dimension (10) :: B
     real(sp) , dimension (10,10) :: A
  </code></pre>
  <p>then inside my loop a series of calculations are performed to fill them with values
  and then I call my subroutine
  and then repeat with new values</p>