[petsc-dev] c++, float128 and complex patch

Satish Balay balay at mcs.anl.gov
Wed Sep 6 11:53:50 CDT 2017


On Wed, 6 Sep 2017, Michael Gegg wrote:

> Hello everyone,
> 
> a while ago I wrote about a patch for petsc with complex number c++ and
> float128 using c99 complex numbers and you suggested to just use petsc with a
> c build and then just call it from c++ (see below).
> 
> I thought that this worked, but I only tried it for my patched version. Now I
> tried to do this for the normal v3.7.6 and I get a lot of errors that
> PetscCompex is not defined when I call it from c++. The installation works
> fine and also the tutorial examples. (which are all c)
> 
> It seems that if I call petsc from c++ it tries to switch to c++ complex
> numbers even though I build petsc with c, which are obviously not defined.

Yes - because a c++ user would want to use c++/complex from their c++ code [even if petsc is buit with c]

> 
> So, could you give me a hint on how I should configure petsc so that this
> works? Is there a way to enforce the c99 complex numbers even when calling
> petsc from c++?

Perhaps this is the change you need?

[untested]

diff --git a/include/petscmath.h b/include/petscmath.h
index a63f1f4977..311d10f081 100644
--- a/include/petscmath.h
+++ b/include/petscmath.h
@@ -214,7 +214,7 @@ PETSC_EXTERN MPI_Datatype MPIU___COMPLEX128;
 #endif  /* PETSC_USE_REAL_ */
 #endif  /* ! PETSC_SKIP_COMPLEX */
 
-#elif !defined(__cplusplus) && defined(PETSC_HAVE_C99_COMPLEX) && !defined(PETSC_USE_REAL___FP16)
+#elif defined(PETSC_HAVE_C99_COMPLEX) && !defined(PETSC_USE_REAL___FP16)
 #if !defined(PETSC_SKIP_COMPLEX)
 #define PETSC_HAVE_COMPLEX 1
 #include <complex.h>



> I always used
> 
> ./configure ... --with-cc=gcc --with-cxx=g++ --with-fc=gfortran
> --download-mpich --with-clanguage=c --with-scalar-type=complex
> --with-precision=__float128 --download-f2cblaslapack
> 
> As I said, with my patch this works fine. Thanks in advance.
> 
> Also I realized that parmetis does only support double and not float128 and so
> building petsc with float128 and parmetis crashes. I also made a patch for
> that, that just declares all parmetis relevant parameters as real_t instead of
> PetscReal. Would you be interested in including this patch? (its only 2 lines)
> 
> Thank you.
> 
> Michael
> 
> 
> Am 03.05.2017 um 18:08 schrieb Michael Gegg:
> > 
> > 
> > 
> > Am 03.05.2017 um 16:27 schrieb Matthew Knepley:
> > > On Wed, May 3, 2017 at 9:22 AM, Michael Gegg <michael.gegg at tu-berlin.de
> > > <mailto:michael.gegg at tu-berlin.de>> wrote:
> > > 
> > >     Hello Petsc developers,
> > > 
> > >     thank you for providing such a marvellous numerics package, we
> > >     had/have a lot of fun using it. For our purposes it was necessary
> > >     to use Petsc with c++, float128 and complex. Since this is not
> > >     possible with the standard build we made a patch. It uses c style
> > >     complex numbers as a workaround.
> > >     It can be used with the Parmetis package (there is a little fix
> > >     in the interface there) and we have made a Slepc patch that then
> > >     also allows to use c++, float128 and complex.
> > >     It would be great if you could include it in the petsc software.
> > >     We checked the patch for v3.7.6 and v3.7.3 (latest Slepc release)
> > > 
> > > 
> > > One question. Why would you compile PETSc with C++ if you wanted to use
> > > C99 complex? You can do that with the C build, and call
> > > PETSc the same way from C++.
> > > 
> > No specific reason. Thanks for the hint, I tried it and it works. I could
> > have saved some effort there, but I also learned a thing or two ;) I just
> > didn't know that this was possible.
> > Thanks,
> > Michael
> > >   Thanks,
> > > 
> > >     Matt
> > > 
> > >     With best regards,
> > > 
> > >     Michael Gegg
> > > 
> > > 
> > > 
> > > 
> > > -- 
> > > What most experimenters take for granted before they begin their
> > > experiments is infinitely more interesting than any results to which their
> > > experiments lead.
> > > -- Norbert Wiener
> > 
> 



More information about the petsc-dev mailing list