comp.lang.ada
 help / color / mirror / Atom feed
* Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules?
@ 2011-12-21  1:08 Nasser M. Abbasi
  2011-12-21 19:11 ` John B. Matthews
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Nasser M. Abbasi @ 2011-12-21  1:08 UTC (permalink / raw)



Sorry for such a basic question on Ada, it has been a while since
I used Ada (but it remains my most favorite computer language).

We know that Fortran stores multi-dimensional arrays in a contiguous
sequence of memory, and Fortran has strong aliasing rules which allows
the compiler to more generate more efficient code when it comes to
Matrices access and manipulation and such. This is one reason that
Fortran code is fast for number crunching.

How is the situation in Ada when it comes to this issue? I am almost
sure that Ada 2D/3D matrices are also contiguous in memory (as compared
to say Java for example).

If so, how is the issue with aliasing rules? I read that c99 has
now a keyword called 'restrict' which is supposed to tell the compiler
that some arrays do not overlap in memory and the compiler can
generate efficient code like Fortran.

So my question really is: Is Ada generated code now for 2D/3D matrices
operations as efficient and Fast as Fortran?  Are there switches for
Gnat that one can use to improve this aspect of the code generation?

Are there are benchmarks comparing Ada for Fortran in this specific area?

Sorry if my question might be too general and not specific, but
I am just only wondering on how Ada number crushing with matrices
compares to Fortran there days.

thanks,
--Nasser



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules?
  2011-12-21  1:08 Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules? Nasser M. Abbasi
@ 2011-12-21 19:11 ` John B. Matthews
  2011-12-22  2:49   ` Jeffrey Carter
  2011-12-21 21:11 ` Adrian-Ken Rueegsegger
  2011-12-21 21:13 ` Adrian-Ken Rueegsegger
  2 siblings, 1 reply; 6+ messages in thread
From: John B. Matthews @ 2011-12-21 19:11 UTC (permalink / raw)


In article <jcrbhs$9q6$1@speranza.aioe.org>,
 "Nasser M. Abbasi" <nma@12000.org> wrote:

> Sorry for such a basic question on Ada, it has been a while since I 
> used Ada (but it remains my most favorite computer language).
> 
> We know that Fortran stores multi-dimensional arrays in a contiguous 
> sequence of memory, and Fortran has strong aliasing rules which 
> allows the compiler to more generate more efficient code when it 
> comes to Matrices access and manipulation and such. This is one 
> reason that Fortran code is fast for number crunching.
> 
> How is the situation in Ada when it comes to this issue? I am almost 
> sure that Ada 2D/3D matrices are also contiguous in memory (as 
> compared to say Java for example).

I'm not sure the standard [1] says exactly how array components (§3.6) 
must be stored, only that "all have the same subtype." Unchecked type 
conversion (§13.9) suggests contiguous representation of components 
for meaningful use. I'm not an implementor, so I'd welcome correction.

> If so, how is the issue with aliasing rules? I read that c99 has now 
> a keyword called 'restrict' which is supposed to tell the compiler 
> that some arrays do not overlap in memory and the compiler can 
> generate efficient code like Fortran.
> 
> So my question really is: Is Ada generated code now for 2D/3D 
> matrices operations as efficient and Fast as Fortran?  Are there 
> switches for Gnat that one can use to improve this aspect of the code 
> generation?
> 
> Are there are benchmarks comparing Ada for Fortran in this specific 
> area?

This response [2] to a similar question has a few relevant links. At 
least one Ada compiler implements parts of its standard library by 
linking to well-know Fortran libraries. I'm sure there are others.

> Sorry if my question might be too general and not specific, but I am 
> just only wondering on how Ada number crushing with matrices compares 
> to Fortran there days.

[1] <http://www.adaic.org/resources/add_content/standards/05rm/html/RM-TOC.html>
[2] <http://stackoverflow.com/a/2662805/230513>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules?
  2011-12-21  1:08 Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules? Nasser M. Abbasi
  2011-12-21 19:11 ` John B. Matthews
@ 2011-12-21 21:11 ` Adrian-Ken Rueegsegger
  2011-12-21 21:13 ` Adrian-Ken Rueegsegger
  2 siblings, 0 replies; 6+ messages in thread
From: Adrian-Ken Rueegsegger @ 2011-12-21 21:11 UTC (permalink / raw)


On 12/21/2011 02:08 AM, Nasser M. Abbasi wrote:
> Sorry for such a basic question on Ada, it has been a while since
> I used Ada (but it remains my most favorite computer language).

[snip]

> Are there are benchmarks comparing Ada for Fortran in this specific area?

