[petsc-users] error: cannot convert ‘bool’ to ‘PetscBool’ for argument ‘2’

Barry Smith bsmith at mcs.anl.gov
Sun May 3 11:04:57 CDT 2015


> On May 3, 2015, at 10:14 AM, Ted Sariyski <tsariysk at craft-tech.com> wrote:
> 
> Hi,
> I am looking at petsc-3.5.3/src/snes/examples/tutorials. All examples, except ex12.c, works fine.
> ex12.c compiles with error: "... cannot convert ‘bool’ to ‘PetscBool’ ..." (see attachment). Do I miss something, or it's a bug?

  It is a bug. Currently PetscBool is an integer so a bool (for example (a == 2)) cannot be passed in when a PetscBool is expected. One needs to use 
((a == 2) ? PETSC_TRUE: PETSC_FALSE) to convert the bool to a PetscBool.

  Barry

  Note that PETSc supports C89 which does not have a bool and compiling as C++ code which handles bools slightly differently than C which is why we haven't just converted over to using a bool and dropped the PetscBool. Hopefully eventually we'll be able to drop the PetscBool.


> Thanks,
> --
> Ted
> 
> 
> /> make ex12
> *********************W-a-r-n-i-n-g*************************
> Your PETSC_DIR may not match the directory you are in
> PETSC_DIR  /home/tsariysk/MFEMv3/pkgs/petsc-3.5.3/petsc-complex-dbg Current directory /work/tsariysk/MFEMv3/tars/petsc-3.5.3/src/snes/examples/tutorials
> Ignore this if you are running make test
> ******************************************************
> mpicxx -o ex12.o -c -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -g -O0   -fPIC -I/home/tsariysk/MFEMv3/pkgs/petsc-3.5.3/petsc-complex-dbg/include -I/home/tsariysk/MFEMv3/pkgs/petsc-3.5.3/petsc-complex-dbg/include -I/home/tsariysk/MFEMv3/pkgs/metis/include -I/home/tsariysk/MFEMv3/pkgs/petsc-3.5.3/petsc-complex-dbg/include -I/opt/mpich-3.1.4/include    `pwd`/ex12.c
> /work/tsariysk/MFEMv3/tars/petsc-3.5.3/src/snes/examples/tutorials/ex12.c: In function ‘PetscErrorCode SetupDiscretization(DM, AppCtx*)’:
> /work/tsariysk/MFEMv3/tars/petsc-3.5.3/src/snes/examples/tutorials/ex12.c:505:155: error: cannot convert ‘bool’ to ‘PetscBool’ for argument ‘2’ to ‘PetscErrorCode DMPlexAddBoundary(DM, PetscBool, const char*, const char*, PetscInt, void (*)(), PetscInt, const PetscInt*, void*)’
> make: *** [ex12.o] Error 1
> 
> 
> ENVIRONMENT:
> ---------------------
> Linux  2.6.18-128.1.1.el5 #1 SMP Tue Feb 10 11:36:29 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
> g++ (GCC) 4.7.1
> mpich-3.1.4
> 
> BUILD:
> ---------
> export PETSC_ARCH=petsc-complex-dbg
> export PETSC_CMAKE_ARCH=${PETSC_ARCH}
> ./configure                                        \
> PETSC_DIR=${PETSC_DIR}  PETSC_ARCH=${PETSC_ARCH}   \
> --prefix=${PETSC_INSTALL_DIR}/${PETSC_ARCH}        \
> --with-cc=mpicc --with-cxx=mpicxx --with-fc=mpif90 \
> --CFLAGS=-O                             \
> --with-x                                \
> --with-precision=double                 \
> --with-scalar-type=complex               \
> --with-clanguage=c++                    \
> --with-debugger=gdb                       \
> --with-debugging                            \
> --with-fortran-datatypes=1                 \
> --with-metis-dir=${PKGSDIR}/metis         \
> --download-f2cblaslapack=yes \
> --download-hdf5=yes \
> --with-valgrind=1
> 



More information about the petsc-users mailing list