So how do we deal with this function not being implemented unless an F2003 compiler is used? Just #ifdef its body and produce a run-time error when an old compiler is used? Satish, are you doing this?<br><br><div class="gmail_quote">
On Thu, May 31, 2012 at 11:36 AM, Satish Balay <span dir="ltr"><<a href="mailto:balay@mcs.anl.gov" target="_blank">balay@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Added configure check.<br>
<br>
<a href="http://petsc.cs.iit.edu/petsc/releases/BuildSystem-3.3/rev/a6a959d40d3d" target="_blank">http://petsc.cs.iit.edu/petsc/releases/BuildSystem-3.3/rev/a6a959d40d3d</a><br>
<span class="HOEnZb"><font color="#888888"><br>
Satish<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Thu, 31 May 2012, Jed Brown wrote:<br>
<br>
> And we have our first petsc-maint breakage due to this Fortran 2003 thingy.<br>
><br>
> On Thu, May 31, 2012 at 9:03 AM, Satish Balay <<a href="mailto:balay@mcs.anl.gov">balay@mcs.anl.gov</a>> wrote:<br>
><br>
> > This code is using "use,intrinsic :: iso_c_binding"<br>
> ><br>
> > Isn't this a fortran 2003 thingy? Perhaps there should be a configure<br>
> > checks for it.<br>
> ><br>
> > Satish<br>
> ><br>
> > On Wed, 30 May 2012, Barry Smith wrote:<br>
> ><br>
> > ><br>
> > >    Blaise,<br>
> > ><br>
> > >     I have pushed PetscOptionsGetEnum() and PetscBagRegisterEnum() for<br>
> > f90 to petsc-dev tests are in src/sys/examples/tutorials<br>
> > ><br>
> > >    Barry<br>
> > ><br>
> > > On May 29, 2012, at 3:29 AM, Blaise Bourdin wrote:<br>
> > ><br>
> > > ><br>
> > > > On May 29, 2012, at 1:18 AM, Barry Smith wrote:<br>
> > > ><br>
> > > >><br>
> > > >> Blaise,<br>
> > > >><br>
> > > >>    How about the attached? My goal is to have the usage be as similar<br>
> > to the other PetscOptions... calls and too not require the Fortran user to<br>
> > be C aware that is, they should not have to append null characters or<br>
> > declare special C type declaration. In other words, the user writes<br>
> > Fortran77 code :-).[see attached file: ex1f.F90]<br>
> > > >><br>
> > > >>    I don't think it should bleed, but then I am no longer a Fortran<br>
> > programmer.<br>
> > > ><br>
> > > > Once a fortran programmer, always a fortran programmer... It's not<br>
> > like there is a lot to forget.<br>
> > > ><br>
> > > > Now I understand what you want. I agree with your goal of making the<br>
> > call standard and transparent. There is one issue with this approach for a<br>
> > function like PetscBagRegisterEnum (as far as I understand the C code),<br>
> > where you don't copy the string array in the bag item structure, but keep a<br>
> > reference to it (l. 80 in bag.c). After Carray and list1 are deallocated,<br>
> > the bag item->list points to some nonsense. I lost my mind trying to find a<br>
> > workaround last week.<br>
> > > ><br>
> > > > Would you be OK with requesting that each of the strings in list have<br>
> > some padding at the end, and be modified in the wrapper (adding the<br>
> > C_NULL_CHAR)? The alternative would be to modify PetscBagRegisterEnum, in<br>
> > order to store the content of list instead of just a reference, which may<br>
> > not be something you want to do right now.<br>
> > > ><br>
> > > > Blaise<br>
> > > ><br>
> > > ><br>
> > > >><br>
> > > >>   Barry<br>
> > > >><br>
> > > >><br>
> > > >><br>
> > > >> On May 27, 2012, at 10:16 AM, Blaise Bourdin wrote:<br>
> > > >><br>
> > > >>> Barry,<br>
> > > >>><br>
> > > >>> If I frame your email, will you sign it for me? ;)<br>
> > > >>><br>
> > > >>> I am traveling so I did not have much time to do it, even in my<br>
> > sleep, but Tim's solution is essentially right.<br>
> > > >>><br>
> > > >>> Have a look at the attached code. I had to write my own interface to<br>
> > PetscOptionsGetEnum, but I have to do the equivalent of FIXCHAR by myself<br>
> > (basically appending  //C_NULL_CHAR). I checked in the debugger, and the<br>
> > list argument that is passed to PetscOptionsGetEList is the same as the one<br>
> > passed from C. Is this what you want?<br>
> > > >>><br>
> > > >>> Do you want to do the FIXCHAR business in the C or fortran side? I<br>
> > suspect that you would prefer not having to append the C_NULL_CHAR in<br>
> > fortran, but I can't figure how to do that without allocating a new array<br>
> > of strings, and causing a memory leak. What do you think?<br>
> > > >>><br>
> > > >>> If this is not what you want, could you meet me half way and write<br>
> > the fortran interface you would like to use, in which case I will try to<br>
> > write the missing fortran parts.<br>
> > > >>><br>
> > > >>> Blaise<br>
> > > >>> <PetscF2003.F90><br>
> > > >>>><br>
> > > >>>> Tim,<br>
> > > >>>><br>
> > > >>>> Thanks. But what I want is all bundled up a routine that takes in<br>
> > the Fortran array of character strings and allocates and copies over them<br>
> > to the C ptr business. Likely I could figure it out myself with but Blaise<br>
> > is such a Fortran wizard he can do it optimally in his sleep :-)<br>
> > > >>>><br>
> > > >>>> Barry<br>
> > > >>>><br>
> > > >>>> On May 25, 2012, at 8:14 PM, Tim Gallagher wrote:<br>
> > > >>>><br>
> > > >>>>> For what it's worth, I answered a question about how to pass<br>
> > string arrays awhile ago on StackOverflow:<br>
> > > >>>>><br>
> > > >>>>><br>
> > <a href="http://stackoverflow.com/questions/9686532/arrays-of-strings-in-fortran-c-bridges-using-iso-c-binding/9686741#9686741" target="_blank">http://stackoverflow.com/questions/9686532/arrays-of-strings-in-fortran-c-bridges-using-iso-c-binding/9686741#9686741</a><br>

