Installing and Running Gadget-2

This is the first of two posts detailing how to install and operate the Gadget-2 hydrodynamics code. Click here for the second post in the series.

Today’s astrobite will be another in a series on career advice and useful astronomical tools.  So far, it looks like there’s been a dearth of posts on the tools of theoretical astrophysics, so I thought I’d take the opporunity to show how easy it is to run a simulation using Gadget-2, a smoothed particle hydrodynamics (or SPH) code.  Gadget-2 is open source and publically available, so anyone can run simulations with it.  In a future post, I’ll discuss how to set up and run a simple hydrodynamics test problem.

The instructions for installing Gadget-2 will be highly platform dependent.  If you’re running Linux or UNIX, you have all of the tools you will need to compile the codes already. If you’re on a Mac, you’ll need to install and update Xcode, which includes all of the compilers you will need.  On Windows, you’ll probably need to install cygwin which will give your Windows installation full UNIX support.

A simulation of cosmic structure formation run with Gadget-2 (Springel et al. 2005).

Since I have a Mac, I’m going to focus on getting these codes working on OS X Snow Leopard.  If you have a different system, it might not be possible to follow my instructions exactly.  I’ll be doing all of the simulations for this series of posts on my laptop, a Macbook Pro.

First, you will need to download a few software packages.

  1. Gadget 2.0.7.
  2. Version 1.9 of the GNU scientific library (GSL).
  3. Version 2.1.5 of the FFTW fast Fourier transform library.
  4. A Message Passing Interface (MPI) library such as Open-MPI or MPICH

Open-MPI is included with OS X so if you have a Mac, do not install an MPI library. Don’t download version 3.x of the FFTW library since it doesn’t include multiprocessor support.

Once you have all of the software downloaded, you will need to extract the .tar.gz archives and install the software. I’m doing everything in terminal (found in your applications folder under Terminal.app). The installation process goes as follows:

1. Extract the software:


goldbaum@~/Documents/code: tar -xzf fftw-2.1.5.tar.gz
goldbaum@~/Documents/code: tar -xzf gadget-2.0.7.tar.gz
goldbaum@~/Documents/code: tar -xzf gsl-1.9.tar.gz

2. Install GSL:


goldbaum@~/Documents/code: cd gsl-1.9/
goldbaum@~/Documents/code/gsl-1.9: ./configure
snip: lots of diagnostic ouput
goldbaum@~/Documents/code/gsl-1.9: make
snip: lots of compilation output
goldbaum@~/Documents/code/gsl-1.9: sudo make install
Password:
snip: lots of diagnostic output
goldbaum@~/Documents/code/gsl-1.9: cd ..

I’ve gone with the default option of installing GSL to root system directories.  If you don’t have administrator privileges, you can install the software to your user directory by adding “–prefix=/folder/to/install/to” to the configure line. Leave out the quotes and change to your choice of folders when you do this for real.

3. Install FFTW:


goldbaum@~/Documents/code: cd fftw-2.1.5
goldbaum@~/Documents/code/fftw-2.1.5: ./configure --enable-mpi --enable-type-prefix --enable-float
snip: lots of diagnostic output
goldbaum@~/Documents/code/gsl-1.9: make
snip: lots of compilation output
goldbaum@~/Documents/code/gsl-1.9: sudo make install
Password:
snip: lots of diagnostic output
goldbaum@~/Documents/code/gsl-1.9: cd ..

4. Edit the Gadget makefile for your system

Gadget has a ton of compile-time parameters, which are extensively described in the User’s Guide. There are several changes to the default makefile that you need to make in order for Gadget to run correctly. Go to the directory you extracted Gadget to, then the Gadget-2 directory inside that folder. Open the makefile in a text editor (e.g. vim, emacs, textedit, notepad), and edit the compile time parameters so the beginning of your makefile looks like the following:


#--------------------------------------- Basic operation mode of code
#OPT += -DPERIODIC
OPT += -DUNEQUALSOFTENINGS

#————————————— Things that are always recommended
OPT += -DPEANOHILBERT
OPT += -DWALLCLOCK

#————————————— TreePM Options
#OPT += -DPMGRID=128
#OPT += -DPLACEHIGHRESREGION=3
#OPT += -DENLARGEREGION=1.2
#OPT += -DASMTH=1.25
#OPT += -DRCUT=4.5

#————————————— Single/Double Precision
#OPT += -DDOUBLEPRECISION
#OPT += -DDOUBLEPRECISION_FFTW

#————————————— Time integration options
OPT += -DSYNCHRONIZATION
#OPT += -DFLEXSTEPS
#OPT += -DPSEUDOSYMMETRIC
#OPT += -DNOSTOP_WHEN_BELOW_MINTIMESTEP
#OPT += -DNOPMSTEPADJUSTMENT

