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

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,839
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
9 votes

Small quadratic programming problem - a simple Fortran code needed

John Burkardt provides parallelepiped_point_dist_3d in his geometry library. The Fortran90 version: https://people.sc.fsu.edu/~...
jdgleeson's user avatar
  • 376
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
  • 6,064
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
8 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
8 votes
Accepted

Small quadratic programming problem - a simple Fortran code needed

Your problem is a bounded variables least squares (BVLS) problem. For small instances, an active set method can quickly solve the problem. Lawson and Hanson have Fortran code for this in their book ...
Brian Borchers's user avatar
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

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

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
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,249
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,935
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

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,935
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,249
4 votes

Analytical testing/quality control for scientific software in professional setting

There's a Sandia technical report discussing the Method of Manufactured Solutions (a generalisation of the concept of exact solutions to PDEs) which goes to some lengths to discuss the concept of ...
origimbo's user avatar
  • 2,249
4 votes
Accepted

A robust algorithm to sort a non-convex polygon vertices

As @HighPerformanceMark mentioned in the comments if the set of vertices $V=\{v_0,\ldots,v_{N-1}\}$ is the only information you have about your non-convex polygon, you did not define it uniquely. One ...
Anton Menshov's user avatar
  • 8,672
4 votes

Interpolation of 1D solution from an original grid to a new grid

A "better technique" is rather subjective. You mean faster, more accurate, easier to program, something else?? Since it's only 1-D, the numerical cost is small (compared to 2D/3D) and there ...
Javier-Acuna's user avatar
3 votes

Alternative to messy grid node indexing within multiple layers of loops

This is not a good way to do modern programming for many reasons. First of all, as you pointed out, this kind of code is hard to read and maintain. Secondly, this tends to be done in old versions of ...
Chris Rackauckas's user avatar
3 votes

A fast I/O file format readable by Fortran, Java, PHP?

HDF5 appears to have some JavaScript support via its HDF Server product. You might be able to use this, though it's a web API and not a native reader. Do you need to use this on the backend (like via ...
Bill Barth's user avatar
  • 10.9k
3 votes
Accepted

Declare variable to substitute one calculate only once

Common subexpression elimination and inlining code are like the bread and butter of compiler optimizations, the first and easiest optimizations that a compiler can do. There is every reason to think ...
Kirill's user avatar
  • 11.4k
3 votes

Best books and notes for beginners in the parallel FORTRAN 90 programming

I'm assuming by 'supercomputer' you're talking about HPC and distributed memory systems, as opposed to shared memory workstations, in which case you have a couple of options when it comes to Fortran. ...
cbcoutinho's user avatar

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