June 10, 2009

More Compiler Complaints: PGI Edition

Continuing my series of pointless complaining about compiler behavior (see here and here for the previous entries), I recently downloaded a trial version of PGI’s compiler to put in my Linux virtual machine to see how that does compiling qthreads. There were a few minor things that it choked on that I could correct pretty easily, and some real bizarre behavior that seems completely broken to me.

Subtle Bugs in My Code

Let’s start with the minor mistakes it found in my code that other compilers hadn’t complained about:

static inline uint64_t qthread_incr64(
           volatile uint64_t *operand, const int incr)
{
  union {
    uint64_t i;
    struct {
      uint32_t l, h;
    } s;
  } oldval, newval;
  register char test;
  do {
    oldval.i = *operand;
    newval.i = oldval.i + incr;
    __asm__ __volatile__ ("lock; cmpxchg8b %1\n\t setne %0"
        :"=r"(test)
        :"m"(*operand),
         "a"(oldval.s.l),
         "d"(oldval.s.h),
         "b"(newval.s.l),
         "c"(newval.s.h)
        :"memory");
  } while (test);
  return oldval.i;
}

Seems fairly straightforward, right? Works fine on most compilers, but the PGI compiler complains that “%sli” is an invalid register. Really obvious error, right? Right? (I don’t really know what the %sli register is for either). Turns out that because setne requires a byte-sized register, I need to tell the compiler that I want a register that can be byte-sized. In other words, that "=r" needs to become "=q". Fair enough. It’s a confusing error, and thus annoying, but I am technically wrong (or at least I’m providing an incomplete description of my requirements) here so I concede the ground to PGI.

Unnecessary Pedantry

And then there are places where PGI is simply a bit more pedantic than it really needs to be. For example, it generates an error when you implicitly cast a volatile struct foo * into a void * when calling into a function. Okay, yes, the pointers are different, but… most compilers allow you to implicitly convert just about any pointer type into a void * without kvetching, because you aren’t allowed to dereference a void pointer (unless you cast again, and if you’re casting, all bets are off anyway), thus it’s a safe bet that you want to work on the pointer rather than what it points to. Yes, technically PGI has made a valid observation, but I disagree that their observation rises to the level of “warning-worthy” (I have no argument if they demote it to the sort of thing that shows up with the -Minform=inform flag).

Flat-out Broken

But there are other places where PGI is simply wrong/broken. For example, if I have (and use) a #define like this:

