xtb icon indicating copy to clipboard operation
xtb copied to clipboard

Fix ESP SegFaults with GCC

Open foxtran opened this issue 2 years ago • 3 comments

I compiled xtb 6.5.1 with cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release (GCC 8.5.0 was found, I did not notice that xtb was compiled with OpenMP support according to make VERBOSE=1 output)

And, then, I tried to compute ESP. Unfortunately, I got some SegFaults when runs were. In Debug mode, I got Fortran runtime errors since read_xyz from mctc_io returns allocated lattice with size 0 and pbc with size 1. I rewrote molecule.f90 a little bit to avoid these issues.

Then, in esp.f, I again got a Fortran runtime error:

At line 127 of file <PATH>/xtb/src/esp.f
Fortran runtime error: Index '706' of dimension 1 of array 'espe' above upper bound of 705

It was due to a part of the routine for checking approximate computing ESP time had espe(i) where i exceeds np after do i=1,np cycle. So, I just put the index to a reasonable value - 1.

foxtran avatar Nov 23 '22 12:11 foxtran

The changes in src/type/molecule.f90 seem unrelated to the ESP fix. Can you provide a reproducer which fails with the previous setup?

I do not remember exactly on which machine I tested this code, but...

  1. git clone [email protected]:grimme-lab/xtb.git
  2. cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug
-- The C compiler identification is GNU 11.3.1
-- The Fortran compiler identification is GNU 11.3.1
  1. cd build
  2. make -j $(nproc)
  3. ./xtb --esp BD.xyz fails with
At line 211 of file /dev/shm/xtb/src/type/molecule.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array 'mol' (3/0)

Error termination. Backtrace:
#0  0x7ff0f4e237c2 in ???
#1  0x7ff0f4e24289 in ???
#2  0x7ff0f4e2489a in ???
#3  0x763454 in __xtb_type_molecule_MOD_initmolecule
        at /dev/shm/xtb/src/type/molecule.f90:211
#4  0x75e068 in __xtb_type_molecule_MOD_structure_to_molecule
        at /dev/shm/xtb/src/type/molecule.f90:382
#5  0x580857 in __xtb_io_reader_MOD_readmolecule
        at /dev/shm/xtb/src/io/reader.f90:95
#6  0x41f772 in __xtb_prog_main_MOD_xtbmain
        at /dev/shm/xtb/src/prog/main.F90:335
#7  0x42bf22 in xtb_prog_primary
        at /dev/shm/xtb/src/prog/primary.f90:57
#8  0x42bfb9 in main
        at /dev/shm/xtb/src/prog/primary.f90:20

Under gdb:

$ gdb --args ./xtb --esp BD.xyz
(gdb) b molecule.f90:211
Breakpoint 1, xtb_type_molecule::initmolecule (mol=..., at=..., sym=<incomplete type>, xyz=..., chrg=0, uhf=0, lattice=..., pbc=..., _sym=4) at /dev/shm/xtb/src/type/molecule.f90:211
211           mol%lattice = lattice
(gdb) p lattice
$1 = ()
(gdb) p size(lattice)
$2 = 0
(gdb) p size(pbc)
$3 = 1

BD.xyz is available here: https://gist.github.com/foxtran/2e56ea6577bebf055967416d572675c9

So, I fixed molecule.f90 just for continuing to debug ESP

foxtran avatar Dec 17 '22 10:12 foxtran

@awvwgk, ping?

foxtran avatar Jan 30 '23 14:01 foxtran

The changes in src/type/molecule.f90 seem unrelated to the ESP fix. Can you provide a reproducer which fails with the previous setup?

Was fixed in #774 and in #907

foxtran avatar Dec 04 '23 13:12 foxtran

@awvwgk, ping?

foxtran avatar Jul 23 '24 09:07 foxtran