[Note – this post refered to MultiNest version 2.7. More up-to-date versions now exist that don’t require many of the things suggested below. But, there are some useful suggestions in the comments.]
Here I will detail the process I’ve gone through to install the Nested Sampling libraries produced by the MultiNest code (see Feroz, Hobson & Bridges, 2009 for a description of what the code does). The code comes with a README file giving some information on the installation process. The code also come with a Makefile
, which may work for some straight away, but did not work for me – so below are the details of how I get everything installed (in particular the supplied example C-wrapper function).
This may only work on a system set up very similar to my own:
>> lsb_release -a LSB Version: core-2.0-ia32:core-2.0-noarch:core-3.0-ia32:core-3.0-noarch:\ core-3.1-ia32:core-3.1-noarch:core-3.2-ia32:core-3.2-noarch Distributor ID: Ubuntu Description: Ubuntu 9.10 Release: 9.10 Codename: karmic
If you have a 64-bit Linux install and a non-Intel processor then these instructions may not work.
You may also need to have su
access to install various libraries such as LAPACK. You may want get install a variety of things like:
>> sudo apt-get install gfortran libblas-dev liblapack-dev
Installing without C-wrapper eggbox
example
The supplied Makefile
assumes that you are compiling to run the code with MPI and uses MPI Fortran compilers. If you just want to build the MultiNest library libnest3.o
without MPI (which I did) then this can be achieved by editing the Makefile
by changing the first couple of lines to:
#FC = mpif90 -DMPI FC = gfortran #FFLAGS += -w -O3 FFLAGS += -w -O3 -ffree-line-length-none
.
The Makefile
s for the examples given in the directories example_gauss_shell
and example_obj_detect
may also need editting e.g. change FC
, FFLAGS
and LIBS
to the following:
FC = gfortran FFLAGS += -w -O3 -ffree-line-length-none LIBS=-L$(NESTED_lib) -lnest3 -llapack
However, without various major changes described below, the example in example_eggbox
(a function to wrap the Fortran-based MultiNest library in C) will not work.
Installing with C-wrapper eggbox
example
[Please see the helpful comment by Fred below that gives information on how to compile this without having to use the Intel compilers and just using gfortran
]
To get the C-wrapper example in example_eggbox
to run you will need to install some Intel libraries (there may be other ways of doing this, but I’m not sure what they would be). This advice below assumes you have a 32-bit architecture and are installing the IA-32 versions of the libraries.
You will need to go to the Intel website and download the free Intel® Compiler Suite Professional Edition for Linux – you will need to register an email address for this, to which you will be sent a serial number to register the software. I had to do this twice to download the C++
compiler and the Fortran compiler seperately, although there may be a way of getting it all together as they contain a lot of the same libraries.
These will be download as l_cproc_p_11.1.072_ia32.tgz
and l_cprof_p_11.1.072_ia32.tgz
respectively. You should then untar the tarballs:
>> tar -xvzf l_cproc_p_11.1.072_ia32.tgz >> tar -xvzf l_cprof_p_11.1.072_ia32.tgz
and you’ll have two directories, l_cproc_p_11.1.072_ia32
and l_cprof_p_11.1.072_ia32
, in which there will be an installer script install.sh
.
First go into the l_cproc_p_11.1.072_ia32
directory for the C++ library and follow these instructions (much of which you will be prompted through on screen, so I will not document every step):
-
Run:
>> ./install.sh
-
Step 1.
Chose Option no. 3 – to install as non-root user (unless you want to install as root, in which case you should run the install script withsudo
). -
Step 3.
Chose Option 2 – “I want to activate and install my product”
Give the serial number you were emailed when you downloaded the product – should be of the form XXXX-XXXXXXXX. Hopefully this should be successful – if not then you can try again with the “Trial period acctivation” which gives you a 30 day trial.[If you’ve run the install process as sudo then this might not work (particularly on the Glasgow astro network) due to the http_proxy environment variable not being set if you run as route, so the license server cannot get online to register your serial number.]
-
Step 4.
We only need to install the MKL and Intel C compiler, so we can do a “Custom install” –
Option 2. Option 2 again “Custom Install – specify individual product components to install”. You can do the “Standard Install”, but this will install a lot of stuff that isn’t necessary for compiling MulitNest.Select components to install:
The first option “Install the Intel(R) C++ Compiler for applications running on IA-32” is required, so select this. The second option “Install the Intel(R) Debugger for applications running on IA-32” may not be necessary, so can be selected if you like. The third option “Install the Intel(R) Math Kernel Library for applications running on IA-32” is required, so select this. The fourth option “Install the Intel(R) TBB for applications running on IA-32” is not necessary, so can be selected if you want it. The fifth option “Install the Intel(R) IPP for applications running on IA-32” is not necessary.You will then be asked for the install location – make sure this is somewhere you have write access to and has enough space – the default will be
${HOME}/intel/Compiler/11.1/072
. Rather than my home directory (which is a network directory) I chose a location on my desktop computers hard disk (which for brevity I will callmy_intel_dir
).After this you may get a screen saying:
Installation configuration – Missing Optional Pre-requisite
——————————————————————————–
There is one or more optional unresolved issues. It is highly recommended to fix
it all before you continue the installation. You can fix it without exiting from
the installation and re-check. Or you can quit from the installation, fix it and
run the installation again.For example I have these various missing optional pre-requisites:
Missing optional pre-requisite
— No compatible Java* Runtime Environment (JRE) found
— operating system type is not supported.
— system glibc or kernel version not supported or not detectable
— binutils version not supported or not detectableHowever, the pre-requisites are optional, so you should be able to choose to “Skip missing optional pre-requisites” and everything still work.
-
Step 5. Configuration summary
Select option 1 to start the install – installation should only take a few minute or so.
Now install the Fortran libraries by going into the l_cprof_p_11.1.072_ia32
directory and again running the install.sh
script. This is basically the same as the steps above, so follow the same process as before (it should also see the license you already entered for the other product – if not enter the serial number you were emailed).
At Step 4 – “Installation Type” again select a “Custom Install”. You will need to install the Fortran compiler, but other stuff such as the MKL will already be installed, so select “Custom Install – specify individual product components to install”. Select to install “Install the Intel(R) Fortran Compiler for applications running on IA-32” and after that it should see the other things are already installed, so you can select to not install them.
You will be prompted for an install location, but it will not allow you to use the same location as before (later you can move the libraries into the same location as the previously installed ones) – e.g. my_intel_fortran
Again there may be missing optional pre-requisites, but you can ignore these and continue with the installation.
Once installed you can copy the installed Fortran libraries into the directories previously created during the C compiler install (various things are in both installs, but these should be identical, so can either be overwritten or not when copying) e.g.
>> cp -r my_intel_fortran/bin/* my_intel_dir/bin >> cp -r my_intel_fortran/Documentation my_intel_dir/Documentation >> cp -r my_intel_fortran/include/* my_intel_dir/include >> cp -r my_intel_fortran/lib/ia32 my_intel_dir/lib/ia32 >> cp -r my_intel_fortran/man my_intel_dir/man >> cp -r my_intel_fortran/Samples my_intel_dir/Samples
You can then delete the Fortran installation.
>> rm -rf my_intel_fortran
Once these are installed you will now have the Intel C++ compiler icc
, the Intel Fortran compiler ifort
and the Intel Math Kernal Libraries. It is also useful to create an environment variable pointing to the libraries and binaries, so I have created INTELLIBS
and INTELBIN
as environment variables giving the path to the Intel libraries and binaries and MNLIB
as the path to my MultiNest library. You may want to add paths to these into your profile setup e.g. for C-shell add the following to your .cshrc file:
setenv PATH ${PATH}:${INTELBIN} setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${INTELLIBS}
You will also want to link the MKL libraries to the same lib
directory as the other codes:
>> cd ${INTELLIBS} >> ln -s ../../mkl/lib/32/* .
Alternatively you could link all the libraries and binary files into somewhere like ${HOME}/lib
and ${HOME}/bin
.
Now to install MultiNest you will need to do some more editing of the Makefile
s. In the Makefile
for the main MultiNest directory you will need to make the following changes to the first couple of lines:
#FC = mpif90 -DMPI FC = ifort #FFLAGS += -w -O3 FFLAGS += -w -O3 -ffree-line-length-none
And here is my Makefile for the example_eggbox
directory:
FC = ifort CC = icc CXX = CC FFLAGS += -w -O3 -ffree-line-length-none CFLAGS += -I. -O3 CXXFLAGS += -I. -O3 LINKLIB = ld -shared LIBDIR = ${HOME}/intel/Compiler/11.1/072/lib/ia32 NESTED_lib = .. NESTED_inc = .. LIBS=-L$(NESTED_lib) -lnest3 -L$(LIBDIR) -lmkl_lapack -lmkl_core \ -lmkl_intel_thread -lmkl_intel -lguide -lpthread MCLIBS = OBJFILES = cnest_c.o all: eggbox %.o: %.cc $(CC) $(CFLAGS) -c $*.cc eggbox: $(OBJFILES) $(FC) $(FFLAGS) -nofor_main -o ../eggbox $(OBJFILES) $(MCLIBS) $(LIBS) clean: rm -f *.o *.mod ../eggbox
Note that the -nofor_main
flag is important.
If you run this then the eggbox
example should work! However, compiling the MultiNest library with ifort
may break the builds in the example_gauss_shell
and example_obj_detect
directories!
If anyone has any corrections, comments or better advice on how to install this then I would be happy to hear it and update these instructions.
Writing your own C function
I have written an example C
code that uses the MultiNest C-wrapper function to perform an evidence calculation and posterior evaluation given a signal model with a sinusoid of given frequency, amplitude and initial phase, a Gaussian likelihood function and uniform priors over a hardcoded range. This can be found here. This uses my own (well Numerical Recipes’) gasdev
function to produce Gaussian random numbers (the code and header file for this function can be found here and here). To make this requires the following Makefile
:
ICC = icc IFC = ifort NESTFLAGS = -w -O3 -ffree-line-length-none -nofor_main NESTLIBS = -L${MNLIB} -lnest3 -L${INTELLIBS} -lmkl_lapack -lmkl_core -lmkl_intel_thread -lmkl_intel -lguide -lpthread nested_test: nested_test.c random.c $(ICC) -O3 -c nested_test.c random.c $(IFC) $(NESTFLAGS) -o nested_test nested_test.o random.o $(NESTLIBS)
This code, which requires three command line inputs: a frequency, and amplitude and an initial phase e.g.
>> nested_test 2.08 3.4 1.243
will put outputs to a directory called nested_test_out. A description of what the outputs contain can be found in the MultiNest README file. As it is code will output it’s progress to the terminal as it goes and give a final log(evidence) value with associated error – this can also be found as the Global Evidence value in nested_test_out/test-stats.dat. The samples from which to create a posterior can be found in nested_test_out/test-.txt – this first column is the sample probability (sample prior mass multiplied by its likelihood & normalized by the evidence), the second is -2*log(likelihood), and the following three are the frequency, amplitude and initial phase of the sample. I’ve written a Matlab function (here) will return either the 1D marginalised posterior, a 2D posterior, or a 3D posterior given this output file:
% function [pars, post] = get_nested_post(pfile, npars, wp, samps) % % This function is for use with the output of the MultiNest code to produce % posteriors from the output samples. As an input it takes in the filename % of the MutliNest output *-.txt file, which should have 2+npars columns: % the first is the sample prior mass weigthed likelihood normalised by the % evidence, the second is -2* log likelihood, and the rest are the % parameter values for each of the samples. If the value of npars is not % the same as the number in file an error will occur. % % wp is a vector containing the parameter(s) for which you want to create % the posterior e.g. wp=1 then you will get a posterior only on the 1st % parameter, or wp=[1 3] will give you a 2D posterior on the 1st and 3rd % parameters. For the moment this can only contain a maximum of three % parameters. % % samps specifies the griding of the output posterior.
Hey
great job. I faced the same problems and after long hours managed to compile MultiNest with gfortran myself on Ubuntu 9.04. Too bad I didn’t find this site before. Now I can also run the eggbox example with gfortran.
Here are the steps I took:
1. Follow the steps in the first part of the tutorial including “Installing without C-wrapper eggbox example”. Hit “make”.
2. Navigate to subdirectory example_eggbox, edit the Makefile.
#FC = mpif90
FC = gfortran
#CC = mpicc
CC = gcc
LIBS = -L$(LIBDIR) -lnest3 -L/usr/lib -llapack -lpthread
#LIBS = -L$(LIBDIR) -lnest3 -L/usr/lib -lmkl_lapack -lmkl -lguide -lpthread
eggbox: $(OBJFILES)
# $(FC) $(FFLAGS) -nofor_main -o ../eggbox $(OBJFILES) $(MCLIBS) $(LIBS)
$(FC) $(FFLAGS) -o ../eggbox $(OBJFILES) $(MCLIBS) $(LIBS)
3. Here comes the tricky part. If you type make now, you will get an error message like
gfortran -w -O3 -o ../eggbox cnest_c.o -lstdc++ -L.. -lnest3 -llapack
cnest_c.o: In function `run’:
cnest_c.c:(.text+0x1cc): undefined reference to `nested_mp_nestrun_’
cnest_c.o: In function `main’:
cnest_c.c:(.text+0x447): undefined reference to `nested_mp_nestrun_’
collect2: ld returned 1 exit status
Go to the main directory and inspect the symbols in the MultiNest library by
nm libnest3.a | grep nestrun
00016ca0 T __nested_MOD_nestrun
Apparently gfortran and the version of ifortran that the authors of MultiNest use have different name mangling conventions. Open cnest_c.c and change the name of the extern function to exactly the output of the above command (mind the underscores!)
//extern void nested_mp_nestrun_(int *mmodal…
extern void __nested_MOD_nestrun(int *mmodal…
//nested_mp_nestrun_(&mmodal…
__nested_MOD_nestrun(&mmodal…
Now everything should compile.
4. You should have three executables in the main directory. Note that they store data in the subdirectory chains/ . If you run ./gauss_shell first, it will store files with prefix “2-“. If you then run ./obj_detect, it will complain with an error
./obj_detect
Null Evidence= -84572.090539486046
*****************************************************
MultiNest v2.7
Copyright Farhan Feroz & Mike Hobson
Release June 2009
no. of live points = 1000
dimensionality = 4
resuming from previous run
*****************************************************
Starting MultiNest
Acceptance Rate: 0.430479
Replacements: 17929
Total Samples: 41649
ln(Z): -14.673778
At line 95 of file posterior.F90 (unit = 55, file = ‘chains/2-phys_live.points’)
Fortran runtime error: Bad integer for item 6 in list input
To get around this, simply remove all the stored data files with
rm chains/2-*
and rerun
./obj_detect
Running the eggbox example should work without further difficulty.
./eggbox
Have fun!
Fred
@Fred Thanks Fred, that’s very useful information. Installing with just gfortran is a far nicer way of doing it. When I was initially trying to compile without the Intel compilers I did try just changing the
nested_mp_nestrun_
function to a variety of different names – but unsurprisingly my random approach to function naming didn’t work very well!Hi Matt,
Just thought I’d let you know that MultiNest version 2.10 is the latest release and apart from struggling with macports and lapack on my mac (which I eventually solved) the whole build went incredibly smoothly, even the C-wrapped eggbox example. None of it needed the intel libaries.
There was just a warning for using the unrecognised option -nofor_main in the eggbox examples. When removed the build gave no errors and the executable ran normally.
Somebody must have been reading your blog.
Cheers
Chris
@Chris Messenger
Hi Chris, I am currently trying to play with multinest on my mac but I still havent managed to make it work mainly because of the lapack! If you could share your experience I would be grateful!!!
Thanks
Hi, I just installed MultiNest 2.17 in Ubuntu 11.04. I installed the packages suggested above:
sudo apt-get install gfortran libblas-dev liblapack-dev
Then I modified top of the main Makefile to look like:
FC = gfortran
CC = gcc
CXX = g++
FFLAGS += -w -O3 -ffree-line-length-none
CFLAGS += -O3
When I save this file, emacs tells me that line 55 looks suspicious, but you can ignore that warning. After running ‘make’, I went into the example_eggbox_C directory and modified the Makefile. My Makefile looks like:
NESTLIBDIR = ..
LAPACKLIB = -llapack
LIBS = -L$(NESTLIBDIR) -lnest3 $(LAPACKLIB)
OBJFILES = eggbox.o
FC = gfortran
CC = gcc
FFLAGS += -w -O3 -ffree-line-length-none
CFLAGS += -O3
all: eggbox
%.o: %.c
$(CC) $(CFLAGS) -c $*.c
eggbox: $(OBJFILES)
$(FC) $(FFLAGS) -o ../eggboxC $(OBJFILES) $(LIBS)
clean:
rm -f *.o *.mod ../eggboxC
Note that I removed the -nofor_main option under the eggbox heading!
At this point, I have gotten all of the examples to work except for the C++ one included in version 2.17. If anyone has gotten that to work, please let me know.
Thanks,
Tanner
Actually, I just got the C++ example working for v2.17. My makefile is:
NESTLIBDIR = ..
LAPACKLIB = -llapack
LIBS = -L$(NESTLIBDIR) -lnest3 $(LAPACKLIB) -lstdc++
OBJFILES = eggbox.o
FC = gfortran
CXX = g++
FFLAGS += -w -O3 -ffree-line-length-none
CFLAGS += -O3
all: eggbox
%.o: %.cc
$(CXX) $(CFLAGS) -c $*.cc
eggbox: $(OBJFILES)
$(FC) $(FFLAGS) -o ../eggboxC++ $(OBJFILES) $(LIBS)
clean:
rm -f *.o *.mod ../eggboxC++
The lines in my Makefiles in this post and the above one were not indented properly, so be sure to account for that.
Hi. According to the readme file, there should be a Matlab version of MultiNest. Is this still available? Thanks!
@frequency Hi, myself and a couple of others have written a basic version of MultiNest in Matlab that we’re planning on very soon adding to the MultiNest repository. I will post on here when we actually get round to doing this, but it shouldn’t be too long.
Hi, I am trying to compile v2.18 on an iMac (OSX 10.7.4).
The lapack library seems to have installed correctly, and after modifying the Makefile for using gfortran I also created libnest3.a . BUT, I am having troubles compiling the examples.
In example_gauss_shell, after hitting make I get the following error message:
——————–
gfortran -o ../gauss_shell params.o like.o nestwrap.o main.o \
-w -O3 -arch x86_64 -ffree-line-length-none -L -lnest3 -L/usr/lib -llapack -lpthread
]Undefined symbols for architecture x86_64:
“___nested__nestrun”, referenced from:
___nestwrapper__nest_sample in nestwrap.o
“___utils1__logsumexp”, referenced from:
___like__slikelihood in like.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [gauss_shell] Error 1
——————–
similar but not identical to others in this thread. The problem with “___nested__nestrun” also appears in other examples. Does anyone know how to solve this issue?
Here is the Makefile I am using:
NESTLIBDIR = ../
LIBS = -L$(LIBDIR) -lnest3 -L/usr/lib -llapack -lpthread
OBJFILES = params.o like.o nestwrap.o main.o
FC = gfortran
FFLAGS += -w -O3 -arch x86_64 -ffree-line-length-none
all: gauss_shell
%.o: %.f90
$(FC) $(FFLAGS) -I$(NESTLIBDIR) -c $*.f90
gauss_shell: $(OBJFILES)
$(FC) -o ../gauss_shell $(OBJFILES) \
$(FFLAGS) $(LIBS)
clean:
rm -f *.o *.mod ../gauss_shell
I’ve finally put the Matlab functions for an implementation of MultiNest on the MultiNest repository. If anyone wants to try these out then feedback is appreciated.
Hi Luca, have a look at Fred’s comment and see if that helps:
I’ve now added a post with a small bit of information about our Matlab implementation of MultiNest.
Hi, I am trying to do linear regression just as illustrated in matlab example. However, it takes quite some time to estimate the parameters in matlab. Is there anyway to speed up the code? I am also trying to work it out using the FORTRAN version, haven’t succeeded yet.
I also faced the “undefined reference to `__nested_MOD_nestrun'” kind of error with the 2.18-CMAKE version. In case you have the Intel’s compilers, I solved this issue entering ‘ccmake’ and changing (“expert mode”) all the compiler paths to Intel’s.
It was “advanced mode” not “expert mode”, that you toggle by pressing [t] inside ‘ccmake’. Sorry!
NOTE: It seems that the mixing between compiler families was what arose the trouble. In spite of the Intel’s, I prepared another ‘release’ entering ‘ccmake’ but changing this time (toggling on “advanced mode”) *ALL* the compiler paths to GNU’s.