helsing.f90 1.5 KB

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