allocatable-array

using allocatable arrays from modules in f2py

纵然是瞬间 提交于 2021-02-10 20:47:57
问题 I'm having issues with allocatable arrays in f2py . In the code below (stored in mymod.f90 ), I created two modules, vars and worker : vars stores and allocates the array b worker contains subroutines to work with this array from vars . The first worker -subroutine adds a scalar to b . This works as expected. The problem is with the next routine that should add a vector of matching first dimension to the array b . The implemented subroutine add_vector2 works, but needs the dimension of the

using allocatable arrays from modules in f2py

感情迁移 提交于 2021-02-10 20:43:36
问题 I'm having issues with allocatable arrays in f2py . In the code below (stored in mymod.f90 ), I created two modules, vars and worker : vars stores and allocates the array b worker contains subroutines to work with this array from vars . The first worker -subroutine adds a scalar to b . This works as expected. The problem is with the next routine that should add a vector of matching first dimension to the array b . The implemented subroutine add_vector2 works, but needs the dimension of the

Fortran 90 doesn't keep lower/upper array bounds after copy to another allocatable array

孤者浪人 提交于 2021-01-27 12:21:26
问题 This doesn't work program main implicit none integer :: nx = 3 integer :: ny = 5 integer :: nz = 8 real, allocatable, dimension(:,:,:) :: A real, allocatable, dimension(:,:) :: B allocate(A(nx,0:ny,nz) ) ! ...do something with array A and at some point cope a slice of A to B: B = A(:,:,1) ! in this case B is (1:nx, 1: ny+1) end program main The code above automatically allocates B and copies A(:,:,1) to B. However it doesn't keep the lower/upper bound of 0/ny, instead B has its lower bound to

Allocatable arrays in CUDA-Fortran device data structures

萝らか妹 提交于 2020-01-07 03:38:05
问题 I'm trying to use allocatable arrays inside "device" data structures that reside in GPU memory. Code (pasted below) compiles, but gives a segfault. Am I doing something obviously wrong? Module file is called 'gpu_modules.F90', given below: !============= ! This module contains definitions for data structures and the data ! stored on the device !============= module GPU_variables use cudafor type :: data_str_def !============= ! single number quantities !============= integer :: i, j real(kind

Fortran function returning unallocated array causes segmentation fault

邮差的信 提交于 2019-12-11 00:29:08
问题 I'm struggling with some Modern Fortran wrappers to some MPI scatter/gather routines. I am trying to have a wrapper interface that only has an array on input and returns the MPI-operated result on output, for several derived types, doing something like this: type(mytype), allocatable :: chunk(:),whole(:) ! [...] chunk descends from previous parts of the code ! Get global array whole = gatherv(array=chunk,receiver_node=cpuid) I'm doing this using functions that return allocatable arrays.

Internal memory representation of Fortran allocatable

荒凉一梦 提交于 2019-12-10 21:05:53
问题 I'd like to know what is the internal memory representation of a fortran allocatable array. I understand this a bit more complex than a raw pointer, since shape and ranks must be stored as well. I also guess it's implementation dependent, since I don't find the info in the Fortran 2003 standard. However, I'd like to know what kind of structures are used to represent allocable arrays (even for just one compiler). I know the question is a bit wide, but any help would be greatly appreciated. 回答1

`Allocatable array must have deferred shape` when moving from g95 to gfortran

℡╲_俬逩灬. 提交于 2019-12-02 11:02:34
问题 When transitioning from using the g95 compiler to gfortran I get the following error when I try to compile what previously had been a working code Error: Allocatable array ' ' at (1) must have a deferred shape This happens in all of my subroutines for all of my allocatable arrays. An example is below. SUBROUTINE TEST(name,ndimn,ntype,nelem,npoin,nface,inpoel,coord,face) IMPLICIT NONE integer:: i, j,testing integer, INTENT(OUT)::ndimn,ntype,nelem,npoin,nface integer, allocatable, dimension(1:

Allocating memory in C for a Fortran allocatable

若如初见. 提交于 2019-12-01 12:56:09
We are trying to take over the memory allocation of a legacy Fortran code (+100,000 lines of code) in C++, because we are using a C library for partitioning and allocating distributed memory on a cluster. The allocatable variables are defined in modules. When we call subroutines that use these modules the index seems to be wrong (shifted by one). However, if we pass the same argument to another subroutine we get what we expect. The following simple example illustrates the issue: hello.f95: MODULE MYMOD IMPLICIT NONE INTEGER, ALLOCATABLE, DIMENSION(:) :: A SAVE END MODULE SUBROUTINE TEST(A)

Allocating memory in C for a Fortran allocatable

不想你离开。 提交于 2019-12-01 10:09:58
问题 We are trying to take over the memory allocation of a legacy Fortran code (+100,000 lines of code) in C++, because we are using a C library for partitioning and allocating distributed memory on a cluster. The allocatable variables are defined in modules. When we call subroutines that use these modules the index seems to be wrong (shifted by one). However, if we pass the same argument to another subroutine we get what we expect. The following simple example illustrates the issue: hello.f95:

Fortran: Choosing the rank of an allocatable array

我的梦境 提交于 2019-11-29 12:45:22
I am trying to write a program where I want the allocatable array A to be of either rank 1, 2, or 3, depending on my input at run-time. I want to do this since the subsequent operations on A are similar, and I have defined in a module an interface work with module procedures that when acted on A , gives the desired result. What I am doing currently is this: program main implicit none integer :: rank,n=10 real*8, allocatable :: A1(:) real*8, allocatable :: A2(:,:) read (*,*) rank if (rank.eq.1) then allocate (A1(n)) else if (rank.eq.2) then allocate (A2(n,n)) end if ! operate on the array if