Building a python extension with Trilinos 10.10 on 64-bit Windows 7

Continuing the journey, the folks at work upgraded me to 64-bit Windows 7 and the Trilinos folks updated to 10.10. Needless to say, I had to rebuild. I can’t definitively say which of these steps is necessary but I can tell you that if you follow them, you can compile a C++ python extension that uses many aspects of Trilinos on this system. And not just a few packages from Trilinos either. In fact, I’m currently using all of the following:

  • Epetra
  • AztecOO
  • Anasazi
  • Teuchos
  • epetraext
  • Amesos

To do this, first run the trilinos cmake system without shared libraries. Then build. This builds things like epetra.lib. Now, go back and turn on shared libraries and build again, this time with shared libraries turned on. This builds the dlls, which I believe are required to build a python extension. If one of the ones you needs fails, just go in to Visual Studio 2008 and open up the Trilinos solution. Right click the project. Change from a static library to a dynamic librray. Change Use of MFC to “Use MFC if a Shared DLL.” Change Use of ATL to “Dynamic Link to ATL.” The rebuild the package. The DLL should be created.

Build trilinos shared library
VS 2008 options to build shared libraries

Once all the static and shared libraries are built, I didn’t even mess with environmental variables (being a grad student and all) so I just copied them all into the build directory of my Python extension. On import, it worked just fine. Amazing!

I have yet to try linking to MSMPI and running large reactor problems on Microsoft HPC but that will be coming someday.

US nuclear scientist considers assassination of Iranian utterly despicable

It’s unclear who assassinated Iranian  nuclear scientist Mostafa Roshan by driving by his car on a motorcycle, placing a magnetized explosive designed to damage the inside of the car but not the outside, and then speeding off through the packed traffic by lane-splitting. Some Iranians have their opinions:

Thousands of mourners chanted “Death to Israel” and “Death to America” on Friday during the funeral of a slain nuclear expert whom Iranian officials accuse the two nations of killing in a bomb blast this week as part of a secret operation to stop Iran’s nuclear program.

The Washington Post

Even some western experts have claimed that it must be Israel:

“If you look at the choice of target, it really could only be Israel,” says Robert Baer, a former CIA agent in the Middle East.

On the other hand, some suspect that certain factions of the Iranian state could have done it due to their suspicious of disloyalty and involvement with western institutions. And in that case, the following message is basically irrelevant.

Perspective: I’m a run-of-the-mill US nuclear scientist working on advanced nuclear reactors to help mankind get energy to improve quality of life.

If Israel and/or other western-like states did this, shame on them. Covertly killing scientists is nothing but counter-productive towards any imaginable goal. The enraged Iranians will likely place a more pressing national priority on developing nuclear weapons, and make it even more secret. In this case, you’re not scaring people from going into the industry, but instead you’re inspiring them to become national heroes. You’re not causing meaningful set-backs in terms of Iranian expertise, the industrial knowledge to manufacture weapons is somewhat well-known. All you’re doing is justifying their quest for nuclear weapons (who would risk losing a major city for one botched assassination attempt?) and making them more angry with the oppressively powerful west.

Countries with nuclear weapons are acting like overgrown bullies on the playground who got held back a few grades. When some less powerful country tries to pick up a stick, the bully smashes it out of his hands and says: only bullies can have sticks. The non-proliferation treaty was meant to prevent the spread of nuclear weapons AND to reduce the nuclear capabilities of the nuclear states to minimal levels. The latter has not happened (as is thoroughly detailed in this wonderful book). I fully understand and support non-proliferation, and accordingly I would like to see more reasonable attempts at stopping the spread. Until we live in a world where all nations can be comfortable in their sovereignty, the non-nuclear states will try to get nuclear weapons. The posturing we’re seeing now, and this and other similar assassinations will only lead to more people trying to get nuclear weapons, in any possible aftermath. These are the most horribly destructive weapons known to man, and indirectly promoting their spread by bickering about minutia and/or invading countries for minor reasons is an extreme disservice to mankind. You’re nourishing seeds that will last for generations telling people that they aren’t safe until they have nuclear weapons.

building a python extension with trilinos on linux and windows

