Questions tagged [fortran]

Fortran is a general purpose programming language widely used by the scientific computing community.

Filter by
Sorted by
Tagged with
79 votes
5 answers
21k views

How much better are Fortran compilers really?

This question is an extension of two discussions that came up recently in the replies to "C++ vs Fortran for HPC". And it is a bit more of a challenge than a question... One of the most often-heard ...
Pedro's user avatar
  • 9,543
66 votes
13 answers
48k views

C++ vs Fortran for HPC

In my computational science PhD program, we are working almost exclusively in C++ and Fortran. It seems like some professors prefer one over the other. I am wondering which one is 'better' or if one ...
drjrm3's user avatar
  • 2,119
51 votes
4 answers
31k views

What makes Fortran fast?

Fortran has a special place in numerical programming. You can certainly make good and fast software in other languages, but Fortran keeps performing very well despite its age. Moreover, it's easier to ...
cauchi's user avatar
  • 897
28 votes
8 answers
7k views

Which package should I use to wrap Modern Fortran Code with Python?

I know of, and have used f2py2e to wrap some old Fortran 77 code, but my understanding is that it does not work with newer Fortran 95 code. I've researched what I should use, and have come across ...
James Tocknell's user avatar
28 votes
3 answers
57k views

How should I install a Fortran compiler on a Mac? (OS X 10.x, x >= 4)

Related question: State of the Mac OS in Scientific Computing and HPC A significant number of software packages in computational science are written in Fortran, and Fortran isn't going away. A ...
Geoff Oxberry's user avatar
24 votes
3 answers
21k views

Intel Fortran Compiler: tips on optimization at compilation

