fortran

performance of internal function

China☆狼群 提交于 2021-01-29 18:10:23
问题 Is there any reason to believe that a fortran internal function would perform better than an external function? e.g. subroutine foo(x,y) real :: x x = bar(y) return contains real function bar(x) real :: x bar = x*x return end function bar end subroutine foo vs subroutine foo(x,y) real :: x real :: bar x = bar(y) return end subroutine foo real function bar(x) real :: x bar = x*x return end function bar For example, does the internal unit allow the compiler to inline that code like some sort of

Convert integers to strings to create output filenames at run time

感情迁移 提交于 2021-01-29 17:25:00
问题 I have a program in Fortran that saves the results to a file. At the moment I open the file using OPEN (1, FILE = 'Output.TXT') However, I now want to run a loop, and save the results of each iteration to the files 'Output1.TXT' , 'Output2.TXT' , 'Output3.TXT' , and so on. Is there an easy way in Fortran to constuct filenames from the loop counter i ? 回答1: you can write to a unit, but you can also write to a string program foo character(len=1024) :: filename write (filename, "(A5,I2)") "hello

fortran matrix vector multiplication optimization

為{幸葍}努か 提交于 2021-01-29 16:30:58
问题 I tried to measure the difference of different matrix-vector-multiplication schemes in Fortran. I have actually written the following code: http://pastebin.com/dmKXdnX6 The 'optimized version' is meant to respect the memory layout of the matrix, by swapping the loops to access the matrix-elements. The provided code should compile with gfortran and it runs with the following rather surprising results: Vectors match! Calculations are OK. Optimized time: 0.34133333333333332 Naive time: 1

Array specification at (1) has more than 7 dimensions in mpif-sizeof.h

我的未来我决定 提交于 2021-01-29 15:38:09
问题 I have the following makelist file: BIN_SUFFIX = cpu OMP_FLAGS = -p OPT_FLAGS = -ofast compiler = mpifort compiler = mpif90 #used in gfortran MISC_FLAGS = -ffree-line-length-300 # CFLAGS += $(OPT_FLAGS) CFLAGS += $(OMP_FLAGS) CFLAGS += $(MISC_FLAGS) LFLAGS = $(CFLAGS) COMPILE = ${compiler} -c LINK = ${compiler} objects = Main_multiphase.o Main_singlephase.o Module.o Init_multiphase.o Init_singlephase.o Misc.o IO_multiphase.o IO_singlephase.o Kernel_multiphase.o Kernel_singlephase.o Mpi_misc.o

Fortran C++ binding - wrong value being read in DLL(C++)

一曲冷凌霜 提交于 2021-01-29 11:17:22
问题 I am trying to use Fortran with C++. I created a DLL(C++) by following this guide. However, instead of creating C++ MathClient.cpp program, which calls this DLL (as it is described in the guide), I created Fortran MathClient.F90 program, which calls this DLL. Fortran main code: PROGRAM MAIN USE MOD_INTERFACE IMPLICIT NONE INTEGER(C_INT) :: A, B INTEGER(C_INT) :: INDEX INTEGER(C_INT) :: CURRENT LOGICAL(C_BOOL) :: BOLEAN A = 1 B = 1 ! Initialize a Fibonacci relation sequence. CALL FIBONACCI

Error when compile umfpack after the update of Mac

安稳与你 提交于 2021-01-29 09:49:55
问题 I was able to use umfpack, but I just found that I cannot use it as before. I guess the reason is my recent update of Mac. I already installed SuiteSparse VERSION 4.5.4. I use the Fortran interface, umfpack.f90, from http://geo.mff.cuni.cz/~lh/Fortran/UMFPACK/. And use gfortran umfpack.f90 umfpack_simple_3subr.f90 -L/usr/local/lib -lumfpack to compile. But I got the following errors: Undefined symbols for architecture x86_64: "__gfortran_os_error_at", referenced from: ___mumfpack_MOD_umfpack

Using f2py for faster calculation on Python

让人想犯罪 __ 提交于 2021-01-29 09:07:38
问题 I'm working on a sequence alignment project with python, and python for loop is too slow. So, I decided to use f2py . I don't know much about fortran, so I'm stuck to the point below. There are two sequence named 'column', and 'row' whose type is np.array For example: column = ['A', 'T', 'G', 'C'] row = ['A', 'A', 'C', 'C'] I created a matrix for the Needleman-Wunsch algorithm, and I scored two sequences (column, row). import numpy as np column = np.array(list('ATGC')) row = np.array(list(

GFortran error: ld: library not found for -lSystem when trying to compile

做~自己de王妃 提交于 2021-01-29 07:16:49
问题 I am getting a strange error when trying to compile a simple fortran-90 file using gfortran. I am working on a macOS mojave system. I have gfortran 8.2.0 installed and I checked to be sure of this by doing the following: Input: gfortran --version Output: GNU Fortran (GCC) 8.2.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Which indicates

MPI Fortran support through the mpi_f08 module with gfortran

拈花ヽ惹草 提交于 2021-01-29 06:09:00
问题 I have some Fortran code I would like to paralelize with MPI. Appereantly, recomended way to use MPI (MPICH, in my case) with Fortran is through mpi_f08 module (mpi-forum entry on the matter), but I have trouble making it work, since corresponding mod file is simply not created (unlike mpi.mod , which works fine, but it's not up to date with Fortran standart). This discussion left me under the impression it's because gfortran can't build the F08 bindings. Below you can see my configuration,

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

二次信任 提交于 2021-01-28 21:04:39
问题 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