When to use OpenMP

General OpenMP discussion

When to use OpenMP

Postby geoff » Thu Jun 12, 2008 7:57 am

I've been working on using OpenMP in our commercial package for about a month now. I have targeted a function which is the most expensive(time) that consists of a matrix-vector multiplication. My question involves is there a rule of thumb for when a function should be parallelized? For instance if the function typically runs in the 10-100 millisecond range, yet is called thousands of times, should it be parallelized? I imagine a function which takes 10 seconds to run is a good target but one that runs in microseconds would not be ideal.

Re: When to use OpenMP

Postby ejd » Thu Jun 12, 2008 9:09 am

You are most likely correct. Unfortunately there is no hard and fast rules for when to use OpenMP. What you want to do, is have enough work so that the reduction in time from the parallel code section more than makes up for the overhead of spawning and joining threads (the cost of going parallel). Generally the overhead is going to run in the 100s of milliseconds - though it depends entirely on the hardware you are running on and the software implementation of OpenMP.

That is one reason that the "if clause" exists on the parallel region. That is so you can do things like:
Code: Select all
#pragma omp parallel for if(n > 100000)
for (i = 0; i < n;, i++) {

This allows the compiler to have duel path code (if an implementation decides to do that). For small values of "n", the code runs serially and for large values of "n" it will run in parallel. (The value of "n" here is totally meaningless other than for example purposes.)
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 7 guests