Channels ▼

Stephen Blair-chappell

Dr. Dobb's Bloggers

Going Parallel: Part 3: Let's Get Started!

May 21, 2009

When I first dipped my toes into parallel programming I hunted around for a legacy application to change from serial to parallel. Rather than work on one of my own apps, I looked for a serial application on the web that had lots of CPU activity. I ended up choosing the Dhrystone benchmark.It was a great learning experience. In the next few blog entries I'm going to try and use the same code and go through the process of making it parallel.

I do remember that the first time I did this It took me quite a number of sessions to get the job completed. Lot's of silly errors. Learning to use the tools at the same time as learning how to add the parallelism took more time than I expected.

On one hand, I was proud that I had made a program parallel. On the other hand, I was a little disappointed that it took me so much time to parallelize a program not that much more complicated than hello world.

In this part of the going parallel blog I'll show how I  identified the where to parallelise

Links to the previous  blog entries

Going Parallel: Part 1: Doing Two Things at Once - Impossible!

Going Parallel: Part 2: So Who's Really Writing Parallel Applications?

The Application

So, on with the show! I'm curious as to how I'll get on. I'm a lot wiser than when I first did this exercise in the dim and distant past. Also, there are many more tools now available to help in the task -- not least the upcoming Intel Parallel Studio. First thing was to get the source code which I obtained from  The file is a self-extracting shell script. If you don't have a shell available on your windows machine, you can get a copy of my extracted and modified files here dhry_1.c, dhry_2.c, dhry.h  

Building the Code

I'm using the latest released version of the Intel Compiler (v11.0.72). Building was straightforward:

    icl /ZI /DTIME dhry_1.c dhry_2.c /o intel.exe

I also built a Microsoft version:

cl /Zi /DTIME dhry_1.c dhry_2.c /o ms.exe

Modifying the Source Code

I modified the code so I could pass in the loop counter at the command prompt. The code snippet below shows my additions in bold:

main (int argc, char * argv[])

if(argc > 1)
    Number_Of_Runs = atoi(argv[1]);
    printf (
"Please give the number of runs through the benchmark: ");
int n;
        scanf (
"%d", &n);
        Number_Of_Runs = n;
    printf (


Why Does the Intel-built Application Run So Much Faster?

The first thing I noticed is that the executable built with the Intel compiler runs much faster than the Microsoft  version.  When building with Intel compiler and the /O2 option we get a speedup of  3.

For the  moment I'm going to use the /Od options and get on with the task of making the program parallel.  In a subsequent blog I'll do some analysis of the speedup. My suspicion is that the number of calculations has been reduced by the optimisation process -- which strictly speaking is not what I want for the benchmark.

Compilerer Optimisation Flag Num Loops  Dhrystones per Second Improvement
Ratio WRT Row 1
Microsoft /O2 (for speed) 10000000 1.6 M 1
Intel /O2 (for speed) 10000000 5.0 M 3
Microsoft /Od (no optimisation) 10000000 1.6 M 1
Intel /Od (no optimisation) 10000000 1.6 M 1


Finding the Hotspot

I'm going to use Intel VTune to determine where the Hot spots are.   The next few screens show the loading and running of the program under VTune.  In the next blog I'll use Intel Parallel Amplifier to look for hotspots.




Looking at the number of clock-tick samples shows that there are a number of functions that contribute to the activity of the application.   In some applications it maybe that just one or two functions are "hot". In this code there are quite a number of functions.

Strategy for Next Steps

It looks to me like the best strategy would be to  parallelise the high-level loop in main.  

    for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)

In the next blog, I'll introduce some parallelism using OpenMP, then try to discover what pitfalls I'm falling into.




Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.