NBISweden / MrBayes

MrBayes is a program for Bayesian inference and model choice across a wide range of phylogenetic and evolutionary models. For documentation and downloading the program, please see the home page:
http://NBISweden.github.io/MrBayes/
GNU General Public License v3.0
232 stars 79 forks source link

Segmentation fault (core dumped) error on ubuntu 18.04 #74

Closed jgarciamesa closed 5 years ago

jgarciamesa commented 6 years ago

Hello, trying to run the tutorial example in chapter 2.1 of the mrbayes3.2 manual I get a segmentation fault (core dumped) error. I tried with the latest develop version and also with the 3.2.6 tag and I get the same error on both. Any ideas?

Thank you

kusalananda commented 6 years ago

What does the Version command show in the command line interface of MrBayes on your system (use the development version)? Also, at what stage in the example does the error occur?

I just now ran that example from the manual without any issues, so it would be good if I could try to compile an equivalent binary of the program that recreates your issue. The version I tested with was compiled with the default settings on everything.

jgarciamesa commented 6 years ago

The output of Version:

---------------------------------------------------------------------------
   Version

   MrBayes pre-3.2.7

   Features:  SSE AVX FMA readline
   Host type: x86_64-unknown-linux-gnu (CPU: x86_64)
   Compiler:  gnu 7.3.0
   ---------------------------------------------------------------------------

I find the error when trying to run mcmc ngen=20000 samplefreq=100 printfreq=100 diagnfreq=1000. I get output until Initial log likelihoods and log prior probs for run 1: then right after that the following line is the error. I hope that is useful. Thank you

kusalananda commented 6 years ago

Hmmm... I compiled it on three virtual machines, Ubuntu 18.04, OpenBSD 6.3 and NetBSD 8.0 (these are the ones I happen to have at home), but on no one of them did the FMA code kick in, probably because of the virtualisation. On the host machine, running macOS Mojave, the FMA code was compiled in. The example in the manual runs just fine on all these four systems.

I will try to locate a different Ubuntu 18.04 machine tomorrow to try again on.

jgarciamesa commented 6 years ago

Thank you for trying to replicate my issue. I have access to a different machine where it run fin, so there is no rush.

I run mb with gdb and this was the message:

Initial log likelihoods and log prior for run 1:

Program received signal SIGSEV, Segmentation fault.
0x00005555558af47 in CondLikeDown_NUC4_FMA ()

Let me know if there is another way to give more feedback. Thank you EDIT: I run Ubuntu 18.04.1 LTS (instead of 18.04)

kusalananda commented 6 years ago

Yeah. That's the FMA code path. On the machine that you have where it runs ok, is it also compiled with FMA support according to the Version command? What's different with that binary otherwise, and what OS is the machine running?

jgarciamesa commented 6 years ago

On my other machine (Fedora 28) is not compiled with FMA support. Also, the compiler version is gnu 8.1.1. Output of version:

 ---------------------------------------------------------------------------
   Version

   MrBayes pre-3.2.7

   Features:  SSE AVX
   Host type: x86_64-unknown-linux-gnu (CPU: x86_64)
   Compiler:  gnu 8.1.1
   ---------------------------------------------------------------------------
kusalananda commented 6 years ago

Ok, I've been able to compile and run and crash in exactly the same way as you, with a debug-enabled version of mb:

Program received signal SIGSEGV, Segmentation fault.
0x0000555555595ad7 in CondLikeDown_NUC4_FMA (p=0x555555a0b050, division=0, chain=0) at likelihood.c:1161
1161                m3 = _mm256_mul_ps (m1, clL[A]);
(gdb) print m1
$16 = {0.997265935, 0.997265935, 0.997265935, 0.997265935, 0.997265935, 0.997265935, 0.997265935, 0.997265935}
(gdb) print clL[0]
$15 = {1, 0, 0, 0, 0, 0, 0, 0}

(A is a constant with value 0)

I'm pretty sure I've seen this before. For now, you may compile your binary on the Ubuntu system with ./configure --disable-fma; make clean; make while we'll have a look at this.

I can't see anything wrong with the data in gdb nor understand what causes the segmentation fault. The same code works on macOS if the FMA code path is used... Intriguing.

kusalananda commented 6 years ago

This is very likely due to alignment of doubles. The data has to have been allocated with an aligned malloc(), and it's either not, or there's something wrong with our AlignedMalloc() routine.

For reference: Google search

kusalananda commented 6 years ago

Yes. It's not a problem in AlignedMalloc() itself, but it is being called a number of times with an alignment of 16 instead of 32, from e.g. mcmc.c:5928:

if (m->useVec == VEC_AVX)
    m->condLikes[i] = (CLFlt*) AlignedMalloc (k * sizeof(CLFlt), 32);
else
    m->condLikes[i] = (CLFlt*) AlignedMalloc (k * sizeof(CLFlt), 16);

It feels like that if-statement should look like