#define PARALLEL_FUNC(initials, type, shorttype, category) \
type qt_##shorttype##_##category (type *array, size_t length, int checkfeb) \
{ \
  struct qt##initials arg = { array, checkfeb }; \
  type ret; \
  qt_realfunc(0, length, sizeof(type), &ret, \
    qt##initials##_worker, \
    &arg, qt##initials##_acc, 0); \
  return ret; \
}
PARALLEL_FUNC(uis, aligned_t, uint, sum);

PGI will die! Specifically, it complains that struct qtuisarg does not exist, and that an identifier is missing. In other words, it blows away the whitespace following initials so that this line:

struct qt##initials arg = { array, checkfeb }; \

is interpreted as if it looked like this:

struct qt##initials##arg = { array, checkfeb }; \

But at least that’s easy to work around: rename the struct so that it has a _s at the end! Apparently PGI is okay with this:

struct qt##initials##_s arg = { array, checkfeb }; \

::sigh:: Stupid, stupid compiler. At least it can be worked around.

Thwarting The Debugger

PGI also bad at handling static inline functions in headers. How bad? Well, first of all, the DWARF2 symbols it generates (the default) are incorrect. It gets the line-numbers right but the file name wrong. For example, if I have an inline function in qthread_atomics.h on line 75, and include that header in qt_mpool.c, and then use that function on line 302, the DWARF2 symbols generated will claim that the function is on line 75 of qt_mpool.c (which isn’t even correct if we assume that it’s generating DWARF2 symbols based on the pre-processed source! and besides which, all the other line numbers are from non-pre-processed source). You CAN tell it to generate DWARF1 or DWARF3 symbols, but then it simply leaves out the line numbers and file names completely. Handy, no?

Everyone Else is Doing It…

Here’s another bug in PGI… though I suppose it’s my fault for outsmarting myself. So, once upon a time, I (think I) found that some compilers require assembly memory references to be within parentheses, while others require them to be within brackets. Unfortunately I didn’t write down which ones did what, so I don’t remember if I was merely being over-cautious in my code, or if it really was a compatibility problem. Nevertheless, I frequently do things like this:

atomic_incr(volatile uint32_t *op, const int incr) {
  uint32_t retval = incr;
  __asm__ __volatile__ ("lock; xaddl %0, %1"
    :"=r"(retval)
    :"m"(*op), "0"(retval)
    :"memory");
  return retval;
}

Note that weird "m"(*op) construction? That was my way of ensuring that the right memory reference syntax was automatically used, no matter what the compiler thought it was. So, what does PGI do in this instance? It actually performs the dereference! In other words, it behaves as if I had written:

atomic_incr(volatile uint32_t *op, const int incr) {
  uint32_t retval = incr;
  __asm__ __volatile__ ("lock; xaddl %0, (%1)"
    :"=r"(retval)
    :"r"(*op), "0"(retval)
    :"memory");
  return retval;
}

when what I really wanted was:

atomic_incr(volatile uint32_t *op, const int incr) {
  uint32_t retval = incr;
  __asm__ __volatile__ ("lock; xaddl %0, (%1)"
    :"=r"(retval)
    :"r"(op), "0"(retval)
    :"memory");
  return retval;
}

See the difference? Again, it’s not hard to fix so that PGI does the right thing. And maybe I was being too clever in the first place. But dagnabit, my trick should work! And, more pointedly, it DOES work on other compilers (gcc and icc at the bare minimum, and I’ve tested similar things with xlc).

May 5, 2009

Muslim Demographics

I recently got sent a link to the Muslim Demographics video on YouTube. It’s pretty alarmist, so I composed an email response. Since it might be interesting to have available to Google, here’s my thoughts, as an antidote to the panic the video is peddling.

Note that snopes.com has their own page discussing this video. They don’t address the accuracy of the facts presented, but its an interesting read nevertheless.


It is probably true that there is an aspect of evolution to religion. If we think of religion as a gene, the dominant religion will be defined (over the long run) by the extent to which it benefits or promotes reproduction, just as any piece of DNA does. Of course, given evangelism, it may be more apt to think of religion as similar to a virus that gets passed from person to person, but I doubt that’d be a popular viewpoint. In any case, of course, religion isn’t a gene, because we’d have to assume that people stick with the religion they’re born with. Christianity started with just 12 Christians, after all, and every last one of them was male (and thus couldn’t pass on any genes without help from an originally non-Christian woman).

That said, I’m skeptical of this video’s claims. For one thing, practically no sources are cited (2.11 is the bare minimum to maintain a society? Says who? How do we know?). For another, it’s interesting to note what gets left out. For example, the video says the Muslim population skyrocketed from 82,000 in the UK to several million, but according to the CIA World Factbook, Muslims are a whopping 2.7% of the UK population. In the Netherlands, the CIA World FactBook says that Muslims are a crushing 5.8% of the population. Not only that, but it says that the Netherlands have a fertility rate of 1.66. Woo! Scary!

Now that I come to think of it… let me look this up.

CountryVideo Claimed Fertility RateCIA FactBook Fertility Rate
France1.81.98
England1.61.66
Greece1.31.37
Germany1.31.41
Italy1.21.31
Spain1.11.31
EU1.381.51

Yikes - they didn’t get a single one correct! The closest was England, and even there they rounded in the wrong direction.

So should we really believe that French Muslims have a birth rate of 8.1? Think about that, EIGHT kids on average, which means that for every childless Muslim woman, there’s another out there with SIXTEEN KIDS. That sounds totally plausible, right?

The Population Reference Bureau (who I’ve never heard of, but they were linked to by about.com) says that in Austria, Muslim women had a fertility rate of 3.1 in 1981, but that by 2001 the rate was a mere 2.3 (apparently they didn’t get the memo from their French kindred). That reflects the falling fertility rates in Muslim countries the immigrants came from. For example, in Turkey the fertility rate dropped from 3.3 in 1985 to 2.2 in 2003. According to the CIA World FactBook, Turkey’s current fertility rate is 2.21. In Morocco it fell from 4.5 to 2.5 in the same time period (CIA says 2.51). And get this: in Iran, it fell from 5.6 to 2.1 in 2003. The CIA World FactBook currently pegs the Iranian fertility rate at a paltry 1.71!

1.71! 1.71! The Iranian culture cannot survive! The US fertility rate is 2.05! We will crush them with our progeny! MUAHAHAHAHA!

Oh, wait, does that not serve the purpose of getting people riled up?

I’m thinking of a word… fearmongering! That’s the one.

It reminds me a lot of grade school. I remember playing with a bunch of computer “simulations” that showed that the world population was exploding and that we’d run out of food by the turn of the millenium. The reason they were wrong is that they made assumptions without realizing it. For example, they assumed that food production would stay constant, and that fertility rates would stay constant. Surprise! They didn’t.

And THAT reminds me of another quote:

Scientists have shown that the moon is moving away at a tiny, although measurable distance from the earth every year. If you do the math, you can calculate that 65 million years ago, the moon was orbiting at a distance of about 35 feet from the earth’s surface. This would explain the death of the dinosaurs … the tallest ones, anyway.

Don’t believe everything you see on YouTube. ;)

April 27, 2009

SlingLink Killed My Network!

This isn’t the most accurate title, but…

I’ve got a SlingLink Turbo that I use for connecting my Macs upstairs to my cable modem downstairs. I went with a network-over-powerline option, because I’ve been having all kinds of intermittent interference problems with my wireless connectivity. So, rather than running an extra-long patch cable up the stairs and taping it down to the carpet, I went the SlingLink route. It seems to be designed specifically for SlingBox applications, but it forwards plain ol’ ethernet signals, and it’s about $40 cheaper than the NetGear equivalents. Huzzah for getting a bargain!

First impression: fabulous! I went along happily for weeks, enjoying my newfound reliable network connection. Then I tried downloading the latest Ubuntu ISO images via BitTorrent, and within five to ten minutes, the internet connection went offline. If I went downstairs and turned the cable modem off-and-on again, the internet would come back. For five to ten minutes. Then it’d go down again.

Surely, I say to myself, that’s a cable-modem problem, right?

I had to have the tech guys from Time Warner’s Cable group come out (twice!) before I finally figured out that it wasn’t their fault (the first time they said they replaced the splitter, and presto, the network was fine! I didn’t go after the ISO again for a while so…). Turns out I didn’t need to restart the cable modem, all I had to do was restart the SlingLink node and I’d get another five to ten minutes out of it. But it ONLY happens when BitTorrent is running; otherwise, the network connection is rock solid!

Weird, no?

So, to experiment, I tried limiting the BitTorrent connections: no dice. Then I tried limiting the BitTorrent bandwidth and all of a sudden the network would stay up. Somewhere between 100Kb/s and 150Kb/s is the cutoff. Something about BitTorrent’s bandwidth seems to either confuse the SlingLink node OR triggers some sort of antiviral cutoff in the SlingLink hardware (either way is annoying). For the record, it’s not a pure bandwidth issue: I can transfer files over the SlingLink network at speeds of over 400Kb/s. As soon as I introduce BitTorrent, though… down she goes.

Maybe it’s a packet-size issue. Maybe it’s a connection-tracking issue. I have no idea. But at least now I know that SlingLink has its limitations. And now, so do you.

October 6, 2008

Congress's CRA Caused the Crash?

It’s recently been suggested to me that the true cause of the subprime mess is that Congress forced banks to loan to poor people (also known as “people who cannot afford to repay the mortgage”), perhaps under the guise of fairness or avoiding racism or classism or something like that.

There would appear to be some truth to this idea, but not like you’d think (surprise! it’s a complicated subject). Congress has indeed encouraged banks to loan money to poor folks, starting with the Community Reinvestment Act (CRA), enacted in 1977, under Carter’s administration. The original idea was to ban a practice known as “redlining”, which essentially was a practice of defining financial no-fly-zones. Anyone who wanted a loan who happened to live within the redlined area wouldn’t be considered by any bank. This resulted in de-facto slums, among other things. Removing the problem is a touchy one, and you’d think would require very specific rules. But rather than be very specific, the law as enacted used very vague language (apparently to pacify critics of the bill who complained that it would be a train-wreck if it required banks to lend to people who couldn’t afford it). According to Wikipedia:

Congress included little prescriptive detail and simply directs the banking regulatory agencies to ensure that banks and savings associations serve the credit needs of their local communities in a safe and sound manner.