Continuing my python extension project, I’ve now successfully built a toy python 2.7 extension in C++ that uses the Epetra package from Trilinos 10.8. I’ve built it on Ubuntu 11.10 (with gcc) and on Windows XP (with Visual Studio 2008) using distutils. It’s a bit of a hack, but it works and is a path forward for me.

I started with Linux, because I figured it would be easier. I learned a few things along the way. First, you have to have built Trilinos with shared libraries enabled. This is required for how Python handles things, I guess, and is made clear under the heading “Shared Libraries” in this file. The PyTrilinos package (which is effectively a professional set of python-trilinos extensions, btw. I needed a custom one!) needs them as well. So run your cmake-gui and check the shared libraries button. Besides the libepetra.a in the build folder, you’ll now also find a In Windows, you’ll get >500 errors if you compile all of trilinos with shared libraries, but Epetra at least worked.
Continue reading building a python extension with trilinos on linux and windows

Speed up REBUS very much

If you use REBUS to analyze your nuclear reactors, and you use a lot of regions, you may be interested in page 13 of this pdf. You can change one line of the source code and the point where it says: “HMG4C CALLED AFTER NEUTRONICS TO UPDATE COMPXS” will fly by instead of sitting there for a very long time. This is a huge fix that ANL knows about and fixed internally but didn’t re-release to RSICC. I think it only affects REBUS-PC, and that REBUS-3 is OK. Enjoy!

the real issues with nuclear energy — a fresh look

I used to think I had nuclear power all figured out. But recently, I’ve revised a few points. Here’s  what’s up with nuclear energy.

Nuclear energy is interesting and cool because (in order):

  1. It can produce huge amounts of electricity without producing CO2 and causing global warming (it’s environmentally sustainable).
  2. It can produce huge amounts of electricity using fuel that isn’t running out anytime soon (it’s materially sustainable).
  3. It can produce huge amounts of electricity day and night, rain or shine (it’s baseload).

Nuclear energy, in its current form, has the following reasonable drawbacks (in order):

  1. If a serious country has a serious nuclear power program, they can spend the time necessary to get nuclear bomb materials.
  2. The up-front cost of a nuclear power plant is huge.
  3. Nuclear waste is scary and remains so for hundreds of thousands of years, at which point it isn’t scary anymore.
  4. Chernobyl was scary.

The following claims are hogwash:

  1. Special material from nuclear power plants can be stolen by terrorists and turned into a bomb!
  2. We can’t build nuclear reactors fast enough to do any good!
  3. Thorium reactors can’t be used to make bombs!
  4. We don’t need baseload electricity anymore! Don’t be so old school!
  5. But we’ll run out of Uranium in 20 years!

The following supporting claims are reasonable:

  1. The current estimates of worldwide Uranium supply are submitted by individual nations to “the Red Book.” These numbers should be taken with some suspicious due to strong economic motivations to claiming you have less Uranium than you actually do so that you can drive up prices. Currently, they claim that at current demand, normal priced uranium should last for 200 years. If the price goes up, there will be more uranium found. If that runs out, the next generation of nukes will have to be breeders. Then we can run on U-238 and Thorium for 10s of thousands of years, if not many more. Scarcity of fuel is not an argument against nuclear power in general. Stop using it.
  2. Recycling nuclear waste isn’t necessary for long-term sustainability, but breeding is. You can breed without recycling in a once-through breeder. Recycling is necessary, however, to turn nuclear waste into a reasonable form that will be safe in ~1000 years rather than ~1 million. Let’s see that burner reactor, INL and Argonne!
  3. Thorium reactors can all be modified to produce weapons-grade U-233. Proponents often claim that Thorium reactors are proliferation-proof because they don’t make Plutonium! Well, they’re wrong. U-233 is actually a better weapon material than Plutonium. I can disable “automatic denaturing” if I own the plant. I can get around “self protection” with a single Protactinium chemist. The true accolades of Thorium reactors are their ability to do thermal breeding and their vastly superior waste form. Those alone are enough to support these reactors as awesome. Don’t go spreading hogwash. We have enough of that.
  4. “There’s nothing you can do to Plutonium that I can’t undo in my bathtub.” Dr. Ron Fleming always says that, referring to self-protecting Pu from terrorists. He’s basically right – the chemistry is well-known. But he’s going to need a large and pricey bath tub. A nation can definitely do this, but terrorists alone cannot. No terrorist group is going to break into a well-guarded nuke plant, pull the highly radioactive spent fuel out of the pool, load it onto a truck, and drive it off to their covert $4-billion reprocessing facility just to get reactor-grade plutonium. That’s just plain stupid. It’s a lot easier to buy the stuff from some angry country or something. Therefore, worrying about plutonium diversion from reactor sites is silly. Diversion from a reprocessing plant is another story: the hard work is already done there (but the Plutonium is still low-grade). This is why once-through breeders are good ideas.
  5. Baseload power is essential to the stability of the grid. There’s billions of dollars in the infrastructure we have that requires baseload. If you invent cheap room-temperature super-conductors, let me know and I might reconsider. Talk to anyone in the utility companies though. This isn’t even a question for a good 50 years.
  6. Nuclear energy is a better phrase than nuclear power. Nuclear power is like North Korea, Russia, USA. Nuclear energy is that stuff charging our plug-in electric vehicles without making CO2.