This is just barely related but maybe it is still of interest to you: as
part of writing the CUDA/Ada binding [1] I did some benchmarking of
matrix operations (addition and multiplication) using the
Ada.Numerics.Real_Arrays package. I compared the native Ada
implementation ("*"-operator), doing the multiplication on the GPU using
the CUDA/Ada binding and a native CUDA C implementation.

We are in the middle of finishing up the article documenting CUDA/Ada
which will contain a section analyzing the performance measurements. The
main focus is on the potential performance penalty of CUDA/Ada vs native
CUDA C though so as mentionend in the beginning this is probably
tangential to your question...

Cheers,
Adrian
--
[1] - http://www.codelabs.ch/cuda-ada/



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules?
  2011-12-21  1:08 Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules? Nasser M. Abbasi
  2011-12-21 19:11 ` John B. Matthews
  2011-12-21 21:11 ` Adrian-Ken Rueegsegger
@ 2011-12-21 21:13 ` Adrian-Ken Rueegsegger
  2 siblings, 0 replies; 6+ messages in thread
From: Adrian-Ken Rueegsegger @ 2011-12-21 21:13 UTC (permalink / raw)


On 12/21/2011 02:08 AM, Nasser M. Abbasi wrote:
> Sorry for such a basic question on Ada, it has been a while since
> I used Ada (but it remains my most favorite computer language).

[snip]

> Are there are benchmarks comparing Ada for Fortran in this specific area?

This is just barely related but maybe it is still of interest to you: as
part of writing the CUDA/Ada binding [1] I did some benchmarking of
matrix operations (addition and multiplication) using the
Ada.Numerics.Real_Arrays package. I compared the native Ada
implementation ("*"-operator), doing the multiplication on the GPU using
the CUDA/Ada binding and a native CUDA C implementation.

We are in the middle of finishing up the article documenting CUDA/Ada
which will contain a section analyzing the performance measurements. The
main focus is on the potential performance penalty of CUDA/Ada vs native
CUDA C though so as mentionend in the beginning this is probably
tangential to your question...

Cheers,
Adrian
--
[1] - http://www.codelabs.ch/cuda-ada/



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules?
  2011-12-21 19:11 ` John B. Matthews
@ 2011-12-22  2:49   ` Jeffrey Carter
  2011-12-23  7:34     ` John B. Matthews
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey Carter @ 2011-12-22  2:49 UTC (permalink / raw)


On 12/21/2011 12:11 PM, John B. Matthews wrote:
>
> I'm not sure the standard [1] says exactly how array components (§3.6)
> must be stored, only that "all have the same subtype." Unchecked type
> conversion (§13.9) suggests contiguous representation of components
> for meaningful use. I'm not an implementor, so I'd welcome correction.

ARM 3.6.2 has the following Implementation Advice:

"'An implementation should normally represent multidimensional arrays in 
row-major order, consistent with the notation used for multidimensional array 
aggregates (see 4.3.3). However, if a pragma Convention(Fortran, ...) applies to 
a multidimensional array type, then column-major order should be used instead 
(see B.5, “Interfacing with Fortran”).'

-- 
Jeff Carter
"Mr. President, we must not allow a mine-shaft gap!"
Dr. Strangelove
33

--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules?
  2011-12-22  2:49   ` Jeffrey Carter
@ 2011-12-23  7:34     ` John B. Matthews
  0 siblings, 0 replies; 6+ messages in thread
From: John B. Matthews @ 2011-12-23  7:34 UTC (permalink / raw)


In article <jcu5sm$2mef$1@adenine.netfront.net>,
 Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> wrote:

> On 12/21/2011 12:11 PM, John B. Matthews wrote:
> >
> > I'm not sure the standard [1] says exactly how array components (§3.6)
> > must be stored, only that "all have the same subtype." Unchecked type
> > conversion (§13.9) suggests contiguous representation of components
> > for meaningful use. I'm not an implementor, so I'd welcome correction.
> 
> ARM 3.6.2 has the following Implementation Advice:
> 
> "'An implementation should normally represent multidimensional arrays 
> in row-major order, consistent with the notation used for 
> multidimensional array aggregates (see 4.3.3). However, if a pragma 
> Convention(Fortran, ...) applies to a multidimensional array type, 
> then column-major order should be used instead (see B.5, “Interfacing 
> with Fortran”).'

Thanks!

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-12-23  7:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-21  1:08 Basic question on Ada multi-dimensional arrays, are they true (contiguous) arrays? aliasing rules? Nasser M. Abbasi
2011-12-21 19:11 ` John B. Matthews
2011-12-22  2:49   ` Jeffrey Carter
2011-12-23  7:34     ` John B. Matthews
2011-12-21 21:11 ` Adrian-Ken Rueegsegger
2011-12-21 21:13 ` Adrian-Ken Rueegsegger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox