fortran95

Calling a subroutine in Fortran (Segmentation fault)

廉价感情. 提交于 2019-12-02 05:22:47
问题 The following code gives segmentation error when compiled with pgf90 on the Linux system, while is run successfully when I used the Intel Visual FORTRAN on Windows. program main implicit none integer:: a(3), b(3) ,c(3) a=[3, 4, 5] b=[1, 2, 3] call sub(a,b,c) write(*,*)'a+b = ',c end program main subroutine sub(a,b,c) implicit none integer, intent(in)::a(:),b(:) integer, intent(out)::c(:) c=a+b end subroutine sub Any explanation for this ? 回答1: When you call a subroutine which has assumed

fortran 95 rounding up on it's own

扶醉桌前 提交于 2019-12-02 02:46:47
I decided to learn the fortran95 language (reason why is not important). However being a beginner I ran into a weird problem I really can't explain, therefor I need help. I have the insertion sort algorithm: subroutine insertion_sort_REAL4(array, array_len) implicit none !parameners integer :: array_len real (kind=4), dimension(array_len) :: array !variables integer :: i,key,hole_pos do i = 0,array_len key = array(i) hole_pos = i; do while ((hole_pos > 0.0) .and. (key < array(hole_pos - 1))) array(hole_pos) = array(hole_pos - 1) hole_pos = hole_pos - 1 end do array(hole_pos) = key end do

Array-valued function

亡梦爱人 提交于 2019-12-02 02:36:20
问题 I'm new in the area of Fortran programming and after testing a few programs I already got a feeling of how to write programs. Now I was trying me on a bit harder program and I run into a problem I couldn't solve by myself. I already googled about the problem but I couldn't find an adequate answer ... So I thought maybe there are one or two Fortran programmers which can give me a hand in solving this problem. The program is very simple it just multiplies two matrices with each other. I was

Array-valued function

柔情痞子 提交于 2019-12-02 01:31:10
I'm new in the area of Fortran programming and after testing a few programs I already got a feeling of how to write programs. Now I was trying me on a bit harder program and I run into a problem I couldn't solve by myself. I already googled about the problem but I couldn't find an adequate answer ... So I thought maybe there are one or two Fortran programmers which can give me a hand in solving this problem. The program is very simple it just multiplies two matrices with each other. I was trying to write a function which performs the task and returns the result matrix back to the invoker. To

Calling a subroutine in Fortran (Segmentation fault)

故事扮演 提交于 2019-12-02 01:24:14
The following code gives segmentation error when compiled with pgf90 on the Linux system, while is run successfully when I used the Intel Visual FORTRAN on Windows. program main implicit none integer:: a(3), b(3) ,c(3) a=[3, 4, 5] b=[1, 2, 3] call sub(a,b,c) write(*,*)'a+b = ',c end program main subroutine sub(a,b,c) implicit none integer, intent(in)::a(:),b(:) integer, intent(out)::c(:) c=a+b end subroutine sub Any explanation for this ? When you call a subroutine which has assumed shape dummy arguments (as is the case in this program), an explicit interface is required. The easiest way to

How to choose the best configuration of 2D array A(i,j)

旧街凉风 提交于 2019-12-01 23:09:58
问题 Hopefully you could me explaining this thing. I'm working with Fortran and actually writing my code on CFD topic, and below (just for sake of simplicity and just for example) are short explanations of my case: I should use one 2D array A(i,j) and one 1D array B(i) I have to do 2 times looping, which is the first looping should be 50,000 times and the second one is 5 times (can't be changed). The point number 2 above should be looped 10,000 times. I write the codes with 2 versions (I called

How to choose the best configuration of 2D array A(i,j)

血红的双手。 提交于 2019-12-01 22:27:51
Hopefully you could me explaining this thing. I'm working with Fortran and actually writing my code on CFD topic, and below (just for sake of simplicity and just for example) are short explanations of my case: I should use one 2D array A(i,j) and one 1D array B(i) I have to do 2 times looping, which is the first looping should be 50,000 times and the second one is 5 times (can't be changed). The point number 2 above should be looped 10,000 times. I write the codes with 2 versions (I called them Prog_A and Prog_B). The first one is as shown below: PROGRAM PROG_A REAL*8, DIMENSION(50000,5):: A

Passing a string inline to a subroutine call, where the parameter has defined length, gives unexpected results

我是研究僧i 提交于 2019-12-01 20:11:38
I found this code to behave unexpectedly module testmodule integer, parameter :: LCHARS = 50 contains subroutine init() call foobar("foobar") end subroutine subroutine foobar(s) character(len=*), intent(in) :: s call bar(s) end subroutine subroutine bar(str) character(len=LCHARS), intent(in) :: str print *, str end subroutine end module program foo use testmodule call init() end program This code prints garbage which is compiler dependent. I see the problem being the fact that I am jumping through a routine with len=* for a string argument, which is then passed to a routine with specified

Program crash for array copy with ifort

回眸只為那壹抹淺笑 提交于 2019-12-01 17:11:51
This program crashes with Illegal instruction: 4 on MacOSX Lion and ifort (IFORT) 12.1.0 20111011 program foo real, pointer :: a(:,:), b(:,:) allocate(a(5400, 5400)) allocate(b(5400, 3600)) a=1.0 b(:, 1:3600) = a(:, 1:3600) print *, a print *, b deallocate(a) deallocate(b) end program The same program works with gfortran. I don't see any problem. Any ideas ? Unrolling the copy and performing the explicit loop over the columns works in both compilers. Note that with allocatable instead of pointer I have no problems. The behavior is the same if the statement is either inside a module or not. I

Program crash for array copy with ifort

感情迁移 提交于 2019-12-01 16:11:49
问题 This program crashes with Illegal instruction: 4 on MacOSX Lion and ifort (IFORT) 12.1.0 20111011 program foo real, pointer :: a(:,:), b(:,:) allocate(a(5400, 5400)) allocate(b(5400, 3600)) a=1.0 b(:, 1:3600) = a(:, 1:3600) print *, a print *, b deallocate(a) deallocate(b) end program The same program works with gfortran. I don't see any problem. Any ideas ? Unrolling the copy and performing the explicit loop over the columns works in both compilers. Note that with allocatable instead of