You can read more about the good and bad of nuclear at

don’t politicize nuclear power

I just saw parts of this release of the senate republican conference roundtable (1hr, 30m) recently, and was happy to hear reasonable talk here about using nuclear power to get us off coal ASAP. Can’t say I disagree. I am, however,  a little worried about nuclear power becoming a partisn issue (haha). This proposal is in line with McCain’s campaign promises of new nukes. I know plenty of people back in Ann Arbor who passionately hate Republicans and will blindly go on hating nuclear power for no reason other than to smite them.  Of course, those people are borderline insane. I think most people are actually reasonable: Rod Adams didn’t pull all support from nuclear power, but then again he’s the most pro-nuclear person on Earth. What about the people who have yet to decide how they feel about nukes?

You know what killed the early hippie subculture? It was the summer of love in 1967 when every 17 year old suburbanite became a hippie. And what killed the original punk movement? Hot Topic. Clearly, to undermine a group’s claim to identity, mainstream society has to claim its unique characteristics for itself (tie-dye shirts of the hippies, dog collars of the punks, and nuclear power of the Republicans). So, in order to keep nuclear power from being politicized, I’d like to see some non-Republicans voice their support in a way that identifies them as a non-Republican. For instance:

I love universal health care AND nuclear power!

or perhaps:

Boy, smoking bans are a great idea. So is the expansion of nuclear power!


Ayn Rand sucks. Say, don’t you think making nuclear power plants is a good idea? I heard that if we recycle all the nuclear waste we have sitting around the USA, we could power the whole country for 90 years.

And you pro-nuke Republicans, recognize that it isn’t beneficial to the planet to try to tie a power source to a political ideal. So, when you rally for nukes, try not to demonize Democrats or anything. Sure it may be difficult not to sometimes, but rise above temptation and promote it as something too elegant to be automatically tied to abortion rights, gun control, and small government.

By the way, since nuclear power utilities are counting on large loan guarantees, doesn’t it seem like the nukes are more in line with Democrat’s “spend more tax dollars for the betterment of society” idea? Huh. Backwards.

If Al Gore endorsed nuclear power today, as a founder of Greenpeace has, we’d be this much closer to solving our energy problems.

Dear Al Gore: Please endorse nuclear power. Thanks  -Nick

compiling and installing MC**2 and dif3d in linux or windows

I thought the search engines were lacking in this topic that I have some experience in, so I figured I better do my part. I have installed MC**2-2 on a windows computer and on a linux computer using similar methods. The XS libraries I obtained differed from the results from my SPARC machine in the later decimal places, and global calculations were nearly identical. I haven’t tested all features, but it seems to work. I’ve also been running DIF3D 8.0 on my Ubuntu machine through a very ridiculous method. It runs in windows under Cygwin nicely.

MC**2-2 on a modern computer