With the Financial Institutions Reform Recovery and Enforcement Act, in 1984, the credit ratings that banks used to evaluate people’s creditworthiness was made public (using a four-tier system) and was required to contain supporting details, so that their decisions could be audited if necessary. The Federal Housing Enterprises Financial Safety and Soundness Act of 1992 supposedly created the Housing and Urban Development (HUD) organization, and according to Fannie Mae’s website:

The Federal Housing Enterprises Financial Safety and Soundness Act (“FHEFSSA”) of 1992 modernized the regulatory oversight of Fannie Mae and Freddie Mac. It created the Office of Federal Housing Enterprise Oversight (“OFHEO”) as a new regulatory office within HUD with the responsibility to “ensure that Fannie Mae and Freddie Mac are adequately capitalized and operating safely.” OFHEO is funded by assessments on Fannie Mae and Freddie Mac and is authorized to act without HUD oversight on a range of regulatory issues enumerated in the statute. FHEFSSA established risk-based and minimum capital standards for Fannie Mae and Freddie Mac. And, it established HUD-imposed housing goals for financing of affordable housing and housing in central cities and other rural and underserved areas.

(emphasis mine) I couldn’t find all the specifics of those housing goals in a quick look through the text of the Act, but it’s long and complicated (maybe someone else will spend the time). Anyway, in an effort to finance these things effectively, Fannie and Freddie created and sold mortgage-backed securities. THIS is where the door was built (aka: the HUD), but the door isn’t yet “open.” More on this in a moment.

Because of the CRA requirements of transparency (imposed in 1984), banks were having trouble selling themselves, especially to out-of-state buyers. Not that the sales wouldn’t happen, but the sales would be slowed by CRA-based protests (I’m not sure what exactly they were protesting). So, Congress passed, in 1994, the Riegle-Neal Interstate Banking and Branching Efficiency Act, which removed the requirements that the banks had to publish the reasons why they made lending decisions under many circumstances, in order to facilitate sale of the banks. The publishing requirements were still in place if you weren’t selling your bank, though.

In 1995, Bill Clinton’s HUD made the policy decision to allow Fannie and Freddie to purchase subprime mortgage securities. Supposedly, HUD expected that Freddie and Fannie would impose their usual high standards upon subprime lenders. They did… mostly (hey, it’s still a subprime loan, after all), for a while, anyway. But this was still a bad idea (more on this in a moment).

In 1999, Congress passed the Gramm-Leach-Bliley Act, which repealed the Depression-era Glass-Steagall Act’s prohibition against banks acting as any combination of investment bank, commercial bank, and/or insurance company. Having more than one of those under one roof was a bad idea in 1929 because it creates conflict-of-interest on the part of the bankers/brokers, but apparently it’s a good idea in 1999. This paved the way for the formation of Citigroup and other investment/commercial/insurance banks. The GLB Act also reduced the number of banks to which the CRA applied, and altered their requirements so that they’d have to report on their CRA compliance less often.

In 2003, the Federal Reserve Bank of New York said:

Today, less than 30 percent of all home purchase loans are subject to intensive review under the CRA. In some metropolitan areas, this share is less than 10 percent.

This was considered bad news because it meant that the remaining 70 percent of loans were virtually un-auditable, and the reasons that loan decisions were made were untraceable. And Congressman Ron Paul made a speech predicting that these policies of increased lending to poor people would result in a credit collapse and a bailout. Spooky, eh?

What about predatory lending practices? In 2002, according to Wikipedia:

Kathleen C. Engel and Patricia A. McCoy published a study of the predatory lending implications of the CRA, noting that by the late 1990s, predatory high cost mortgages to “gullible borrowers” were leading to foreclosures against low-income people of color and the elderly.

As a result, the FDIC decided to strongly discourage the practice of “predatory lending”. And any bank found guilty of predatory lending was considered a higher risk, resulting in a lower CRA performance rating for that bank, both of which made FDIC insurance significantly more expensive. Interestingly, this move seems to have been quite effective. A study sponsored by a New York law firm (Traiger & Hinckley LLP, whoever they are), in January 2008 found:

Our study suggests that without the CRA, the subprime crisis and related spike in foreclosures might have negatively impacted even more borrowers and neighborhoods. Compared to other lenders in their assessment areas, CRA Banks were less likely to make a high cost loan, charged less for the high cost loans that were made, and were substantially more likely to eschew the secondary market and hold high cost and other loans in portfolio. Moreover, branch availability is a key element of CRA compliance, and foreclosure rates were lower in metropolitan areas with proportionately greater numbers of bank branches.

