[petsc-users] complex number issues
Barry Smith
bsmith at mcs.anl.gov
Thu May 20 13:54:45 CDT 2010
On May 20, 2010, at 7:24 AM, RenZhengYong wrote:
>
> On Wed, May 19, 2010 at 8:56 PM, Satish Balay <balay at mcs.anl.gov> wrote:
> I don't understand the code change - but if you want to use c99
> complex - you can build petsc with:
>
> --with-scalar-type=complex --with-clanguage=c [which is the default for clanguage]
>
> And no code-change needed for PETSc. However if your code uses c++ -
> you might have to address that..
> Badly, my code uses C++. I compiled PETSc with "--with-scalar-type=complex --with-clanguage=c" and I
> added
> include ${PETSC_DIR}/conf/variables
> include ${PETSC_DIR}/conf/rules
> in my makefile. So, could it possible to specify g++ for my code and to link c-version petsc?
>
So long as you do not use any C++ feature of PETSc you can do this. BUT C's complex numbers are C's and may not work with a C++ compiler. With C++ code you may simply need to use the C++ complex type, this has nothing to do with PETSc.
How do you know that C's complex is 50 times faster than C++'s? That is not our experience.
Barry
> kind regards,
> Zhengyong
>
> Satish
>
> On Wed, 19 May 2010, RenZhengYong wrote:
>
> > Hi, PETSc team,
> > I wrote a C++ code dealing with electromagnetic problems, which can smoothly
> > call PETSc complied by using " --with-scalar-type=complex
> > --with-clanguage=cxx" .
> > To improve the performances of the C++ code, I changed the complex number of
> > type from std::complex<double> to double _Complex (C99 standard, roughly
> > 30~50 times faster compared to std::complex<double>). But when I find that
> > the C99 complex number head file <complex.h> will lead to the following
> > kinds of errors"
> >
> > /usr/include/c++/4.3/complex:57: error: expected identifier before
> > ‘__complex__’
> > /usr/include/c++/4.3/complex:58: error: expected identifier before
> > ‘__complex__’
> > /usr/include/c++/4.3/complex:58: error: expected unqualified-id before ‘<’
> > token
> > /usr/include/c++/4.3/complex:59: error: expected identifier before
> > ‘__complex__’
> > /usr/include/c++/4.3/complex:59: error: expected unqualified-id before ‘<’
> > token
> > /usr/include/c++/4.3/complex:60: error: expected identifier before
> > ‘__complex__’
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:157: error:
> > expected unqualified-id before ‘__complex__’
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:306: error:
> > ‘PetscScalar’ does not name a type
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:339: error:
> > ‘PetscScalar’ does not name a type
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:469: warning:
> > ‘PetscGlobalSum’ initialized and declared ‘extern’
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:469: error:
> > ‘PetscScalar’ was not declared in this scope
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:469: error:
> > expected primary-expression before ‘,’ token
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:469: error:
> > ‘PetscScalar’ was not declared in this scope
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:469: error:
> > expected primary-expression before ‘,’ token
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:469: error:
> > expected primary-expression before ‘)’ token
> > /home/Zhengyong/packages/petsc-3.1-p1/include/petscmath.h:469: error:
> > initializer expression list treated as compound expression
> >
> >
> > Could you please give me some idea to deal with these problems?
> >
> > Kind regards,
> > Zhengyong Ren
> >
> >
>
>
>
> --
> Zhengyong Ren
> AUG Group, Institute of Geophysics
> Department of Geosciences, ETH Zurich
> NO H 47 Sonneggstrasse 5
> CH-8092, Zürich, Switzerland
> Tel: +41 44 633 37561
> e-mail: zhengyong.ren at aug.ig.erdw.ethz.ch
> Gmail: renzhengyong at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100520/1d8c0ba4/attachment.htm>
More information about the petsc-users
mailing list