[petsc-dev] Fwd: [petsc-maint #75297] Issue when saving an MPI dense matrix

Barry Smith bsmith at mcs.anl.gov
Fri Jun 3 13:27:01 CDT 2011


On Jun 3, 2011, at 11:50 AM, Jed Brown wrote:

> On Fri, Jun 3, 2011 at 18:34, Barry Smith <bsmith at mcs.anl.gov> wrote:
> So it turns out that gcc has an option -Wconversion that warns one about ALL implicit conversions of sizes it does. This could be used to find all the places we pass PetscInt to MPI calls that require int but unfortunately it reports so much other stuff that it seems unusable. For example, see below.
> 
> I think this other stuff can be dealt with. I use -Wconversion in Dohp and my builds are all clean [1]. It does report some things that really are not errors (e.g. positive integer literal becomes size_t and then is put back in int, but should be known at compile time to fit), but it has not been an inordinate amount of work to keep the builds clean. In the output you showed, it looks like most of the errors are coming through macros. The macros can probably be modified to silence them.


   Actually aside from the MPI calls it looks like the big problems are:

#elif defined(PETSC_HAVE_ISINF) && defined(PETSC_HAVE_ISNAN) && !defined(_GLIBCXX_CMATH)
PETSC_STATIC_INLINE PetscErrorCode PetscIsInfOrNanScalar(PetscScalar a) {
  return isinf(PetscAbsScalar(a)) || isnan(PetscAbsScalar(a));
}

which wants floats, not doubles. I tried casting to float and it didn't help so not sure how to fix.   And


#if defined(PETSC_HAVE_BUILTIN_EXPECT)
#  define PetscUnlikely(cond)   __builtin_expect(!!(cond),0)
#  define PetscLikely(cond)     __builtin_expect(!!(cond),1)

which I also didn't know how to fix.


   Barry




> 
> Clang also has -Wconversion. You could try building with a recent clang to see if it's as noisy.
> 
> 
> [1] Except for a couple places where I use VALGRIND_MAKE_MEM_UNDEFINED() which has a bad conversion buried deep inside it's macro bowels. I work around this with the annotation
> 
>  PragmaGCC(diagnostic ignored "-Wconversion")
> 
> which expands in terms of _Pragma() on systems that support it. Old versions of GCC don't support pragmas inside of function bodies, so they generate warnings if -Wconversion is turned on. Everything else works fine.
> 
> This pragma solution to selectively disable -Wconversion works for both GCC and Clang. It might also work for Intel and any other compilers that claim to be gcc-compatible-ish. On other compilers, you don't have to worry about -Wconversion because you just won't turn it on.




More information about the petsc-dev mailing list