Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. program main
  2.  
  3. complex(8),allocatable::array(:,:)
  4.  
  5. allocate(array(17, 17))
  6. array = 1.0d0
  7.  
  8. call fft(array(1:16,1:16))
  9.  
  10. contains
  11.  
  12. subroutine fft(a)
  13. use mkl_dfti
  14.  
  15. implicit none
  16.  
  17. complex(8),intent(inout)::a(:,:)
  18.  
  19. type(dfti_descriptor),pointer::desc
  20. integer::stat
  21.  
  22. stat = DftiCreateDescriptor(desc, DFTI_DOUBLE, DFTI_COMPLEX, 2, shape(a) )
  23. stat = DftiCommitDescriptor(desc)
  24. stat = DftiComputeForward(desc, a(:,1))
  25. stat = DftiFreeDescriptor(desc)
  26.  
  27. end subroutine
  28.  
  29. end program
  30.  
  31. program main
  32. implicit none
  33.  
  34. real(8),allocatable::a(:,:)
  35.  
  36. pause
  37.  
  38. allocate(a(8192,8192))
  39.  
  40. pause
  41.  
  42. call random_number(a)
  43.  
  44. pause
  45.  
  46. call foo(a(:4096,:4096))
  47.  
  48. pause
  49.  
  50. contains
  51.  
  52. subroutine foo(a)
  53. implicit none
  54.  
  55. real(8)::a(:,:)
  56.  
  57. open(unit=16, file='a_sum.txt')
  58.  
  59. write(16, *) sum(a)
  60.  
  61. close(16)
  62.  
  63. end subroutine
  64.  
  65. end program
  66.  
  67. module m_foo
  68. implicit none
  69.  
  70. contains
  71.  
  72. subroutine foo(a)
  73. implicit none
  74.  
  75. real(8),contiguous::a(:,:)
  76.  
  77. integer::i, j
  78.  
  79. open(unit=16, file='a_sum.txt')
  80.  
  81. write(16, *) sum(a)
  82.  
  83. close(16)
  84.  
  85. call nointerface(a)
  86.  
  87. end subroutine
  88.  
  89. end module
  90.  
  91. subroutine nointerface(a)
  92. implicit none
  93.  
  94. real(8)::a(*)
  95.  
  96. end subroutine
  97.  
  98. program main
  99. use m_foo
  100.  
  101. implicit none
  102.  
  103. integer,parameter::N = 8192
  104. real(8),allocatable::a(:,:)
  105.  
  106. integer::i, j
  107. real(8)::count
  108.  
  109. pause
  110.  
  111. allocate(a(N, N))
  112.  
  113. pause
  114.  
  115. call random_number(a)
  116.  
  117. pause
  118.  
  119. call foo(a(:N/2,:N/2))
  120.  
  121. pause
  122.  
  123. end program
  124.  
  125. program main
  126. implicit none
  127.  
  128. complex(8),allocatable::a(:,:)
  129.  
  130. allocate(a(16,16))
  131.  
  132. a = 0.0d0
  133. a(1:4,1:4) = 1.0d0
  134.  
  135. call fft(a(1:4,1:4))
  136.  
  137. write(*,*) a(1:4,1:4)
  138.  
  139. pause
  140.  
  141. a = 0.0d0
  142. a(1:4,1:4) = 1.0d0
  143.  
  144. call fft_stride(a(1:4,1:4), 1, 16)
  145.  
  146. write(*,*) a(1:4,1:4)
  147.  
  148. pause
  149.  
  150. contains
  151.  
  152. subroutine fft(a) !{{{
  153. use mkl_dfti
  154.  
  155. implicit none
  156.  
  157. complex(8),intent(inout)::a(:,:)
  158.  
  159. type(dfti_descriptor),pointer::desc
  160. integer::stat
  161.  
  162. stat = DftiCreateDescriptor(desc, DFTI_DOUBLE, DFTI_COMPLEX, 2, shape(a) )
  163. stat = DftiCommitDescriptor(desc)
  164. stat = DftiComputeForward(desc, a(:,1))
  165. stat = DftiFreeDescriptor(desc)
  166.  
  167. end subroutine !}}}
  168.  
  169. subroutine fft_stride(a, s1, s2) !{{{
  170. use mkl_dfti
  171.  
  172. implicit none
  173.  
  174.  
  175. complex(8),intent(inout)::a(:,:)
  176. integer::s1, s2
  177.  
  178. type(dfti_descriptor),pointer::desc
  179. integer::stat
  180.  
  181. integer::strides(3)
  182.  
  183. strides = [0, s1, s2]
  184.  
  185. stat = DftiCreateDescriptor(desc, DFTI_DOUBLE, DFTI_COMPLEX, 2, shape(a) )
  186. stat = DftiSetValue(desc, DFTI_INPUT_STRIDES, strides)
  187. stat = DftiCommitDescriptor(desc)
  188. stat = DftiComputeForward(desc, a(:,1))
  189. stat = DftiFreeDescriptor(desc)
  190.  
  191. end subroutine !}}}
  192.  
  193. end program
  194.  
  195. program ...
  196. call fft(4,4,a(1:4,1:4))
  197. end program
  198.  
  199. subroutine fft(m,n,a) !{{{
  200. use mkl_dfti
  201.  
  202. implicit none
  203.  
  204. complex(8),intent(inout)::a(*)
  205. integer :: m, n
  206.  
  207. type(dfti_descriptor),pointer::desc
  208. integer::stat
  209.  
  210. stat = DftiCreateDescriptor(desc, DFTI_DOUBLE, DFTI_COMPLEX, 2, (/m,n/) )
  211. stat = DftiCommitDescriptor(desc)
  212. stat = DftiComputeForward(desc, a)
  213. stat = DftiFreeDescriptor(desc)
  214.  
  215. end subroutine !}}}
  216.  
  217. program ...
  218. call fft_strided(4,4,a,16)
  219. end program
  220.  
  221. subroutine fft_strided(m,n,a,lda) !{{{
  222. use mkl_dfti
  223.  
  224. implicit none
  225.  
  226. complex(8),intent(inout)::a(*)
  227. integer :: m, n, lda
  228.  
  229. type(dfti_descriptor),pointer::desc
  230. integer::stat
  231.  
  232. integer::strides(3)
  233.  
  234. strides = [0, 1, lda]
  235.  
  236. stat = DftiCreateDescriptor(desc, DFTI_DOUBLE, DFTI_COMPLEX, 2, (/m,n/) )
  237. stat = DftiSetValue(desc, DFTI_INPUT_STRIDES, strides)
  238. stat = DftiCommitDescriptor(desc)
  239. stat = DftiComputeForward(desc, a)
  240. stat = DftiFreeDescriptor(desc)
  241.  
  242. end subroutine !}}}
  243.  
  244. integer, dimension(10:20) :: array
  245. integer :: i
  246.  
  247. array = [ (i, i=10,20) ]
  248. call foo(array(10:20:2))
  249.  
  250. subroutine foo(a)
  251. integer, dimension(:) :: a
  252. integer :: i
  253.  
  254. print*, lbound(a), ubound(a)
  255. do i=lbound(a,1), ubound(a,2)
  256. print*, a(i)
  257. end do
  258.  
  259. end subroutine foo
  260.  
  261. 1 6
  262. 10 12 14 16 18 20
  263.  
  264. integer, dimension(10:) :: a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement