Skip to main content
Share Your Experience: Take the 2024 Developer Survey
33 votes
Accepted

Is it possible for user written algorithms to outperform libraries' built-in optimized functions?

Although LAPACK has some incredibly optimized code, it can still be worth it to write your own version in a few cases. The most important reason (and the reason they make you do it in your course). ...
Thijs Steel's user avatar
  • 1,723
21 votes
Accepted

The real myth of GPU (specifically CUDA) really speed up FEM/CFD

Here's the deal with GPUs. On a GPU, every single core is slow. Really slow. However, you have thousands of cores. If you can effectively use the thousands of cores at a time, then your algorithm will ...
Chris Rackauckas's user avatar
14 votes
Accepted

Beating typical BLAS libraries matrix multiplication performance

Consolidating the comments: No, you are very unlikely to beat a typical BLAS library such as Intel's MKL, AMD's Math Core Library, or OpenBLAS.1 These not only use vectorization, but also (at least ...
14 votes
Accepted

Whittaker-Shannon interpolation: Accuracy dies with speedup; can it be fixed?

I was able to reproduce the behavior reported in the question, and traced the observed inaccuracies to the following line: ...
njuffa's user avatar
  • 1,875
14 votes
Accepted

Increasing computational performance by using 16 bit numbers

There has been considerable recent interest in numerical linear algebra using mixed precision with some combination of 16, 32, 64, and 128 bit floating point arithmetic. For example, a low ...
Brian Borchers's user avatar
13 votes
Accepted

Is there an algorithm or graph theory that allows me to not need to store an intermediate matrix when calculating AT*Y1*A + BT*Y2*B?

BLAS may not have a function to compute what you are asking for, but the product $$ Y_N = A^TY_AA + B^T Y_B B $$ means that the entries $(Y_N)_{ij}$ are defined by $$ (Y_N)_{ij} = \sum_{k,l} (A^T)...
Wolfgang Bangerth's user avatar
13 votes

Faster Logistic Function

Yes! There are nice approximations of the logistic. Plot of Approximating Functions As shown below, several functions approximate the logistic (shown as blue dots). This graph is available ...
Richard's user avatar
  • 3,971
11 votes
Accepted

What is the state of the art algorithm for diagonalizing real symmetric matrices?

The QR/Francis algorithm is the go-to choice for dense eigenproblems, but there are a few competitors around: The Jacobi algorithm (like QR, another algorithm with an unfortunate name, which can be ...
Federico Poloni's user avatar
10 votes

How to properly calculate CPU and GPU FLOPS performance?

You can calculate GFLOP rates this way, but the numbers are pretty meaningless on today's hardware: Floating point operations require a variable number of clock cycles. An addition is generally ...
Wolfgang Bangerth'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,829
8 votes
Accepted

Integer operations vs floating point operations

There is a nice discussion on StackOverflow regarding floating point vs integer operations. In short, the performance of the operations depends a lot on processor architecture how the data is stored ...
Anton Menshov's user avatar
  • 8,672
8 votes
Accepted

Fastest Way to Mutiply $10^4$ 2x2 Matrices

In general, I agree with Chris's comment that using a compiled language with the allocation of the matrices on the stack can help significantly. Several possibilities if we are limited to Python and ...
Anton Menshov's user avatar
  • 8,672
8 votes

Is it possible for user written algorithms to outperform libraries' built-in optimized functions?

@ThiysSteel covers a lot, here is another perspective I find important: Even if you have available excellent implementations of any algorithm you might need, you still need to understand some of the ...
Simon's user avatar
  • 181
7 votes

Is it possible for user written algorithms to outperform libraries' built-in optimized functions?

To clarify @ThiysSteel's good answer: The point is not to attempt to surpass the optimization of code written by very experienced people, who'd wrangled with it for decades. The point is to acquaint ...
paul garrett's user avatar
7 votes

Is it possible for user written algorithms to outperform libraries' built-in optimized functions?

I used to try to optimize code via using assembly language (as opposed to C). I had some clear success, where a real-time microphone array worked with assembly language, but it would not work at all ...
JosephDoggie's user avatar
6 votes
Accepted

Why is the speed of the parts of the LU-decomposition so different?

First, don't forget to also time the LU decomposition in a loop! Otherwise it's not really a fair comparison. If I do that, I get the following timings: ...
Christian Clason's user avatar
6 votes
Accepted

Implementation of Jacobi iteration

If you really want to speed it up, I'd suggest changing your iteration to a SSOR iteration. This can converge much faster than jacobi, and if you are already OpenMP parallelized, there's not much you ...
EMP's user avatar
  • 2,089
6 votes
Accepted

Is operation count a reliable predictor of performance when comparing two formulations?

No. There a number of aspects of modern computer architecture that make operation counts unreliable as a way to compare the performance of algorithms. These include memory caches, vector ...
Brian Borchers's user avatar
6 votes

Is it possible for user written algorithms to outperform libraries' built-in optimized functions?

This might be tangent but i feel it worth adding. A common way for user code to beat libraries is to exploit structure the libraries are not aware of. Block diagonal matrices are easier to work in ...
worldsmithhelper's user avatar
6 votes

Faster Logistic Function

If only low-accuracy approximations are needed, it is highly advisable to perform all computation in single precision, for example IEEE-754 binary32 format, usually ...
njuffa's user avatar
  • 1,875
5 votes

The real myth of GPU (specifically CUDA) really speed up FEM/CFD

To extend Chris Rackauckas's exhaustive answer with a reference try to look pdf by Torres, Gonzalez-Escribano, Llanos. It is about the tuning of a gpu, that is an important aspect for performance. ...
Mauro Vanzetto's user avatar
5 votes

Why am I not seeing faster neural network training after upgrading to a vastly better GPU?

I suppose, you right and your network is not that big to 100%-utilize the GPU. The bottle-neck here seems to be not the GPU itself, but the transfer rate between RAM and VRAM and here the difference ...
Vlad's user avatar
  • 114
5 votes

Integer operations vs floating point operations

Integer operations are generally faster than floating point operations, but the gap is far less than it was, say, 30 years ago when everyone was still counting FLOPS. The difference may be a factor of ...
Wolfgang Bangerth's user avatar
5 votes
Accepted

Improve Mandelung constant code

As mentioned by @Richard, loops in Python are slow. Two solutions come to my mind: Use NumPy and vectorize the operations. This will speed up your calculations at the cost of storing your ...
nicoguaro's user avatar
  • 8,525
4 votes

Integer vs float multiplication performance, modern CPUs

In general, the answers is no. Modern CPU's excel at problems which have high arithmetic intensity and are implemented using floating point arithmetic. A few figures will help explain the ...
Carl Christian's user avatar
4 votes
Accepted

Time complexity analysis

It's O(n), but it depends on the sorting algorithm you use. Finding unique elements is O(n) with a hash table. You use one for loop to count incidents and a subsequent loop to extract uniques. ...
Richard's user avatar
  • 3,971
4 votes

In Eigen, can a sparse matrix contain vectors/objects instead of simple scalar values?

Certainly. There are a few things you have to define for your type that are listed on this page in the documentation: https://eigen.tuxfamily.org/dox/TopicCustomizing_CustomScalar.html It basically ...
Tyler Olsen's user avatar
  • 1,512
4 votes

Is it possible for user written algorithms to outperform libraries' built-in optimized functions?

The point of learning how to write "the QR iteration algorithm" is not because eig will be slower. It is because "the QR iteration algorithm" ...
Yakk - Adam Nevraumont's user avatar
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

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