Software Archive
Read-only legacy content
17061 Discussions

how can I offload more than one part of a whole array ?

Bobo_S_
Beginner
235 Views

If I have a global array A, which contains all my data. I may use different parts of A in an offload sections. How do I just copy content of parts (more than one) I am interested in to mic but not copy all the content of global array. I have an example and how can I make it work? Thanks,

      PROGRAM   MAIN
      IMPLICIT NONE
      integer N
      PARAMETER        (N=10)
      DOUBLE PRECISION, allocatable:: a(:)
      integer i
      allocate(a(N))
      do i = 1, N
         a(i) = i*0.1
      end do
      call mytest1(a,N)
      STOP
      END

      SUBROUTINE  mytest1(a,n)
      IMPLICIT NONE
      INTEGER n
      DOUBLE PRECISION a(*)
      !dir$ offload_transfer target(mic)
     &     in(a(2:3): alloc_if(.TRUE.) free_if(.FALSE.))

      !dir$ offload_transfer target(mic)
     &     in(a(5:7): alloc_if(.TRUE.) free_if(.FALSE.))

      !dir$ offload begin target(mic) nocopy(a(1:n))
      write(*,*) a(2:3)
      write(*,*) a(5:7)
      !dir$ end offload
      RETURN
      END

I can compile it, but when I run it, it gives: offload error: address range partially overlaps with existing allocation.

 Is there any way to copy more than one parts of a huge array to offload and do the calculation in offload ?

Thanks

0 Kudos
2 Replies
Ravi_N_Intel
Employee
235 Views

You cannot have "a" pointing to 2 different memory location a(2:3) and a(5:7).  You allocate the total size of the array you want and transfer sections of array data you want to use as shown below.

SUBROUTINE  mytest1(a,n)
 IMPLICIT NONE
 INTEGER n
 DOUBLE PRECISION a(*)
 !dir$ offload_transfer  target(mic) nocopy(a(1:n) : alloc_if(.TRUE.) free_if(.FALSE.))
 
 !dir$ offload_transfer target(mic) in(a(2:3): alloc_if(.FALSE.) free_if(.FALSE.))
 
 !dir$ offload_transfer target(mic) in(a(5:7): alloc_if(.FALSE.) free_if(.FALSE.))
 
 !dir$ offload begin target(mic) nocopy(a(1:n): alloc_if(.FALSE.) free_if(.TRUE.))
 write(*,*) a(2:3)
 write(*,*) a(5:7)
 !dir$ end offload
 RETURN
 END
0 Kudos
jimdempseyatthecove
Honored Contributor III
235 Views

If array a is truly intended to be global, then move it out of the PROGRAM block into a module and attribute it as residing in both places. Then insert once only code to allocate it on Host and alloc_if(.true.) and copy or not to MIC. Then do not pass (a,n) around on subroutine calls.

Jim Dempsey

0 Kudos
Reply