helsing.f90 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. program helsing
  2. ! helsing.f90
  3. ! This file creates a matrix defined by :
  4. ! A(i,j)= -log|z(i)-z(j)| , if i .neq. j
  5. ! -log|r(i)|
  6. ! where z(i) are n somehow randomly distributed points in a unit square
  7. ! centered at the origin in the complex plane and where each r(i) is a
  8. ! number in (0,d(i)[, d(i) being the distance between the point z(i)
  9. ! and its nearest neighbour.
  10. ! For more details, see:
  11. ! S. Duminil, A parallel implementation of the CMRH method for dense
  12. ! linear systems, Numer. Algor., DOI : 10.1007/s11075-012-9616-4
  13. !
  14. ! We store this matrix in matrixfile.dat
  15. ! Author: Sebastien Duminil
  16. integer :: m,n,coef,d,i,j,init(4)
  17. real(kind=8) :: l,r
  18. real(kind=8), allocatable, dimension(:) :: xx,yy,value,value2
  19. real(kind=8), allocatable, dimension(:,:) :: A
  20. open(unit=20,file='inputfile.dat',status='old')
  21. read(20,*)init
  22. n=init(1)
  23. close(20)
  24. m=n
  25. allocate(value(2*m),value2(m),xx(m),yy(m),A(n,n))
  26. open(unit=30,file='vecrand.dat',status='old')
  27. read(30,*)value
  28. do i=1,m
  29. xx(i)=value(2*i-1)
  30. yy(i)=value(2*i)
  31. end do
  32. close(30)
  33. open(unit=40,file='rand0.dat',status='old')
  34. read(40,*)value2
  35. close(40)
  36. coef=-1
  37. do i=1,n
  38. d=0
  39. do j=1,m
  40. r=dsqrt((xx(i)-xx(j))**2+(yy(j)-yy(i))**2)
  41. if (r>0) then
  42. A(i,j)=coef*log(r)
  43. if (d.eq.0)then
  44. d=j
  45. l=dble(0.5*value2(i)*dble(d))
  46. A(i,i)=-log(l)
  47. end if
  48. end if
  49. end do
  50. end do
  51. deallocate(xx,yy,value,value2)
  52. open(unit=10,file='matrixfile.dat',status='unknown')
  53. do i=1,n
  54. write(10,*) (A(i,j),j=1,n)
  55. end do
  56. close(10)
  57. deallocate(A)
  58. end program helsing