#————————————— Output
#OPT += -DHAVE_HDF5
#OPT += -DOUTPUTPOTENTIAL
#OPT += -DOUTPUTACCELERATION
#OPT += -DOUTPUTCHANGEOFENTROPY
#OPT += -DOUTPUTTIMESTEP

#————————————— Things for special behaviour
#OPT += -DNOGRAVITY
#OPT += -DNOTREERND
#OPT += -DNOTYPEPREFIX_FFTW
#OPT += -DLONG_X=60
#OPT += -DLONG_Y=5
#OPT += -DLONG_Z=0.2
#OPT += -DTWODIMS
#OPT += -DSPH_BND_PARTICLES
#OPT += -DNOVISCOSITYLIMITER
#OPT += -DCOMPUTE_POTENTIAL_ENERGY
#OPT += -DLONGIDS
#OPT += -DISOTHERM_EQS
#OPT += -DADAPTIVE_GRAVSOFT_FORGAS
#OPT += -DSELECTIVE_NO_GRAVITY=2+4+8+16

#————————————— Testing and Debugging options
#OPT += -DFORCETEST=0.1

#————————————— Glass making
#OPT += -DMAKEGLASS=262144

The most important change is commenting out the HAVE_HDF5 line to avoid a compilation error.

Next, you’ll need to edit the makefile once more to tell it where you’ve installed GSL and FFTW. My makefile looks like this:


#----------------------------------------------------------------------
# Here, select compile environment for the target machine. This may need
# adjustment, depending on your local system. Follow the examples to add
# additional target platforms, and to get things properly compiled.
#----------------------------------------------------------------------

#————————————— Select some defaults

CC = mpicc # sets the C-compiler
OPTIMIZE = -O2 -Wall -g # sets optimization and warning flags
MPICHLIB = -lmpich

#————————————— Select target computer

SYSTYPE=”Goldbaum”

#————————————— Adjust settings for target computer

ifeq ($(SYSTYPE),”Goldbaum”)
CC = mpicc
OPTIMIZE = -O3 -Wall
GSL_INCL = -I/usr/local/include
GSL_LIBS = -L/usr/local/lib
FFTW_INCL= -I/usr/local/include
FFTW_LIBS= -L/usr/local/lib
MPICHLIB = -L/usr/lib
endif

You can define your own SYSTYPE and tell Gadget where you’ve installed GSL and FFTW. By default, they’re in /usr/local/. The MPI library that comes with OS X is in /usr/lib/.

Now you’re almost done! Just save the changes you’ve made, exit out of your editor and run “make” in the Gadget-2 code directory. That should produce an executable called Gadget2 that you can run simulations with.

There are a number of test cases that come with Gadget.  You might try running the galaxy collision test since it makes some nice looking outputs that can be readily visualized using IDL routines included with Gadget.  To run the galaxy collision test, first set up a folder with all of the needed executables and parameter files:


goldbaum@~/Documents/code/Gadget-2.0.7: mkdir galaxy
goldbaum@~/Documents/code/Gadget-2.0.7: cp Gadget2/Gadget2 galaxy/
goldbaum@~/Documents/code/Gadget-2.0.7: cp Gadget2/parameterfiles/galaxy.param galaxy/
goldbaum@~/Documents/code/Gadget-2.0.7: cd galaxy/

Then edit galaxy.param so that the first two lines look like:


% Relevant files

InitCondFile /path/to/Gadget-2.0.7/ICs/galaxy_littleendian.dat
OutputDir /path/to/Gadget-2.0.7/galaxy/

You should change the path to the initial conditions directory and the output directory to reflect the directory structure on your computer. You’re now ready to run your first simulation! Invoke Gadget with the following command:


mpirun -np 2 ./Gadget2 galaxy.param

The command mpirun initializes an MPI program, in this case Gadget. The paramater -np 2 tells mpirun to run Gadget with two processors.  Gadget in turn looks in galaxy.param for parameters of the simulation. If you have more than two processors, feel free to change the 2 in “-np 2” to the number of processors on your system. You can check how many processors you have by running System Profiler.app which is included with OS X. You might want to try playing with increasing the number of outputs to make a simple movie of the galaxy collision:

Next time, we’ll setup and run a simple hydrodynamics test. Stay tuned!

About Nathan Goldbaum

Nathan is a third year graduate student in Astrophysics at UCSC. His interests include the local ISM, molecular clouds, and the role of star formation in galactic evolution.

