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@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/