# What does Static, Dynamic and Single Dynamic linking mean?

I use Intel MKL for BLAS and use the Intel MKL Link Line Advisor for help with the command line options.

The advisor provides options for Static, Dynamic and Single Dynamic Library. What do these terms mean?

There have been numerous posts on SO regarding this but all of them have been focused on developing softwares rather than scientific/mathematical codes. (This one was especially useful)

• How are these terms relevant to Parallel Computing?
• Is one "better" than the other? (I know that better would need to be defined more precisely but I don't know how to as of now)
• What is used more commonly and why?
• What does the programmer need to consider when linking?
• Just as a note, if you haven't seen it, the newer Intel compilers (I think version 11 and newer) provide the -mkl flag which should remove the need to use the link line advisor for most cases. Mar 19, 2012 at 15:55
• @Aesin, I was wondering. Is it the most optimal way of linking? Mar 19, 2012 at 16:14
• I don't know, unfortunately - I've not really done any testing, and the manual doesn't go into any detail about what it's doing or how it combines with other options. It does statically link MKL if you specify -static and dynamically links it if you don't, though. It's certainly a lot better from an ease of use point of view, in any case. Mar 19, 2012 at 18:28

The terms static linking and dynamic linking are not directly related to parallel computing, though it has been known for quite some time that dynamic loading (as opposed to loading a statically-compiled executable) does not scale well on network file systems due to the heavy metadata load caused by the dynamic loader searching load paths for target libraries.

It is hard to make general statements about whether static or dynamic libraries are better in high performance computing. Certainly for most supercomputing applications, it is simpler and preferred to statically link. Why is this? On the current generation of supercomputers, there is usually only one job running per node, which strongly reduces any benefits of reduced memory consumption due to shared libraries. Additionally, scientific computing codes tend not to be very sophisticated in terms of language features or program design, and they rarely make use of language features that require dynamic loading (such as plugin modules). Dynamic libraries have the additional difficulty of being much less portable across operating systems than static libraries. This has lead to the creation of several tools for automating the installation of dynamic libraries, which can sometimes create more problems than they solve.

As a consequence of all of this, most HPC systems use static compilation when available. Static libraries are viewed as faster, easier to install and maintain, and generally more robust. HPC codes based on Python are one of the exceptions to this, but they are still subject to the performance problems associated with dynamic loading (several users on scicomp are actually working on this problem right now!).

When you are choosing static vs. dynamic linking, you need to consider how and where your code will be deployed, whether the underlying libraries are likely to change or move, and the performance characteristics of your network file system. You should also evaluate whether you need dynamic linking, either through a library dependence or to interoperate with a dynamic scripting language such as Python.

Single Dynamic Library is an Intel-specific term. It refers to the packaging of their dynamic libraries into a single meta-library to simplify the linking process. If you will be using dynamic linking with Intel libraries, this form is probably preferred unless you are doing something complicated.

• Excellent answer! Just one more thing: I realize dynamic linking would be unnecessary and the choice will be between static and single dynamic. You say that I should choose the latter unless I'm doing something complicated (which I am not). So, should I link using Single Dynamic? [FWiW, I'm working on Krylov Subspace Methods] Mar 18, 2012 at 5:31
• Sorry! I meant you should use static by default but prefer single dynamic over dynamic. Mar 18, 2012 at 6:17
• I did some benchmarking and I found : Dynamic : 0:42.92 Static : 0:42.93 Single Dynamic : 0:42.97 averaged out over 1000 values. Mar 18, 2012 at 6:47
• It's worth noting that on some HPC systems you have to statically link -- on the BlueGene/L systems this is the case, for example, because the reduced OS on the compute nodes doesn't support dynamic linking. Mar 19, 2012 at 15:53
• I'm a bit confused by your statement: "On the current generation of supercomputers, there is usually only one job running per node, which strongly reduces any benefits of reduced memory consumption due to shared libraries." Did you mean to say that there is only one process per node? I'm not sure how one job per node affects the situation. When statically linking each process will store a full copy of the executable which can be significant as cores per processor grow. Dynamic linking will only require one copy of the dynamic library per shared memory space. Nov 13, 2013 at 3:57