fortran - Filling Multidimensional Arrays -
i have created derived type access multi-dimensional arrays. each array associate name in array nm.
my problem consists how fill array values once have allocated memory.
an initial idea has been use multi-dimensional array input. might run memory problems if store 2 copies arrays can big. better idea might pass one-dimensional array data along first dimension , specification on position of second , third dimensions data should reside.
i value suggestions on possibly better ways fill arrays derived types if there people have experience working big data sets.
type :: multia character (len=65) :: nm(3) real, allocatable :: ma(:,:,:) real, allocatable :: mb(:,:,:) real, allocatable :: mc(:,:,:) contains procedure :: set end type multia subroutine set (m, nm, u, i, j) class (multia), intent (inout) :: m character (len=65) :: nm real, intent (in) :: u(:) integer, intent (in) :: i, j if (nm .e. (m% nm(1))) m% ma(:,i,j) = u else if (nm .e. (m% nm(2))) m% mb(:,i,j) = u else if (nm .e. (m% nm(3))) m% mc(:,i,j) = u end if end subroutine set
if concern duplication of arrays such in
m%ma = [...] ! humongous array
then fortran 2003 offers move_alloc
intrinsic moves allocation (including values) 1 variable another.
subroutine set (m, u, v, w) class (multia), intent (inout) :: m real, intent (inout), allocatable, dimension(:,:,:) :: u, v, w call move_alloc(u, m%ma) call move_alloc(v, m%mb) call move_alloc(w, m%mc) end subroutine set
called like
type(multia) m real, dimension(:,:,:), allocatable :: u, v, w ! ... allocating , setting u, v, w call m%set(u, v, w) ! components of m allocated, u, v, w, not allocated
from notes (in fortran 2008) of intrinsic:
it expected implementation of allocatable objects typically involve descriptors locate allocated storage; move alloc implemented transferring contents of descriptor descriptor , clearing descriptor from.
that is, expectation there no copying of data or array temporaries.
this assumes, of course, can't allocate components of m
, assign there directly.
Comments
Post a Comment