gfortran

Passing an internal procedure as argument

被刻印的时光 ゝ 提交于 2019-12-18 06:50:32
问题 I want to solve a differential equation lots of times for different parameters. It is more complicated than this, but for the sake of clarity let's say the ODE is y'(x) = (y+a)*x with y(0) = 0 and I want y(1) . I picked the dverk algorithm from netlib for solving the ODE and it expects the function on the right hand side to be of a certain form. Now what I did with the Intel Fortran compiler is the following (simplified): subroutine f(x,a,ans) implicite none double precision f,a,ans,y,tol,c

Fortran array cannot be returned in function: not a DUMMY variable

北城以北 提交于 2019-12-18 06:49:38
问题 Being new to Fortran 90 free-form, I would really like to know why the following piece of code snippet would not work: program test2 implicit none !!! A program to practice f90 writing. ! Define double precision data integer, parameter :: dp = kind(1.d0) real(dp) :: a(3), b(3) integer :: i a = (/(i, i=1, 3)/) b = (/(i, i=1, 3)/) write (*, *) m31tensorprod(a, b) contains function m31tensorprod(a, b) real(dp), dimension(3), intent(in) :: a, b real(dp), intent(out) :: m31tensorprod(3, 3) integer

Combining F77 and F95 fortran code

岁酱吖の 提交于 2019-12-17 21:13:19
问题 I'm working on some scientific code that is mostly F77 but also some F95. In places, I need to include F77 code into my F95 code. Is there a way to get this code to play nicely within my code by using a particular compiler flag or something? I'm using gfortran and occasionally ifort. It is possible for me to modify the legacy code but I would need to do it in a sensible way to maintain backwards compatibility with other F77 code while also being forwards compatible with F95 code. I get errors

gfortran openmp segmentation fault occurs on basic do loop

丶灬走出姿态 提交于 2019-12-17 16:53:46
问题 I have a program which distributes particles into a cloud-in-cell mesh. Simply loops over the total number of particles (Ntot) and populates a 256^3 mesh (i.e. each particle gets distributed over 8 cells). % gfortran -fopenmp cic.f90 -o ./cic Which compiles fine. But when I run it (./cic) I get a segmentation fault. I my looping is a classic omp do problem. The program works when I don't compile it in openmp. !$omp parallel do do i = 1,Ntot if (x1(i).gt.0.and.y1(i).gt.0.and.z1(i).gt.0) then

Numerical Precision in Fortran 95:

别说谁变了你拦得住时间么 提交于 2019-12-17 14:54:08
问题 I have the following Fortran code: Program Strange Real(Kind=8)::Pi1=3.1415926535897932384626433832795028841971693993751058209; Real(Kind=8)::Pi2=3.1415926535897932384626433832795028841971693993751058209_8; Print*, "Pi1=", Pi1; Print*, "Pi2=", Pi2; End Program Strange I compile with gfortran, and the output is: Pi1= 3.1415927410125732 Pi2= 3.1415926535897931 Of course the second is correct, but should this be the case? It seems like Pi1 is being input to memory as a single precision number,

Numerical Precision in Fortran 95:

﹥>﹥吖頭↗ 提交于 2019-12-17 14:53:22
问题 I have the following Fortran code: Program Strange Real(Kind=8)::Pi1=3.1415926535897932384626433832795028841971693993751058209; Real(Kind=8)::Pi2=3.1415926535897932384626433832795028841971693993751058209_8; Print*, "Pi1=", Pi1; Print*, "Pi2=", Pi2; End Program Strange I compile with gfortran, and the output is: Pi1= 3.1415927410125732 Pi2= 3.1415926535897931 Of course the second is correct, but should this be the case? It seems like Pi1 is being input to memory as a single precision number,

R v3.4.0-2 unable to find libgfortran.so.3 on Arch

你说的曾经没有我的故事 提交于 2019-12-17 12:47:41
问题 I was just on vacation for a month so am unable to say the exact point at which this happened, but R from the official Arch repos is now unable to start, citing /usr/lib64/R/bin/exec/R: error while loading shared libraries: libgfortran.so.3: cannot open shared object file: No such file or directory I thought that perhaps a symlink was improperly placed or destroyed, so I looked in /usr/lib to try to find it: ls -halt /usr/lib/libgfortran.so.* lrwxrwxrwx 1 root root 20 May 16 03:01 /usr/lib

Allocatable array valued function. gfortran vs ifort

一个人想着一个人 提交于 2019-12-17 07:56:25
问题 Why is there different behavior between ifort and gfortran here? Compiled with ifort it returns false and with gfortran true. I ran into this problem before in my own code and decided to use a subroutine instead, but a recent question made me question this behavior. function allocateArray(size) integer, allocatable, dimension(:) :: allocateArray integer size allocate(allocateArray(size)) end function allocateArray From the main program integer, allocatable, dimension(:) :: a a = allocateArray

Why is this a function declared inside the module and then used somewhere else in the same module not seen by the linker?

落花浮王杯 提交于 2019-12-17 07:53:38
问题 I have a function (in case anyone is interested, it is this function) in a module that looks like this MODULE MYMODULE IMPLICIT NONE ! Some random stuff CONTAINS CHARACTER*255 FUNCTION strtok ( source_string, delimiters ) [...] END FUNCTION strtok SUBROUTINE DO_SOMETHING ( ) CHARACTER(LEN=255) :: strtok [...] ! END SUBROUTINE DO_SOMETHING END MODULE MYMODULE The strtok function is a version of C's strings tokenizer, and I'll be using this function from the DO_SOMETHING subroutine. I need to

gfortran for dummies: What does mcmodel=medium do exactly?

左心房为你撑大大i 提交于 2019-12-17 06:39:09
问题 I have some code that is giving me relocation errors when compiling, below is an example which illustrates the problem: program main common/baz/a,b,c real a,b,c b = 0.0 call foo() print*, b end subroutine foo() common/baz/a,b,c real a,b,c integer, parameter :: nx = 450 integer, parameter :: ny = 144 integer, parameter :: nz = 144 integer, parameter :: nf = 23*3 real :: bar(nf,nx*ny*nz) !real, allocatable,dimension(:,:) :: bar !allocate(bar(nf,nx*ny*nz)) bar = 1.0 b = bar(12,32*138*42) return