Thoughts on Programming Languages for Scientific Computing

7 #

I have a friend who works in chemistry / protein folding and thus does a lot of computational stuff within that field. Coming from an application/web programming background, I was utterly shocked when she mentioned that FORTRAN is widely used in computational simulations. The great programmer Nietzsche once declared that “FORTRAN is dead”, and I held that belief too, thinking that FORTRAN was only used in the days when C and C++ weren’t developed and programmers didn’t have anything else. I didn’t know a single person who uses FORTRAN.

But I was wrong. It turns out that FORTRAN is still actively used in scientific computing. In addition, it is not an “outdated language”. FORTRAN actually has quite a few versions which have evolved and added on modern programming languages features over the years.

The biggest draw of FORTRAN is speed. It’s one of the lowest level out of all the high level programming languages (like C, C++, Pascal, Java, etc.). The language, intended for scientific computing, was designed to be fast. In comparison, languages like C and C++ were designed as general purpose languages that could be used for a variety of purposes.

But I wasn’t totally sold on FORTRAN. I don’t like the syntax and rather code in C++ any day. I didn’t believe that C++ was all that much slower than FORTRAN so I decided to do some research into this matter. The following comes from an email I wrote:

  1. FORTRAN is widely cited to be “20% to a factor of ten” faster than C++. I didn’t find anything for C, but I think the speed of C is about the same as C++.
  2. However, the data in #1 was published in 1997. In the modern day, C and C++ compilers have been heavily optimized to produce speeds comparable to FORTRAN. Some modern benchmark results are here:

    (These two benchmarks show FORTRAN to be about the same as C/C++
    depending on how the code is written and compiled)
    http://dan.corlan.net/bench.html (maybe around the year 2000)
    http://dan.corlan.net/amd64_dual_core_benchmarks.html (newer version)

    (This benchmark shows FORTRAN to be much slower than C/C++. Java is
    even faster!)
    http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all

    (This benchmark shows C++ being slightly faster than FORTRAN)
    http://pauloherrera.blogspot.com/2006/12/introduction-ive-read-lot-of-things.html

  3. In addition, there is a library for C++, called Blitz++, which allows C++ programs using the library to approach the speed of FORTRAN. Benchmarks are here:
    http://www.oonumerics.org/blitz/benchmarks/
    (Note the percentages, ie. 95.7%, is the speed relative to the
    comparable FORTRAN program. So 100% is the same speed.)

    Also note that the benchmarks for Blitz++ were completed in like the year 2000. I expect if the same benchmarks were run today with modern compilers, the results would be even better.

  4. Therefore, I conclude that C/C++ is comparable to the speed of FORTRAN and depending on what you are doing and how you write the code can be faster than FORTRAN. So it depends on your preference of the programming language. I would probably always pick C++ over FORTRAN since I am more familiar with C++ and I think C++ code is easier to write and read.
  5. Surprisingly, python *can* be really fast. See:
    http://scipy.org/PerformancePython
    Of course, it will never approach the speed of C++ or FORTRAN, but Python code can be very easy to write and for medium sized projects, you can write the code much faster.
  6. Surprisingly, Java *can* be faster than C/C++. This is largely attributed to compiler optimizations that Java can do that C/C++ can’t do. See:

    http://www.idiom.com/~zilla/Computer/javaCbenchmark.html

    http://www.kano.net/javabench/ (see links at bottom of the page for more java vs c++ benchmarks)
    http://www.kano.net/javabench/data (good graphs)

    In my opinion, Java code is easier to write than C++ code. You might also get advantages of portability since Java code can pretty much run on any computer unmodified.

  7. Unsurprisingly, Matlab is slow. Even when Matlab code is optimized, it is at least 2 times as slow as comparable C/C++ code. Unoptimized, it can be 30 times or more slower! Of course, the good thing about Matlab is that you can easily write programs that perform math — much faster than with C/C++, Java, Python, or FORTRAN. So Matlab might be good to test an idea or implement something on a small scale.

Overall conclusion: C++ speed is about the same or only a little bit slower than FORTRAN. As C++ compilers become more optimized, the difference decreases. Java seems pretty fast, so I would probably do more research on it. If it *really* comparable to C/C++ speeds, I would probably use Java. For medium scale applications, I would use Python. For small scale applications, I would use Python or Matlab.

Project Update and Computer Irony

2 #

Eugene asked me today via email how things were going. I figured I should post the response here too so that other people can know what’s up too:

It’s going alright. Low efficiency though since I’m constantly distracted by stuff. Also, since I want to do it the “right way” sometimes it’s a lot slower (as opposed to building it in Rails at the loss of some extensibility and compatibility since I’m trying to make it so that other people can run it on their own server). If it was just an app running on one server with no one else using it, then rails would probably be the best way.

