Open MPI logo

Hardware Locality Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Hardware Locality Development mailing list

Subject: Re: [hwloc-devel] What does this C99 notation mean?
From: Samuel Thibault (samuel.thibault_at_[hidden])
Date: 2011-02-14 08:22:28


Jeff Squyres, le Mon 14 Feb 2011 14:15:19 +0100, a écrit :
> On Feb 11, 2011, at 10:51 PM, Samuel Thibault wrote:
>
> > Jeff Squyres, le Sat 12 Feb 2011 04:34:36 +0100, a écrit :
> >> static void
> >> hwloc_setup_groups_from_distances(struct hwloc_topology *topology,
> >> unsigned nbobjs,
> >> struct hwloc_obj **objs,
> >> float *_distances)
> >> {
> >> float (*distances)[nbobjs][nbobjs] = (float (*)[nbobjs][nbobjs])_distances;
> >>
> >> As far as I can tell, _distances is a 1D array of floats, but it is of size (nbobjs*nbobjs) -- i.e., you could think of it as a 2D array, and index the i'th column in the j'th row at _distances[i * nbobjs + j]. From how its used in the code, distances is treated as a 2D array -- i.e., distances[i][j] is accessed.
> >
> > That's exactly it. It permits to keep code less clumsly to read.
>
> Does it silently make a (temporary) 2nd array of pointers for the 2nd dimension indexing, or does the compiler translate all distances[i][j] to _distances[i*nbojbs + j] ?

No, it's the matrix type, with only one level of indirection, [i][j]
being automatically translated into [i*nobjs+j].

Samuel