Pages

Showing posts with label computing. Show all posts
Showing posts with label computing. Show all posts

Monday, January 24, 2011

My Favorite Computer Science Quotes.


Some of my favorite quotes relating to computer science:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
- Rick Osborne
 Perl – The only language that looks the same before and after RSA encryption.
- Keith Bostic
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
- Rich Cook
It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration.
- E. W. Dijkstra
The trouble with programmers is that you can never tell what a programmer is doing until it’s too late. - -- Seymour Cray
Talk is cheap. Show me the code.
- Linus Torvalds
Software is a gas; it expands to fill its container.
– Nathan Myhrvold
In the future, computers may weigh no more than 1.5 tonnes.
– Popular mechanics, 1949 
Python's a drop-in replacement for BASIC in the sense that Optimus Prime is a drop-in replacement for a truck.
- Cory Dodt
Any really good ones that I am missing?

Friday, December 10, 2010

Oh The Things We Can Do With Computers!



Iran has an embarrassing problem which illustrates what we can do with computers today.  If you were to ask, even a few years ago, what we had to do to take out Iran's nuclear capabilities, you would probabley be told what Senator McCain suggested: "Bomb bomb bomb, bomb bomb Iran"

However, it appears no bombing may be necessary.  It turns out Iran's computers at their nuclear sites have been strategically infected with a computer worm they can't figure out how to remove.  Of course, just a couple weeks ago President Mahmoud Ahmadinejad assured the word they quickly discovered the worm and took care of it.  However, the above article suggests this is not the case.

This has caused me to marvel what we can accomplish with computers these days.   We appear to live in a world where you can take out your enemy from the comfort of your own home. :)

Some choice quotes from the article:

1.  A little about the worm itself.
The Stuxnet worm... is the most sophisticated cyberweapon ever created... It was a cybermissile designed to penetrate advanced security systems. It was equipped with a warhead that targeted and took over the controls of the centrifuge systems at Iran’s uranium processing center... and it had a second warhead that targeted the massive turbine at the nuclear reactor in Bashehr.
2.  My favorite quote of all:
“The Iranians don’t have the depth of knowledge to handle the worm or understand its complexity,” ... raising the possibility that they may never succeed in eliminating it.
3.  And finally, what may be Iran's best case scenario?:
They are completely dependent on outside companies for the construction and maintenance of their nuclear facilities. They should throw out their computers as well. But they can’t...
“With the best of expertise and equipment it would take another year for the plants to function normally again
Well, good luck Iran.  But the good news for you is if this is successful enough you may avoid McCain's plan B.  :)

Friday, October 29, 2010

Python Versus IDL For Astronomers and Our Beautiful Sun.

Given our recent trashing of IDL I thought I would be fair and admit:
  1. The majority of the plotting issues we discussed have actually been addressed in the new IDL 8.0.
  2. AstroBetter, a site with the purpose of providing "tips and tricks for professional astronomers", has a good honest assessment of the pros and cons of IDL versus Python. (A list that is continuously updated.)
That said, I will point out a few things (being the biased person I am):
  1. There are real reasons why the Hubble, James Webb space telescope and ALMA teams as well as STScI are migrating a lot of their code base to Python .
  2. For that matter, this is why CERN is providing python wrappers for their major pieces of software like ROOT
  3. I agree with these decisions. :)
Just some observations.  That said, enjoy a beautiful picture of the sun taken by Alan Friedman:


Wednesday, October 27, 2010

Computer Language Fragmentation in Physics Knows No End.

As a graduate student I have written papers where, in order to collaborate, I had to write code in: C, C++, FORTRAN (77 and 90), IDL, Jython, Matlab, Python and have just been told for my next project I need to modify hundreds of lines of Perl scripts.  Furthermore, UCI did their numerical methods course in Java as they thought that was a good intermediate language. (And I have had to design web pages in html if that in any way counts.)

So, just to get real world physics done this non-CS guy has had to master ~8-10 languages enough to get papers out the door with different collaborators.  Does the computer language fragmentation in physics know no end?  Fortunately, once you have learned 2-3 languages the rest are pretty much straight forward provided you have good documentation.

You all know I love Python.  If people could just write everything in Python except the speed critical parts I would be happy. (And if you must use FORTRAN do not use 77!!!)

Sorry this is not the most profound post but I just needed to vent.

Friday, September 24, 2010

Sometimes Academics Lose Sight Of What People Want/Need.


For some people, once they grab hold of some sector of academia they want to study it to death and know the ins and outs to the nth order.  Often, these are they who become the professors.

However, sometimes we forget that some just want someone to show them how to use this knowledge to "program video games".

Image from Abstruse Goose.

Wednesday, May 12, 2010

Programming Practices That Are Deadly. (Literally).


I was tempted to use a goto statement the other day... until I read this.  Thank heavens I didn't make that mistake.  Phhheeeewww.

Thursday, April 8, 2010

C Is The Most Popular Languange Again!

I'm sure many of you have heard the news that C is back at the top as being the most popular programming language again, according to TIOBE who monitors this stuff.  (Java held it's ground for so many years.)

There should be some type of Nobel Prize type prize that should be bestowed upon Dennis Ritchi.  There are probably few accomplishments in the 20th century that have had more effect on society than the C programming language.  From it we also got Unix (and all that led to), tons of computer programs and many other languages based off of C. (For all you Windows and Mac fans, C has been a crucial part of those OS's too.)

C, for all of its criticisms, is one great language.  Despite all the advances in computer science over the years, at the end of the day, many people continue to come back to C.  (Unlike FORTARN where the entire civilized world has moved on, except for people who are slaves to codes that were written by previous generations of scientists.)

Let's also not forget, Python is really just a "grandiose wrapper" around C. :)

Thursday, March 18, 2010

On The Overuse Of Semicolons While Programming.



 Dilbert's real error is he obviously isn't using Python. :)

Wednesday, February 10, 2010

Will Scientists Adopt Fortran's New OO Structure?

First off, the correct answer to any question of this nature should start out as "Well, whenever possible Python should be used, but in the few cases it shouldn't..."

That said, I was wondering if anyone thought scientists would ever adopt Fortran's new object-oriented structure?  (For those who don't know, new in Fortran 2003 has "Object-oriented programming support: type extension and inheritance, polymorphism, dynamic type allocation, and type-bound procedures.")

I ask this because I have a friend here at Irvine who is trying to rewrite his group's Fortran code so that it is object oriented and thought:
  1. Object orientivity has traditionally been an argument for scientists to switch from Fortran to C++. (If you don't need something that strong you really should be using Python. :))
  2. I have a high performance computing book that touts Fortran's biggest pro is it forces numerical programmers to avoid objects because of the overhead they often add to numerical performance.
  3. One reason Fortran is still used so much is nobody wants to rewrite the codes their group uses as it would take too much time and effort.
  4. If you are going to object-orient your code, is it really better to re-write it in Fortran 2003, as my friend is doing, or just rewrite in in C++?
  5. Maybe object-orientivity has less overhead in Fortran compared to C++? For example pointers in Fortran are not allowed to "change type" in Fortran giving them a slight performance edge in their ability to be optimized?  Does anyone know if similar types of performance advantages will also carry over to Fortran's object structure?
Anyways who would have ever thought: Fortran has an object oriented structure!  I just wonder, will scientists adopt it?

Tuesday, February 9, 2010

Should Scientists Release Their Codes?

Slashdot has an article where Professor Ince is calling for scientists to make their codes public.  The idea is, it makes what scientists are doing more transparent.

I can think of various pros and cons. However, I know of a few scientists, like Dr. Eiichiro Komatsu (First author for the WMAP 5 and 7 cosmological interpretation papers) who make many of their codes public.

His codes are well written and set up so that by default you can reproduce many things in the literature.  I'm not saying all scientists should follow, but I will say this:  I have 100% confidence in the results Dr. Komatsu gets as I can reproduce them myself and see exactly what he did at each step.


Anyone have any thoughts?

Saturday, January 30, 2010

Compilers Can Make A Big Difference.

I wrote a certain C program that traditionally has taken 10 minutes to run.  Today I tried running it and after 45 minutes I crashed it thinking I must have introduced some bug causing it to not run correctly.  I started puting print statements everywhere and could not find a single place where the bug was.

Than, after an hour of playing with print statement, I noticed I was compiling with gcc when in the past I compiled with Intel's compiler icc.  I had no idea, but the types of rutines I wrote run literally ~7 times faster with icc than gcc.  This is not true about all C codes, but it is about this one.

Here's a new personal testimony Intel could use:
When I don't compile my codes with Intel compilers they run so slow comparitivley that one is almost convinced there must be major bugs in the code.

Tuesday, June 30, 2009

Very Interesting Graph


Look at the above picture. It should absolutely awe you. Our computational power has exponential looking growth In a log plot!!! The types of calculations will will be able to do during our own lifetimes will just be staggering to think about!

Furthermore, supercomputers today can make calculations 1000 times faster than just ~10 years ago and a million times faster than ~20 years ago. This means the top supercomputer computing speed doubles about every year.

And Nick, this also means I will be able to solve the complex problems you are solving with Fortran in ~5 years in Python just as quickly. :) I'll just have to bask in the easy to use, batteries included programming language, running on lightning fast hardware. I doubt I will ever solve a problem more numerically complicated than those. (And this is assuming I don't convert the slow parts of the code to C and call it from Python. It would be more work, but I would only have to wait 1-2 years in that case.)

Saturday, May 30, 2009

New Computers and Old Methods

Recently (yesterday) I got a new laptop. It is an HP and I actually got a pretty good deal on it. Unfortunately it is an HP and it didn't come with the option to downgrade (upgrade) to XP. So at the moment it is running Vista (don't worry I will make it a dual boot and put Linux on it, I need it for research). As part of connecting to the UNC network you have to register the MAC address of the Ethernet car and wireless card. This is fairly standard for a secured network so you would think that finding the MAC address would be a fairly standard and easy process.

Most of you know that the only way you can get XP to tell you a MAC address is to open a command prompt and type in ipconfig /all to get the networking information. So when I started up Vista I assumed that they would have done something about this and would have made finding the MAC address easier (say putting it in the control panel, under internet and networking options, for example, like they do in Mac OSX), you know, making it possible to find it through the GUI like everything else they do. Well I checked the internet and the only way to get Vista to tell you the MAC address is, you guessed it, ipconfig /all.

They have just about everything else that can be accessed through the GUI you would think they would include the MAC address, but that would be too logical. Maybe Windows 7....(maniacal laughter).

Tuesday, April 21, 2009

To Be Fair To Fortran

Okay, here is, in my opinion, why FORTRAN deserves to not be executed:
It is easier to write fast numerical programs in FORTRAN than in any other language.
To write fast codes in C++ you have to do one of two things:
  1. Use only the low level C objects, in which case you are in many respects no better off than FORTRAN since you are just trading one proceedural language for another. (Which doesn't have bound checking or other safety features FORTRAN has).
  2. If you use the real power of C++: classes and templates for well done modular and generic programming, you will have to be a slight programming expert. It takes a lot to properly learn how to use classes and templates and even more how to use them in a way to achieve the speed of FORTRAN. It can happen, but it does take a fair amount of learning.
For me the question is: Are we better off using a language which does not require a lot of programming training to write fast codes at the cost of what I described in my last post, or are we better off using a language which will take years to really master but in the end will produce codes just as fast without the headaches I described before?

As you know I tend to think numerical programmers need to be CS experts. It think it is better for the computing community for the reasons I already described. But maybe there is room for a language where you can write fast codes immediately without becoming a CS expert first.

Friday, April 17, 2009

Room For Fortran?

As many of you know, I have real issues with FORTRAN. I tend to think progress in physics is held back by FORTRAN programmers for these reasons:
  1. Students taking CS classes to learn good programming practices cannot come back and apply them to their FORTRAN code. It's like we loose all that great knowledge by making students program in FORTRAN.
  2. Collaboration is minimized. Sure, high performance groups can collaborate since they know FORTRAN, but collaboration outside such niche groups is ruined. At least with C++ you can collaborate with the C/Java/C# programmers which is the overwhelming majority of programmers.
  3. Inability to reuse code as. Almost every FORTRAN programmer has to write code that has been written before by someone else. Some RK4 or Monte Carlo or etc.. routine. FORTRAN doesn't have the modern features like object oriented/generic programming so that code can be shared and reused more easily. Sure, some code is shared, but not at the same level as modern languages.
  4. Turns numerical programmers into people who can only write numerical programs? Seriously, other than numerical codes, what can you write in FORTRAN? To give physicists the ability to write more than just numerical codes will open the doors to greater progress.
Unfortunatly, here is the timeline of a FORTRAN programmer:
  1. Learns Java in his undergraduate CS class it was recommended he take.
  2. Starts doing research with some group where all the codes are in Fortran.
  3. Has to relearn a lot of programming and misses out being able to apply the good practices he could have taken from the CS department.
  4. Over time is convinced FORTRAN is great.
  5. Keeps a copy of Numerical Recipes close since he will have to write these routines that could easily be shared if he used another language.
  6. Pretty much can't do solid collaboration with people outside the high performance computing community, nor write anything other than numerical programs.
Now, I admit I am being extreme, but this is a big fear I have. I worry about scientific progress being held back.

At least, starting with FORTRAN 2003, object oriented and generic programming is merged into FORTRAN which will hopefully fix #3 above. I'm actually going to spend some free time looking into it. (Imagine that!) Also, at least FORTRAN has array checking.

Practical Realization:

I do realize that so much code is written in FORTRAN we can't just rewrite it all. But that doesn't mean I like the fact so much of the high-performance computing world is in this position.

Monday, April 13, 2009

Special Honors

Today I found out that I have been bestowed special honors. I have a whole chapter of a text book dedicated to me (or rather a problem I had). Unfortunately the author decided not to specifically say why he had included the chapter but knowing the author and my particular problem I can see that it was included as a direct result of my problem.

You may remember the books by Dr. Spencer used in the Numerical Techniques courses (230, 330, 430). Well, I had to go back and look through the books lately because I am currently the TA for the computing class here at UNC. As I was looking through the Introduction to MATLAB manual online to refresh my memory about a few things I noticed that the manual had been updated and a few chapters added. One of the chapters (Chapter 14: Fitting Functions to Data) seemed rather um...personal shall we say.

You may recall that a while ago I was working on my galaxy problem. Well I was trying to fit an arbitrary function to some data and was having a hard time with it. I went to Dr. Spencer for some help and he looked over what I had done and said, "I don't believe it! You have committed the classic mistake of fitting a function to data. This is something I have been warning students about for years but I have never actually seen anyone do it! You are the first!" What I had done was a little complex but the short of it was that I had solved for the data that I had input in the first place. After he explained what I had done he said, "I should include a section on this stuff in the classes because you probably won't be the last to make this mistake." (Maybe not those words exactly, it's been a few years, but he said something like that.)

So when I saw that chapter I just had to laugh because now future generations of BYU physics majors will have to solve those problems and read through that chapter all because of a mistake I made while writing a MATLAB script. If you look at the problem given in the chapter it has some striking similarities to the problem that I was trying to solve...yeah well I know that I made an impact. I wonder if I could put it on my resume?

Sunday, March 22, 2009

If programming languages were religions?

I found an interesting article entitled If programming languages were religions... I wanted to point it out because a.) It is sort of funny/clever, b.) it mentions Mormonism. From the article:

C would be Judaism - it's old and restrictive, but most of the world is familiar with its laws and respects them. The catch is, you can't convert into it - you're either into it from the start, or you will think that it's insanity. Also, when things go wrong, many people are willing to blame the problems of the world on it.

Java would be Fundamentalist Christianity - it's theoretically based on C, but it voids so many of the old laws that it doesn't feel like the original at all. Instead, it adds its own set of rigid rules, which its followers believe to be far superior to the original. Not only are they certain that it's the best language in the world, but they're willing to burn those who disagree at the stake.

C++ would be Islam - It takes C and not only keeps all its laws, but adds a very complex new set of laws on top of it. It's so versatile that it can be used to be the foundation of anything, from great atrocities to beautiful works of art. Its followers are convinced that it is the ultimate universal language, and may be angered by those who disagree. Also, if you insult it or its founder, you'll probably be threatened with death by more radical followers.

C# would be Mormonism - At first glance, it's the same as Java, but at a closer look you realize that it's controlled by a single corporation (which many Java followers believe to be evil), and that many theological concepts are quite different. You suspect that it'd probably be nice, if only all the followers of Java wouldn't discriminate so much against you for following it.

Perl would be Voodoo - An incomprehensible series of arcane incantations that involve the blood of goats and permanently corrupt your soul. Often used when your boss requires you to do an urgent task at 21:00 on friday night.

Python would be Humanism: It's simple, unrestrictive, and all you need to follow it is common sense. Many of the followers claim to feel relieved from all the burden imposed by other languages, and that they have rediscovered the joy of programming. There are some who say that it is a form of pseudo-code.

Some readers will be happy to know C# is on the rise, as is Python and C++. Thank heavens Perl is on the way down and Fortran isn't even mentioned. (Though one commenter pointed out Fortran programmers are like the Amish. I couldn't agree more.)

Tuesday, March 17, 2009

Finally Learned MPI

I have used several codes that use MPI but not written one from scratch. I have only added to codes others have done the MPI work for. To be honest, I had a hard time reading the online documentation. However, a post doc showed me a code (below) that opened opened my eyes to what is going on. I am posting it in case it could be of some help to others:

To compile run:
mpicc testmpi.c

To run type:
mpirun -np 4 ./a.out

The trick is to understand each of the 4 processors runs the whole code but is assigned a rank. As you can see in the for loop and print statement, a conditional on rank causes the processor to know which code is "its" job. First you have to Init and assign a rank and size which comes from the -np 4 passed above. The MPI_Barrier command pauses the program until all the processors have caught up with the others, and the MPI_Reduce command takes all the values each processor has computed and feeds them back to the master processor. As you can see I am taking each sum and "MPI_SUM"ing them together as "MPI_DOUBLE"s and feeding my master processor "0" the sum into the value Sum.

I then make the master processor print the total Sum.

#include < stdio.h >
#include "mpi.h"

int main(int argc, char** argv)
{
int rank, size;
int i;
double sum=0, Sum;

MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

for (i = rank*1000/size; i < (rank + 1)*1000/size; i++) {
sum += 1.0;
}
printf("%d gets sum = %g\n",rank,sum);

MPI_Barrier(MPI_COMM_WORLD);
MPI_Reduce(& sum,&Sum,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);

if (rank == 0)
printf("Total sum %g\n!",Sum);

MPI_Finalize();
}

Friday, December 26, 2008

It May End With a Whimper, But The Solar System Started With A Bang

When studying stellar evolution, the really interesting stuff are the ways that high mass stars die - supernovae. Our sun, by comparison, will be far less exciting as it dies the slow death of a cooling white dwarf in about 5 billion years. However, a paper recently published by Boss et al (available here) and summarized nicely by Physics Today (available here) shows that the excitement in our solar system probably happened about 5 billion years in the other direction. Their research shows that our sun and its planets probably formed due to a supernova shock wave passing through.

The supernova shock wave theory had been around since the 1970's when it was discovered that meteorites in our solar system contained the decay products of aluminum-26 and iron-60. Aluminum-26 and iron-60 can only be produced naturally by supernovae and are both very short lived (in astronomical terms) with half-lives of 717,000 and 1,500,000 years respectively. For the decay products of these elements to be present in meteorites in our solar system, the solar system must have formed within a few hundred thousand years of a supernova explosion - an astronomical blink of an eye when you consider the age of our sun (~4.5 billion years). So either the supernova was an extremely unlikely coincidence or it caused the formation of our solar system.

The problem, however, was that when astrophysicists tried to model the collapse of a star-forming cloud due to a supernova shock wave passing through, the results were not pretty. Instead of initiating a collapse the shock wave actually tended to delay the collapse by heating the gas (causing it to expand) or even blowing the proto-solar cloud apart completely. So while the data clearly pointed towards supernova induced collapse, the mechanics of that process remained elusive.

The paper published by Boss et al. has finally solved the mystery. Using the FLASH code, they were able to show that the shock wave would compress the gas and start the collapse and that the heating caused by the shock could be radiated out of the cloud by molecules like molecular hydrogen, water, and carbon dioxide. The problem with previous models was that they used a rough parametrization for the radiative cooling while the FLASH simulations use a complex set of chemical reaction networks that provide much more physically accurate models for cooling. These simulations have answered a question that has been floating around for three decades that may never have been answered any other way.

****************************

On another note, I'd like to express my support for the model of modern code development that the FLASH code and others have helped to popularize. Twenty years ago when you wanted to run a simulation, you sat down and wrote your own code, used it once or twice, and then wrote another code for your next project. Today the problems in many areas of astrophysics are so complex that it would be impractical if not impossible for a single person to write a code that could do cutting edge research. The FLASH code incorporates advanced computational methods, cutting-edge algorithms for massive parallelization, hydrodynamic and magnetohydrodynamic solvers, massive nuclear and chemical reaction networks, general and special relativistic mechanics, radiative transfer models, particle physics, and more. No one person has the understanding and expertise to write a code that could do all of those things - and even if they did it would take an individual years to decades to produce a working code that contained it all.

FLASH was developed by a team that contained engineers, chemists, physicists, and computer scientists. It was written in the same way that most large pieces of commercial software are written. It is highly modular and very well documented. It is a code that can tackle problems like the one mentioned above because it includes so many diverse physical processes in a framework that allows the effective use of some of the world's largest supercomputers.

If more codes were written this way, more meaningful science would get done. I believe that in 10 years or so, almost all numerical science will use codes developed like FLASH.

I should also note that FLASH is not the only code to follow this model. Other codes large codes like the molecular dynamics code NAMDI, the cosmological codes ENZO and GADGET, and even some smaller ones like the code I use for solar and stellar convection models, ASH, were developed this way. FLASH is, however, probably the most well-known and best example of this new mode of code writing.

Wednesday, November 12, 2008

Sage, a Free Maple/Mathematica Replacement (Plus More on Python)


Sage is a free open source computer algebra system written in and based on Python. You can download it free or use it online for free like a Mathematica or Maple worksheet. It can do very many things that Maple and Mathematica can do.

Seriously, you should try it before you knock it! It is a blessing to have something like this free for use.

Yet Another Reason to Learn Python!

Sage is basically just a fancy wrapper around the Python language coupled with the scipy/numpy libraries. So, learn some Python using numpy and scpiy and:
  1. Chuck Matlab!, Python/Numpy/Scipy can do all this just as fast and easy. (and free.)
  2. Eventually chuck Maple and Mathematica as Sage matures.
  3. Read this wonderful book, learn how to mix Python with your Fortran/C/C++ code and become a much more happy and productive programmer.
  4. Be able to program in all computer areas, GUI, numerical, system, etc... (Something you can't do with Matlab/Mathematica/Fortran.)