How-to: Install MCNP4C2 on Mac OS X 10.4.10 (Intel)

MCNP (Monte Carlo N-Particle) is a transport code that is used throughout the physics community to model how particles interact as they travel through a system. The code is quite old, and therefore requires tweaking to get it running on newer systems like Mac OS X 10.4.10. There are programs and compilers it needs to use when installing that aren’t included in Mac OS X anymore due to their age, and a few that are on the Mac OS X CD that came with your computer, but aren’t installed by default. The first things we need are:

A FORTRAN-77 compiler and a ‘C’ compiler of the same version.
The ‘fsplit’ program.
X11 installed.
The XCode tools.

The last is the easiest to install, and may come in useful if you ever do any programming under OS X. The XCode tools are on the Mac OS X install disc 1 that came with your Intel Mac. Open the CD and start the XCode installer (XCodeTools.mpkg) in

/Mac OS X Install Disc 1/XCode Tools/

During the installation, you get the option to customise the install, just select everything. I know some which are needed by MCNP, like the X11 SDK (software development kit), the GCC (GNU compiler collection) compilers the 10.4 SDK; but only selecting some messes things up and you never know when you’ll need them.

Once these are installed, you have to find the X11 installer (you’ve just installed the deveopment kit, but not the X11 application itself). X11 is the window server that allows you to display the geometry you define in MCNP. Double-click the X11User.pkg package on the Mac install CD at the path:

/Mac OS X Install Disc 1/System/Installation/Packages.

Run the installer and your done with the CD.

Now you need to install the FORTRAN-77 compiler, G77 version 3.4.0, and the C compiler CC 3.4.0. Both of these are done in the next step, are free, and are part of the GNU Comppiler Collection (GCC). This step is taken from

http://www1.gly.bris.ac.uk/~wookey/MEFTLG/g77.htm


Download the compilers’ source code to your desktop by clicking the link below, then double-click the downloded file to unpack the code to a folder on your desktop.

ftp.gnu.org/gnu/gcc/gcc-3.4.0/gcc-3.4.0.tar.gz

Then download the patch file to your desktop (which allows this old compiler set to run on an Intel Mac) by right clikcing this link and saving. This may add ‘.txt’ to the file, if it does, right click and select ‘Get Info’. Then remove the .txt suffix.

http://www1.gly.bris.ac.uk/~wookey/MEFTLG/gcc-3.4.0.diffs

Now you need to make your account an administrator account if it wasn’t one already, then open a Terminal window (found in /Applications/Utilities/) and type the following commands, hitting return at the end of each line:

cd Desktop
patch -p0 < ./gcc.3.4.0.diffs
cd gcc-3.4.0

./configure –enable-altivec –enable-languages=c,f77
sudo make bootstrap
sudo make install

(It seems that wordpress is removing two hyphens in an attempt to be smart. Both the ‘enable’ directives should be prepended by two hyphens, not a single one.  The single hyphen between ‘enable’ and ‘langauges’ should be single, though.)

The ’sudo make bootstrap’ command will ask for your password and take forever, even on my new 2.2GHz Core 2 Duo MacBook Pro! The ’sudo install’ command may tell you nothing else was required, so thats cool.This will create a few new programs in you /usr/local/bin folder, these are the compilers. One this is done you can delete the gcc-3.4.0 folder from your desktop. Then open up a terminal window, we are going to add the g77 (FORTRAN) and gcc-3.4.0 compilers to the standard folder where all things like this are kept. This allows you to invoke them from the terminal without typing the folder path each time too. We add them to this magical folder (/usr/bin) by creating a symbolic link (an alias in Mac language or shortcut if you speak Windows). In the terminal, type:

sudo ln -s /usr/local/bin/g77 /usr/bin/g77
sudo ln-s /usr/local/bin/gcc /usr/bin/gcc-3.4.0

Done! This leaves the 3.4.0 versions of the compilers in your /usr/local/bin folder so the XCode-installed new shiny versions don’t get messed with.Now we need to install ‘fsplit’ which is needed during the MCNP install when it splits up its monolithic FORTRAN source into smaller files, as I said MCNP is old. Download the fsplit source to your desktop:

http://ftp.bg.openbsd.org/OpenBSD/src/usr.bin/fsplit/fsplit.c

The open a Terminal and type

cd Desktop
cc -o fsplit fsplit.c

This compiles the program and places it on your desktop. Then type:

sudo mv ./fsplit /usr/bin

which moves the compiled program to the magical folder which the terminal likes all programs to be in. Then delete the fsplit.c file.

Now have a coffee, then we’re ready to install MCNP (finally). Put the CD in and open up a terminal window. When writing a folder path you can press tab, and the path will attempt to complete itself. If it can’t, for example when there are 2 folders beginning with the letter ‘c’, then press tab again and a list of all the possible matches will come up.

You’ll use this now if the MCNP CD isn’t called what I type below, mine was just called MCNP, but yours may not be. Whatever though, it will be the name that appears on the desktop.

mkdir /Applications/mcnp
cd /Applications/mcnp
gunzip -c /Volumes/MCNP/C701TAR.GZ | tar xvf -
gunzip -c /Volumes/MCNP/D200TAR.GZ | tar xvf -

This creates two folders in you /Applications/mcnp folder called ‘mcnp’ and ‘mcnp4c2′ the former containes cross-section data and the latter is the source code for MCNP itself. You have to place the cross sections is another folder, in terminal again:

cd /Applications/mcnp/mcnp/xs
sudo mkdir /usr/mcnpxs
mv ./* /usr/mcnpxs

Done. Now delete the /Applications/mcnp/mcnp folder. Leave the mcnp4c2 folder though, we need that now.

In Finder, go to the mcnp4c2 folder we just created and double click the install.fix file. This can be opened in TextEdit, where we just need to uncomment a few lines.Scroll down to the line that says FIXES FOR SYSTEM 5 (PC LINUX), below it is asks you to ‘uncomment the two lines for a debuggable version’ (some of you may need this when running MCNP), all this means is delete the ‘c’ charachter from the two lines below the statment, so they look like this:

5 2 4 1 1
DEBUG=”-g”

Save and close the file. Now you need to open up the mcsetup.id file in the mcnp4c2 folder. This opens in TextEdit again, so scroll down to the line that says ‘COM file to make MCNP 4C2 on the PC Linux’. The section of code below this line are all the commands used to compile MCNP, its automated later on, but these need to change a bit so they use the right compilers which we installed earlier. A few lines down you see

7 'mv compile mcnpc.c','cc -c mcnpc.c',......

Change the ‘cc’ part to read ‘gcc-3.4.0′ (without the quotation marks). A few lines down you see ‘./fsplit’ which you simply change to ‘fsplit’. This is ready to go now. You told it to use gcc-3.4.0, which is the same version as the g77 comiler we installed, this was very important.Open up a terminal window and type:

cd /Applications/mcnp/mcnp4c2
chmod a+x ./install
./install linux mncp

This then starts the install program, you’re greeted with a few options, you can change a few, but not all of them work with the Mac, and will tell you they haven’t been tested on linux (which were pretending to be, shhh don’t tell anyone).

In this mode you type 1.1, then press 5 to change to a linux setup, then type 2.3, press 2, then enter the amount of RAM you have according to the formula:

\frac{(RAM-2)}{4}\times 10^6

Where the value ‘RAM’ is in MB. This will say there’s an error with the value you typed (whoa THAT much RAM doesn’t exist!), again, MCNP = OLD. Just press C to continue.

Then back in the main MCNP install screen, press P to start installation. Should only take a few mins at most, not 20-40 like it says!

Once it’s done, you can delete most of the source. Open a terminal and type:

cd /Applications/mcnp
mv mcnp4c2/mcnp ./
mv mcnp4c2/xs ./
rm -r mcnp4c2
sudo ln -s /Applications/mcnp/mcnp /usr/bin/mcnp

Done! MCNP is now installed, and all you need to do is open a terminal and type ‘mcnp’ to run it! (It’ll ask for a input file, but if you’ve done all this then you’d probably know that!)

Ask questions, I’ll do my best!

8 Responses to “How-to: Install MCNP4C2 on Mac OS X 10.4.10 (Intel)”

  1. Jack Says:

    Thanks for the post, I’ve been trying to install MCNP on my machine for a few months now with no luck. I have MCNP5/MCNPX, do you know if the installation procedure is the same?

    Thanks,
    Jack

  2. Jonathan Dann Says:

    Jack,

    Unfortunately not, I haven’t had the pleasure of using MCNP5 or X as my hospital doesn’t have the license for them. I think 5 is on order at the moment, but could take years! From what I’ve read you might need the Absoft or IBM FORTRAN compilers, and I think both have a free trial. The g77 (FORTRAN compiler) stuff I wrote about isn’t tested with MCNP5/X, and neither is MCNP4 tested on Mac OS X, nor is the g77 normally available for Intel Macs. Took me weeks to find out how!

    I think the new ones were built with the Mac in mind though and a quick Google search came up with

    http://www.nea.fr/abs/html/ccc-0730.html

    However, it doesn’t say if it was tested on Intel, but the use of the IBM FORTRAN 90 compiler suggests it was an older G4 or G5 (PowerPC) machine.

    Keep subscribed to the post, you never know when I’ll get MCNP5 from my hospital, I’ll post a comment if I get it working. And thanks for saying thanks!

  3. Jonathan Dann Says:

    Also, give it a try, the key is to use the same versions of g77 and gcc (which I did above) if you get any weird log errors after trying it with those two compilers, send me the log and I’ll have a look.

  4. Tad Says:

    Just wondering if there was any follow-up from Jack? I’ll be trying to install MCNP5/X on an Intel Mac shortly as well and wondering if he tried it with the compilers you mentioned… Thanks too for the article–very informative!

  5. Jonathan Dann Says:

    Hi Tad,

    No follow-up at the moment unfortunately! Would be worth checking back here every now and then. One day I’ll get the 5/X upgrade too.

    And you’re welcome for the tutorial :)

  6. xiaoyu Says:

    I don’t know what any of that was about! Yay!
    But I love you.

  7. Jack Says:

    Hi Jonathan,

    Thanks for the help. I’ve been pretty busy at work and haven’t had any time to try to set this up. I’m hoping to get a chance within the next few weeks. As soon as I try, I’ll let you know the results.

  8. Jonathan Dann Says:

    Just so everyone knows, I updated this with a little fix to the fist set of terminal commands. Was a stupid mistake, if you’ve had problems, try again. Gonna try with Leopard tonight!

Leave a Reply