fortran90

partition a 2D array column-wise and use allgather

心已入冬 提交于 2019-12-23 02:36:08
问题 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

OpenMP Crashing with Large Arrays

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 02:29:39
问题 I'm using Fortran and OpenMP, but I keep encountering an issue when I try to parallelize loops using OpenMP when there are large arrays. For example, the following code: PROGRAM main IMPLICIT NONE INTEGER, PARAMETER :: NUMLOOPS = 300000 REAL(8) :: TESTMAT(NUMLOOPS) INTEGER :: i,j !$OMP PARALLEL SHARED(TESTMAT) !$OMP DO DO i=1,NUMLOOPS TESTMAT(i) = i END DO !$OMP END DO !$OMP END PARALLEL write(*,*) SUM(TESTMAT)/(NUMLOOPS) END PROGRAM main compiled using this Makefile: .SUFFIXES: .f90 F90 =

Force explicit variable declaration with gfortran

风格不统一 提交于 2019-12-22 18:22:10
问题 I am linking some fortran code (f90) from matlab using mex and I am having matlab freeze occasionally. In the past, I had freezing happening due to mismatch between data types (say integer*4 vs integer*8). The code I am linking has many implicitly defined variables, so I am wondering if there is a hidden data type conflict that only occurs occasionally. To rule out data type mismatch as the cause of the freeze, I would like to have the compiler requiring all variables to be explicitly

Interface mismatch in dummy procedure 'f' when passing a function to a subroutine

梦想与她 提交于 2019-12-22 12:19:39
问题 I am trying to write a subroutine (for minimisation) that has two arguments: an array x of any length a function f that takes an array of that length and returns a scalar example module: module foo contains subroutine solve(x, f) real, dimension(:), intent(inout) :: x interface real pure function f(y) import x real, dimension(size(x)), intent(in) :: y end function end interface print *, x print *, f(x) end subroutine end module and test program: use foo real, dimension(2) :: x = [1.0, 2.0]

vectorize a loop which accesses non-consecutive memory locations

佐手、 提交于 2019-12-22 11:13:06
问题 I have a loop of this structure Reference : Maxwell Code Example do z=1,zend do y=1,yend do x=1,xend k=arr(x,y,z) do while(k.ne.0) ix=fooX(k) iy=fooY(k) iz=fooZ(k) x1=x(ix ,iy ,iz) x2=x(ix+1,iy ,iz) x3=x(ix ,iy+1,iz) x4=x(ix+1,iy+1,iz) x5=x(ix ,iy ,iz+1) x6=x(ix+1,iy ,iz+1) x7=x(ix ,iy+1,iz+1) x8=x(ix+1,iy+1,iz+1) y1=y(ix ,iy ,iz) y2=y(ix+1,iy ,iz) y3=y(ix ,iy+1,iz) y4=y(ix+1,iy+1,iz) y5=y(ix ,iy ,iz+1) y6=y(ix+1,iy ,iz+1) y7=y(ix ,iy+1,iz+1) y8=y(ix+1,iy+1,iz+1) z1=z(ix ,iy ,iz) z2=z(ix+1,iy

Ampersand in 5th column and at the end of the line

女生的网名这么多〃 提交于 2019-12-22 10:53:55
问题 I came across some code today that looks like this: subroutine sub(hello,world,this,routine,takes,a, & & crazy,large,number,of,arguments, & & so,many,that,it,gets,split,across,four, & & lines) It seems that the ampersands in the 5th column are in case the user wants to compile the code with a f77 compiler -- My question is whether this is legitimate (standard conforming) fortran 90 code. I suppose that it probably isn't standard conforming f77 code since the trailing ampersands aren't in

Non-advancing read in Fortran with free format

笑着哭i 提交于 2019-12-22 04:43:48
问题 I want to read a line in a file, which includes three real numbers, without advancing the pointer. So I wrote: (TXT is the variable representing my file which has a value of 80) read(TXT, *, ADVANCE='NO') (numbers(i),i=1,3) However, I got an error message saying: "error #6568: This use of the ADVANCE, SIZE, or EOR specifier is invalid." So how should I write it to make it correct? Thanks. 回答1: You can use advance='no' only with an explicit format. The reason is the following : advance='no'

How can I find the cause for a memory leak in Fortran 2003 program?

本秂侑毒 提交于 2019-12-21 22:57:47
问题 I have a Fortran program I wrote using Fotran 2003 and compiled using Intel(R) Fortran Compiler XE for applications running on IA-32, Version 12.1.2.273 Build 20111128 after running my program for a long run ( it's a physical computation ) I have the out read: Insufficient memory to allocate Fortran RTL message buffer, message I guessed it has to do with memory leak in my program How can I find out where is the leak occurring and how to fix it? 回答1: As the first answer indicates, your

optimization of a seven do cycle

巧了我就是萌 提交于 2019-12-21 20:00:04
问题 I have 3 array and I have to do this summation The implemented code is do i=1,320 do j=1,320 do k=1,10 do l=1,10 do m=1,10 do r=1,10 do s=1,10 sum=sum+B(k,l,r,s,m)*P(i,j,r,s,m) end do end do A(i,j,k,l,m)=sum end do end do end do end do end do It takes 1 day to execute the code. Is there a way to optimize it? Thanks. 回答1: The trick in these things is to look for common patterns and use existing efficient routines to speed them up. M.S.B is, as usual, completely right that just flipping your

Vim highlighting weird parts of FORTRAN

社会主义新天地 提交于 2019-12-21 04:34:10
问题 I am using VIM theme molokai, if that makes any difference. I have been learning FORTRAN lately and when I write a FORTRAN program using VIM, I have weird coloring depending on my whitespace. For instance, if I tab things over as is (no indenting) I have this purple highlight on only a portion of the word (sometimes it isn't there, notice the PRINTs and READs). If I tab it over it looks normal: I am new to VIM (not to mention FORTRAN) so I am not sure what's happening, I don't mind tabbing