Blog Archive

Wednesday, August 19, 2020

[tutorial] Install and test 'parallel' in your linux system (8/19/2020)

 Step 1: check installation.

Check whether parallel is already there by typing the following command in your terminal:

which parallel

If it display:

/usr/bin/parallel

It means you are okay to move forward to step 3.

Otherwise, go to step 2.


Step 2: install parallel.

sudo apt-get update -y

sudo apt-get install -y parallel


After installation, you can go back to step 1 to ensure everything is ok.


Step 3: prepare demo:

Suppose, your script is demo1.sh and its contents are:

date; sleep 2; date

date; sleep 2; date


Step 4: run a demo in traditional sequential way without fancy tool:

date;bash demo1.sh;date

And you should expect something like:


Wed Aug 19 18:18:20 PDT 2020

Wed Aug 19 18:18:20 PDT 2020

Wed Aug 19 18:18:22 PDT 2020

Wed Aug 19 18:18:22 PDT 2020

Wed Aug 19 18:18:24 PDT 2020

Wed Aug 19 18:18:24 PDT 2020



Step 5:run a demo in parallelized way with our fancy tool 'parallel'

Now you can type the following command in your terminal:

date;parallel < demo1.sh;date


And you should expect to see something like the following:


Wed Aug 19 18:16:25 PDT 2020

Academic tradition requires you to cite works you base your article on.

When using programs that use GNU Parallel to process data for publication

please cite:


  O. Tange (2011): GNU Parallel - The Command-Line Power Tool,

  ;login: The USENIX Magazine, February 2011:42-47.


This helps funding further development; AND IT WON'T COST YOU A CENT.

If you pay 10000 EUR you should feel free to use GNU Parallel without citing.


To silence this citation notice: run 'parallel --citation'.


Wed Aug 19 18:16:26 PDT 2020

Wed Aug 19 18:16:28 PDT 2020

Wed Aug 19 18:16:26 PDT 2020

Wed Aug 19 18:16:28 PDT 2020

Wed Aug 19 18:16:28 PDT 2020


Step 6: comparison and conclusion.

Now, let's check the displaying information.

If we focus on the first and last line of the output from step 5, that is:

Wed Aug 19 18:16:25 PDT 2020

Wed Aug 19 18:16:28 PDT 2020


The whole script takes 3 seconds. It is less than 4 seconds. You save 1 second. If you have more tasks and more cores, you can even observe more time saving.


If we focus on the first and last line of the output from step 4, that is:

Wed Aug 19 18:18:20 PDT 2020

Wed Aug 19 18:18:24 PDT 2020


The whole script takes 4 seconds



Reference:

[1] https://www.gnu.org/software/parallel/parallel_tutorial.html

[2] https://www.msi.umn.edu/support/faq/how-can-i-use-gnu-parallel-run-lot-commands-parallel