[Patch, Fortran] -fcoarray=lib: Change handling of this_image() and num_images()
Tobias Burnus
burnus@net-b.de
Fri Mar 7 07:42:00 GMT 2014
The current coarray implementation uses a global static variable for
this_image() and num_images(), which is set by the CAF init function,
which is called by before the Fortran main function.
I somehow had the thinko that this permits for better optimizations than
a library call. However, global variables are not really optimization
friendly and I failed to come up with a scenario, where a global
variable works better.
In addition, there are two problems with a global variable: If the code
uses coarrays in a library but no in the main code (e.g. the main
program is written in C), the variable won't be initialized at all.
And the second problem relates to the upcoming Technical Specification
(TS) 18508 on Additional Parallel Features in Fortran. That TS
introduces teams - and calling this_image() from within a team will give
a different result to this_image(distance=1), which applies to the
parent's team.
Hence, the attached patch adds a this_image() and num_images() library
function. As the library is only build statically and -fcoarray=lib is
not widely used due to lacking communication support, I wouldn't count
this patch as real ABI break and there shouldn't be a problem from that
side.
I do include the distance= argument for both intrinsics and for
num_images also a failed= argument. Those have been proposed in TS18508.
I think it makes sense to prepare for that TS - if it won't be accepted,
one can still remove it (cf. argument above). Regarding the failed: One
needs to support three states: Unset (-1, all images); set to .false.
(0, all nonfailed images), and .true. (1, all failed images).
Additionally, I have changed the "size" argument to the unsigned size_t,
which matches both the current type in the front-end and the
conventional type for malloc calls.
Built and currently regtesting on x86-64-gnu-linux. When successful:
OK for the trunk? (It should be localized enough for 4.9 but 4.10 is
probably more appropriate.)
Tobias
PS: Regarding TS18508: My impression is that the current draft (14-130 /
N2007) is quite well shaped and will be accepted with only minor
modifications. There will be soon a WG5 letter ballot, after which it
should be even clearer where the standard is heading to.
PPS: I intent to create an SVN branch to collect the coarray changes.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: caf-this_image.diff
Type: text/x-patch
Size: 16250 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20140307/9a7ace4b/attachment.bin>
More information about the Fortran
mailing list