0.5 is a single precision constant, and when you assign it to a double precision variable you may not have all the precision you want. If you’re lucky, like with 0.5, you have the full precision, because 0.5 has an exact representation in both single and double precision. But with 0.3 for instance you will be unlucky because it does not have an exact representation. So, when you want to make calculation in double precision, take the habit of writing double precision constants: 0.5 shoud be 0.5d0.
ipiv in you code is supposed to be an integer array.
you can take advantage of the array syntax to simplify a lot of things:
program test
implicit none
integer :: n,nrhs,lda,ldb,info
double precision, allocatable :: a(:,:),b(:),x(:)
integer, allocatable :: ipiv(:)
n = 3
allocate(A(n,n),b(N),x(N),ipiv(n))
A(1,:) = [ 3d0, 2d0, -1d0 ]
A(2,:) = [ 2d0, -2d0, 4d0 ]
A(3,:) = [ -1d0, 0.5d0, -1d0 ]
b(:) = [ 1d0, -2d0, 0d0 ]
x = b
nrhs = 1
lda = n
ldb = n
call dgesv(n,nrhs,A,lda,ipiv,x,ldb,info)
write(*,*) x(:)
end