views:

78

answers:

1

Hi,I added openMp code to some serial code in a simulator applicaton, when I run a program that uses this application the program exits unexpectedly with the output "The thread 'Win32 Thread' (0x1828) has exited with code 1 (0x1)", this happens in the parallel region where I added the OpenMp code, here's a code sample:

#pragma omp parallel for private (curr_proc_info, current_writer, method_h) shared (exceptionOccured) schedule(dynamic, 1) 
    for (i = 0 ; i < method_process_num ; i++)
    {
         current_writer = 0;
        // we need to add protection before we can dequeue a method from the methods queue,

        #pragma omp critical(dequeueMethod)  
        method_h = pop_runnable_method(curr_proc_info, current_writer);

        if(method_h !=0 && exceptionOccured == false){
            try {
            method_h->semantics();
            }
            catch( const sc_report& ex ) {
                ::std::cout << "\n" << ex.what() << ::std::endl;
                m_error = true;
                exceptionOccured = true;  // we cannot jump outside the loop, so instead of return we use a flag and return somewhere else
            }

        }
    }

The scheduling was static before I made it dynamic, after I added dynamic with a chunk size of 1 the application proceeded a little further before it exited, can this be an indication of what is happening inside the parallel region? thanks

A: 

Hi

As I read it, and I'm more of a Fortran programmer than C/C++, your private variable curr_proc_info is not declared (or defined ?) before it first appears in the call to pop_runnable_method. But private variables are undefined on entry to the parallel region.

I also think your sharing of exception_occurred is a little fishy since it suggests that an exception on any thread should be noticed by any thread, not just the thread in which it is noticed. Of course, that may be your intent.

Cheers

Mark

High Performance Mark
Thanks for your reply mark, there are 2 ways to make a variable private to a thread, the one that you suggested, and the one that I am using where I define them as private in the pragma clause, and they are declared right before the code that I pasted, otherwise I'd have gotten a compilation error, and yes that's my intent of using the flag exceptionOccured.
Noona
Yes, you've defined curr_proc_info in your pragma clause, but you haven't assigned it a value before passing it into the function pop_runnable_method. If that function requires curr_proc_info to have a value you will have problems. If that function assigns a value to curr_proc_info I'm out of ideas.
High Performance Mark
I want to assign values to it in the function that I am calling (using call by reference). The reason behind the problem has to do with OpenMp scheduling or something OpenMp related, that's where I am hoping to get advice.
Noona
So if you remove the schedule clause and let OpenMP use its defaults, your code runs correctly ?
High Performance Mark
yes, when I disable OpenMp support in Visual studio the program runs correctly.
Noona
But what happens when you enable OpenMP support but do not include a scheduling clause in your pragma statement ?
High Performance Mark
the same thing happens, that's why I added the the schedule clause.
Noona