Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
34 Views

Fortran Derived Type To Intel Xeon Phi

Hi,

 

I am trying to copy an array of the following structure to Xeon Phi (offload model in KNC)

type phys
   integer , dimension(:), allocatable :: arr1
end type phys

I found out in the following article -

https://software.intel.com/en-us/articles/asynchronous-data-transfer-and-computation (para 2 last statement)

that this is not supported. Is there some recent support? What are the alternatives except fixing the dimension of arr1.

 

Thanks,

Amlesh

0 Kudos
4 Replies
Highlighted
Employee
34 Views

Sorry, the document requires some updating. We will have it revised.

There is support in our current PSXE 2016 (16.0 compiler) release for offloading a derived-type with an allocatable component. The simple example below comes from another internal report related to this support.

program offload10
      use mic_lib

      type my_derived_type
        integer                         :: i
        real                            :: r
        real, dimension(7)              :: a
        real, dimension(:), allocatable :: b
      end type

      type(my_derived_type) :: s

      allocate(s%b(7))

      s%i = 1 ;       s%r = 2. ;       s%a = 3. ;       s%b = 4.

      num_dev = OFFLOAD_NUMBER_OF_DEVICES()
      write (0,'(a,i2)') 'Host :: Number of devices = ', num_dev
      write (0,*)

      write (0,'(a,1x,i4,1x,f5.2,/,7(f5.2,1x),/,7(f5.2,1x))') 'host', s%i, s%r, s%a, s%b
      write (0,*)

!dir$ offload begin target (mic) in(s) in(s%b)
      write (0,'(a,1x,i4,1x,f5.2,/,7(f5.2,1x),/,7(f5.2,1x))') 'MIC ', s%i, s%r, s%a, s%b
      s%i = 2 ;       s%r = 4. ;       s%a = 6. ;       s%b = 8.
!dir$ end offload

      write (0,*)

!dir$ offload begin target (mic) out(s%i, s%r, s%a, s%b)
      write (0,'(a,1x,i4,1x,f5.2,/,7(f5.2,1x),/,7(f5.2,1x))') 'MIC ', s%i, s%r, s%a, s%b
!dir$ end offload

      write (0,*)
      write (0,'(a,1x,i4,1x,f5.2,/,7(f5.2,1x),/,7(f5.2,1x))') 'host', s%i, s%r, s%a, s%b
      write (0,*)

end program

 

$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.3.210 Build 20160415
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

$  ifort DPD200361783.f90
$ ./a.out
Host :: Number of devices =  2

host    1  2.00
 3.00  3.00  3.00  3.00  3.00  3.00  3.00
 4.00  4.00  4.00  4.00  4.00  4.00  4.00

MIC     1  2.00
 3.00  3.00  3.00  3.00  3.00  3.00  3.00
 4.00  4.00  4.00  4.00  4.00  4.00  4.00

MIC     2  4.00
 6.00  6.00  6.00  6.00  6.00  6.00  6.00
 8.00  8.00  8.00  8.00  8.00  8.00  8.00

host    2  4.00
 6.00  6.00  6.00  6.00  6.00  6.00  6.00
 8.00  8.00  8.00  8.00  8.00  8.00  8.00

 

0 Kudos
Highlighted
Beginner
34 Views

Hi Kevin,

I think this issue is taken care of in version 15.0.2 also (i've this version and above code works on it).

Now please have a look at the following code -

program abcde

type phys
   integer , dimension(:), allocatable :: phys_arr1
end type phys

type(phys) :: phys_array(2)
type(phys) :: phys_scalar

integer :: i, j

  do i = 1,2
    allocate(phys_array(i)%phys_arr1(16))
  end do

    allocate(phys_scalar%phys_arr1(16))

   do i = 1,16
      phys_scalar%phys_arr1(i) = i
   end do

   do i = 1,2
      do j = 1,16
          phys_array(i)%phys_arr1(j) = j
      end do
   end do

    !dir$ offload begin target(mic:0) in(phys_scalar%phys_arr1, phys_array(1)%phys_arr1,phys_array(2)%phys_arr1)
      print *,"Array 1 Mic is ",phys_array(1)%phys_arr1
      print *,"Array 2 Mic is ",phys_array(2)%phys_arr1
      print *,"Scalar Mic is ",phys_scalar
    !dir$ end offload


end program abcde

In my system, it generates the following output -

[amlesh@node5 offloading]$ ifort -v
ifort version 15.0.2
[amlesh@node5 offloading]$ ifort abcde.f90 
[amlesh@node5 offloading]$ ./a.out 
[Offload] [MIC 0] [File]                    abcde.f90
[Offload] [MIC 0] [Line]                    28
[Offload] [MIC 0] [Tag]                     Tag 0
 Array 1 Mic is            1           2           3           4           5
           6           7           8           9          10          11
          12          13          14          15          16
 Array 2 Mic is 
 Scalar Mic is            1           2           3           4           5
           6           7           8           9          10          11
          12          13          14          15          16
[Offload] [HOST]  [Tag 0] [CPU Time]        0.016002(seconds)
[Offload] [MIC 0] [Tag 0] [MIC Time]        0.010511(seconds)

Please note the strange behavior for phys_array(2). (There's one more issue, when I change the order in which I specify sending the phys_arrays in the "in" clause, I get a segmentation fault).

Even if the above issue is taken care of, what about if the dimension of phys_array is say 800 (instead of 2) and there are some 20 allocatable arrays inside the derived type "phys". It would be impractical to specify everything in the "in/inout" clause. (this is the case with the application I am working on, above is just a dummy code). Please suggest possible software solutions, if available.

 

Thanks,

Amlesh

0 Kudos
Employee
34 Views

General expressions such as phys_array(1)%phys_arr1 are not supported in the offload directives.

The compiler not issuing a diagnostic is a bug.

In your example, what you've written as phys_scalar, *is* supported.

0 Kudos
Highlighted
Employee
34 Views

Thank you Rajiv for the clarification. I escalated the non-diagnostic to Development.

(Internal tracking id: DPD200412581)

0 Kudos