Hello! Right now I'm hoping to point data that is inside a derived type to an array (target) that is of different dimensions and is passed to the rest of the world (e.g. Python) via iso_c_binding. The application is a ray trace program, where each derived type is passed to and computed in a separate thread via openMP, and all the results are aggregated into the c type arrays. I'd like to point 1D arrays inside the derived types to subsets of higher-D (more than 3D) arrays.
The following is drawn from my current attempt to accomplish this. Obviously it doesn't work, so I'm grateful in advance either for tips to fix, or a possible alternate approach! (I feel like I'm headed the wrong way, though it's possibly because the shape that this code has taken over the last few years (my fault) has penned me in.)
module dataInterface type rayType real, dimension(:), pointer :: x, y, z real :: initElev, initAz, finElev, finAz, freq end type type inputParams integer :: nPts, nFreq, nAz, nElev end type end module
subroutine rayMain(inputParams, outputX, outputY, outputZ) bind(c, name="rayMain") use dataInterface use iso_c_binding implicit none real(c_double), dimension(inputParams%nPts, inputParams%nFreq, inputParams%nElev, inputParams%nAz), target :: outputX, outputY, outputZ type(rayType), dimension( inputParams%nFreq, inputParams%nElev, inputParams%nAz) :: rays real(dp), dimension(inputParams%nFreq) :: f real(dp), dimension(inputParams%nAz) :: az real(dp), dimension(inputParams%nElev) :: elev integer :: ii, jj, kk do ii = 1,inputParams%nFreq do jj = 1, inputParams%nElev do kk = 1,inputParams%nAz rays(ii,jj,kk)%x => outputX(:,ii,jj,kk) rays(ii,jj,kk)%y => outputY(:,ii,jj,kk) rays(ii,jj,kk)%z => outputZ(:,ii,jj,kk) enddo enddo enddo ! this is not complete, obviously, but the ray trace is looped over the lists of frequencies and initial angles ... call raytrace(rays, elev, az, f) end subroutine
Note that there are other moving parts, such as porting onto GPGPU, so moving data onto and off of devices is a factor, as is overall memory usage efficiency (i.e., not carving off and writing/reading multiple copies of the same data in memory). I'm trying to narrow the scope of this question!