if (m->useVec == VEC_AVX || m->useVec == VEC_FMA)

This also probably also applies to the if-statement on line 6611 whereas the if-statement on line 5962 seems to incorporate this already.

And, indeed, fixing these two if-statements seems to avoid triggering the segmentation fault. I will submit a PR for the others to look at.

jgarciamesa commented 6 years ago

I compiled the binary on the Ubuntu machine with ./configure --disable-fma; make clean; make and now runs without issues. Thank you for your help.

kusalananda commented 6 years ago

@jgarc111 If you check out the feature/FMA_segfault_fix branch (which is a temporary branch with the bugfix to this on it that will be deleted once the code has been properly reviewed and merged), then I imagine that compiling MrBayes as usual will also work. In fact, it would be very nice indeed if you could test this.

git checkout feature/FMA_segfault_fix
git pull
./configure
make clean
make
jgarciamesa commented 6 years ago

I tested it and I could run the tutorial without issues on my Ubuntu machine. Thank you for such fast help @kusalananda

pedro-mb commented 5 years ago

Hi, I'm currently having the same issue. When running the "Simple Analysis" example from Chapter 2 in the Tutorial
I'm using:

MrBayes, Bayesian Analysis of Phylogeny Version: 3.2.7a Features: SSE AVX readline Host type: x86_64-unknown-linux-gnu (CPU: x86_64) Compiler: gnu 7.3.0

on Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-45-generic x86_64). I already compiled the binary using the instructions from INSTALL and also with ./configure --disable-fma; make clean; make , and I'm always getting the 0 -- [-8042.406] (-9005.499) (-8565.227) (-8533.188) * [-8979.230] (-7860.732) (-8999.568) (-8942.331) Segmentation fault (core dumped)

Thanks in advance... Pedro

kusalananda commented 5 years ago

Thanks Pedro. I will try to reproduce you issue locally as soon as I can find/set up a similar system.

nylander commented 5 years ago

Hi,

the comment by @pedro-mb relates to a binary compiled with SSE AVX readline features, and not with FMA (which @kusalananda addressed earlier).

I can't reproduce this behavior on Ubuntu 18.04.2 (GNU/Linux 4.15.0-46-generic x86_64) compiling the master (and develop) branch from current github code (i.e. release 3.2.7a). Note, however, the difference in (Ubuntu) versions compared to @pedro-mb (18.04.1, with kernel version 4.15.0-45-generic). I would be surprised, however, if the dump is caused by system changes in Ubuntu (based on the fact that I did not experience the crash running the "Tutorial: A Simple Analysis" in the past.).

Furthermore, it would help if you could describe when (after which MrBayes command) this core dump happens.

Below are the commands I used. See also [https://github.com/NBISweden/MrBayes/blob/testing/beagle/ubuntu-18.04.md] for setting up MrBayes on a bare-bone Ubuntu system.

/Johan

Compile:

$ git clone https://github.com/NBISweden/MrBayes.git
$ cd MrBayes
$ git checkout master
# Repeat for branch `develop` if needed:
$ ./configure --without-beagle
$ make
$ cp src/mb src/mb-no-beagle
$ make clean
$ ./configure
$ make
$ cp src/mb src/mb-beagle
$ make clean

MrBayes commands:

set autoclose=yes nowarnings=yes
showbeagle
exe ../examples/primates.nex
lset nst=6 rates=invgamma
mcmc ngen=20000 samplefreq=100 printfreq=100 diagnfreq=1000
sump
sumt
quit

MB binary info:

$ ./mb-no-beagle -v
MrBayes, Bayesian Analysis of Phylogeny

Version:   3.2.7a
Features:  SSE AVX readline
Host type: x86_64-unknown-linux-gnu (CPU: x86_64)
Compiler:  gnu 7.3.0

$ ldd mb-no-beagle
    linux-vdso.so.1 (0x00007fff8da59000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd7348ad000)
    libreadline.so.7 => /lib/x86_64-linux-gnu/libreadline.so.7 (0x00007fd734664000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd734273000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fd735061000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fd734049000)

$ ./mb-beagle -v
MrBayes, Bayesian Analysis of Phylogeny

Version:   3.2.7a
Features:  SSE AVX Beagle readline
Host type: x86_64-unknown-linux-gnu (CPU: x86_64)
Compiler:  gnu 7.3.0

$ ldd mb-beagle
    linux-vdso.so.1 (0x00007ffd90da2000)
    libhmsbeagle.so.1 => /usr/local/lib/libhmsbeagle.so.1 (0x00007f32a6314000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f32a5f76000)
    libreadline.so.7 => /lib/x86_64-linux-gnu/libreadline.so.7 (0x00007f32a5d2d000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f32a5b0e000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f32a571d000)
    libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f32a5513000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f32a518a000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f32a4f72000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f32a694d000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f32a4d48000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f32a4b44000)

System info:

$ lsb_release -a
LSB Version:    core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:    18.04
Codename:   bionic