> > > >>>>><br>
> > > >>>>> Tim<br>
> > > >>>>><br>
> > > >>>>> ----- Original Message -----<br>
> > > >>>>> From: "Barry Smith" <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>><br>
> > > >>>>> To: "For users of the development version of PETSc" <<br>
> > <a href="mailto:petsc-dev@mcs.anl.gov">petsc-dev@mcs.anl.gov</a>><br>
> > > >>>>> Sent: Friday, May 25, 2012 8:57:52 PM<br>
> > > >>>>> Subject: Re: [petsc-dev] What needs to be done before a release?<br>
> > > >>>>><br>
> > > >>>>> Blaise<br>
> > > >>>>><br>
> > > >>>>> If you provide a fortran function to convert an array of Fortran<br>
> > strings to an array of C strings and tell us how to delete the result then<br>
> > we'll provide a PetscOptionsGetEnum() for Fortran.<br>
> > > >>>>><br>
> > > >>>>> Barry<br>
> > > >>>>><br>
> > > >>>>> On May 2, 2012, at 12:02 PM, Blaise Bourdin wrote:<br>
> > > >>>>><br>
> > > >>>>>> Barry,<br>
> > > >>>>>><br>
> > > >>>>>>>> Also, fortran wrappers over PetscOptionsEnum and<br>
> > PetscBagRegisterEnum would be nice. I understand that it<br>
> > > >>>>>>>> is a bit tricky since it involves passing fortran arrays of<br>
> > strings.<br>
> > > >>>>>>><br>
> > > >>>>>>> Yup. We'd be willing to support these from FORTRAN but someone<br>
> > else has to do the dirty work of figuring out how to handle those array of<br>
> > strings (maybe F2003?).<br>
> > > >>>>>><br>
> > > >>>>>> I am attaching a simple proof of concept example that<br>
> > demonstrates how to write a fortran interface and call petsc C functions<br>
> > from fortran using F2003 C-interoperability instead of going through the<br>
> > fortran bindings.<br>
> > > >>>>>><br>
> > > >>>>>> Don't be put off by all the warnings if you use gfortran. They<br>
> > would be easy to avoid. Basically, right now, you detect the fortran<br>
> > integer and real kinds that match that of the C ones. It would be quite<br>
> > simple to get the fortran C-interoperable integer and real types associated<br>
> > with the C type of PetscInt, PetscReal etc.<br>
> > > >>>>>><br>
> > > >>>>>> Basically, we (I?) could write a fortran interface and a fortran<br>
> > function for the tricky functions involving arrays of string, instead of<br>
> > creating a custom binding in C. Are you willing to let some fortran<br>
> > pollution into the petsc code? Where would these function have to be?<br>
> > > >>>>>><br>
> > > >>>>>> Blaise<br>
> > > >>>>>><br>
> > > >>>>>> PS: you need FCFLAGS='-ffixed-line-length-none<br>
> >  -ffree-line-length-none -ffree-form' or some subset of these to compile<br>
> > with gfortran. I'm not sure why these are not the default with a file<br>
> > suffix .F90<br>
> > > >>>>>><br>
> > > >>>>>> <PetscF2003Binding.F90><br>
> > > >>>>>> --<br>
> > > >>>>>> Department of Mathematics and Center for Computation & Technology<br>
> > > >>>>>> Louisiana State University, Baton Rouge, LA 70803, USA<br>
> > > >>>>>> Tel. <a href="tel:%2B1%20%28225%29%20578%201612" value="+12255781612">+1 (225) 578 1612</a>, Fax  <a href="tel:%2B1%20%28225%29%20578%204276" value="+12255784276">+1 (225) 578 4276</a><br>

