Tips on Efficient Coding

SAFE Research Data Center

Errikos Melissinos, Research Assistant - May 2022

Logo SAFE

Documentation:
*.ipynb file Please note that .ipynb file requires a Jupyter environment, for ex. Google Colab, Jupyter lab,
YouTube video (22 mins). Sections:

The cluster offers storage, cores, memory and convenience.

Using the Cores - Multiprocessing

Prelude

Before going into the multiprocessing I would like to look a little bit into a few tips for efficient programming.

So let's assume that we want to make a calculation for each row in a dataset:

Now actual multiprocessing

The standard library used in python is multiprocessing. However, I will jump directly to something that I find more convenient, namely concurrent.futures.

So, it does not really make sense to introduce parallel computation for relatively simple tasks. It costs in coding and the computational overveads can actually make it slower.

Let's look at a case when it could help.

What about without multiprocessing?

The Computational Cluster also offers a lot of memory!

There is not much that I can actaully show you here as the title actually says it all.

However, even if the cluster offers a lot of memory it would also be good to know some practises in order to economise on the size of the data in memory. So, let me load a relatively large dataset: