Home > Archive > Fortran > August 2007 > BIND and ELEMENTAL
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
BIND and ELEMENTAL
|
|
| Jared Ahern 2007-08-18, 4:29 am |
| Hello all,
According to the Intel v10 language reference at:
<http://www.osc.edu/hpc/manuals/INTE...e/10.0.023/doc/
main_for/mergedProjects/lref_for/source_files/rffunct.htm>
I find that "You cannot specify ELEMENTAL if lang-binding is specified
in suffix." Looking around at the F2003 final draft, I don't happen
to see this (but I could be missing it); does anyone know if this is
an Intel limitation or part of the standard? If the latter, why?
I've been working on a math library project that seems great for
BIND(C), but nearly all of the functions and subroutines are
ELEMENTAL. Since I have a bug with a couple functions on the C side
when compiling with g95/gcc, I thought I'd try ifort, but it doesn't
compile at all when I use BIND(C). Now I'm thinking that I may not be
able to do this at all - I'll post a reduced test-case soon for
comment. Is the iso_c_binding stuff currently in a released version
of gfortran?
Thanks!
Jared
| |
| robert.corbett@sun.com 2007-08-18, 4:29 am |
| On Aug 17, 8:24 pm, Jared Ahern <jared.ah...@gmail.com> wrote:
> Hello all,
>
> According to the Intel v10 language reference at:
>
> <http://www.osc.edu/hpc/manuals/INTE...e/10.0.023/doc/
> main_for/mergedProjects/lref_for/source_files/rffunct.htm>
>
> I find that "You cannot specify ELEMENTAL if lang-binding is specified
> in suffix." Looking around at the F2003 final draft, I don't happen
> to see this (but I could be missing it); does anyone know if this is
> an Intel limitation or part of the standard? If the latter, why?
It's constraint C1242 of the Fortran 2003 standard. The
constraint is
C1242 (R1227) A prefix shall not specify ELEMENTAL
if proc-language-binding-spec appears in the
function-stmt or subroutine-stmt.
I suppose the constraint is there because C functions are not
required to follow the rules for Fortran elemental functions
and subroutines.
Bob Corbett
| |
|
| On Aug 17, 9:24 pm, Jared Ahern <jared.ah...@gmail.com> wrote:
> Hello all,
>
> According to the Intel v10 language reference at:
>
> <http://www.osc.edu/hpc/manuals/INTE...e/10.0.023/doc/
> main_for/mergedProjects/lref_for/source_files/rffunct.htm>
>
> I find that "You cannot specify ELEMENTAL if lang-binding is specified
> in suffix." Looking around at the F2003 final draft, I don't happen
> to see this (but I could be missing it); does anyone know if this is
> an Intel limitation or part of the standard? If the latter, why?
>
> I've been working on a math library project that seems great for
> BIND(C), but nearly all of the functions and subroutines are
> ELEMENTAL. Since I have a bug with a couple functions on the C side
> when compiling with g95/gcc, I thought I'd try ifort, but it doesn't
> compile at all when I use BIND(C). Now I'm thinking that I may not be
> able to do this at all - I'll post a reduced test-case soon for
> comment. Is the iso_c_binding stuff currently in a released version
> of gfortran?
>
> Thanks!
> Jared
It's a standard-related issue, but it seems to me that the constraint
should have been reduced to treat the function as PURE when using
BIND(C)... Since the following workaround works just fine:
module myModule
contains
pure function myFunction2(arg1) bind(C, NAME = 'myFunction')
result(res)
integer :: res
integer, intent(IN) :: arg1
res = myFunction(arg1)
end function
elemental function myFunction(arg1)
integer :: res
integer, intent(IN) :: arg1
res = myFunction(arg1)
end function
end module myModule
The restriction applies to the BIND(C) attribute, not to !DEC$
directives ---so, if you don't mind to use extensions (i.e., if the
job needs to be done no matter what), you can try the proper
combination of C/STDCALL/ALIAS/DECORATE.
| |
| Jared Ahern 2007-08-18, 7:08 pm |
| OK - thanks all! I missed that part of the standard. I'll have to
fix it with preprocessing to get a C version then.
I have found that I can link to c++ too with g95, with full-out
classes for my TYPEs on that side, and calls to fortran with
references, which is nice. This requires a bit of preprocessing
though, to get the name mangling right in the BIND(C,name="...')
statement. Should be easy enough to get rid of the ELEMENTALs, I can
alter the two or three library routines that use that property.
- Jared
| |
| David Thompson 2007-08-26, 4:27 am |
| On Sat, 18 Aug 2007 15:51:04 -0700, Jared Ahern
<jared.ahern@gmail.com> wrote:
> OK - thanks all! I missed that part of the standard. I'll have to
> fix it with preprocessing to get a C version then.
>
> I have found that I can link to c++ too with g95, with full-out
> classes for my TYPEs on that side, and calls to fortran with
> references, which is nice. This requires a bit of preprocessing
> though, to get the name mangling right in the BIND(C,name="...')
Alternatively, you should be able to write your C++ routines using
extern "C" (linkage), and then _call_ them as if they were plain C.
(But their bodies are still C++ and can use classes etc.) You can't
overload such routines or isolate them in namespaces, but if you want
to call them from Fortran you don't want to do those anyway.
> statement. Should be easy enough to get rid of the ELEMENTALs, I can
> alter the two or three library routines that use that property.
>
- formerly david.thompson1 || achar(64) || worldnet.att.net
|
|
|
|
|