> > <a href="http://www.math.lsu.edu/~bourdin" target="_blank">http://www.math.lsu.edu/~bourdin</a><br>
> > > >>>>>><br>
> > > >>>>>><br>
> > > >>>>>><br>
> > > >>>>>><br>
> > > >>>>>><br>
> > > >>>>>><br>
> > > >>>>>><br>
> > > >>>>><br>
> > > >>>><br>
> > > >>><br>
> > > >>> --<br>
> > > >>> Department of Mathematics and Center for Computation & Technology<br>
> > > >>> Louisiana State University, Baton Rouge, LA 70803, USA<br>
> > > >>> Tel. <a href="tel:%2B1%20%28225%29%20578%201612" value="+12255781612">+1 (225) 578 1612</a>, Fax  <a href="tel:%2B1%20%28225%29%20578%204276" value="+12255784276">+1 (225) 578 4276</a><br>
> > <a href="http://www.math.lsu.edu/~bourdin" target="_blank">http://www.math.lsu.edu/~bourdin</a><br>
> > > >>><br>
> > > >>><br>
> > > >>><br>
> > > >>><br>
> > > >>><br>
> > > >>><br>
> > > >>><br>
> > > >><br>
> > > >> <ex1f.F90><br>
> > > ><br>
> > > > --<br>
> > > > Department of Mathematics and Center for Computation & Technology<br>
> > > > Louisiana State University, Baton Rouge, LA 70803, USA<br>
> > > > Tel. <a href="tel:%2B1%20%28225%29%20578%201612" value="+12255781612">+1 (225) 578 1612</a>, Fax  <a href="tel:%2B1%20%28225%29%20578%204276" value="+12255784276">+1 (225) 578 4276</a><br>
> > <a href="http://www.math.lsu.edu/~bourdin" target="_blank">http://www.math.lsu.edu/~bourdin</a><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > > ><br>
> > ><br>
> > ><br>
> ><br>
> ><br>
><br>
<br>
</div></div></blockquote></div><br>