Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Problem with a generic interface
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
<"name.surnameat  
View profile  
 More options Apr 25 2012, 10:03 am
Newsgroups: comp.lang.fortran
From: \"Vladimír Fuka <\"name.surname at <mffDOTcuniDOTcz">>
Date: Wed, 25 Apr 2012 16:03:56 +0200
Local: Wed, Apr 25 2012 10:03 am
Subject: Problem with a generic interface
Hello, I have a problem with a generic interface and C binding, as  
demonstrated in a following program. I am receiving compile time error in  
the second call. As I understand it, it is because of the assumed size  
array. Is there any way to fix it? (At least because of theoretical  
reasons, I can live without the generic interface.)

     Vladimir

"ge.f90", Line = 37, Column = 6: ERROR: Incorrect argument rank in generic  
procedure call "FFTW_PLAN_GEN"

or

Error: There is no specific function for the generic 'fftw_plan_gen' at (1)

program test
   use iso_c_binding
   implicit none

   integer, parameter :: C_FFTW_R2R_KIND = C_INT32_T

   interface fftw_plan_gen
     type(C_PTR) function fftw_plan_r2r_1d(n,in,out,kind,flags) bind(C,  
name='fftw_plan_r2r_1d')
       import
       integer(C_INT), value :: n
       real(C_DOUBLE), dimension(*), intent(out) :: in
       real(C_DOUBLE), dimension(*), intent(out) :: out
       integer(C_FFTW_R2R_KIND), value :: kind
       integer(C_INT), value :: flags
     end function fftw_plan_r2r_1d

     type(C_PTR) function fftw_plan_r2r_2d(n0,n1,in,out,kind0,kind1,flags)  
bind(C, name='fftw_plan_r2r_2d')
       import
       integer(C_INT), value :: n0
       integer(C_INT), value :: n1
       real(C_DOUBLE), dimension(*), intent(out) :: in
       real(C_DOUBLE), dimension(*), intent(out) :: out
       integer(C_FFTW_R2R_KIND), value :: kind0
       integer(C_FFTW_R2R_KIND), value :: kind1
       integer(C_INT), value :: flags
     end function fftw_plan_r2r_2d
   end interface fftw_plan_gen

   type(c_ptr) :: p
   real(c_double), dimension(1,1) :: a

   p= fftw_plan_r2r_2d(1_c_int,1_c_int, a, a, 0_c_int32_t, 0_c_int32_t,  
0_c_int)

   p= fftw_plan_gen(1_c_int,1_c_int, a, a, 0_c_int32_t, 0_c_int32_t,  
0_c_int)

   write (*,*) transfer(p,1_c_size_t)
end program test


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
<"name.surnameat  
View profile  
 More options Apr 25 2012, 10:38 am
Newsgroups: comp.lang.fortran
From: \"Vladimír Fuka <\"name.surname at <mffDOTcuniDOTcz">>
Date: Wed, 25 Apr 2012 16:38:03 +0200
Local: Wed, Apr 25 2012 10:38 am
Subject: Re: Problem with a generic interface
Seems, that I have to change the interface provided by FFTW to something  
like dimension(n0,*).

       Vladimir