72 Comments

  1. I recommend using –prefix=$HOME/opt or something like that,, which doesnt require root permission. Also, I’ve learned through many experiments that having a specific version in /usr/local can kill other programs that depend on another version of that library or package. One approach I’ve taken is a method which allows you to maintain several versions of compilers/python/packages/.. per shell, but on demand.
    If you’re the only user on your own laptop or desktop, the urge is not as large, but still, I’ve found all too often I have to perform nasty surgery on /usr//local

    Reply
    • I am getting the following error on configuring FFTW
      I ran this:
      ./configure –enable-mpi –enable-type-prefix –enable-float –prefix=/home/alankar/Documents/Gadget/dependencies/fftw
      I got this error:
      configure: WARNING: unrecognized options: –enable-type-prefix

      Reply
  2. Hi,

    This post is great, please make more of this type. I’m definitely going to try and run a simulation.

    Please also show some ways of analyzing the simulations beyond the nice video (which I’m also not sure how to make).

    Thanks.

    Reply
  3. While ceating the exectuable ./Gadget2 by “make”, I get the following error.

    opt/mpich2/lib -L/usr/local/lib -lgsl -lgslcblas -lm -L/usr/local/lib -lsrfftw_mpi -lsfftw_mpi -lsrfftw -lsfftw -o Gadget2
    /usr/bin/ld: cannot find -lsrfftw_mpi
    collect2: ld returned 1 exit status
    make: *** [Gadget2] Error 1

    Can anyone please help me to fix it?
    Thanks very much!

    Reply
    • You need to install both precisions of fftw.

      ./configure –prefix= –enable-typeprefix
      –enable-mpi
      make
      make install
      make clean
      ./configure –prefix= –enable-float
      –enable-type-prefix –enable-mpi
      make
      make install

      make sure you are using FFTW 2.1.5 or greater (but less than 3)

      Reply
      • I have this same problem, running on OS X Lion. For some reason Lion does not come stock with mpi installed, so I had to install open mpi. Now I can’t get past this compile-time error about the fftw library.

        ld: library not found for -lsrfftw_mpi
        collect2: ld returned 1 exit status
        make: *** [Gadget2] Error 1

        When you run the make commands in the comment above, you are referring to the GSL’s Makefile, right?

        Reply
        • Okay i understand the generated makefiles now, but I think there are certain arguments i need to apply in the fftw configure command to generate the right makefiles for my OS environment… has anyone overcome this issue?

          Reply
  4. Thanks, your help is greatly appreciated!

    Followed it to the letter and I’m happily colliding galaxies…

    Chesh

    Reply
  5. Thanks for the great post.

    I’ve installed Gadget2 on my mac and no error appeared. However, whenever I run the executable I have an error:

    error in opening file ‘~/Documents/Gadget-2.0.7/galaxy/cpu.txt’
    task 0: endrun called with an error level of 1

    Does anyone know why is that ?

    Reply
    • Hi Hossam,

      Are you sure that there is a galaxy directory?

      Reply
      • Thanks for your quick reply!

        Yes I am sure. I made a Galaxy directory in which I copied the executable and the galaxy.param file.

        Reply
        • Hmm, I’m really not sure. Perhaps the problem is that you are referencing your home directory using the ‘~’ shortcut. Try to use the absolute path (e.g. /home/Documents/…) instead. Are you sure that you have permissions to write to the galaxy directory?

          Reply
  6. hi i am a student of astro physics
    I have done what ever you suggest in above but after i finished the step 3 then i go to directory where i have extracted Gadget-2.0.7 and try to open it it shows message like this “The folder contents could not be displayed. You do not have the permissions necessary to view the contents of “Gadget-2.0.7”.so what to do please help me.

    Reply
  7. hi is there any one who can help me i have install this Gadget2.0.7 in linux ubuntu but i am not able to run this proprly after step 3. please if you can then write this in linux code step wise. please please

    Reply
    • I’m nearly done installing Gadget2.0.7 on Ubuntu (11.10) if you’re still interested.

      Reply
      • hi i am trying to install gadget2 on Ubuntu.I am successful in installing and running the simulations but i have a problem on visualizing the output of it.I have used “paraview” software to visualize it but the output is not clear.
        could you please help me which software do i have to use to visualize the output of gadget2.

        Reply
        • i fixed the problem.

          Reply
  8. Hi Hossam,

    I think you may have left out making changes to galaxy.param. I made the same mistake and got the exact same error as you did. I made changes to the first line as indicated in the blog but forgot change the second line. Make sure that
    OutputDir /path/to/Gadget-2.0.7/galaxy/ is also edited correctly

    Reply
  9. Hi, I’m a student of astronomy and will work with this software in my thesis, however following this installation guide to install FFTW but I get this message after the second instruction

    fernando@fernando ~/Documentos/GADGET/fftw-2.1.5 $ ./configure –enable-mpi –enable-type-prefix –enable-float
    .
    .
    .
    configure: error: couldn’t find mpi library for –enable-mpi

    then, when I give the instruction: make the output is

    make: *** No targets specified and no makefile found. Stop.

    Can anyone help me?

    Thanks

    FERNANDO

    Reply
    • Hi Fernando,

      It looks like you either need to install an MPI library or make sure that the MPI object files are in your LD_LIBRARY_PATH. I’d give you more instructions on how to install openmpi but I need more details on your system setup.

      Reply
      • Hi Nathan

        Very Thanks for your response. I achieved to install MPI and continue with the fftw installation…
        Now I have other problem, when I´m editing the Makefile there are a line that I don´t know how complete. This is my configuration

        SYSTYPE=”fernando”

        ifeq ($(SYSTYPE),”fernando”)
        CC = mpicc
        OPTIMIZE = -O3 -Wall
        GSL_INCL = -I/usr/local/include
        GSL_LIBS = -L/usr/local/lib
        FFTW_INCL= -I/usr/local/include
        FFTW_LIBS= -L/usr/local/lib
        MPICHLIB =-L/usr/lib
        HDF5INCL =
        HDF5LIB = -lhdf5 -lz
        endif

        but, when I do make in Gadget2 folder an error occur:

        mpicc -O3 -Wall -DPERIODIC -DUNEQUALSOFTENINGS -DPEANOHILBERT -DWALLCLOCK -DPMGRID=128 -DSYNCHRONIZATION -DHAVE_HDF5 -I/usr/local/include -I/usr/local/include -c -o main.o main.c
        In file included from main.c:8:0:
        proto.h:10:18: fatal error: hdf5.h: No such file or directory
        compilation terminated.
        make: *** [main.o] Error 1

        The question is: I need to specify a path in HDF5INCL = ?

        Very very thanks for your help!!

        **Nathan in the other hand, you will go to Astroinformatics 2012 next July in UCSD?

        Reply
        • Hi Fernando,

          Your makefile snippet looks ok. I think the problem is that you need to turn off HDF5 support in the compile flags section:

          OPT += -DHAVE_HDF5

          Should be:

          #OPT += -DHAVE_HDF5

          You may want to install hdf5 in the future and recompile gadget with hdf5 support. Hdf5 is much nicer and easier to use than the flat binary format Gadget supports by default.

          I will not be at UCSD in July although I know several people who will be there.

          Reply
    • Hi,Fernando
      i am also the student of astrophysics and doing my master thesis on large structure formation using GADGET2 software.
      In which topics are you doing thesis.

      Reply
  10. Hi Nathan, Very thanks again for your help…
    Now I´m trying run the example, however a new error occur, I think that this is a problem of a path, but I don´t find where is it…

    This is the output….

    This is Gadget, version `2.0′.

    Running on 2 processors.
    cp: cannot create regular file `/Documentos/GADGET/Gadget-2.0.7/galaxy/parameters-usedvalues’: No such file or directory

    Allocated 25 MByte communication buffer per processor.

    Communication buffer has room for 504122 particles in gravity computation
    Communication buffer has room for 204800 particles in density computation
    Communication buffer has room for 163840 particles in hydro computation
    Communication buffer has room for 152408 particles in domain decomposition

    Hubble (internal units) = 0.1
    G (internal units) = 43007.1
    UnitMass_in_g = 1.989e+43
    UnitTime_in_s = 3.08568e+16
    UnitVelocity_in_cm_per_s = 100000
    UnitDensity_in_cgs = 6.76991e-22
    UnitEnergy_in_cgs = 1.989e+53

    error in opening file ‘/Documentos/GADGET/Gadget-2.0.7/galaxy/cpu.txt’
    task 0: endrun called with an error level of 1

    MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
    with errorcode 1.

    NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
    You may or may not see output from other processes, depending on
    exactly when Open MPI kills them.
    —————————————-
    mpirun has exited due to process rank 0 with PID 2594 on
    node fernando exiting without calling “finalize”. This may
    have caused other processes in the application to be
    terminated by signals sent by mpirun (as reported here).

    my configurarion of galaxy.param is

    InitCondFile /Documentos/GADGET/Gadget-2.0.7/ICs/galaxy_littleendian.dat
    OutputDir /Documentos/GADGET/Gadget-2.0.7/galaxy/

    Thanks a lot…

    FERNANDO

    Reply
    • Hi Fernando, are you sure that the directory

      /Documentos/GADGET/Gadget-2.0.7/galaxy/

      already exists? Gadget will not create it for you.

      Reply
  11. Hi
    Dear Nathan

    in the line you have written:

    ifeq ($(SYSTYPE),”Goldbaum”)
    CC = mpicc
    OPTIMIZE = -03 -Wall
    GSL_INCL = -I/usr/local/include
    GSL_LIBS = -L/usr/local/lib
    FFTW_INCL= -I/usr/local/include
    FFTW_LIBS= -L/usr/local/lib
    MPICHLIB = -L/usr/lib
    endif

    this is not ” -03 -Wall”
    This is ” -O3 -Wall”
    you have mistaken O with zero.

    thanks for your good and useful comments.

    Reply
    • Fixed! Thanks for letting me know. Have fun with Gadget 🙂

      Reply
      • Hi again
        Nathan
        how can I visualize this run,
        I installed SPLASH but encountered with this message.

        ERROR: no columns of real numbers found
        *** ERROR: zero/undetermined number of column in file ***
        Would you help me fix it?

        Reply
        • The galaxy merger test doesn’t include SPH particles so SPLASH does not recognize the output files as being from an SPH simulation.

          SPLASH doesn’t read gadget star particles. You’ll need to write your own analysis scripts if you want to take a look at the snapshots.

          Reply
        • Hi
          seyed mohammad ali najafi

          how can we visualize the output of the gadget2 files. I have used “Paraview” software but the output is not clear.
          could you please help me.

          Reply
  12. do you know how can I install HDF5 for linux (ubuntu)?

    Reply
    • The instructions in this post should work on ubuntu. You should also be able to say sudo apt-get install hdf5. You’ll need to link against the version of hdf5 that apt installs so you’ll have to modify your gadget makefile accordingly.

      Reply
  13. Hi Nathan,

    It’s probably something simple, but do you know what’s going on here?:

    CFH5:Gadget2 matty$ make
    mpicc -O3 -Wall -DPERIODIC -DUNEQUALSOFTENINGS -DPEANOHILBERT -DWALLCLOCK -DPMGRID=128 -DSYNCHRONIZATION -I/usr/local/include -I/usr/local/include -c -o main.o main.c
    make: mpicc: No such file or directory
    make: *** [main.o] Error 1

    I’ve installed Openmpi with no problems (On Lion btw).

    Thanks,
    Matt.

    Reply
    • Hi Matt,
      The MPI compiler wrappers aren’t in your search path. Where did you install openmpi? Is that folder in your $PATH?

      If MPI is installed correctly, you should be able to say “which mpicc” at the command line. This will tell you where mpicc is located, assuming everything is configured correctly

      Reply
  14. Hi. I am really new and just starting with gadget. I ran your SPH particles simulation as an example and it ran well. But for the galaxy merger one that you posted, after following all the steps you mentioned I got::
    :~/research2/Gadget-2.0.7/galaxy$ mpirun -np 2 ./Gadget2 galaxy.param
    Note: This is a massively parallel code, but you are running with 1 processor only.
    Compared to an equivalent serial code, there is some unnecessary overhead.

    This is Gadget, version `2.0′.

    Running on 1 processors.
    Code was compiled with periodic boundary conditions switched on.
    You must set `PeriodicBoundariesOn=1′, or recompile the code.
    Note: This is a massively parallel code, but you are running with 1 processor only.
    Compared to an equivalent serial code, there is some unnecessary overhead.

    This is Gadget, version `2.0′.

    Running on 1 processors.
    Code was compiled with periodic boundary conditions switched on.
    You must set `PeriodicBoundariesOn=1′, or recompile the code.”

    After this, I changed the command to “-np 1” and changed the `PeriodicBoundariesOn=1′ in galaxy.param file. But in that case I didn’t get any snapshot file. Cannot understand what is wrong. The sph particle simulation ran well, but can’t figure out what is wrong with this one.

    Reply
    • My best guess is that your mpi library isn’t configured correctly. It looks like mpirun is running two instances of gadget rather than one instance running on two processors.

      Reply
    • Just had this exact same problem.

      You need to add a hashtag in front of the OPT += -DPERIODIC line in the makefile, giving:

      #OPT += -DPERIODIC

      Then make it again, and go through the same steps.

      /Michael

      Reply
  15. Nathan,

    I was wondering if you could help me? I’m a Master student in the UK needed to do some galaxy simulation.

    I am running through the steps of installing Gadget2 on my Macbook Pro running Mountain Lion, however I have run into a few problems. I’ve listed them here, any help you can give me would be brilliant and thank you for your time in advance.

    Ok, so I have downloaded all the relevant modules and software packages you talk about. I’ve extracted the software into a dedicated folder and I have successfully installed GSL without any problems.

    I then come to install the FFTW. I navigate to the directory and do the ./configure command with the flags you’ve put in the text. It gives a lot of output before saying, and I quote:

    “configure: error: couldn’t find mpi library for –enable-mpi”

    So I think: OK, I’ll download and MPI library like the ones you mention, and I have tried both OpenMPI and MPICH2. On installing OpenMPI I get the following:

    “configure: error: C and Fortran 77 compilers are not link compatible. Can not continue.”

    And on installing MPICH2 I get:

    “configure: error: **** Incompatible Fortran and C Object File Types! ****
    F77 Object File Type produced by “gfortran -O2” is : : Mach-O object i386.
    C Object File Type produced by “gcc -O2″ is : : Mach-O 64-bit object x86_64.”

    My compilers come from the newest version of Xcode (4.5.1) downloaded from the Mac App store and I have installed the command line tools from within Xcode.

    I was wondering what you think I should do or if know yourself how to get around this? I am pretty novice with all of this stuff so any help (however basic) is much appreciated.

    Thanks in advance and all the best,
    Jono

    Reply
    • Hi Jono: you need a fortran compiler. Apple in their infinite wisdom do not bundle gfortran with Xcode. Take a look at the R for Mac OSX site at AT&T research.

      Reply
  16. Hi Nathan,
    I have another question:
    where can we find governing equation in Gadget2 and how can we change this equations?
    appreciating your help previously.

    Reply
  17. I’ve installed fftw-2.1.5, openmpi and MPICH but get this basic error upon gadget compile:

    bash-3.2$ make
    mpicc -O3 -Wall -DUNEQUALSOFTENINGS -DPEANOHILBERT -DWALLCLOCK -DSYNCHRONIZATION -I/usr/common/pdsoft/include -c -o main.o main.c
    make: mpicc: No such file or directory
    make: *** [main.o] Error 1

    Any ideas? I thought mpicc would have already been installed. Matt asked the same question but I have installed openmpi already…

    bash-3.2$ sudo port install openmpi
    —> Computing dependencies for openmpi
    —> Cleaning openmpi
    —> Scanning binaries for linking errors: 100.0%
    —> No broken files found.

    I’m on Lion, as Matt was. How can I add the MPI wrappers to the search path manually? Thanks.

    Reply
    • Hi Brendan. Sorry I can’t be of much help, I’ve never done this on Lion. You need to make sure that the mpi compiler wrappers are in your search path. Compare your $PATH environment variable with the location of the compiler wrappers.

      Reply
  18. Hi Nathan,

    I found a work around.

    cd /opt/local/bin
    sudo ln openmpicc mpicc

    I then installed fftw with correct flags and it seemed to work.

    But now when I compile Gadget I get the following which

    mpicc main.o run.o predict.o begrun.o endrun.o global.o timestep.o init.o restart.o io.o accel.o read_ic.o ngb.o system.o allocate.o density.o gravtree.o hydra.o driftfac.o domain.o allvars.o potential.o forcetree.o peano.o gravtree_forcetest.o pm_periodic.o pm_nonperiodic.o longrange.o -g -L/usr/common/pdsoft/lib -Wl,”-R /usr/common/pdsoft/lib” -lgsl -lgslcblas -lm -lsrfftw_mpi -lsfftw_mpi -lsrfftw -lsfftw -o Gadget2
    ld: warning: directory not found for option ‘-L/usr/common/pdsoft/lib’
    ld: unknown option: -R /usr/common/pdsoft/lib
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [Gadget2] Error 1

    Would it be a double precision thing with fftw?

    Reply
    • You’re trying to link against a library that lives in a directory which doesn’t appear to exist (/usr/common/pdsoft/lib).

      Check you gadget makefile and make sure that it’s using a SYSTYPE appropriate for your computer.

      Reply
  19. Hi, I’ve just running gadeget2 into a amd a8 4processors but it takes to long. How much does it take for the example galaxy.param on your laptop??

    thanks

    Reply
  20. Hi Dear Nathan,

    Can u tell me, where can we find governing equation in Gadget2 and how can we change these equations?
    appreciating your help previously.

    Reply
  21. Thank you so much for this brilliant post.
    I have a problem which I hope you can solve 🙂
    When I try to run Gadget2 with the following command:
    $ mpirun -np 2 ./Gadget2 galaxy.param

    I get the following errors:
    This is Gadget, version `2.0′.

    Running on 2 processors.
    cp: ./Desktop/Gadget-2.0.7/galaxy/parameters-usedvalues: No such file or directory

    Allocated 25 MByte communication buffer per processor.

    Communication buffer has room for 504122 particles in gravity computation
    Communication buffer has room for 204800 particles in density computation
    Communication buffer has room for 163840 particles in hydro computation
    Communication buffer has room for 163840 particles in domain decomposition

    Hubble (internal units) = 0.1
    G (internal units) = 43007.1
    UnitMass_in_g = 1.989e+43
    UnitTime_in_s = 3.08568e+16
    UnitVelocity_in_cm_per_s = 100000
    UnitDensity_in_cgs = 6.76991e-22
    UnitEnergy_in_cgs = 1.989e+53

    error in opening file ‘./Desktop/Gadget-2.0.7/galaxy/cpu.txt’
    task 0: endrun called with an error level of 1

    application called MPI_Abort(MPI_COMM_WORLD, 1) – process 0

    ===================================================================================
    = BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
    = EXIT CODE: 1
    = CLEANING UP REMAINING PROCESSES
    = YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
    ===================================================================================

    Again, thank you very much !

    Reply
    • Hi Jinsu,

      The reason gadget crashed is because it couldn’t open the file ‘./Desktop/Gadget-2.0.7/galaxy/cpu.txt’. This isn’t a file you have to create, instead it’s a file gadget uses to output cpu usage statistics. If I had to hazard a guess about what’s going wrong, it would be that the directory ‘./Desktop/Gadget-2.0.7/galaxy’ doesn’t exist. Gadget assumes that you’ve already properly setup the output directory you specify and won’t print a particularly helpful error message if someone goes wrong. If you still can’t figure out what’s going wrong, it would help if you paste your galaxy.param file somewhere i can see (like pastebin.com) and describe where you put the Gadget2 executable. Please make sure you’ve followed my instructions in the post exactly.

      As for the question you asked on the other post, I use ffmpeg to generate movies. Say I’ve generated the frames of a movie in .png format and put them all into a folder. Additionally, let’s assume I’ve given them filenames like movie_frame_xxxx.png where xxxx is a number between 0000 and 9999. In that case, I can convert the frames into a movie with the following command:

      ffmpeg -i movie_frame_%04d.png -sameq movie.mp4

      ffmpeg is a little bit limited in that the movie frames need to have uniform filenames and no gaps are allowed in the frame sequence, so if there isn’t a movie_frame_0123, the movie will stop at movie_frame_0122, even if there are additional frames after movie_frame_0123.

      Reply
      • Hi Nathan,

        First, I am so sorry for replying late.
        I just checked your reply.
        And, I would like to thank you again.
        I re-followed your instruction and I could run Gadget-2 successfully.
        The problem was my PATH.
        I tried /Users/kimjinsu/Documents/……… instead of /Documents/…..

        It is really fantastic I can now actually run the Gadget-2 !!

        I will try ffmpeg soon.
        Thank you so so so much !

        Have a nice day.

        Best,
        Jinsu Kim

        Reply
        • Hello, Nathan,

          I tried ffmpeg -i splash_%04d.png -sameq movie.mp4.
          But, I failed……..
          What is %04d ??

          First I tried
          gsplash snap_* -> 2 -> 1 -> 9 -> return -> /png
          and then
          ffmpeg -i splash_%04d.png -sameq movie.mp4
          but it doesn’t work.

          I am sorry to bother you.
          Please help me 🙂

          I will look forward to getting your reply.

          Thank you very much.

          Best,
          Jinsu Kim

          Reply
  22. hello nathan this is a great post. I generated the snapshot files in galaxy directory and installed splash to view the snapshot files but encountered following problem. Can you tell me how to produce the images that you have in the website from the snapshots?

    Reply
  23. Due to the problem mentioned in splash ..I can see only a red screen and nothing else 🙁

    Reply
    • Hi,

      I don’t think SPLASH can render the star particle only galaxy dataset that comes with Gadget. I used the IDL scripts that come with the Gadget distribution to make the movie at the end of the post. SPLASH will be able to visualize datasets that include SPH particles, as in the next post in the series.

      Reply
    • You probably need to see a softening length at the command line. e.g.
      export GSPLASH_DARKMATTER_HSOFT=”0.78124946″
      Though I have not done this example, it has allowed me to read dark matter only Gadget snapshots.

      Reply
  24. Hi,
    I’ve been running galaxy simulations in GADGET2 using almost all of the defaults in the provided galaxy.Makefile.and galaxy.param file and i am sucessfull in running it according to above instruction.
    Can we change any parameters for simulation (like Omega 0, OmegaLamda and OmegaBaryon).if so could you please suggest me the parameters that can be changed by me in simulating galaxy collision test.

    Reply
  25. Can this simulation run in the standard single computer or laptop? If can, is it will be slowed due to only one computer?

    Reply
  26. Thanks a lot for the installation guide. I need another guide: “how to write Initial condition files”. Only a readme file is given in there, no user guide. if u have any info about writing initial condition files, please share.

    thanks

    Reply
  27. Hey Nathan,
    Trying to get my code running but whenever i run gadget’s make i get the following error:
    afitts@ubuntu:~/Gadget-2.0.7/Gadget2$ make
    mpicc -O3 -Wall -DPERIODIC -DUNEQUALSOFTENINGS -DPEANOHILBERT -DWALLCLOCK -DPMGRID=128 -DSYNCHRONIZATION -DHAVE_HDF5 -I/usr/common/pdsoft/include -l/usr/local/fftw-2.1.5/include -l/usr/local/hdf5-1.6.10/include -c -o main.o main.c
    In file included from main.c:8:0:
    proto.h:10:18: fatal error: hdf5.h: No such file or directory
    compilation terminated.
    make: *** [main.o] Error 1

    i have hdf5 installed in /usr/local/hdf5-1.6.10 so i do not understand why gadget cannot find it. After some digging i have discovered that gadget is looking in /usr/include or /usr/lib but not the directories i have entered into the Makefile:
    ifeq ($(SYSTYPE),”MPA”)
    CC = mpicc
    OPTIMIZE = -O3 -Wall
    GSL_INCL = -I/usr/common/pdsoft/include
    GSL_LIBS = -L/usr/common/pdsoft/lib -Wl,”-R /usr/common/pdsoft/lib”
    FFTW_INCL= -l/usr/local/fftw-2.1.5/include
    FFTW_LIBS= -L/usr/local/fftw-2.1.5/lib
    MPICHLIB =
    HDF5INCL = -l/usr/local/hdf5-1.6.10/include
    HDF5LIB = -L/usr/local/hdf5-1.6.10/lib -lhdf5 -lz
    endif

    Could you explain why my makefile is looking in the wrong place or how to get it to look in the correct location? Thanks.
    -Alex

    Reply
    • Hi Alex,

      That error means your C compiler cannot find the “hdf5.h” header, which is provided by the hdf5 library. Do you have HDF5 installed in /usr/local/hdf5-1.6.10, as you have indicated in your makefile snippet?

      You also do not need to compile gadget with hdf5 support. To turn it off, comment out “HAVE_HDF5” in the makefile, as I mention in the post.

      Reply
      • I do indeed have HDF5 installed in that specific location. The file in question, ‘hdf5.h’, is located in /usr/local/hdf5-1.6.10/include. I realize that hdf5 is not required for the compilation of gadget but would like to use it regardless. I would also like to note that when i comment out “HAVE_HDF5” i am met with another error:
        pm_periodic.c:21:28: fatal error: srfftw_mpi.h: No such file or directory
        compilation terminated.
        make: *** [pm_periodic.o] Error 1
        which appears to be an error with fftw-2.1.5. This is odd as well as i have installed the package (with mpi enabled) into a similar location, /usr/local/fftw-2.1.5

        Reply
      • So for the time being i have foregone using HDF5. i installed fftw in my home directory instead and now i have colliding galaxies! thanks for the help Nathan. Ill comment back if i ever figure out why /usr/local wasn’t a good location.

        Reply
  28. Hey Nathan,
    Thanks for the posts. I’ve managed to get everything working. I am more interested in modelling a box of gas without gas to equilibrium then “turning on” gravity and watch the system (< Jean's length) evolve to a black hole.
    Can you give some pointers for this set up?

    Reply
    • I mean > Jean’s length!

      Reply
      • Hi Sean, I am just starting to look at simulating the condensation of the primordial gas into the population III stars and black holes (I suspect more black holes were produced than stars going on how many quasars there are/were). Looks like you are a few steps ahead of me. How did your simulations go?

        Reply
  29. I am stuck in this step :- cp Gadget2/Gadget2 galaxy/

    Reply
  30. Hey!

    I was able to generate snapshots after running galaxy code. Now I want to convert those .png files to a movie clip. Whats the easiest way to do that? I’m using ubuntu 14.04. Thanks.

    Reply
  31. I have another problem. When I try “make” command, it starts making exe file, however a few seconds after running I get this one:

    /usr/bin/ld: /home/omid/Simulation/HDF5/lib/libhdf5.a(H5PL.o): undefined reference to symbol ‘dlclose@@GLIBC_2.2.5’
    /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
    collect2: error: ld returned 1 exit status
    galaxy.Makefile:226: recipe for target ‘Galaxy’ failed
    make: *** [Galaxy] Error 1

    I tried to find out what this “DSO” means exactly(this abbreviation stands for dynamic shared object files). Any one here has any idea?

    Reply
  32. error in opening file ‘~/PHY_PROJ_SOURCES/Gadget-2.0.7/Gadget2/cluster/cpu.txt’
    task 0: endrun called with an error level of 1

    Reply
  33. Hi Nathan,

    I have Gadget2 up and running and I have tried to run the Galaxy collision model, but I have found a small problem. Somw of the parameters in the galaxy.param file have the value 0 (zero) at them. (Namely, many of the cosmological parameters). When I try to run the code, as it is, it stalls at the first memory information.

    I have tried to fill out the values and although the model runs, I am not sure it is the correct values I have given it.

    What cosmological parameters do you use in the model, including the boxsize?

    Reply
  34. can u pls help me in running gadget 2.0.7 on windows 10.pls i need it badly ,nathan.

    Reply
  35. make and sudo commands not found- error in cygwin . how to resolve ?

    Reply

Trackbacks/Pingbacks

  1. Dark Matter Micro-Haloes in the Milky Way « astrobites - [...] using N-body simulations (which can be run using a code such as GADGET which Nathan talked about in a…
  2. Running your first SPH simulation « astrobites - [...] astrobite will be a sequel to a post I wrote a few months ago on using the smoothed particle…
  3. My first Gadget2 tests | Elbrunz's Blog - [...] with the cosmological simulation code Gadget2. To start I followed the instructions found here. All I’m going to write…
  4. A More Accurate Look At Galaxy Formation | astrobites - [...] talked about papers that use simulations in many previous astrobites, and Nathan even wrote a couple of posts about…
  5. Install Gadget-2 | kaizokuow's tech - […] https://snatverk.blogspot.fr/2013/02/nbody-simulations-with-gadget2.html https://astrobites.org/2011/04/02/installing-and-running-gadget-2/ […]

Leave a Reply