program main
use mpi
Use MKL_CDFT

Integer, parameter :: N=4
complex(8), allocatable ::local_A1D(:),A(:,:)
integer :: ierr,id,len(2),numprocs,lsize,nx,lstart,i,j
type(DFTI_DESCRIPTOR_DM), POINTER :: FFT

call MPI_INIT(ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,numprocs,ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,id,ierr)

allocate(A(N,N))
a=transpose(reshape((/ 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16 /), shape(a)))
len(1)=N
len(2)=N
status = DftiCreateDescriptorDM(MPI_COMM_WORLD,FFT,DFTI_DOUBLE,DFTI_COMPLEX,2,len)
status=DftiGetValueDM(FFT,CDFT_LOCAL_SIZE,lsize)
status=DftiGetValueDM(FFT,CDFT_LOCAL_NX,nx)
status=DftiGetValueDM(FFT,CDFT_LOCAL_X_START,lstart)
print*,id, lsize,nx,lstart
allocate(local_A1D(lsize))

do i=1, N
local_A1D(i)=A(i,lstart)
enddo

Status = DftiCommitDescriptorDM(FFT)
Status = DftiComputeForwardDM(FFT,local_A1D)
Status = DftiFreeDescriptorDM(FFT)
call mpi_gather(local_A1D,lsize,MPI_COMPLEX16,A,lsize,MPI_COMPLEX16,0,mpi_comm_world,ierr)
deallocate(local_A1D)
if (id==0) print*, A
call mpi_finalize(ierr)
end program main













