fortran90

How to flush stdout in Fortran 90?

心不动则不痛 提交于 2019-12-08 18:02:39
问题 I see a lot online on using the flush function in Fortran to flush output. I am wondering, specifically for Fortran 90, and specifically for stdout, what form this should take as a one-liner to put into my code? My guess is flush(*) . 回答1: flush() is not a function, but either a non-standard intrinsic subroutine, and hence invoked in a call statement call flush(unit_number) or a standard statement in Fortran 2003, hence invoked as a statement flush(unit_number) Commonly, standard output is

Gnuplot vector fortran

二次信任 提交于 2019-12-08 15:38:22
问题 How do you plot this program(fortran) in vector form in gnuplot?? the command: call execute_command_line("gnuplot plotvel.txt") does not seem to work. Nothing happens And what does using 1:2:3:4 mean?? in " plot "file.dat" using 1:2:3:4 with vectors filled head lw 3 " call execute_command_line("gnuplot plotvel.txt") 回答1: First of all, you are making a data file plotdata.txt at the beginning of the program, while trying to plot file.dat later, so that Gnuplot cannot find the latter. After

Fortran 90 with C/C++ style macro (e.g. # define SUBNAME(x) s ## x)

强颜欢笑 提交于 2019-12-08 13:44:45
问题 I am recently working with a F90 code project. I am using gfortran (linux and MinGW) to compile it. There is something interesting in file loct.F90. # define TYPE real(4) # define SUBNAME(x) s ## x # include "loct_inc.F90" # undef SUBNAME # undef TYPE # define TYPE real(8) # define SUBNAME(x) d ## x # include "loct_inc.F90" # undef SUBNAME # undef TYPE ... The loct_inc.F90 file looks like this: subroutine SUBNAME(loct_pointer_copy_1)(o, i) ... end subroutine SUBNAME(loct_pointer_copy_1)

Using MPI_Send/Recv to handle chunk of multi-dim array in Fortran 90

六月ゝ 毕业季﹏ 提交于 2019-12-08 02:36:29
I have to send and receive (MPI) a chunk of a multi-dimensional array in FORTRAN 90. The line MPI_Send(x(2:5,6:8,1),12,MPI_Real,....) is not supposed to be used, as per the book "Using MPI..." by Gropp, Lusk, and Skjellum. What is the best way to do this? Do I have to create a temporary array and send it or use MPI_Type_Create_Subarray or something like that? The reason not to use array sections with MPI_SEND is that the compiler has to create a temporary copy with some MPI implementations. This is due to the fact that Fortran can only properly pass array sections to subroutines with explicit

generating random numbers in a Fortran Module

醉酒当歌 提交于 2019-12-08 00:39:08
问题 Now I am facing the problem that in a module , with a seed I am generating random numbers to be used in a loop of a function but each time I call that function, the same random numbers are generated (because the seed is obviously the same ) but it's supposed that it must continue the series or at least it must be different between calls. One solution could be that the main program gives a new seed to be used in the module but I think it there could be another elegant solution. I am using

Have a function in fortran return a reference that can be placed on the left-hand-side of an assignment

拥有回忆 提交于 2019-12-07 17:40:38
问题 As stated in the title, I want to directly modify data that I access through a pointer retrieved from a function. Having a reference returned by a function appearing on the l.h.s. of an assignment(=) is no issue in C++ but the following minimal example in fortran errors out: module test_mod implicit none integer, target :: a=1, b=2, c=3 ! some member variables contains function get(i) integer, pointer :: get integer, intent(in) :: i select case (i) case (1) get => a case (2) get => b case (3)

Automatic width integer descriptor in fortran 90

我的未来我决定 提交于 2019-12-07 09:13:49
问题 I wanted to use automatic integer width descriptor in fortran 90. I referred to Output formatting: too much whitespace in gfortran This question says that I can use I0 and F0,0 for "auto" width. Here is my sample code (complied with GNU Fortran Compiler): PROGRAM MAIN IMPLICIT NONE INTEGER :: i REAL :: j WRITE (*,*) 'Enter integer' READ (*,100) i 100 FORMAT (I0) WRITE (*,*) 'Enter real' READ (*,110) j 110 FORMAT (F0.0) WRITE (*,100) 'Integer = ',i WRITE (*,110) 'Real = ',j END PROGRAM There

Function call stopping/hanging when containing a write-statement, but only when linking with certain libraries during compilation

孤街浪徒 提交于 2019-12-07 09:00:16
问题 Here is my minimal example: program test implicit none real :: testfunc write(*,*) "Writing from main" write(*,*) testfunc() end program test function testfunc() result(y) real :: y write(*,*) "Write from function g" y=1.0 return end function testfunc When compiling with a simple gfortran test.f90 or when including a library like Slatec gfortran test.f90 -lslatec It works fine. However, when changing the library to -llapack of -lblas, then the program hangs at runtime when calling testfunc().

Using 2d array vs array of derived type in Fortran 90

血红的双手。 提交于 2019-12-07 02:46:57
问题 Assuming you want a list of arrays, each having the same size. Is it better performance-wise to use a 2D array : integer, allocatable :: data(:,:) or an array of derived types : type test integer, allocatable :: content(:) end type type(test), allocatable :: data(:) Of course, for arrays of different sizes, we don't have a choice. But how is the memory managed between the 2 cases ? Also, is one of them good code practice ? 回答1: In general, you want to use the simplest data structure that

partition a 2D array column-wise and use allgather

只愿长相守 提交于 2019-12-06 19:39:25
I have a fortran MPI code in which a compute intensive function is invoked on every element of a 2D array. I'm trying to split the tasks among the ranks. For example if there are 30 columns and 10 ranks, then each rank gets 3 columns. The following code does this split and gathers the results using allgather. But the final array doesn't have the values from all ranks. program allgather include 'mpif.h' !create a 2 x 30 myarray integer :: x=2,y=30 integer :: numprocs,myid integer :: i,j,k,myelements,mycolumns,jb,je integer*4,dimension(:),allocatable :: displacement,recvcnt real :: checksum real