The FDIC’s measures to prevent irresponsible and predatory lending worked, and worked really well. So, if CRA wasn’t the problem, what was? What brought down Fannie Mae?

Remember the HUD? They expected that Fannie and Freddie would buy only the best quality subprime loans. But that backfired: what that ended up doing was making the market for these loans, including the even-crappier ones, bigger. According to Patricia McCoy, teacher of securities law at the University of Connecticut, cited in a Washington Post article, “That just pumped more capital into a very unregulated market that has turned out to be a disaster.” The HUD’s policies and encouragement are probably largely to blame for that market being particularly popular. It isn’t clear where the HUD’s policies started in 1992, but by 2000 the HUD required Fannie and Freddie to use 50% of their budget for “affordable” housing (sub-prime housing is one category that is considered “affordable”). Bush’s HUD upped that requirement to 56% in 2004. Clinton’s HUD opened the door by allowing subprime investing. But for some reason, it didn’t really take hold as a preferred strategy for investing in “affordable” housing.

Consider this: between 2005 and 2008, Fannie made loans to risky (sub-prime) borrowers of more than $270 billion dollars. That staggering sum is more than three times as much as all earlier years combined. But if it was all the HUD’s fault, then between 2005 and 2008, Fannie should have only increased subprime investment by about 6%, not 300%. And this would seem to have only a tangential relationship with the 30-year-old CRA. Something happened in 2004 or 2005! (One allegation I’ve heard is that Countrywide Mortgage started strong-arming Fannie into buying more of their riskiest loans at about that point.)

According to a New York Times article, Fannie Mae’s CEO, Daniel H. Mudd, under pressure from competing banks stealing his market and from Congress members demanding that they loan more to low-income folks, was between a rock and a hard place:

So Mr. Mudd made a fateful choice. Disregarding warnings from his managers that lenders were making too many loans that would never be repaid, he steered Fannie into more treacherous corners of the mortgage market, according to executives.

For a time, that decision proved profitable. In the end, it nearly destroyed the company and threatened to drag down the housing market and the economy.

Nevertheless, folks like the venerable Wall Street Journal blame the CRA for encouraging loose lending standards:

This 1977 law compels banks to make loans to poor borrowers who often cannot repay them.

And yet somehow, the CRA’s actual effect appears to have been the exact opposite: banks that were covered by the CRA were LESS likely to make sub-prime loans than banks that had were unaffected by the CRA. Those independent mortgage companies (unaffected by the CRA) made “high-priced loans” at more than twice the rate of banks governed by the CRA, according to Janet L. Yellen, President of the Federal Reserve Bank of San Francisco. According to the congressional testimony of Michael Barr (law professor at University of Michigan), 50% of the subprime loans were made by non-CRA mortgage companies, and another 25-30% came from mortgage companies only partially regulated by the CRA—-fully CRA-regulated institutions are responsible for “perhaps” one-in-four sub-prime loans. To quote the professor: “the worst and most widespread abuses occurred in the institutions with the least federal oversight.” And even more definitively, the Bank for International Settlements (an international organization of central banks) concluded:

Contrary to some media commentary, there is no evidence that the Community Reinvestment Act was responsible for encouraging the subprime lending boom and subsequent housing bust. This Act only applies to depositories, and did not cover most of the important subprime lenders. Depositories showed a lesser tendency to write subprime loans than lenders not subject to the Act (Yellen 2008).

Weird… you mean banks behave more responsibly when someone is peering over their shoulder? Say it ain’t so!

It seems to me that a large part of the Fannie problem was the HUD, enabling large scale sub-prime investing, and encouraging Fannie and Freddie to invest heavily in “affordable” housing. But that’s not the entirety of the problem; the HUD opened the door, but cannot have been responsible for the huge increase in sub-prime investment starting in 2005. However, even minimal investment in sub-prime mortgages (that HUD was trying to create) created demand in the sub-prime mortgage-backed securities market, which drove up the cost and encouraged other folks to invest as well.

I think the real lesson to be learned here is that there is no simple answer to questions like “what caused this economic mess?”, no matter how much politicians would love to say “it’s the other guy and his party’s fault”.