flush for arrays and subobejcts in fortran

General OpenMP discussion

flush for arrays and subobejcts in fortran

Postby MartinStein » Fri Feb 15, 2008 7:43 am

How can I flush a subobject, i.e. something like !$ omp flush(name%component), in fortran?
There are no comments on flushes of structures in the openmp specifications (or I have missed them).

Similarly how can I flush array elements ptr(i) for a pointer ptr to an array?

Any help is greatly appreciated!
Martin
MartinStein
 

Re: flush for arrays and subobejcts in fortran

Postby ejd » Tue Feb 19, 2008 10:04 pm

There is no way to flush an array element, structure component, or subobject in OpenMP. In fact, there is so much confusion about how to use flush, that there have been discussions about removing the flush(list) form.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: flush for arrays and subobejcts in fortran

Postby MartinStein » Wed Feb 20, 2008 7:37 am

Well, now I simply use flush instead of flush(list), and I didn't expect that I get significant penalty.
What I forgot to ask and which is still nebulous to me: What is the "flush-set" of a flush without a list. This word is mentioned in Spec1.4.2 (Version2.5) but not defined (or did I miss it, a search didn't reveal anything).
As I see it the memory location of array(i) is not flushed in the example below. Hence from the specification I couldn't derive how to synchronize such read/writes to arrays (same for subobjects). I guess and assume that compilers do the flush for all read/writes, but the specification does not enforce it, or am I wrong?


Example:

!$omp parallel
...
arrayPointer(i) = expr
...
!$omp flush

!$omp end parallel
MartinStein
 

Re: flush for arrays and subobejcts in fortran

Postby ejd » Wed Feb 20, 2008 10:12 am

The term "flush set" is not defined. However, under the section on the flush construct it states:

A flush construct without a list, executed on a given thread, operates as if the whole threadvisible
data state of the program, as defined by the base language, is flushed.

So in theory, all variables visible to the thread are flushed. However, an implementation may be smart enough not to flush all variables. For example, flushing variables private to the thread makes no sense.

Compilers do not have to do flushes before all reads/writes according to the OpenMP spec. There are points where flushes are defined to happen by the spec, because it eases programming for the user. If it were done everywhere, then you would see a substantial performance penalty. That is the reason that the flush construct was added to the OpenMP spec - to allow the user to add them in the (hopefully) rare cases that need them. Most of the time, unless the user is trying to do synchronization between threads, flushes are not really required to get work done.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: flush for arrays and subobejcts in fortran

Postby MartinStein » Wed Mar 05, 2008 5:00 am

Thanks for the clarification. I have misunderstood that passage (threadvisible data) and thought only refers to threadvisible variables which would have excluded array elements.

(To your other remarks concerning flush: I definitely need them and have experienced race conditions were I forgot to insert them. In fact for recursive data structures with orphaned openmp directives and the possibility of several threads working on the same tree node I didn't see how to avoid locks (with locks for each node) and flushs before calls to omp_unset_lock. The task construct of spec3.0 would simply the problem.)


Last bumped by Anonymous on Wed Mar 05, 2008 5:00 am.
MartinStein
 


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 4 guests