arpack-ng icon indicating copy to clipboard operation
arpack-ng copied to clipboard

Data type issues in ICB interfaces

Open pv opened this issue 6 years ago • 1 comments

Expected behavior

The ICB wrappers should correctly pass arguments such as rvec to the Fortran routines.

Actual behavior

logical(kind=c_bool) and logical are not compatible types on e.g. gcc/gfortran 9, in particular having different sizes (1 byte vs. 4 bytes).

As a consequence, it breaks passing rvec=false to the Fortran routines, because the larger data type accesses some garbage on stack and becomes nonzero.

Where/how to reproduce the problem

  • arpack-ng: 8a46621
  • OS: fedora
  • compiler: gcc/gfortran 9.1.1
  • configure: ./configure --enable-icb

Steps to reproduce the problem

You can step from dseupd_c to dseupd in icb_arpack_c using gdb and see rvec is not correctly passed.

Or, like so:

set -e

git clone --depth 1 https://github.com/opencollab/arpack-ng.git tmp
cd tmp

# add print+exit statement to beginning of dseupd.f, just for simple illustration
sed -i -e "s/msglvl = mseupd/write(*,*) 'dseupd rvec =', rvec\n      stop/" SRC/dseupd.f

# call via ICB
cat <<__EOF__ > testbug.c
#include <stdbool.h>
#include "arpack.h"
int main() {
    bool rvec = false;
    dseupd_c(rvec, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    return 0;
}
__EOF__

./bootstrap
./configure --enable-icb
make -j6

gcc -IICB -I. -o testbug testbug.c SRC/.libs/libarpack.a -llapack -lblas -lgfortran -lm

echo "The following should print rvec = .false."
./testbug

which prints here

The following should print rvec = .false.
 dseupd rvec = T

pv avatar Jul 24 '19 20:07 pv

OK, far from home. I'll try to have a look when possible. Did you try with several compiler / version ?

fghoussen avatar Jul 25 '19 07:07 fghoussen

Pb fixed: closing issue.

fghoussen avatar Jan 26 '23 20:01 fghoussen