We have a project which evolves Nvidia GPU and Intel Xeon Phi. The host code and the GPU code is written in Fortran and compiled by pgfortran. To offload some of our job to the Phi, we have to make a shared library compiled by the ifort( static link cannot work) and call the shared subroutine from the pgfortran part of the code. By doing so, we can offload arrays from the pgfortran part of code to the intel fortran shared library which can communicate with the Xeon Phi.
Now I'm trying to pass a derived type which contains allocatable arrays from the pgfortran part of code to the ifort shared library. Looks like there are some problems.
Here is a simple example( no Xeon Phi offload directive here):
caller.f90:
program caller
type cell
integer :: id
real, allocatable :: a(:)
real, allocatable :: b(:)
real, allocatable :: c(:)
end type cell
integer :: n,i,j
type(cell) :: cl(2)
n=10
do i=1,2
allocate(cl(i)%a(n))
allocate(cl(i)%b(n))
allocate(cl(i)%c(n))
end do
do j=1, 2
do i=1, n
cl(j)%a(i)=10*j+i
cl(j)%b(i)=10*i+j
end do
end do
call offload(cl(1))
print *, cl(1)%c
end program caller
called.f90:
subroutine offload(cl)
type cell
integer :: id
real, allocatable :: a(:)
real, allocatable :: b(:)
real, allocatable :: c(:)
end type cell
type(cell) :: cl
integer :: n
print *, cl%a(1:10)
print *, cl%b(1:10)
end subroutine offload
Makefile:
run: caller.o libcalled.so
pgfortran -L. caller.o -lcalled -o $@
caller.o: caller.f90
pgfortran -c caller.f90
libcalled.so: called.f90
ifort -shared -fPIC $^ -o $@
Notice the "cl%a(1:10)" here, witout the "(1:10)" there would be nothing printed.
This code finally printed out the elements in the cl(1)%a and then hit a segmentation fault in the next line where I tried to print out the array cl(1)%b.
If I change the "cl%a(1:10)" to "cl%a(1:100)", and delete the "print *, cl%b(1:10)". It would give a result of:

We can find that the elements in the b array are there but I just can not fetch them by the "cl%b(1:10)".
I know that this may be caused by the different derived type structure of different compilers. But I really want a way by which we can pass this kind of derived type between compilers. Any solutions?
Thank you!