[petsc-dev] ugliness due to missing lapack routines

Jed Brown jedbrown at mcs.anl.gov
Sat Feb 9 10:40:10 CST 2013


On Sat, Feb 9, 2013 at 10:22 AM, Karl Rupp <rupp at mcs.anl.gov> wrote:

> Hi,
>
> I'm super-late in jumping in (again) into the discussion. Before we can
> even think about doing anything C-AST-related, we need to reduce the CPP
> usage to a much smaller amount. I'll try to come up with a categorization
> of CPP usage in PETSc during next week.
>
> Some of the CPP macros are fairly simple to be integrated into a C-AST.
> Conditional objects including operations on them are a lot harder, e.g.
>
> void my_func()
> {
>   PetscInt   ierr;
> #if defined(PETSC_HAVE_SOMETHING)
>   PetscInt   headache;
> #endif
>
>   PetscFunctionBegin;
>   ...
> #if defined(PETSC_HAVE_SOMETHING)
>   some_func(headache);
> #else
>   other_func();
> #endif
>

If we we did negative defines

#define PETSC_HAVE_SOMETHING 0

then we could have normal code

  if (PETSC_HAVE_SOMETHING) {
    some_func(ibuprofen);
 } else { ... }

The problem with this is that (a) we always need to define everything so
petscconf.h becomes larger and configure becomes more tightly coupled in
some ways, and (b) any use of #if defined(PETSC_HAVE_SOMETHING) will
evaluate true even for a negative define. This last instance is such a
confusing source of bugs that almost every project avoids it.

To convert this to usual C semantics, we could use (yet another) macro trick

https://github.com/torvalds/linux/commit/69349c2dc01c489eccaa4c472542c08e370c6d7e
https://plus.google.com/+LinusTorvalds/posts/9gntjh57dXt (crowd-sourced
solution)

With this sort of thing, we could write

if (PETSC_HAVE_(SOMETHING)) {
  some_func(no_headache);
} else { ... }

which can be reasoned about using normal C semantics. The condition
evaluates at compile time so the code produced (with any optimization) is
identical. If different functions are called in the two cases, the linker
may request both of them. (This can be good or bad.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20130209/eb6fee1e/attachment.html>


More information about the petsc-dev mailing list