Hot answers tagged

14 votes
Accepted

How to compare runtimes of two algorithms in a reproducible way

To make more robust comparisons (on linux), you can : 1) On Intel CPUs the turbo overclocks your CPU. This is controlled by the temperature of the CPU, so it can behave differently from one run to ...
Anthony Scemama's user avatar
11 votes
Accepted

What is the difference between MATLAB and FORTRAN?

When one uses a low–level programming language, e.g. C++ or FORTRAN, one essentially controls lots of things: how parameters are passed, how data structures are aligned in memory, what is the most ...
56th's user avatar
  • 901
10 votes
Accepted

Accuracy loss in single-precision Euclidean norm computation

The squares are harmless (as long as they don't overflow/underflow), because the relative perturbation they introduce is of the order of the machine precision $u\approx 10^{-8}$. Your troubles here ...
Federico Poloni's user avatar
9 votes
Accepted

Linear interpolation in Fortran

There is no built-in Fortran functionality to do linear interpolation. You could either use a library or write your own routine. I haven't tried compiling or testing and my fortran may be a bit rusty, ...
Doug Lipinski's user avatar
9 votes
Accepted

Loop optimization with f2py, Cython and Numba

I think that the problem is linked to the way in which f2py generates the fortran interface: the argument to fortranrun.f2py should be stored as a F_CONTIGUOUS ...
Stefano M's user avatar
  • 3,819
9 votes

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

You should consider giving Julia a try. Let me explain what's going on in the design space right now that would be of interest to you. Full disclosure I am the lead developer of JuliaDiffEq. ...
Chris Rackauckas's user avatar
8 votes

What is the difference between MATLAB and FORTRAN?

In general, you will be much more productive writing software in a higher-level language (e.g MATLAB) that has features useful in describing problems in your particular domain (e.g. matrices in ...
Bill Greene's user avatar
  • 5,954
8 votes

Why there are people that still prefer fortran 77 over new versions?

I think it's generally true that there are no advantages of Fortran 77 over either newer versions of Fortran or in fact any number of other programming languages that are widely used in scientific ...
Wolfgang Bangerth's user avatar
7 votes

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

Shoutout to Kyle Mandli and Endulum who each contributed to this answer in the comments. First, I took Endulum's suggestion and removed the redundant reshapes. ...
Robert Bassett's user avatar
6 votes

Fortran code for Ewald summation

Notice that the summation in $U^{(r)}$ is incorrect. You want to sum over all the copies of the atoms in the lattice of periodic boxes, not just those whose indices satisfy $i > j$. In the ...
Juan M. Bello-Rivas's user avatar
6 votes
Accepted

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

One issue causing the jagged spectra at high wavenumbers is under sampling there. For example consider the 2D analogue of your binning procedure: You don't want to sample from the red zones as they ...
James's user avatar
  • 1,869
6 votes

How do I program periodic boundary conditions?

Typically, you would add "guard cells", that is (for u) u(-1) and u(n+1) with your notation. Before each integration step: u(n+1) = u(0) u(-1) = u(n) and ...
Pierre de Buyl's user avatar
5 votes

Fortran code for Ewald summation

The National Institute of Standards and Technology (NIST) proposes different inputs and outputs to test your implementation. Have a look there: https://www.nist.gov/mml/csd/chemical-informatics-...
max's user avatar
  • 207
5 votes

Finite element library in fortran

I would recommend writing your own code using PETSc. The most complex part of a parallel FE code is parallel assembly and solve and PETSc takes care of both. The latest version of PETSc also has ...
stali's user avatar
  • 1,759
5 votes
Accepted

Finite element mesh software

I'd say Gmsh. I used it for a few finite element projects, and it was mostly easy to work with. The mesh output formats are very parseable, and there's at least one third-party parser (MeshPy) that ...
Geoff Oxberry's user avatar
5 votes

Efficently invert tiny matrix in Fortran

Here are the routines we use in QMC=Chem for small matrices. QMC=Chem is under GPL license, so if your code is also under GPL, you can use them. EDIT: To get the inverse, you need to multiply the ...
Anthony Scemama's user avatar
5 votes

How do I write dimensionally agnostic code?

The clear answers if you want to keep Fortran speed are to use a language which has proper code generation like Julia or C++. C++ templates have already been mentioned, so I'll mention Julia's tools ...
Chris Rackauckas's user avatar
5 votes
Accepted

derivative of an array

Purely in terms of terminology, it's probably better to talk about taking discrete partial derivatives of variable fields stored in an array, rather than differentiating an array itself. Regarding ...
origimbo's user avatar
  • 2,229
5 votes
Accepted

implementation of a simple SPH example

The SPH implementation of the function in your question reads as: $f(x,y)=\frac{1}{2}\big(\frac{\partial x}{\partial x}+\frac{\partial y}{\partial y}\big)=\frac{1}{2}\nabla\cdot\textbf{r}\approx\frac{...
BalazsToth's user avatar
5 votes
Accepted

What is good practice for protecting parent scope variables in Fortran?

There are several tools to make a codebase more structured. In your example, the subroutine within big() is called without arguments, but changes something in the outer scope, as you said. To prevent ...
MPIchael's user avatar
  • 2,621
5 votes

More stable method of back substitution?

Back-substitution is backward stable, and this implies that its error is of the same order as the error induced by truncation of the input data to machine precision, (machine precision)x(condition ...
Federico Poloni's user avatar
5 votes
Accepted

ifort: everithing ok, but with gfortran: segmentation fault

The variable c isn't initialized anywhere in the program, so the value that it will have at runtime can be anything. Here I've entered a slight modification of the ...
Daniel Shapero's user avatar
5 votes
Accepted

Shall I use global, heap allocated array or local, stack allocated one if references to its elements are made too many times?

TL,DR: Leave it on the heap, but switch your loop order. For starters, the program stack has fairly limited space. If you're making arrays that large, I'd be very surprised if it fit on the stack. ...
Daniel Shapero's user avatar
5 votes

Causes for different results for different number of nodes in MPI

There is no way for anyone to tell you where the issue comes from without access to the actual code. But here are common reasons why the output (legitimately) differs for different numbers of ...
Wolfgang Bangerth's user avatar
5 votes

Eigen C++ Library Over 4x Slower than Fortran

Despite my initial conviction that I was including all relevant compiler flags, in fact I wasn't. I forgot the -fopenmp flag on the C++ compiler, which enables ...
Robert Bassett's user avatar
4 votes

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

f90wrap is build on top of f2py and automatically generates the Python wrappers for the underlying Fortran code base, including access to derived types. A set of simple examples show how it works.
davidovitch's user avatar
4 votes
Accepted

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

I have implemented a method that works pretty well for reconstructing edge information in surfacic meshes (or facet information in volumetric meshes), but I am working in C++. I'll try to explain that ...
BrunoLevy's user avatar
  • 2,305
4 votes
Accepted

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

One thing that C++ includes that Fortran doesn't have is extensive support for generic programming and compile-time code ...
Darren Engwirda's user avatar
4 votes

What is the difference between MATLAB and FORTRAN?

There are already very good answers, and I want to add only two aspects: Vendor Lock: If you choose Matlab or similar Packages (Mathematica etc.), you chain yourself to that vendor. Many ...
MPIchael's user avatar
  • 2,621
4 votes

Why there are people that still prefer fortran 77 over new versions?

In general the features that are being removed from the language are either pointless or dangerous, so I'd definitely recommend you may sure you write new code to compile under a later standard, even ...
origimbo's user avatar
  • 2,229

Only top scored, non community-wiki answers of a minimum length are eligible