Note that there are some explanatory texts on larger screens.

plurals
  1. POPass a fortran derived type which contains allocatable array between different compilers(PGI and Intel)
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>Here is a simple example( no Xeon Phi offload directive here):</p> <p>caller.f90:</p> <pre><code>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 </code></pre> <p>called.f90:</p> <pre><code>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 </code></pre> <p>Makefile:</p> <pre><code>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 $@ </code></pre> <p>Notice the "<code>cl%a(1:10)</code>" here, witout the "<code>(1:10)</code>" there would be nothing printed. </p> <p>This code finally printed out the elements in the <code>cl(1)%a</code> and then hit a segmentation fault in the next line where I tried to print out the array <code>cl(1)%b</code>.</p> <p>If I change the "<code>cl%a(1:10)</code>" to "cl%a(1:100)", and delete the "<code>print *, cl%b(1:10)</code>". It would give a result of:</p> <p><img src="https://i.stack.imgur.com/cGgG6.png" alt="results"></p> <p>We can find that the elements in the b array are there but I just can not fetch them by the "<code>cl%b(1:10)</code>".</p> <p>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? </p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload