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 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

Just starting with Using OpenMP? "Chat"

Postby Ernst0 » Mon Apr 16, 2012 11:51 pm

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
Ernst0
 
Posts: 24
Joined: Sun Nov 23, 2008 2:32 pm

Re: Just starting with Using OpenMP? "Chat"

Postby ruud » Tue Apr 17, 2012 11:52 pm

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
ruud
 
Posts: 23
Joined: Mon Nov 26, 2007 2:13 am

Re: Just starting with Using OpenMP? "Chat"

Postby Ernst0 » Wed Apr 18, 2012 6:18 pm

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.
Ernst0
 
Posts: 24
Joined: Sun Nov 23, 2008 2:32 pm

Re: Just starting with Using OpenMP? "Chat"

Postby ruud » Thu Apr 19, 2012 4:13 am

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
ruud
 
Posts: 23
Joined: Mon Nov 26, 2007 2:13 am

Re: Just starting with Using OpenMP? "Chat"

Postby tomriddle » Thu May 31, 2012 9:03 am

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?
I'm a web developer in Ipswich who does web design - Ask me if you need help!
tomriddle
 
Posts: 2
Joined: Thu May 31, 2012 8:36 am

Re: Just starting with Using OpenMP? "Chat"

Postby brad87uk » Tue Jun 26, 2012 4:20 am

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.
brad87uk
 
Posts: 1
Joined: Wed Jun 13, 2012 9:40 am

Re: Just starting with Using OpenMP? "Chat"

Postby Sarah3134 » Tue Jul 15, 2014 9:17 am

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 saleprivate blog networksteroids for salesteroids for salecannabis seeds for salemarijuana seeds for salemarijuana seedspot seeds for salemarijuana seedsmackeeperkratom for salebuy salviabongs for saleprivate blog networkprivate blog networkbuy kratombuy steroidssalvia for salemackeeper couponMarijuana Seeds For Sale Reviews - Best Cannabis Seeds For Sale
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
Sarah3134
 
Posts: 1
Joined: Sun Jul 13, 2014 12:38 pm


Return to Using OpenMP - The Book and Examples

Who is online

Users browsing this forum: No registered users and 2 guests