# cuda fortran fdtd code and i have problem with shared memory

**URL:** <https://forums.developer.nvidia.com/t/cuda-fortran-fdtd-code-and-i-have-problem-with-shared-memory/134998>\
**Category:** Legacy PGI Compilers (archived)\
**Created:** [August 15, 2016, 1:12pm UTC](https://forums.developer.nvidia.com/t/cuda-fortran-fdtd-code-and-i-have-problem-with-shared-memory/134998 "2016-08-15T13:12:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmiri61](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rmiri61](https://forums.developer.nvidia.com/u/rmiri61)\
**Post date:** [August 15, 2016, 1:12pm UTC](https://forums.developer.nvidia.com/t/cuda-fortran-fdtd-code-and-i-have-problem-with-shared-memory/134998/1 "2016-08-15T13:12:54Z")

</div>

hello …

there is part of my simple code that i use shared memory to make process time faster but i get wrong answer … it seems that phi0 don’t shift in array … for simplicity i used one block threads in dimension of (64:64) …

i’ll be appreciate if you tell me that where is my problem ?

!!!  
module simpleOps\_m  
use cudafor  
contains

attributes(global) subroutine inc(phip1,phim1,phi0,coef,rho0, ds,N\_z,N\_rho)

implicit none  
!my dimension is (64:64)  
real\*8 :: phim1(64,64),phi0(64,64),coef(64,64),rho0(64,64)

real\*8 , shared :: phim1\_s(64,64) , coef\_s(64,64) , rho0\_s(64,64),&  
phip1\_s(64,64),phi0\_s(64,64)

real_8 :: phip1(64,64)  
real_8, value :: ds  
integer , value :: N\_z,N\_rho

integer :: is , js , i , j

!!! local shared array  
is=threadidx%x  
js=threadidx%y  
  
  
  
  
phim1\_s(is,js) = phim1(is,js)  
coef\_s(is,js) = coef(is,js)  
rho0\_s(is,js) = rho0(is,js)  
phip1\_s(is,js) = phip1(is,js)  
phi0\_s(is,js) = phi0(is,js)

call syncthreads()

if(is\>1 .AND. is\<64 .AND. js\>1 .AND. js\<64) then

phip1\_s(is,js)=-phim1\_s(is,js)+coef\_s(is,js)\*((-4.0d0+2.0d0/coef\_s(is,js))_phi0\_s(is,js) &  
+phi0\_s(is-1,js) & !..%down to center  
+phi0\_s(is+1,js) & !..%up to center  
+(1.0d0-ds/(2.0d0_rho0\_s(is,js)))_phi0\_s(is,js-1) & !..%left to center  
+(1.0d0+ds/(2.0d0_rho0\_s(is,js)))\*phi0\_s(is,js+1))

end if

call syncthreads()  
  
  
phip1(is,js) = phip1\_s(is,js)  
  
  
end subroutine inc  
end module simpleOps\_m  
!!!

i import my variables and then transfer them to shared memory and then used them but i get wrong answer because phi0 don’t shift …

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [August 15, 2016, 3:49pm UTC](https://forums.developer.nvidia.com/t/cuda-fortran-fdtd-code-and-i-have-problem-with-shared-memory/134998/2 "2016-08-15T15:49:43Z")

</div>

Hi MIRI,

I don’t see anything obvious in this code snip-it that would account for incorrect answers. However, I’m not sure what you mean when you wrote “it seems that phi0 don’t shift in array”.

Can you please explain a bit more on what you believe is the cause for the error? Also, can you either post or sent to PGI Customer Service ([trs@pgroup.com](mailto:trs@pgroup.com)) an example that we can use to replicate the issue?

Thanks,  
Mat