I’m hoping to get a really basic version released (nothing really special) next week so other people can play around with it too. At the same time, I’m going to try to set up the commercial side of it (but not release it to the public yet) so that I can try focusing on security and speed.

But in all, it’s more difficult than I imagined. Most of the time is spent debating what’s the best way to do it and by looking at how other scripts do it.

There are also some setbacks….like these past days, windows suddenly began corrupting my files after each reboot or hibernation for no good reason. Actually, I think it’s this program called RollBack Rx which is supposed to be a data recovery software that runs in the background (yeah, what irony). So I went to uninstall the program, but after I uninstalled it, the program took with it a chunk of core windows files which rendered windows useless.

So I used a Feisty live cd to mount the C drive over samba and used my other computer to copy over files from the windows cd. Unfortunately, that didn’t help at all.

So I went to reinstall windows. But I discovered that my DVD/CD drive suddenly couldn’t read CD-Rs (I’m working with Toshiba to get it exchanged although they want me to send my whole laptop in). My two windows CDs were both CD-Rs (legit versions, might I add).

Finally, I decided to install Feisty since it was a hard-pressed CD (I got it from the Ship-It service) and my CD/DVD drive could read that. Since I don’t use tablet functionality a lot when I’m at home, I figured I could live with Ubuntu for a while until I get my DVD/CD drive fixed.

It’s surprisingly good. It actually set up my digitizer pen out of the box (although right click doesn’t work). Wireless also works out of the box. Video and audio are good (although I had to tweak video a bit). It even tells me that the battery life on the logitech wireless mice is only at 14%!

Well, in truth, it’s not like I didn’t know that Feisty was good. Three of Avery’s computers run Ubuntu so I had quite some experience with it. But compared to two years ago when I tried out Ubuntu, Feisty does very good hardware detection. So I’ll probably be using Ubuntu for a while until I can get windows back on (mainly for MS OneNote).

Some email stats

6 #

I was in the process of backing up my email today from Gmail (by using Thunderbird). I think this is a good idea for anyone using Gmail just in case they lose your email or accidentally delete your account (this is rare but happens). So from February 9th 2007 to April 15th 2007 (a little over 2 month), I received and sent out a total of 1836 emails. I think <200 of that are emails I sent out, and about 1/3rd of the 1836 emails are probably personal correspondence (ie. No emails from college mailing list, computer generated emails from accounts, etc.). No spam was counted in the 1836 emails. I thought these numbers were somewhat interesting to share.

Survived Core

4 #

Finally, I completed all of my 5 finals and finished the second term of sophomore year…. I’m a survivor of Caltech’s Core curriculum! Last year, as a freshman, finishing core seemed so far away. Now I’m finally starting to understand how differential equations, probability, and statistics plays in with quantum mechanics and statistical/thermal physics. Now, I’m finally starting to see how all of this ties in with chemistry and the properties of materials… Damn, but I still feel like I know nothing. In a way, when I was in high school and even last year, quantum mechanics and all of this complicated math stuff seemed really mystical and unattainable. Now that I know some of it, I still feel the same. Nothing has really changed… but I really appreciate being able to learn this kind of science.

P.S. I’m sticking around Caltech for spring break.

Firefox Can’t / Failed Update Problem Solved

4 #

I lost this post when my previous host tried to transfer my site to another server. Luckily, Eugene had a copy of the post on hand, and this is the recovered post:

In the past, Firefox was giving me a lot of grief when I could never update the program automatically. It always failed with the error message: “Software Update Failed. One or more files could not be updated. Please make sure all other applications are closed and that you have permission to modify files, and then restart Firefox to try again.” Once, I tried working with people in the firefox IRC room, but after an hour, no one could come up with a solution. Today, I happened to chance upon Richard Davies’ blog post where he describes how he solved his update failed problem. He noted that Y’z Dock, a mac os-like dock bar for windows monitors the programs in the dock and therefore, prevents firefox from overwriting the files. BINGO! I use AquaDock instead of Y’z Dock (less resource hog), but the exact reasoning applied here. All I had to do was shut down AquaDock and Firefox was able to update perfectly. Hopefully, this post will reach people who are having the same problem.

Tags:

Frustrations of Rails and Wikis!

2 #

Argggg! I just spent the last 3 hours looking around for a good wiki system to use for Avery’s new web site. I was daring and wanted to try Instiki, a beautiful ruby based wiki. I was trying to set up fcgid with apache2, but that didn’t work out very well. So then I decided to ditch apache and go with lighttpd instead. But then lighttpd became a pain, and since it didn’t integrate well with subversion, I decided to go back to apache and set up a proxy to seamlessly pass the urls to Ruby’s WEBrick server (the default one). That worked well except that Instiki insisted on having a directory after the base path of the url (ex. test.com/someword/show/HomePage when I wanted test.com/show/HomePage). So I decided not to use it.

So I then went back to looking around for good php wikis and was dismayed at how crappy all of the current ones are. MediaWiki is too bloated. DokuWiki can’t use MySQL so it doesn’t scale up for larger sites. WikkaWiki is good, but the development on it isn’t very active (edit: The project is active, but just has slow release cycles), and in my previous experience, it takes some work to skin. Other wiki’s were too bloated, visually unappealing, or forced linking with WikiWords. I was thinking to myself: “Gah! Is it really *that* difficult to make a php wiki with these features: [insert what I was thinking here]?!” I really wanted to start coding one, but decided not to since I still had lots of work to do.

Erg, it’s really frustrating though. Now I don’t really have a good solution except for maybe falling back on a Wordpress CMS, but that goes against my idea of a wiki.

Hot Weather

4 #

When everyone boarded the flight from Philadelphia to Los Angeles, we were all wearing heavy jackets or coats since the weather this morning in Philadelphia was fairly cold. When I stepped out of the plane in Los Angeles, I had to exclaim: “Damn!” It was burning hot in LA and seemed like the summer. I thought to myself: “What the H happened to winter?! It was colder here when I left Caltech. It should be even colder now!” This weather is kind of unsettling even though it is really nice.

Interchangable Prefrosh

2 #

So my roommate and I are hosting a prefrosh for Caltech’s Prefrosh Weekend. The way it works is that prefrosh fill out this interest sheet which are distributed to each of the houses and each house allows their members to pick who they want to host.

When Avery had it’s prefrosh picks, I got there fairly on time and scanned through the interests sheets. Within a few sheets, I was astounded and exclaimed: “They’re all the same!” And a bunch of people agreed. Really!

Well, I suppose some things had to be similar like academic interests. Of course they all put something like science or math. But then there are fields like: Who is your ideal host? The general answer (on over 90% of the sheets I’ve read) was something like:
Nice, sleeps early, someone who doesn’t listen to loud rock, etc.

Then there is this other question: What do you like to do besides science and engineering? Now this question was pretty funny. Here’s the 90% response:
I like to listen to soft Jazz, read books, and I play [insert some classical music instrument]. Some of them play a sport like Tennis. But overall, there was virtually no distinguishing characteristics between prefrosh. I kind of understand admissions officers rejecting applications since they were the normal boring “science and math” person now.

Another question was: What kind of music do you listen to and how loud? What kind would you avoid?
90% response was: Soft jazz or classical at a low volume. Avoid loud rock or rap.
One response included: I detest heavy metal.

The final question was: What are the top three things that interest you at Caltech?
90% response:
1. Academics/Research
2. Meeting smart people.
3. Getting freedom/Being able to manage own time.

So I bet you’re probably saying to yourself: “Well, Mike, weren’t you like that when you applied too?” Okay, I admit I wrote down some of the same things like academics/research and playing musical instruments, but I wrote a LOT more than that. While 90% of these kids wrote like one liners, I filled up the spaces with my interests ranging from music (all sorts of intruments and styles) to anime/manga and martial arts. And hell no, I didn’t write classical/jazz music as my favorite type. I mean, I like playing classical and jazz, but I don’t like to listen to them for enjoyment. They get boring pretty quickly whereas rock is much more energizing with catchy beats and lyrics. Somehow I get this feeling that a lot of the prefrosh are religous so they have this thing against supposedly immoral music like rock and rap.

Alright, I must also admit that I’m slightly misrepresenting the prefrosh here since I was only reading the sheets that were distributed to Avery (selected by a group of Avery students). And they just had to select some of the most boring people around.

Finally, if you happen to be offended by this rant, I apologize. In retrospect, there’s nothing wrong with doing whatever one likes to do. That’s right, be your own person!

Don’t take this post seriously! And if you took the last sentence seriously, then there is no hope for you.

Some Respect for Windows

2 #

Okay, so we all know that Windows sucks. But when fanboys tout Mac OS X as the best operating system ever and starts attacking Microsoft because they can’t deliver the features that Mac OS X has, here’s something to think about (from pseudorandom):

A Mac running OS X is simpler to install, use, and maintain than a PC running Windows because Apple controls both the hardware and the software. Apple only has to design for hardware configurations that it itself has built. Were Apple to ship OS X for “bog-standard 32-bit PC hardware”, it would be just as frustrating as Windows. Microsoft has a far more difficult time shipping new versions of their OS not because they’re incompetent, but because their task is orders of magnitude larger than Apple’s, made so by the unending hardware configurations forced upon them by the commoditized market for PC hardware. In other words, were Apple to ship OS X for any old PC, its ease of use would drop dramatically, while its development and support costs would rise astronomically.

Tags:

Cheap-o Comics as a Page Background?!

3 #

I was looking at some server logs today and found this interesting Xanga blog. Notice anything, er um, strange? It’s using my cheap-o crappy Evangelion comic as the page background! First of all, that’s hilarious. Second of all, what has compelled someone to do this?! I don’t understand!

Tags: