« August 2006 | Main | November 2006 »

September 2006 Archives

September 7, 2006

Why Are Compilers So Idiotic?

It astonishes me how idiotic some compilers can be.

I’ve been working with some unusual compilers recently: the PGI compilers from the Portland Group, and the XL compilers from IBM. I’ve been attempting to get them to compile some standard libraries for testing parallel operations. For example, I want them both to compile LAM-MPI, and BLAS, and LAPACK.

In fighting with them to get them to function, I’ve discovered all sorts of quirks. To vent my frustrations, I am documenting them here. Specifically, IBM’s XL compilers today.

I’m compiling things with the arguments -O4 -qstrict -qarch=ppc970 -Q -qcpluscmt. This takes some explanation. I’m using -O4 instead of -O5 because with the latter, the LAPACK libraries segfault. That’s right. Fortran code, with nary a pointer in sight, segfaults. How that happens is beyond me. The -qarch=ppc970 flag is because, without it, code segfaults. What does this mean? This means that the compiler can’t figure out what cpu it’s running on (which, hey, I’ll give them a pass on that one: I’m not running this compiler on a “supported” distribution of Linux) and is inserting not only bad code but bad pointer dereferences (HUH?!?).

When compiling LAPACK, you’re going to discover that the standard Fortran function ETIME, which LAPACK uses, doesn’t exist in XL-world. Instead, they decided it would be more useful to have an ETIME_ function. See the underscore? That was a beautiful addition, wasn’t it? I feel better already.

While compiling LAM with any sort of interesting optimization (the benefits of which are unclear in LAM’s case), you’re going to discover that XL’s -qipa flag (which is implicitly turned on by -O3 and above) can cause extremely long compile times for some files. How extreme? I’m talking over an hour on a 2Ghz PPC with several gigabytes of RAM. But don’t worry! Even though it looks like the compiler is stuck in an infinite loop, it’s really not, and will actually finish if you give it enough time. Or you could just compile LAM without optimization, it’s up to you.

Next nifty discovery: some genius at IBM decided that all inline functions MUST be static. They have to be, otherwise the world just comes apart at the seams. Nevermind the fact that the C standard defines the inline keyword as a hint to the compiler, and specifically forbids the compiler from changing the semantics of the language. What does this matter? A common, sensible thing a library can do is to define two init functions, like so:

inline int init_with_options(int foo, int bar, int baz)
        ...do stuff...
        return n;
int init(void)
        return init_with_options(0, 0, 0);

Now what do you suppose the author of such code intends? You guessed it! He wants to let the compiler know that dumping the contents of init_with_options() into init() is a fine thing to do. The author is not trying to tell the compiler “nobody will ever call init_with_options().” But that’s what the XL compilers think the author is saying. Better still, the documentation for XL explains that there’s a compiler option that may help: -qnostaticinline “Wow!” you say to yourself, that sounds promising! Nope. The option doesn’t seem to do a thing. You should have been clued in by the fact that the documentation says that that option is on by default. No, sorry, all inline functions are static, and there’s nothing you can do about it. If you didn’t want them static, you shouldn’t have given such hints to the compiler.

Here’s another good one: what does the user mean when he specifies the -M compiler flag? Well, let’s think about this. The documentation for that option says:

Creates an output file that contains information to be included in a “make” description file. This is equivalent to specifying -qmakedep without a suboption.

Now, what do you think -M really does? Oh, it does what it says, alright: creates a .d file. But it also doesn’t stop the compiler from actually attempting to COMPILE the file. So, now that you’ve got your dependencies built so that you know in what order to compile things, you tell make to have another go at building things. But what’s this? It’s already been compiled (incorrectly!)! Joy! My workaround is to run the compiler like so:

rm -f /tmp/foo
xlc -M -c -o /tmp/foo file.c

Now, when gcc and other compilers handle the -M flag, they spit out dependencies to stdout, rather than creating a file. Many complex Makefiles that you really don’t want to go mutzing with rely on that behavior. How do we get XL to do the same? Here’s one you wouldn’t have suspected: -MF/dev/stdout What’s the -MF flag supposed to do? Modify an existing Makefile, that’s what. See, isn’t that an excellent idea?

Speaking of excellent ideas, IBM decided that the C language needed some extensions. And I can’t begrudge them that; everybody does it. Among the extensions they added was a __align() directive, along the lines of sizeof(), that allows you to specify the alignment of variables that you create. You’d use it like so:

int __align(8) foo;

Unfortunately, in the standard pthread library headers, there are several structs defined that look like this:

struct something {
        void * __func;
        int __align;

You see the problem? Of course, there’s no way to tell XL to turn off the __align() extension. You would think that using -qlanglvl might do it, because it supposedly allows you to specify “strict K&R C conformance”. You’d be wrong. Your only option is to edit the headers and rename the variable.

Other ways in which XL tries to be “intelligent” but just ends up being idiotic is it’s handling of GCC’s __extension__ keyword. For example, in the pthreads headers, there is a function that looks like this:

int pthread_cancel_exists(void)
        static void * pointer =
        __extension__ (void *) pthread_cancel;
        return pointer != 0;

The reason GCC puts __extension__ there is because pthread_cancel may not exist, and it wants to have pointer be set to null in that case. Normally, however, if you attempt to point to a symbol that doesn’t exist, you’ll get a linking error. XL, of course, barfs when it sees this, but not in the way you think. XL attempts to be smart and recognize common uses of __extension__. Somehow, somewhere, the error you get will be:

found ), expected {

Really makes you wonder what the heck it thinks is going on there, doesn’t it? The solution? Remove “__extension__” and it works fine.

That’s all for now. I’m sure I’ll find more.

September 18, 2006

The Pope on Islam

This was originally an email, but I thought what the heck: it works as a blog post. My mom asked me what I thought of the Pope’s much-debated speech at the University Regensburg recently, where he quoted a Byzantine emperor who said unflattering things about Muhammad and his religion.

I replied:

For what it’s worth, I think his speech was worth reading: what snippets you get from the media aren’t exactly reflective of what he actually said. The speech is here. The quote is in the third paragraph, but the first four paragraphs are actually relatively easy (and interesting!) to get through.

The comment, in context, is far more benign than it is made out to be. It could have been approached with a bit more appreciation for the fact that the whole world, including the known-to-be-rather-touchy Muslims, is/are listening. At the same time, though, I’m unconvinced that being more delicate would help: some of the Muslim leaders (fascists that they are) derive their power and influence by directing the outrage of their populace away from themselves, and so have a vested interest in reading mountains into any mole-hill that can be twisted into sounding like an offense.

Anyway, as I read the passage in question, it sounds something like this, in layman’s speak (I’m being only slightly facetious here):

I was reading this book recently, about this Muslim and this Christian who did a lot of arguing about religion. The Christian was so upset by the Islamic endorsement of the use of violence in religion that he said some very shocking things, for example, ‘Muhammad was an idiot, and added only evil to the Jewish faith; God hates violence and we all know it, and anyone who says otherwise is probably selling weapons.’ The point he makes about God and violence is a valid one, which I will now discuss at length.

See what I mean? The first part of the quote didn’t need to be there, though he isn’t explicitly endorsing it… but it still sticks out. I suppose it could be compared to someone saying:

As someone once said, “Mohammad is evil”

While that’s an overly simplistic reading of his speech, there’s a valid point there. The way the speech is written, the objectionable part of the quote in question appears to have been quoted to give the listener an idea of how outraged at the religious endorsement of violence the fellow who said it was. As such, it’s hardly something that needed to be said to make the whole logical train work, but the Pope certainly isn’t indicating explicit agreement with that part of what the Byzantine emperor said.

Personally, I think this is essentially a case of an “academic” throwing a somewhat out-there quote into his lecture to keep his audience awake. He forgot that he is neither a professor working in an ivory tower anymore, nor is he the high-profile Catholic theologian whose work will only ever be read by priests, theologians, and devoted Catholics. A serious mistake.

Something I would point out that doesn’t get much attention in the media: the official penalty for insulting Muhammad is death. This isn’t quite a matter of ruffling some feathers, this is a matter of prompting the Al Qaeda cells in Italy to be awakened and set in motion to assassinate the Pope (assuming there are some). Of course, that would only further demonstrate his point, about the ludicrousness of using violence to spread faith (I don’t know which word should be in quotes: “spread” or “faith”).

I find the reactions to this speech particularly interesting as well. Much of the news media seems quick to condemn Benedict for using such a shocking quote. On the other hand, these are the same people who were the first to defend the free speech rights of the Dutch cartoonists. But of course, since the Pope isn’t a cartoonist and is instead that odious head-Catholic, his “free speech” rights don’t even come up. Better still, the point the Dutch were trying to make is the same that the Pope was trying to make: violence has become entwined with religion for many Muslims. (Of course, there were also plenty of cowards in the media, who stifled attempts to publish the Dutch cartoons (not that the cartoons were very funny, I don’t think).)

I’ve also heard a priest give his own take on the row, which was predictably very defensive of the Pope. He pointed out that this wasn’t the only quotation in the speech. The Pope also quoted Muhammad himself, as part of his point, practically in the same breath. In the Qur’an, there is a passage (surah 2,256) that reads “There is no compulsion in religion.” That’s a passage written by Muhammad early in his life, and one which the Catholic Church would agree with (if you don’t believe it, don’t do it: that’s a major part of the doctrine of the primacy of conscience). Part of what peeved the Byzantine emperor at the time was the contradiction of Muhammad’s later writing, for it was only shortly before Muhammad died that he added the command to spread the Islamic faith by the sword: a command that adds compulsion to religion. Now, that observation and criticism of the Islamic faith (and of Muhammad) is all very sound and logical, but doesn’t really address the fact that the Pope quoted a nasty-sounding assertion by this Byzantine emperor.

The other amusing reaction I’ve heard is people using the opportunity to vent their anger with the facts of history and the Catholic Church. Some people take the opportunity to say things like “the Pope shouldn’t point fingers at extremist activities in other religions, when his own faith has been a party to the Crusades and the Spanish Inquisition, among other nasties.” Which, truly, is an absurd reaction. It reminds me of a comedy routine by Eddie Izzard who said that we really ought to make the Germans and Japanese be the world’s peace-makers. They’ve very organized, and they can fly in and go “hey, hey now, we’ve done the killing thing, it really doesn’t work out, so knock it off!” Without making any defenses of the Church’s behavior in those two cases (and I think there’s a lot more to be said on those subjects), who better to say “yeah, been there, done that, it was a bad idea”? Granted, there seems to be some hypocrisy to that, but at the same time, the Pope, like everyone else, has a moral obligation to speak out against moral atrocities and abuse, such as those perpetrated by today’s Islamic fascists.

Anyway, that’s my perspective on things. Kind of helter-skelter comments, but that’s my brain today, for you.

To top it off, here’s a cartoon I thought was apt:

About September 2006

This page contains all entries posted to Kyle in September 2006. They are listed from oldest to newest.

August 2006 is the previous archive.

November 2006 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.34