$ uname -r
4.15.0-46-generic

$ lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              12
On-line CPU(s) list: 0-11
Thread(s) per core:  2
Core(s) per socket:  6
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               45
Model name:          Intel(R) Core(TM) i7-3930K CPU @ 3.20GHz
Stepping:            7
CPU MHz:             3614.145
CPU max MHz:         3800.0000
CPU min MHz:         1200.0000
BogoMIPS:            6403.86
Virtualization:      VT-x
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            12288K
NUMA node0 CPU(s):   0-11
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts flush_l1d

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-27ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04) 
pedro-mb commented 5 years ago

Hi,

the core dump happens after running the mcmc command:

mcmc ngen=20000 samplefreq=100 printfreq=100 diagnfreq=1000

   Setting number of generations to 20000
   Setting sample frequency to 100
   Setting print frequency to 100
   Setting diagnosing frequency to 1000
   Running Markov chain
   MCMC stamp = 4586456531
   Seed = 278574097
   Swapseed = 1554799624
   Model settings:

      Data not partitioned --
         Datatype  = DNA
         Nucmodel  = 4by4
         Nst       = 6
                     Substitution rates, expressed as proportions
                     of the rate sum, have a Dirichlet prior
                     (1.00,1.00,1.00,1.00,1.00,1.00)
         Covarion  = No
         # States  = 4
                     State frequencies have a Dirichlet prior
                     (1.00,1.00,1.00,1.00)
         Rates     = Invgamma
                     The distribution is approximated using 4 categories.
                     Shape parameter is exponentially
                     distributed with parameter (1.00).
                     Proportion of invariable sites is uniformly dist-
                     ributed on the interval (0.00,1.00).

   Active parameters: 

      Parameters
      ---------------------
      Revmat              1
      Statefreq           2
      Shape               3
      Pinvar              4
      Ratemultiplier      5
      Topology            6
      Brlens              7
      ---------------------

      1 --  Parameter  = Revmat
            Type       = Rates of reversible rate matrix
            Prior      = Dirichlet(1.00,1.00,1.00,1.00,1.00,1.00)

      2 --  Parameter  = Pi
            Type       = Stationary state frequencies
            Prior      = Dirichlet

      3 --  Parameter  = Alpha
            Type       = Shape of scaled gamma distribution of site rates
            Prior      = Exponential(1.00)

      4 --  Parameter  = Pinvar
            Type       = Proportion of invariable sites
            Prior      = Uniform(0.00,1.00)

      5 --  Parameter  = Ratemultiplier
            Type       = Partition-specific rate multiplier
            Prior      = Fixed(1.0)

      6 --  Parameter  = Tau
            Type       = Topology
            Prior      = All topologies equally probable a priori
            Subparam.  = V

      7 --  Parameter  = V
            Type       = Branch lengths
            Prior      = Unconstrained:GammaDir(1.0,0.1000,1.0,1.0)

   The MCMC sampler will use the following moves:
      With prob.  Chain will use move
         0.93 %   Dirichlet(Revmat)
         0.93 %   Slider(Revmat)
         0.93 %   Dirichlet(Pi)
         0.93 %   Slider(Pi)
         1.85 %   Multiplier(Alpha)
         1.85 %   Slider(Pinvar)
         9.26 %   ExtSPR(Tau,V)
         9.26 %   ExtTBR(Tau,V)
         9.26 %   NNI(Tau,V)
         9.26 %   ParsSPR(Tau,V)
        37.04 %   Multiplier(V)
        12.96 %   Nodeslider(V)
         5.56 %   TLMultiplier(V)

   Division 1 has 413 unique site patterns
   Initializing conditional likelihoods
   Using standard AVX likelihood calculator for division 1 (single-precision)
   Initializing invariable-site conditional likelihoods

   Initial log likelihoods and log prior probs for run 1:
      Chain 1 -- -8664.781206 -- 42.620562
      Chain 2 -- -8329.253664 -- 42.620562
      Chain 3 -- -8938.295679 -- 42.620562
      Chain 4 -- -8815.081487 -- 42.620562

   Initial log likelihoods and log prior probs for run 2:
      Chain 1 -- -8855.053613 -- 42.620562
      Chain 2 -- -8737.302211 -- 42.620562
      Chain 3 -- -8958.640816 -- 42.620562
      Chain 4 -- -8961.784757 -- 42.620562

   Using a relative burnin of 25.0 % for diagnostics

   Chain results (20000 generations requested):

       0 -- [-8664.781] (-8329.254) (-8938.296) (-8815.081) * [-8855.054] (-8737.302) (-8958.641) (-8961.785) 
Segmentation fault (core dumped) 

anyway, I now installed mrbayes using apt-get and it runs smoothly with no errors. Thank you

nylander commented 5 years ago

Hi, the mb version you get from apt-get is version 3.2.6 (at least from Ubuntu's repositories up until Ubuntu 19.04, and Debian unstable). /Johan