On Apr 15 2011, Richard Guenther wrote:
On Fri, Apr 15, 2011 at 2:04 PM, Tobias Burnus <bur...@net-b.de> wrote:

Q2: Can this be optimized in some way?

For simple types you could use atomic instructions for the modification
itself instead of two SYNC ALL calls.

Well, even with atomic you need to have a barrier; besides the example was only for illustration. I think if one uses the variable in "foo" before the first sync all, one even would need two barriers - atomic read/write or not. (For the current example, setting the value in "foo" is pointless. And the obfuscated way the variable is set, makes the program fragile: someone modifying might not see the dependency and break it.)

As long as all variables that need protection are global a random function
call before and after is enough to avoid optimization.

Today in gcc, perhaps.  But it's NOT a good idea to rely on it, as it
is broken by many of the optimisations that Fortran traditionally uses
I don't think that gfortran uses them, but could be wrong, and it might
well change.

It also doesn't extend to threading, whether the extra threads are
explicit or 'helper' threads.  Extra incantations are needed.


Regards,
Nick Maclaren.




Reply via email to