MC**2 is a nice lattice physics code mostly used for fast reactors. It uses ENDF-V data and has excellent treatment of the unresolved resonances and stuff. According to my friends at Argonne National Lab, MC**2-3 is coming out soon, and it will compile easily on PCs. That’ll be nice, and it will make this discussion irrelevant. It’s going through verification right now. Anyway, until then, here’s the general idea. Get VMWare server and install Solaris 10 for i386 on it. This comes with the f77 compiler that MC**2 can actually use. Once you have that all installed, go in there and extract the MC**2 source. Edit the mcc.f file. Make these code changes:

  1. on line 12029 change REAL*16 to REAL*8. x86 architectures don’t support quad precision
  2. on lines 32858 and 32859, do the same.
  3. starting on line 32900, uncomment the lines with DEXP and DLOC and comment out QLOG and DLOG for a total of 4 changes ( 2 uncomments, 2 comments).
  4. Same on line 32937, but only one swap this time.
  5. Add an extra space before the text on line 44534. This is some error in the RSICC distribution.

I’ve done this on Solaris 10 with great success, and now I’m trying it out on OpenSolaris, on my new external hard drive. I had to give it 1GB of RAM or it was crazy slow. OK it works in opensolaris too. Here are the steps:

  1. gunzip and untar p350tar1.gz
  2. edit exec_compile.mcc.sun script and change the lib and jobdir variables to where ever.
  3. make the code changes to mcc.f as discussed
  4. run a copy of the script with the uncompress and copies commented out so it doesn’t overwrite your changes (I did this a few times)

I had to turn optimization in the script from O3 to O2, or else I got a core dump on compiling mcc. f. If all goes well, you should have the MC2 executable.

Now you have to make the libraries. The code to convert libraries needs similar code changes. Change All REAL*16 s to REAL*8, the QLOG to DLOG, and the QEXP to DEXP. It will compile now. I added the cwd to my path and the script ran nicely. Notice that when you change the code, you can’t just re-run the script as is because it uncompresses the original files each time. I made a copy of the script and commented out all the uncompresses after running it the 1st time.

My last pitfall was that there was a write-protected ISOTXS file in the directory I was trying to run in and MC2 dumped the core on execution. I deleted this file and reran with wonderful success.

I witnessed one of the guys who lead the development team of Windows 3.1 try to compile MC**2 once with the intel ifort compiler. He got it compiled, but it failed at runtime with memory allocation errors. That’s the story of my life.

DIF3D8 on a modern PC

DIF3D 8.0 compiles with G95. I followed instructions I found here to do it. I did run into a problem, however, with memory allocation when running on Linux. In Windows XP, under Cygwin, the instructions work perfectly. I am able to run in Linux by using the Cygwin-compiled executable through WINE. This is, conceptually, extremely ridiculous as it is using an emulator to run a program which is emulating the platform that I’m on. Go figure. The bottom line is that it works and it runs quite quickly — moreso than on the ancient solaris machines I used to run on. I think it should be quite easy to get it working natively on linux using G95 with a little effort, so let me know if you figure it out.

Cross section libraries

When transfering XS libraries from one machine to another, it is important to do so in ASCII, or BCD (binary coded decimal) mode. When I run MC**2, I get a binary ISOTXS file that will not transfer nicely to other computers. I use a utility to convert this to ISOBCD, which I then convert back to ISOTXS on the computer I’d like to run on.

thorium workshop, 2nd iteration

I’m at the thorium workshop here at school. There’s a guy from Thor power in Norway giving a talk. It’s interesting.

Fleming just suggested BeO as a moderator in a Th reactor. It’s diffusion length is just right (more than water, less than graphite), it won’t burn like graphite in air, and it increases your beta-effective with it’s delayed photoneutrons and stuff. I should tell will this.

But I’m actually working on BP stuff. I ran the BP search before the TRU search on the 2nd iteration of case 2. The BP search direction is loading correctly now, but it’s not covering the full power peak. I’m going to get power plots that correspond to the search direction plots now. It was very simple to do with my plotSearchDir2 function. (I have a good library I guess). It’s very useful to see these two together, layered on top of each other with the compiz fusion opacify functionality. Wow.

My mpeg4 povray videos didn’t work on JCLs mac computer. I’ll have to look into that. Ah, mac’s don’t support the avi container. I did this:

ffmpeg -f mp4 -vcodec mpeg4 -i case3-flyby.avi

to convert it to quicktime and sent it to him to see if it would have worked. It did.

There are asymmetries that show up in the 2nd iteration of the v4 case. They’re worse in the 3rd iteration. None help the peaking factor. What the heck. Should have gotten 1/3 core model to work. Must finish manuscript. Will stick with 1st iteration.  Damn damn damn.