[petsc-dev] Cross-compiling/batch systems and getting rid of --know-sizeof-<type> (or at least making it not required at all)

Balay, Satish balay at mcs.anl.gov
Wed May 22 11:31:09 CDT 2019


I tried this test with MS compiler (cl), sun/solaris (cc) - it worked with both.

Also worked with 'gcc -std=c89'

Satish

On Wed, 22 May 2019, Jed Brown via petsc-dev wrote:

> Agreed, though need to test that all relevant compilers error
> appropriately (and that we accurately detect such errors).  Satish may
> remember which are most problematic.
> 
> There are a few other --known arguments that we may need to think about.
> I think these are tough:
> 
>   --known-snrm2-returns-double=0
>   --known-sdot-returns-double=0
> 
> 
> Byte swapping to/from big endian for integer types can be written in a
> portable way that compiles to no-op (at least when optimization is on;
> but see [1]), but I don't think that's possible for floating point data.
> Of course we could just compile code for both options and select which
> one to call at run-time.  Since they operate on arrays instead of
> individual values, the dispatch should be negligible.
> 
> [1] It's sometimes buggy. https://bugs.llvm.org/show_bug.cgi?id=41545
> 
> "Smith, Barry F. via petsc-dev" <petsc-dev at mcs.anl.gov> writes:
> 
> >   It would be fantastic if we could avoid the need for the known values and ideally the need for batch completely!!!!
> >  
> >   This is a great idea. 
> >
> >> On May 22, 2019, at 5:02 AM, Lisandro Dalcin via petsc-dev <petsc-dev at mcs.anl.gov> wrote:
> >> 
> >> Barry/Satish, you know that making requests without patches is not my style, but this one involves messing with BuildSystem, so please pardon me.
> >> 
> >> I have a easy and quick proposal for compile-time determination of sizeof() for the various C types. For example, in our Cray XC40, I'm passing all these flags to configure to avoid the need of running with batch:
> >> 
> >> $ grep known-sizeof reconfigure-arch-gnu-opt.py
> >>     '--known-sizeof-MPI_Comm=4',
> >>     '--known-sizeof-MPI_Fint=4',
> >>     '--known-sizeof-char=1',
> >>     '--known-sizeof-double=8',
> >>     '--known-sizeof-float=4',
> >>     '--known-sizeof-int=4',
> >>     '--known-sizeof-long-long=8',
> >>     '--known-sizeof-long=8',
> >>     '--known-sizeof-short=2',
> >>     '--known-sizeof-size_t=8',
> >>     '--known-sizeof-void-p=8',
> >> 
> >> 
> >> Look at the following two line C source, TYPE and SIZE have to be passed through the preprocessor in this quick example. Defining main is of course not required if we pass `-c` to the compiler.
> >> 
> >> $ cat check-sizeof.c
> >> typedef char assert_sizeof[(sizeof(TYPE)==SIZE)*2-1];
> >> int main(int arg, char *argv[]) { return 0;}
> >> 
> >> Let's try to determine sizeof(double) by compile-time checks that do not need to run the executable.
> >> 
> >> $ cc -DTYPE=double -DSIZE=1 check-sizeof.c
> >> check-sizeof.c:1:14: error: size of array ‘assert_sizeof’ is negative
> >>     1 | typedef char assert_sizeof[(sizeof(TYPE)==SIZE)*2-1];
> >>       |              ^~~~~~~~~~~~~
> >> 
> >> $ cc -DTYPE=double -DSIZE=2 check-sizeof.c
> >> check-sizeof.c:1:14: error: size of array ‘assert_sizeof’ is negative
> >>     1 | typedef char assert_sizeof[(sizeof(TYPE)==SIZE)*2-1];
> >>       |              ^~~~~~~~~~~~~
> >> 
> >> $ cc -DTYPE=double -DSIZE=4 check-sizeof.c
> >> check-sizeof.c:1:14: error: size of array ‘assert_sizeof’ is negative
> >>     1 | typedef char assert_sizeof[(sizeof(TYPE)==SIZE)*2-1];
> >>       |              ^~~~~~~~~~~~~
> >> 
> >> Up to here, sizeof(double) is not 1, nor 2, nor 4.
> >> 
> >> Let's try now if sizeof(double) is 8:
> >> 
> >> $ cc -DTYPE=double -DSIZE=8 check-sizeof.c
> >> 
> >> No compile error. Success! Now we know sizeof(double) is 8, we don't need to run an executable, which is ideal for cross-compiling or to avoid running the configure test with batch.
> >> 
> >> 
> >> -- 
> >> Lisandro Dalcin
> >> ============
> >> Research Scientist
> >> Extreme Computing Research Center (ECRC)
> >> King Abdullah University of Science and Technology (KAUST)
> >> http://ecrc.kaust.edu.sa/
> 


More information about the petsc-dev mailing list