fortran

I have a Fortran program that should give segmentation fault but it doesn't

吃可爱长大的小学妹 提交于 2021-01-28 20:36:15
问题 As simple as the title. I have a student who got a segmentation fault and I was trying to prove him why does this happen. Instead, I ended up wondering why it doesn't. The code is this: program main implicit none real*8, allocatable:: u(:) integer :: i allocate(u(2)) do i=0, 1000 u(i) = i print *, u(i) enddo end program main I would expect this to crash at i=3 , but it doesn't. Compiled with both ifort and gfortran with -O0 to -O3 回答1: What about turning on the bounds checking option for

FFT Multiple 1d transforms using FFTW

自作多情 提交于 2021-01-28 19:41:35
问题 I have a 3-dimensional array U(z,y,x) and I want to perform a complex Fourier transform in z for all values of y and x. I am planning to use the FFTW library. I figured out from the FFTW manual that there is a way to perform multiple 1d transforms at once(mentioned below). CALL dfftw_plan_many_dft(PLAN, rank, n, howmany, in, inembed, istride, idist, out, onembed, ostride, odist, FFTW_MEASURE) I don't clearly understand what inembed and outembed means. Could you provide more insight into this

How to continue an OpenMP directive on the next line in free-from Fortran? [duplicate]

蹲街弑〆低调 提交于 2021-01-28 11:16:36
问题 This question already has answers here : OpenMP Several “shared”-directives? (2 answers) Closed last month . I have a line of a Fortran code, e.g., !$omp do private(aa, bb, cc) schedule(dynamic) reduction(+:alpha, beta, gamma) Suppose this line contains several arguments and the length exceeds 132 characters, gfortran will lead to error message. I tried to use & to break the line. But I am not sure how to start the next line. As other case, directly start the next line without ! leads to

MPI send-receive issue in Fortran

一世执手 提交于 2021-01-28 09:41:52
问题 I am currently starting to develop a parallel code for scientific applications. I have to exchange some buffers from p0 to p1 and from p1 to p0 (I am creating ghost point between processors boundaries). The error can be summarized by this sample code: program test use mpi implicit none integer id, ids, idr, ierr, tag, istat(MPI_STATUS_SIZE) real sbuf, rbuf call mpi_init(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD,id,ierr) if(id.eq.0) then ids=0 idr=1 sbuf=1.5 tag=id else ids=1 idr=0 sbuf=3.5 tag

Abaqus DFLUX subroutine in Fortran

六月ゝ 毕业季﹏ 提交于 2021-01-28 08:40:49
问题 this is my first post here and I hope I will be clear describing the issues I'm having with Abaqus subroutine . I'm quite a newbie using Fortran . Basically, my goal is to define a non-uniform surface heat flux over an open cross-section tube and I'm using the DFLUX subroutine . Being open cross-section, the flux is influenced by the self-shadowing of the structure and has to be defined accordingly. Apparently the subroutine is called at each integration point, so that the coordinates of

Exponentiation in Fortran/gfortran to high precision

时光总嘲笑我的痴心妄想 提交于 2021-01-28 04:45:34
问题 How does gfortran handle exponentiation with a integer vs a real? I always assumed it was the same, but consider the example: program main implicit none integer, parameter :: dp = selected_real_kind(33,4931) real(kind=dp) :: x = 82.4754500815524510_dp print *, x print *, x**4 print *, x**4.0_dp end program main Compiling with gfortran gives 82.4754500815524510000000000000000003 46269923.0191143410452125643548442147 46269923.0191143410452125643548442211 Now clearly these numbers almost agree -

Detecting wrongful aliasing at compile or run time

浪尽此生 提交于 2021-01-28 04:37:42
问题 Is there some tool (or compile flag) that can detect problematic aliasing in Fortran code either during compilation or at run time? I see gfortran has -Waliasing , but that only detects the most egregious case (e.g. call whatever(x,x) , but not call whatever(x(1),x(1)) ). Intel's ifort has -fno-alias , but apparently that just means the compiled code may give different results. Consider a code like this: program main implicit none real :: x(100) integer :: i do i=1,size(x) x(i) = i end do

How can I read a 2D file which content is not separated by spaces in Fortran

可紊 提交于 2021-01-27 23:13:33
问题 I have a matrix stored in a file (number.txt), like this: 12323456 54254311 76534522 How can I read such matrix in Fortran, so the result would be: 1 2 3 2 3 4 5 6 5 4 2 5 4 3 1 1 7 6 5 3 4 5 2 2 It is very easy to separate these columns using awk and read it in Fortran. But, I would like to know if I can do all this using only Fortran. After I am done with I will need to multiple this matrix by its transpose. 回答1: Fortran formatted input and output is based on fields . Fields are not

How can I read a 2D file which content is not separated by spaces in Fortran

十年热恋 提交于 2021-01-27 22:04:10
问题 I have a matrix stored in a file (number.txt), like this: 12323456 54254311 76534522 How can I read such matrix in Fortran, so the result would be: 1 2 3 2 3 4 5 6 5 4 2 5 4 3 1 1 7 6 5 3 4 5 2 2 It is very easy to separate these columns using awk and read it in Fortran. But, I would like to know if I can do all this using only Fortran. After I am done with I will need to multiple this matrix by its transpose. 回答1: Fortran formatted input and output is based on fields . Fields are not

Interpret strings as variable names in Fortran [duplicate]

淺唱寂寞╮ 提交于 2021-01-27 21:03:54
问题 This question already has answers here : Determine variable names dynamically according to a string in Fortran (4 answers) Closed 3 years ago . I'd like to access a real variable with a name equal to a string of characters that I have. Something like this (I'll make the example as clean as possible): character(len=5) :: some_string real :: value value = 100.0 some_string = 'value' At this point, how do I create an association between the character array value and the name of my real variable,