Just starting with Using OpenMP? "Chat"

Use this forum to discuss the book: Using OpenMP - Portable Shared Memory Parallel Programming, by Barbara Chapman, Gabriele Jost and Ruud van der Pas Read the http://openmp.org/forum/viewtopic.php?f=8&t=465 for book info and to download the examples. Post your feedback about the book and examples to this forum
Post Reply
Ernst0

Just starting with Using OpenMP? "Chat"

Post by Ernst0 »

Forgive and delete if this is an inappropriate thread but this seems to be a place to commune as I learn to use OpenMP.

I just started to read the book and it seems rather good. Perhaps I will glean what I need as I go since I program in C as my hobby.

Anyway, I am here and I will check back here to see if there are others learning too.
The examples have been downloaded and I successfully compiled the chapter3 so that is a start.

Okay then, feel free to chat with me on OpenMP if that is allowed.

------------------------------

Currently I am pondering using threads to each call an instance of a function with an integer that is incremented in the parallel region.
This seems to be a reasonable place to start to me and what I believe will be the program structure.
I assume a shared integer incremented or a for loop can provide an instance of value a thread can take with it into its instance of that function.
I assume that each thread will have a copy of that function all to itself. Seems like a good way to increase work done.

To ask a question. Is that reasonable usage? I do have more to read but I'll toss that out for conversation.

Ernst0

ruud

Re: Just starting with Using OpenMP? "Chat"

Post by ruud »

Hi Ernst,

Thanks for using our book!

I'm afraid it is not sufficiently clear to me what your questions are about. Could you share some code with us? That will make the discussion a lot easier.

Ruud

Ernst0

Re: Just starting with Using OpenMP? "Chat"

Post by Ernst0 »

I will share as soon as I can. Please forgive my sloth.

Part of this sloth is deciding what structure the data will take and how to process things..
A friend says think twice code once. So that is where I am and I appreciate your attention but don't worry too quick at this point.

I'm starting to read your white paper. There is much to cover.

Oh I can ask this. Is it realistic to have several threads call a function? Are they each going to have am instance of that function to each thread or is this considered branching outside of the Parallel region?
I have not advanced to writing anything yet so it is more research. But I have the cores so I am bound to get there.

Again respects and thanks.

ruud

Re: Just starting with Using OpenMP? "Chat"

Post by ruud »

Hi Ernst,

I just answered your question in the other thread, but will repeat the key part here for sake of completeness. I'll also answer your question.

Yes, you can execute functions in parallel. What you can't do is have a thread prematurely jump out of a parallel region. This is because there is a barrier at the end of the region and the run-time system will wait for all threads to have arrived there. If one or more threads jump out of the region that number will never be reached though and your program will hang.

Usually this kind of jumping is used in case something goes wrong, but that is easily handled in the following way:

Code: Select all

my_error = 0;
#pragma omp parallel shared(my_error)
{
    (void) my_function(&my_error);

} // End of parallel region

if (my_error != 0 ) { printf("Oops, something went wrong: error count = %d\n",my_error);}
The source of "my_function" has to contain something like this:

Code: Select all

void my_function(int *my_error)
{
     ... whatever you want to do ...

    if (something_goes_wrong) {
      #pragma omp critical
      { *my_error++;}
}
The critical section is needed in case multiple threads want to update my_error at the same time.

Ruud

tomriddle

Re: Just starting with Using OpenMP? "Chat"

Post by tomriddle »

But, two threads could never run two parallel functions at the same time though, right?
A CPU can only run one instruction at once, so what if two threads access the memory, will one be 1ms after another?

brad87uk

Re: Just starting with Using OpenMP? "Chat"

Post by brad87uk »

tomriddle wrote:But, two threads could never run two parallel functions at the same time though, right?
A CPU can only run one instruction at once, so what if two threads access the memory, will one be 1ms after another?
threading is unlikely to achieve true parallelism. For this reason, multiprocessing is generally a better bet.

Sarah3134
Posts: 1
Joined: Sun Jul 13, 2014 12:38 pm

Re: Just starting with Using OpenMP? "Chat"

Post by Sarah3134 »

ruud wrote:Hi Ernst,

I just answered your question in the other thread, but will repeat the key part here for sake of completeness. I'll also answer your question.

Yes, you can execute functions in parallel. What you can't do is have a thread prematurely jump out of a parallel region. This is because there is a barrier at the end of the region and the run-time system will wait for all threads to have arrived there. If one or more threads jump out of the region that number will never be reached though and your program will hang.

Usually this kind of jumping is used in case something goes wrong, but that is easily handled in the following way:

Code: Select all

my_error = 0;
#pragma omp parallel shared(my_error)
{
    (void) my_function(&my_error);

} // End of parallel region

if (my_error != 0 ) { printf("Oops, something went wrong: error count = %d\n",my_error);}
The source of "my_function" has to contain something like this:

Code: Select all

void my_function(int *my_error)
{
     ... whatever you want to do ...

    if (something_goes_wrong) {
      #pragma omp critical
      { *my_error++;}
}
bongs for salevaporizers for salevaporizers for salesteroids for salesteroids for salecannabis seeds for salemarijuana seeds for salemarijuana seedspot seeds for salemarijuana seedsmackeeperbuy kratomsalvia for salemackeeper couponcpnm.uskondosyokai.comjohnsonvalleyrallyx.comcocktailbarka.comxreccorp.comaccredited-tpi.comelectricallifecyclesolutions.comaberdeenseals.co.ukniwebsports.comzendogcafe.comanimeanarchy.netkittelsonforcongress.comhydragroupltd.com
The critical section is needed in case multiple threads want to update my_error at the same time.
Ruud
Hey guys,

I too am just getting my head around as OpenMP, and this is exactly the same problem i am having. This helps me start to get a better understanding, but i don't suppose you would be able to post the link to the other thread you mentioned if possible please so i could see the full reply?

I've tried searching for it but no luck so far :-/

Sarah
Last edited by Sarah3134 on Tue Aug 04, 2015 9:57 am, edited 3 times in total.

MarkB
Posts: 802
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Just starting with Using OpenMP? "Chat"

Post by MarkB »

Hi Sarah,

The other thread Ruud refers to is here http://openmp.org/forum/viewtopic.php?f=3&t=1410

If you are still having problems, please start a new thread on the main Using OpenMP forum here: http://openmp.org/forum/viewforum.php?f=3

Post Reply