I will start with my personal experience in our lab. Back in the ifort 9 and 10 days, we used to be quite aggressive with the optimizations, compiling with -O3 and processor specific flags (-xW -xSSE4....
FrenchKheldar's user avatar
21 votes
4 answers
9k views

F2Py with allocatable and assumed shape arrays

I would like to use f2py with modern Fortran. In particular I'm trying to get the following basic example to work. This is the smallest useful example I could ...
MRocklin's user avatar
  • 3,068
20 votes
6 answers
54k views

Python vs FORTRAN

Which one is better: FORTRAN or Python? And I guess that in both cases you need Gnuplot, am I right? I'm working on a Windows machine at the moment. I'd like to use it to get numerical solutions for ...
Nick's user avatar
  • 413
20 votes
7 answers
1k views

How do I write dimensionally agnostic code?

I often find myself writing very similar code for one, two, and three dimensional versions of a given operation/algorithm. Maintaining all of these versions can become tedious. Simple code ...
Matthew Emmett's user avatar
19 votes
4 answers
8k views

Row major versus Column major layout of matrices

In programming dense matrix computations, is there any reason to choose a row-major layout of the over the column-major layout? I know that depending on the layout of the matrix chosen, we need to ...
smilingbuddha's user avatar
19 votes
5 answers
3k views

Parallel Scientific Computation Software Development Language?

I want to develop a parallel scientific computation software from scratch. I want some thoughts on which language to start. The program involves reading/writing data to txt files and doing heavy ...
electrique's user avatar
18 votes
1 answer
2k views

How to Run MPI-3.0 in shared memory mode like OpenMP

I am parallelizing code to numerically solve a 5 Dimensional population balance model. Currently I have a very good MPICH2 parallelized code in FORTRAN but as we increase parameter values the arrays ...
Franklin Betten's user avatar
17 votes
6 answers
2k views

Are there open-source scientific libraries which use modern Fortran with OOP?

I've spent the last couple of months on coding a Fortran program for solving a particular PDE system (describes fluid flow/combustion). I tryed to use latest-standard Fortran and the new OOP ...
tiam's user avatar
  • 864
17 votes
2 answers
12k views

Which version of Fortran should I learn?

I'm a Mechanical Engineering student interested in the field of aerospace engineering where, I'm told, Fortran is still commonly used. Which version of Fortran should I invest my time to learn?
user26358's user avatar
  • 271
15 votes
3 answers
8k views

Fortran: Best way to time sections of your code?

Sometimes while optimizing code it is required to time certain portions of the code, I have been using the following for years but was wondering if there is a simpler/better way to do it? ...
Isopycnal Oscillation's user avatar
14 votes
1 answer
383 views

Is there a tool out there that can generate interval extensions of Fortran (or C) functions by parsing Fortran (or C) code?

Case studies in my PhD thesis require that I have interval extensions of Fortran subroutines in CHEMKIN-II (apologies for the link; it's the best one I could find for a package no longer distributed ...
Geoff Oxberry's user avatar
13 votes
4 answers
2k views

Is C slower than Fortran on the spectral norm shootout (using gcc, intel and other compilers)?

The conclusion here: How much better are Fortran compilers really? is that gfortran and gcc are as fast for simple code. So I wanted try something more complicated. I took the spectral norm shootout ...
Ondřej Čertík's user avatar
13 votes
2 answers
8k views

How to work with function pointers in Fortran in scientific programs

Here is a typical usage of function pointers in C. I would like to do something similar in Fortran. I have some ideas, but I would like to know if there is some canonical way to do so. The function ...
Ondřej Čertík's user avatar
13 votes
3 answers
6k views

Memory usage in fortran when using an array of derived type with pointer

In this sample program I'm doing the same thing (at least I think so) in two different ways. I'm running this on my Linux pc and monitoring the memory usage with top. Using gfortran I find that in the ...
chris's user avatar
  • 1,055
11 votes
2 answers
23k views

How to set double precision values in Fortran

Recently, I've encountered a bizarre problem with FORTRAN95. I initialized variables X and Y as follows: X=1.0 Y=0.1 Later I add them together and print the ...
Paul's user avatar
  • 12k
11 votes
4 answers
2k views

Matrix exponential of a skew-Hermitian matrix with fortran 95 and LAPACK

I'm just getting tucked into fortran 95 for some quantum mechanics simulations. Honestly, I've been spoiled by Octave so I've taken matrix exponentiation for granted. Given a (small, $n\leq 36$) skew-...
qubyte's user avatar
  • 491
10 votes
4 answers
4k views

Learning Fortran

I was wondering what is the best way to learn how to program in Fortran ? I've been looking for books, the examples that seemed OK to me were "Fortran 95/2003 Explained" and "Fortran For Scientists ...
Nick's user avatar
  • 413
10 votes
2 answers
1k views

An Octree Code in Fortran

I am new to scientific computing. I am looking for a Fortran ( preferably f90) implementation of an Octree. My problem requires an Octree which divides my domain until there aren't more than some N ...
rivendell's user avatar
  • 365
10 votes
3 answers
3k views

Matrix exponential of a real asymmetric matrix with Fortran 95 and LAPACK

I recently asked a question along the same lines for skew-Hermitian matrices. Inspired by the success of that question, and after banging my head against a wall for a couple of hours, I'm looking at ...
qubyte's user avatar
  • 491
10 votes
1 answer
3k views

Fortran 90/95: Deallocating variables

I understand the crucial importance of freeing memory when certain variables or arrays need to be reused later in the program, or may not be in use for a while. However, in my experience with ...
Salim's user avatar
  • 165
10 votes
4 answers
5k views

Are DAXPY, DCOPY, DSCAL overkills?

I have implemented CG in FORTRAN by linking it to Intel MKL. When there are statements like: (Refer Wikipedia) p=r; x=x+alpha*p r=r-alpha*Ap; or similar ...
Inquest's user avatar
  • 3,344
9 votes
3 answers
4k views

How do I know if my code is being vectorized by the compiler?

As exemplified by Jed Brown's answer to Costs of lookups versus calculations, using vectorized vs non-vectorized floating point operations results in much faster code. Many modern compilers claim ...
Matthew Emmett's user avatar
9 votes
2 answers
1k views

Library with polylogarithm function [duplicate]

I am looking for a reliable library where I can find polylogarithm function and newton/secant method for solving non-linear equations. Basically I have something like this: ...
Bociek's user avatar
  • 191
8 votes
7 answers
8k views

What is the difference between MATLAB and FORTRAN?

In our university some Ph.D students for computational methods prefer FORTRAN over MATLAB. I can't understand why? What is the difference between them when are used in computational methods like ...
MohammadSh's user avatar
8 votes
1 answer
619 views

Why Is This Python Code Faster Than Fortran Wrapper with F2PY?

I am writing a proof-of-concept implementation of Newton's method for minimizing the negative log-likelihood term in a logistic regression model. I'm comparing the performance of a native python ...
Robert Bassett's user avatar
8 votes
2 answers
487 views

Filtering a dataset to get a more uniform distribution for neural network training

I'm looking into using artificial neural networks (ANN) to predict the reaction rates in my fluid instead of solving the full system of stiff ODEs. Some people from my lab have already done some work ...
FrenchKheldar's user avatar
8 votes
1 answer
2k views

How to get sparse complex matrices from my code to PETSc efficiently

What is the most efficient way to get a complex sparse matrix from my Fortran code to PETSc? I understand that this is problem dependent, so I tried to give as many relevant details as possible below. ...
Ondřej Čertík's user avatar
8 votes
1 answer
1k views

Generalized Singular Value Decomposition: only compute the r largest singular values

I want to compute the Generalized Singular Value Decomposition for sparse matrices with a size of up to 1000000 x 1000000 (not necessarily square). The method is going to be used in machine learning (...
Matthias Munz's user avatar
7 votes
4 answers
3k views

Need Fortran 77 compiler

Does anyone know a compiler for Fortran 77 available as a free download? I have pre-written 77 code from a source published in the early 90's that I just need to compile, build, and run. But I don't ...
user5246's user avatar
7 votes
4 answers
4k views

Fortran code for Ewald summation

I am trying to write a code to calculate the potential and forces, for the same using ewald summation.For this purpose, the formula for potential and force I have used is : $$ U = U^{(r)} + U^{(k)} +...
user35952's user avatar
  • 201
7 votes
2 answers
14k views

Linear interpolation in Fortran

Is there a Fortran subroutine which performs linear interpolation in one-dimenional data? I need something similar to MATLAB function interp1.
kyperros's user avatar
  • 139
7 votes
2 answers
2k views

Finite element library in fortran

I want to create a finite element code in fortran. There are many libraries out there on internet. Can someone suggest me a good finite element library in fortran? I am looking for Ease of use (...
343_458's user avatar
  • 171
7 votes
1 answer
4k views

computing turbulent energy spectrum from isotropic turbulence flow field in a box

I have my 3 dimensional velocity flow-field u, v and w at a given instant of time from DNS using pseudo-spectral method. I need to calculate the energy spectrum ( in Fourier space ) as a function of ...
user4557934's user avatar
7 votes
1 answer
2k views

Eigen C++ Library Over 4x Slower than Fortran

I am experimenting with ways to call compiled programs from Python. My primary interest is iterative optimization methods, so I'm testing an implementation of Newton's method to solve a logistic ...
Robert Bassett's user avatar
6 votes
1 answer
185 views

How to compare runtimes of two algorithms in a reproducible way

I am solving one relatively simple problem with two different algorithm: one which uses brute force while the other is optimized. For a variety of reasons I actually cannot show the codes here but I ...
solalito's user avatar
  • 337
6 votes
5 answers
300 views

Evaluate the sum

I want to evaluate the sum $$\sum_{k=1}^\infty \left(\frac{i+1}{\sqrt{2}}\right)^k\cdot k^{-\alpha}$$ where $i=\sqrt{-1}$ and $\alpha\in[\frac{3}{4},1]$ with 8 digits accuracy. If I am willing to ...
Qomo's user avatar
  • 61
6 votes
1 answer
2k views

Loop optimization with f2py, Cython and Numba

I tried to used f2py, Cython and Numba to make a simple loop structure be faster in python. Python implementation: ...
Erik Kjellgren's user avatar
6 votes
1 answer
666 views

Causes for different results for different number of nodes in MPI

I am trying to develop what might be called legacy Fortran code from my group. Upon testing, I found that the program (which takes about a day to run on 20 processes) works when run on a single node (...
tmph's user avatar
  • 337
6 votes
1 answer
1k views

Meshing options to generate number of the sides of and element (tetgen-triangle)

I wrote a finite element code in fortran 90. This code is really fast, except the meshing process. I used triangle and tetgen for meshing in 2D and 3D, respectively, so this process is fast, of ...
yemino's user avatar
  • 515
6 votes
1 answer
1k views

Grid mapping from an unstructured triangular mesh to a regular rectangular mesh

I am modeling fracture propagation using a 2-D dynamic unstructured grid. As the fracture propagates over time, the elements move accordingly. For a given time step, I would like to interpolate the ...
rolio's user avatar
  • 61
6 votes
2 answers
6k views

Fortran, making a more efficient bilinear interpolation

I'm trying to write an efficient bilinear (2D)-interpolation, after reading some recipes, as a fortran-mex for Matlab that is used extensively throughout a long algorithm of solar image processing, ...
Wall-E's user avatar
  • 161
5 votes
2 answers
292 views

Recommended language/environment for large scale semi-continuous biological models

We have a fairly large (maybe 1000 equations) differential-algebraic equation model written in ACSLX, an obsolete modelling environment similar to Modelica. The model represents the evolution of a ...
Simon Woodward's user avatar
5 votes
3 answers
1k views

What do C, C++ and Java have that Fortran 2003 don't? [closed]

As you may know, Fortran is widely and longly (?) used in science. I've heard a lot of people saying that we natural scientists should all migrate to C++ or Java. I've seen people increasingly ...
Leonardo Castro's user avatar
5 votes
1 answer
1k views

Half precision in Fortran

To improve the time efficiency of my code, I'd like to test a lower precision for real number, using e.g. half precision (2 bytes). However, I'm not sure if I can do that in Fortran. After playing ...
Matthieu's user avatar
5 votes
0 answers
526 views

Iteratively finding both left and right eigenvectors for non-symmetric complex matrix

I have a complex, non-Hermitian matrix $\mathbf{A}$, for which I need to find a few eigenvalues and eigenvectors in the generalised eigenvalue problem: $$\mathbf{A}\cdot \mathbf{x} = \lambda \mathbf{...
DaveP's user avatar
  • 161