[Beowulf] Stroustrup regarding multicore

Lux, James P james.p.lux at jpl.nasa.gov
Tue Aug 26 12:21:25 EDT 2008



-----Original Message-----
From: beowulf-bounces at beowulf.org [mailto:beowulf-bounces at beowulf.org] On Behalf Of Perry E. Metzger
Sent: Tuesday, August 26, 2008 8:06 AM
To: Michael H. Frese
Cc: Beowulf at beowulf.org
Subject: Re: [Beowulf] Stroustrup regarding multicore


"Michael H. Frese" <Michael.Frese at NumerEx-LLC.com> writes:
> C is not much better.  I once worked a young computational programmer
> for almost a week to get him to prove to himself that a C source
> program couldn't walk through a 2-d array the hard way as fast as a
> Fortran source program unless the stepping was coded by hand.

I don't understand what that means. I've been programming in C for
about 25 years, and I have known Fortran since the mid-1970s.

> He didn't believe that a 2-d array in C is syntactically a 1-d array
> of pointers to 1-d arrays,

He was right. You are just plain wrong.

char foo[10][10]

allocates 100 consecutive addresses in memory.

In case you don't believe me, try out the following program:

----------------------------------------------------------------------
#include <stdio.h>

char foo[10][10];

int main(int argc, char **argv)
{
        int i, j;

        for (i = 0; i < 10; i++)
                for (j = 0; j < 10; j++)
                        printf("%d\n", &(foo[i][j]));
}
----------------------------------------------------------------------

It will print 100 consecutive integers, the addresses of the character
array elements.

> and the row pointers must be fetched from memory!

I call bull. That's just totally false. You clearly don't know how C
works.

-----------------------------
The example you give is going to be compiler dependent.  There's no requirement in K&R (I think.. some scum of the earth has apparently borrowed my copy, or it's buried under a pile of papers, so I can't check) that the rows be stored in contiguous memory.  In fact, relying on ANY particular interpretation of pointer values is dangerous. For all you know the compiler or runtime goes out and allocates noncontiguous chunks of memory for each and every element of the array.  Pointer arithmetic is deprecated.

All that is guaranteed is that you can retrieve the successive elements of the array by successive values of the index.

Jim Lux

_______________________________________________
Beowulf mailing list, Beowulf at beowulf.org
To change your subscription (digest mode or unsubscribe) visit http://www.beowulf.org/mailman/listinfo/beowulf



More information about the Beowulf mailing list