[Omp] A problem with guard objects and exceptions on Intel

Dieter an Mey anmey at rz.rwth-aachen.de
Wed Aug 23 10:30:29 PDT 2006


Michael,

I could not resist to try out the code myself.
I add a few print statments and it seems to run well using the Sun 
compiler and also Gcc 4.2
But the Intel compiler seems to have problems (V9.1)

Either the code hangs when constructing the first guard object or I get 
a segmentation violation (this time in the destructor when unsetting the 
OpenMP lock, as I can see with totalview.)-

I hope the sources are OK - I am still no C++ guy

regards,
Dieter


Michael Suess schrieb:
> Dieter,
> 
> I tried:
> 
> $ulimit -s 4000
> $ulimit -s 8000
> $ulimit -s 16000
> $ulimit -s 32000
> $ulimit -s unlimited
> 
> Nothing made any difference (and I still do not understand why it should - I 
> am hardly putting anything on the stacks at all).
> 
> Thanks, Michael
> 
> 
>> Micheal,
>>
>> try something in between small and unlimited.
>> I had such a case as well.
>>
>> Dieter
>>
>> Michael Suess schrieb:
>>> On Wednesday 23 August 2006 01:38, Micah Elliott wrote:
>>>> On 2006-08-22 Michael Suess wrote:
>>>>> I have just published a blog entry comparing the merits of
>>>>> guard objects vs. the critical construct (with C++ and OpenMP).
>>>>> The problem I have now is: My test programs with exceptions and
>>>>> guard objects do not work for the Intel Compiler. Since this
>>>>> would not be the first time I missed something, I figured I
>>>>> would double check here before filing a bug with Intel.
>>>>>
>>>>> So if you find the time, please take a look at the code for the
>>>>> guard object, enclosed in the following article:
>>>>> http://www.thinkingparallel.com/2006/08/21/scoped-locking-vs-critical-i
>>>>> n- openmp-a-personal-shootout/
>>>> I didn't take much time in looking at the code, but I did compile
>>>> what I found on the site with icpc, and saw that you'll get the
>>>> SEGV if you don't increase your stack limit (e.g., "ulimit -s
>>>> unlimited" in bash).
>>> Hi Micah,
>>>
>>> your advice does not seem to help:
>>>
>>> $ ulimit -s unlimited
>>>
>>> $ ulimit -s
>>> unlimited
>>>
>>> $ icpc test_omp_guard_exceptions.cpp -o test_omp_guard_exceptions
>>> omp_guard.cpp -openmp
>>> test_omp_guard_exceptions.cpp(18) : (col. 2) remark: OpenMP DEFINED
>>> REGION WAS PARALLELIZED.
>>>
>>> $ ./test_omp_guard_exceptions
>>> Segmentation fault
>>>
>>> I am curious, though: Why do you think the stack size is too small? I am
>>> not using much stack space in my program, as far as I can see...
>>>
>>> Thanks anyways,
>>> Michael
> 


-- 
--------------------------------------------------------------------
Dieter an Mey
High Performance Computing               Hochleistungsrechnen
RWTH Aachen University                   Rechen- und Kommunikations-
Center for Computing and Communication   zentrum der RWTH Aachen
phone: ++49-(0)241-80-24377              Seffenter Weg 23
fax:   ++49-(0)241-80-22134              52074 Aachen, Germany
email: anmey at rz.rwth-aachen.de
--------------------------------------------------------------------
-------------- next part --------------

#ifndef OMP_GUARD_HPP_

#define OMP_GUARD_HPP_

 

#include <omp.h>

 

/** This is a class for guard objects using OpenMP

*  It is adapted from the book

*  "Pattern-Oriented Software Architecture". */

class omp_guard {

public:

    /** Acquire the lock and store a pointer to it */

    omp_guard (omp_lock_t &lock);

    /** Set the lock explicitly */

    void acquire ();

    /** Release the lock explicitly (owner thread only!) */

    void release ();

    /** Destruct guard object */

    ~omp_guard ();

 

private:

    omp_lock_t *lock_;  // pointer to our lock

    bool owner_;   // is this object the owner of the lock?

   

    // Disallow copies or assignment

    omp_guard (const omp_guard &);

    void operator= (const omp_guard &);

};

 

#endif /*OMP_GUARD_HPP_*/
-------------- next part --------------
#include <omp.h>
#include <cassert>
#include <stream.h>

#include "omp_guard.hpp"

int main (void)
{
	omp_lock_t my_lock;

	// how many exceptions have been thrown (should be one for each thread)
	int ex_count = 0;

	// how many threads will be created (most likely)
	int numthreads = omp_get_max_threads ();

	omp_init_lock (&my_lock);

	#pragma omp parallel
	{
		cout << "Here I am " << omp_get_thread_num() << endl;
		try {
			omp_guard my_guard (my_lock);
			throw omp_get_thread_num ();
		}
		catch(int e) {
			#pragma omp atomic
			++ex_count; 
			cout << ex_count << endl;
		}
	}
	assert (ex_count == numthreads);
	omp_destroy_lock (&my_lock);

	return 0;
}




/** The class contained in this file is a guard object */

 

#include "omp_guard.hpp"

 

/** Construct guard object and acquire our lock */

omp_guard::omp_guard (omp_lock_t &lock) : lock_ (&lock)

    , owner_ (false)

{

    acquire ();

}

 

/** Explicitly set our lock */

void omp_guard::acquire ()

{

    omp_set_lock (lock_);

    owner_ = true;

}

 

/** Explicitly unset our lock.

* Only unset it, though, if we are still the owner.

*/

void omp_guard::release ()

{

    if (owner_) {

	owner_ = false;

	omp_unset_lock (lock_);

    }

}

 

/** Destruct guard object, release the lock */

omp_guard::~omp_guard ()

{

    release ();

}




More information about the Omp mailing list