Dne Wed, 25 Apr 2012 16:03:56 +0200 """Vladimír Fuka  <""name.surname at  
<mffDOTcuniDOTcz">> napsal(a):

--
Tato zpráva byla vytvořena převratným poštovním klientem Opery:  
http://www.opera.com/mail/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
glen herrmannsfeldt  
View profile  
 More options Apr 25 2012, 11:06 am
Newsgroups: comp.lang.fortran
From: glen herrmannsfeldt <g...@ugcs.caltech.edu>
Date: Wed, 25 Apr 2012 15:06:19 +0000 (UTC)
Local: Wed, Apr 25 2012 11:06 am
Subject: Re: Problem with a generic interface
\"Vladimír Fuka <\"name.surname at <mffDOTcuniDOTcz">> wrote:

> Hello, I have a problem with a generic interface and C binding, as  
> demonstrated in a following program. I am receiving compile time error in  
> the second call. As I understand it, it is because of the assumed size  
> array. Is there any way to fix it? (At least because of theoretical  
> reasons, I can live without the generic interface.)

Assumes size array should be fine.

> "ge.f90", Line = 37, Column = 6: ERROR: Incorrect argument rank in generic  
> procedure call "FFTW_PLAN_GEN"
(snip)
> Error: There is no specific function for the generic 'fftw_plan_gen' at (1)

(snip)

>   interface fftw_plan_gen

(snip of 1D case)

>     type(C_PTR) function fftw_plan_r2r_2d(n0,n1,in,out,kind0,kind1,flags)  
>             bind(C, name='fftw_plan_r2r_2d')
>       import
>       integer(C_INT), value :: n0
>       integer(C_INT), value :: n1
>       real(C_DOUBLE), dimension(*), intent(out) :: in
>       real(C_DOUBLE), dimension(*), intent(out) :: out
>       integer(C_FFTW_R2R_KIND), value :: kind0
>       integer(C_FFTW_R2R_KIND), value :: kind1
>       integer(C_INT), value :: flags
>     end function fftw_plan_r2r_2d
>   end interface fftw_plan_gen
>   type(c_ptr) :: p
>   real(c_double), dimension(1,1) :: a

Yes, the 2D array a won't match the dimension(*) array, even
though it is legal for an assumed size array.

Exactly what Fortran does with assumed size isn't so obvious,
but the usual implementation passes the address of the first element.
If you instead dimension(1,*) or, as you note later (n0,*), then
it should work.

I am not sure if you can get away with two different ones with
the same name and different rank inside the generic. (In case
you want to allow either 1D or 2D passed to fftw_plan_r2r_2d.)
More likely, though, you can give them different names, but the
same bind(name='name') and it will allow it through.

>   p= fftw_plan_r2r_2d(1_c_int,1_c_int, a, a, 0_c_int32_t, 0_c_int32_t,  
> 0_c_int)
>   p= fftw_plan_gen(1_c_int,1_c_int, a, a, 0_c_int32_t, 0_c_int32_t,  
> 0_c_int)

Another possibility is to pass a c_ptr to the function, and put
c_loc(a) for each array argument. That is assuming that you don't
want it to select the generic based on rank.

-- glen


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Anton Letnes  
View profile  
 More options Apr 26 2012, 1:48 am
Newsgroups: comp.lang.fortran
From: Paul Anton Letnes <paul.anton.let...@nospam.gmail.kthxbai.com>
Date: Thu, 26 Apr 2012 07:48:01 +0200
Local: Thurs, Apr 26 2012 1:48 am
Subject: Re: Problem with a generic interface
Are you trying to make Fortran bindings to the FFTW library? Because
FFTW includes those by default. Or am I missing something?

Paul

On 25.04.12 16:03, \"Vladimír Fuka <\"name.surname at >> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
<"name.surnameat  
View profile  
 More options Apr 26 2012, 3:42 am
Newsgroups: comp.lang.fortran
From: \"Vladimír Fuka <\"name.surname at <mffDOTcuniDOTcz">>
Date: Thu, 26 Apr 2012 09:42:08 +0200
Local: Thurs, Apr 26 2012 3:42 am
Subject: Re: Problem with a generic interface
No, I am not making it. I am just adding some generic interfaces to my  
program in order to have less preprocessor macros. I include the same  
subroutine body for complex and real versions x 3 different dimensions and  
x 2 (possibly 3) precisions. Now if I specify the dimension or use other  
approach recommended by Glen, that even enables different kinds, the  
generic name works without change in all of these.

      Vladimir

Dne Thu, 26 Apr 2012 07:48:01 +0200 Paul Anton Letnes  
<paul.anton.let...@nospam.gmail.kthxbai.com> napsal(a):

--
Tato zpráva byla vytvořena převratným poštovním klientem Opery:  
http://www.opera.com/mail/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
<"name.surnameat  
View profile  
 More options Apr 26 2012, 3:47 am
Newsgroups: comp.lang.fortran
From: \"Vladimír Fuka <\"name.surname at <mffDOTcuniDOTcz">>
Date: Thu, 26 Apr 2012 09:47:48 +0200
Local: Thurs, Apr 26 2012 3:47 am
Subject: Re: Problem with a generic interface
Thanks. I will probably not need more versions for various array ranks. I  
think that possibility of two different bindings for the same C symbol is  
possible only in some TS addendum to Fortran 2008 and not widely  
implemented. At least my compilers cannot use it. But I will remember the  
solution to pass just the pointer, if I need it.

    Vladimir

Dne Wed, 25 Apr 2012 17:06:19 +0200 glen herrmannsfeldt  
<g...@ugcs.caltech.edu> napsal(a):

--
Tato zpráva byla vytvořena převratným poštovním klientem Opery:  
http://www.opera.com/mail/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »