

I was once at a conference’s poster session presenting some of my PhD results which had been obtained using a national supercomputer. Being the responsible and devoted PhD student I was, naturally I had spent plenty of time preparing for the upcoming questions. My assumption of course was that the line of questioning would be perhaps related to fluid dynamics, or parallel computing, or even to finite element analysis. To my surprise the first and only question posed to me by the session’s chair was a simple “why did you need a supercomputer to solve THIS problem” -emphasis on the “this”. And I’ll admit that besides replying that we were using what we described as a massive amount of degrees of freedom, I really had no more to argue in favor of my case. Of course the question was not asked in bad faith, moreover it triggered a deeper line of questioning in my already overthinking brain. For instance, why do we even need a massive number of degrees of freedom? Or, could we have obtained our same conclusions based on a simplified but equally meaningful problem? Also, was our software prepared to take exploit completely the given hardware, both algorithmically as technically?
This short story is a brief introduction to the topic that will be explored in this post. An appropriate technical title would have been something like “On the Importance of Algorithmic Optimization and Good Coding Practices”, however I think its best to keep things casual and try to answer the posed question of “why do we need a supercomputer at all?”. For this reason, here we will explore if its not possible to avoid - at least in some measure - using a supercomputer to explore new scientific topics and instead make use of what essentially is also a supercomputer in everything but name: the laptops and desktops that most of all have at home or work, and which most likely are currently in front your eyes right now. Since, isn’t it true that “The purpose of computing is insight not numbers”, as Richard Hamming would say? Is it then possible to do supercomputing at home?
In order to delimitate the scope of this work, we have to choose a scientific application. It has to be meaningful, nontrivial, and ideally not-too-boring. So I propose to make use of a very simple discretization method called “Smoothed Particle Hydrodynamics”, which has been applied to a range of different fields such asfluid simulations to orbiting stars, down to Earth to video games and granular material modeling. So in what follows I will briefly and bluntly introduce the SPH method and describe how we make use of it to illustrate our ideas. For the readers that have no appetite for equations or those who simply do not make use of SPH and never will, feel free to skip to the next section where a more diagrammatic approach is followed. Those who get their curiosity tickled the work of Monaghan (2005) provides an excellent introduction to the topic.
Smoothed particle hydrodynamics is a meshless discretization method, or a particle method depending on the source you consult. In mesh-based methods, such as FEM and all its variants, a grid is used to describe a domain -e.g., a canal where a fluid flows through. This grid (or mesh) is composed of elements of a certain geometry, such as triangles or squares, and in turn consist of nodes. These characteristics impose a connection between the nodes that compose an element, the neighboring elements sharing nodes and the whole grid being in a sense “stiff” due to this connectivity. In SPH there is none of this, the nodes, or particles, are free floating around the defined domain, with no particular connectivity between them. Some sources describe it as saying that each particle represents a complete infinitesimal elements on its own.
In mathematical terms, we can interpolate a scalar quantity $A$ at position $x$ via a sum of all particle contributions:
A\left(x\right)_S = \sum_j m_j \frac{A_j}{\rho_j}W\left( x-x_j,h \right)
understood as an iteration of all $j$ particles around $x$, using each particles density $\rho$, mass $m$, and position $x_j$. The function $W$ is called the smoothing kernel, which performs the interpolation within a distance $h$, after which $W(x,h)=0$, as illustrated in Figure 1. This tells us that not all neighbor particles $j$ contribute to the interpolation at point $x$.

Figure 1: Core radius distance $h$ for the interpolation $W(x,h)$. Beyond $h$ we have that $W(x,h)=0$.
Similar expressions can be derived for the derivates of the scalar quantity $A\left(x\right)$, that is for $\nabla A_s\left(x\right)$ and $\nabla^2 A_s\left(x\right)$, which are not given nor addressed here for brevity.
In order to test this technique, we decide to simulate a free surface, confined fluid -the fluid bounces on every wall of the containing box- for which the Navier-Stokes equation suffices.
Our approach is based on a simplified version of Müller et al (2003). So let the acceleration per particle be given by
\rho \frac{Dv}{Dt}=-\nabla \rho + \rho g + \mu\nabla^2 v
with $v$ the velocity of a given particle, and the right-hand-side terms are the pressure, external forces, and viscosity respectively. So essentially what we have to is find the forces acting on each particle. For brevity, we give the computed forces as a list below:
f^{pressure}_i=\sum_j m_j \frac{p_j}{\rho_j}\nabla W\left( x_i-x_j,h \right)
f^{viscosity}_i=\mu \sum_j m_j \frac{\mu_j-\mu_i}{\rho_j}\nabla^2 W\left( x_i-x_j,h \right)
f^{gravity}=-9.81
Our case study for analysis is based on a simplified scenario in 2 dimensions, where we will try to maximize the number of molecules while attempting to limit the increase of runtime as the number of particles increases. This means, ideally we want to run dramatically large simulations in the same time as a small one.
The way the scenario works is illustrated in Figure 2 below, where a water column is affected by gravity, pressure, and viscosity until it settles down into an oscillating fluid at the bottom of the container.
![]() (a)Step 0 | ![]() (b) Step 1000 |
![]() (c) Step 4000 | ![]() (d) Step 9999 |
Figure 2: Free surface fluid example. The water column settles into a standing fluid at the bottom of the container.
This simulation included 6084 molecules, our target now is to explain how we can achieve a higher number of particles in the same hardware with the promise of at least limiting the total runtime (in seconds) with respect to the increase of particle number.
As a first, simple approach, the simulation was implemented using a very direct technique where each particle is compared against all others, whether they are close to each other or not. So a particle $i$ will check every other particle $j$ to see of they are within the distance $h$. We call this an all-to-all approach, and it will be used as a starting point for our hypothetical analysis. Initial insight can be found by carrying out a study of how the runtime increases together with the number of particles.

Figure 3: Plot of number of particles N and runtime in seconds, the dashed line serves as a reference.
Such a result is given in Figure 3 for up to 32000 particles for a short simulation lasting 50 time steps. We can easily conclude that at 32000 particles we needed about 1 second per time step, such that if a “real” simulation consisting sometimes of 50000 steps then that would imply 50000 seconds which in hours is “only” about 14 hours of waiting for the simulation to be done. Of course one could argue that I only used 4 cores of my computer and, in an ideal world, one could use instead one node of HSUper with 72 cores and reduce this time by a factor of 18 such that we would only need to wait little less than 45 minutes.
Although in principle this perspective is correct, it does not change the fact that we have a bad algorithm and that we would be wasting a lot of compute power in unnecessary operations (like comparing distances between particles that are clearly far away from each other).
Additionally, if we would want to simulate a larger number of particles N, say 1 million particles, then for 50 steps we would have to wait again 14 hours in my laptop and 45 minutes in HSUper, from which we conclude that even in a parallel capable node with 72 cores we would have to wait 45000 minutes -only 750 hours and only 31 days- for 50000 steps. So we should resist our temptation to connect to the supercomputer for now, and try to improve our current implementation.
We already introduced our first performance metric, the total runtime of the simulation. Additionally there are other critical aspects we should keep track of as our optimization goes further.
Let’s make a list of things that can give us a hint as to the performance status of our codebase:
chrono header provides us with high performance time counters.One of the first things we should be interested on is: where is the time mostly spent in our simulation or workflow?
This is called detecting a hotspot.
For the specific case of SPH, our gut feeling would say that most of the time and effort is spent calculating the forces between the particles. A high-level overview of the SPH simulation flow is:
Here, we made use of time counters to determine that our time is spent as follows:
for the 50 steps of duration. Turns out our gut feeling was righ, we now have the raw numbers to determine that our attention and effort must focus on the routines associated to computing forces and density.
Having detected our hotspots, we can move on to creating a performance baseline of our application. We begin by measuring the metrics mentioned above.
We will measure these metrics using perf, a profiler commonly found in all linux-based systems.
This keeps our analysis simple and general, although we have to use the command perf list to figure out which performance counters (or events) are available in our system.
Then we can use the profiler as
perf stat -r 5 -e fp_arith_inst_retired.scalar,cache-references,cache-misses sim-sph.out
with -r 5 we average five different runs and with -e we tell perf which events to measure (after exploring the list). We measure floating operations with fp_arith_inst_retired.scalar and cache behavior with cache-references,cache-misses. Since perf also measures the total runtime, we use it for our analysis.
So for our initial approach of all-to-all we can now give some basic performance measurements:
With these measurements we have two components of the same story. On one side, the performance metrics give us a mixed evaluation of our current approach: OK-ish GFLOPS, low MPUPS, what seem to be several cache-misses, and a runtime that does not tell us much on its own. On the other side, we now that the used implementation is of unavoidable $O(N^2)$ complexity, as we mentioned before. From both of these we learn that no matter how good our performance metrics might be, we will always be limited by the intrinsic nature of the algorithm.
Therefore it is clear that independently of our measurements, we are bound algorithmically and its time to implement a new approach. Since we eventually want to run a simulation with several hundred thousand or even a million of particles, it is time to do some algorithmic optimization.
One obvious thing to do, as mentioned previously, would be to limit the “neighborhood” of search for each particle to their immediate neighbors. This is called a linked cells algorithm, where the particles are sorted into cells of a regular grid.
![]() (a) Use of regular grid over the whole domain | ![]() (b) In 2d, one cell has 8 neighbors (in gray) |
Figure 4: Regular grid used to sort particles into cells
This is shown in Figure 4 (a), corresponding to same particle distribution as in Figure 1 (b). Using a grid it is now possible to compute the forces between particles by traversing their directly neighboring cells, as shown in Figure 4 (b). Although we are still going to find some neighboring particles beyond $h$, the toal number of distance comparisons is greatly reduced. With this optimized algorithm we can rerun our scenarios and measure the performance.
For the same scenario as before, with 6084 particles:
Several things changed a lot:
So, although the raw evidence might tell us something is wrong, it is evident that a better implementation has been achieved. A strong indication for this are the MPUPS=1.97, which is about 20 times larger than the all-to-all approach.
Finally, we could now rerun also the largest scenario of 37000 particles and record the runtime. We configure the simulation and run it for 50 steps for a total of 1.45 seconds, a speedup of $S=\frac{66.7}{1.91}=34$ for the same hardware. Purely based on algorithmic improvements. Moreover, to achieve an equally slow time as the all-to-all, we would have to run a simulation with 250k particles. So we have increased our “maximum” simulation size by almost 8 at the same runtime cost.
We started by promising to give a perspective on how to do supercomputing at home, by attempting to run a very large simulation with the resources we have at home. So far, we have a simulation with 200k that can run at a rate of around 1 step per second. Can we improve on this?
Turns out there are many additional techniques we can test, see for instance Dominguez et al (2013). One of them is the use of neighbor lists, as in Band et al (2019), where the authors claim an improvement over the “simple” linked cells approach. As in Figure 4 (b), we can use the regular grid to determine which particles are neighbors within $h$ of the red particle. Then we can make a list of these neighbors and directly compute the forces without checking the distances. Without spending too much time on the details, we can directly give the peformance metrics as:
Clearly some slight improvements, which might indicate there is further room for improvement.
As a final result, we can give the same plot as in Figure 3 for these two new approaches. For more than 100000 particles and 50 steps, we reproduce the same N vs. runtime experiment as the one used as a performance baseline with the all-to-all technique. In Figure 5 these results are given for comparison.

Figure 5: Plot of number of particles N and runtime in seconds, in blue the simple linked-cells approach and in red the neighbor lists approach to force computation.
If compared against the results in Figure 3, we see that not only the time for the 32000 particles is now dramatically lower, but also that even for up 150000 particles the total runtime does not come close to the largest all-to-all scenario in Figure 3.
Finally, we can summarize our performance metrics in a table, given below, for the N=6084 scenario. Not only we show that our runtime is progressively lower, but that we perform now less unnecessary operations while accessing less cache memory.
| Metric | All-to-all | Linked-cells | Neighbor-lists |
|---|---|---|---|
| Runtime (s) | 2.277 | 0.170 | 0.130 |
| Total FLOPs (GFLOP) | 18.680 | 0.336 | 0.325 |
| Performance (GFLOPS) | 6.74 | 1.97 | 2.50 |
| Cache miss rate (%) | 43.29 | 46.00 | 45.00 |
| Cache references (million) | 81.0 | 6.0 | 5.8 |
| Particle updates (MPUPS) | 0.109 | 1.98 | 2.34 |
Of course all algorithms incur a use cost, usually the more complex an algorithm the higher the price to pay. For instance, nothing was said about “Build” costs of creating a linked cells scheme and sorting the particles into the cells. Nor about how expensive it is to create a list of neighbors per particle, which usually requires more distance comparisons than the linked cells.
Several of these aspects are discussed in the given literature sources, but interested readers can directly pull the code and carry out their tests and come up with their own conclusions. The code can be found here.
I’ll give several disclaimers before concluding this post. First of all, yes our case study was very simple and yes by all means we did not cover everything what a proper performance engineering approach should do. By no means was our analysis here exhaustive nor our techniques the “best”, there is a wide range of colors and flavors out there for every taste and situation. So all readers are cordially invited to go through the “Literature” of their specific fields.
Another important point is that the intention here was not to discourage using the supercomputer, the intention was to discourage using it “for everything”. For instance, the optimization approach here presented would directly port to better performance in a HSUper node -or in any multicore node in that case. Readers and users are urged to make use first of the resources at hand first, i.e. intelligence and their own laptop, before moving on to a more complex system like HSUper.
If we could summarize our message to the CBRZ community it would as follows. Know your codebase like thyself, so that you can use your prefered or available performance measuring tool to detect hotspots in your code Then be aware of what you want to achieve, both scientifically as computationally. Ask yourself questions such as “what is the smallest/largets scenario I can use to gain the desired insight?” or “what does the literature say regarding my desired experiments?”. Generate a performance baseline to improve on, as we did with the all-to-all approach. With it and with a proper literature-based plan, optimize your hotspots to improve your performance. Measure the improvements and write down the results. And finally, ask yourself “do I need to use the supercomputer?” Whether the answer is yes or no is up to you, but if you do then do it efficiently.
Finally, from a personal perspective I do believe that trying to keep algorithms and their code implementations simple, such that one does not depend on external equipment like a supercomputer, is of utmost importance to the progress of the Computational Sciences. Not long ago, researchers like you and I had no access to powerful computing equipment to carry out computer experiments, however their work is still so valuable that most of us still cite their publications in our own work. Perhaps its time to go back to a simpler way of working, relying more on our ingenuity than in the power of compute.