comp.lang.ada
 help / color / mirror / Atom feed
From: Keean Schupke <keean.schupke@googlemail.com>
Subject: Re: Efficient Sequential Access to Arrays
Date: Mon, 16 Jul 2012 23:40:21 -0700 (PDT)
Date: 2012-07-16T23:40:21-07:00	[thread overview]
Message-ID: <9b134675-b217-4a62-beb1-8b044029aa61@googlegroups.com> (raw)
In-Reply-To: <ju2496$988$1@speranza.aioe.org>

On Monday, 16 July 2012 23:23:34 UTC+1, (unknown)  wrote:
> I&#39;m confused.  The Subject line here is &quot;Efficient Sequential Access to Arrays&quot;
> and you gave a sample piece of code
> &gt;  for J in S .. E loop
> &gt;      Y := Y + X(J).Z;
> &gt;  end loop;
> and mentioned stepping through X with a pointer rather than an index.
> 
>   But now you are talking about algorithms mentioned in
> &gt;  http://www.cs.princeton.edu/~rs/AlgsDS07/01UnionFind.pdf
>   which have to do with nodes connected in a graph.  I&#39;m not seeing there
> anyplace where the relation between a(i) and a(i+1) is different from the
> relation between a(i) and a(i+anything) - each node is independent and
> may be connected to any other node, not just to those with &quot;nearby&quot; memory
> addresses.

Look for example at the connected points example, or the Percolation example, or the hex game example. There are problems where the connectedness of subsets is only one part of the problem. In this case connectedness is one part, and spatial proximity is another.

> 
>    -----------
> As to
> &gt;  for J in S .. E loop
> &gt;      Y := Y + X(J).Z;
> &gt;  end loop;
>   if S and E are random and typically fairly far apart, and the array
> X remains constant, how about grouping Xs, eg
>   X_Grouped := (others=&gt;0);
>   for i in X&#39;range loop
>     X_Grouped(i/Group_Size) := X_Grouped(i/Group_Size) + X(i);
>   end loop;
> 
>   then instead of summing N = (E-S+1) X&#39;s, you can sum X_Grouped from
> S/Group_Size .. E/Group_Size, which takes 1/Group_Size as many array
> access and adds, and then handle the partial groups at the ends, which
> will take 2*(Group_Size/2) operations on average.  So instead of
> N sums on average, you will have N/Group_Size + Group_Size.  (Handling
> the partial groups at the ends more carefully also cuts that second
> term in half.)

This example was supposed to be a simple way to show the compiler does not optimise the multiply out of each array access, and it does not represent the actual problem.

The real problem is that each element needs to be addressed spatially (say as a 2D grid) so that all 4 direct, and 4 diagonal neighbours can be quickly found (using indexed-addressing), another is that we need to be able to tell if any two elements are in the same group (using disjoint-set union-find), and another is that we need to be able to iterate through all the members of a group given any element in that group.

If there is a faster data structure that meets all those requirements, then I am listening.

    
Cheers,
Keean.



  reply	other threads:[~2012-07-22  0:33 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-15 18:40 Efficient Sequential Access to Arrays Keean Schupke
2012-07-15 19:48 ` Dmitry A. Kazakov
2012-07-15 20:03   ` Keean Schupke
2012-07-15 20:56     ` Keean Schupke
2012-07-16 11:34       ` Jacob Sparre Andersen
2012-07-15 21:05     ` tmoran
2012-07-15 21:08       ` Keean Schupke
2012-07-16  1:19         ` tmoran
2012-07-15 21:44     ` Georg Bauhaus
2012-07-16  7:47     ` Dmitry A. Kazakov
2012-07-16 10:16       ` Keean Schupke
2012-07-16 14:57         ` Dmitry A. Kazakov
2012-07-16 16:39           ` Keean Schupke
2012-07-16 17:02             ` Georg Bauhaus
2012-07-16 18:48             ` Dmitry A. Kazakov
2012-07-16 19:12               ` Keean Schupke
2012-07-17  6:31                 ` Dmitry A. Kazakov
2012-07-17  6:50                   ` Georg Bauhaus
2012-07-17  8:42                     ` Dmitry A. Kazakov
2012-07-17  7:24                   ` Keean Schupke
2012-07-16 19:43             ` John B. Matthews
2012-07-16 20:44               ` Keean Schupke
2012-07-16 22:23             ` tmoran
2012-07-17  6:40               ` Keean Schupke [this message]
2012-07-17  9:01                 ` Dmitry A. Kazakov
2012-07-18  8:10                   ` Keean Schupke
2012-07-18 18:11                     ` tmoran
2012-07-19 10:41                       ` Keean Schupke
2012-07-19 11:18                         ` Georg Bauhaus
2012-07-19 19:58                           ` Keean Schupke
2012-07-21  8:24                             ` Keean Schupke
2012-07-21 11:52                               ` Georg Bauhaus
2012-07-21 16:14                                 ` Keean Schupke
2012-07-21 17:09                                   ` Keean Schupke
     [not found]                                   ` <i78m081tccmp078spmsei1l5vnj3k0kbkj@invalid.netcom.com>
2012-07-22 15:50                                     ` Keean Schupke
2012-07-22  5:13                               ` Shark8
2012-07-15 21:35   ` J-P. Rosen
2012-07-15 19:52 ` Shark8
2012-07-15 20:16   ` Keean Schupke
2012-07-15 21:33     ` Georg Bauhaus
2012-07-17 18:16 ` Florian Weimer
2012-07-22 10:01 ` robin.vowels
2012-07-30  6:31   ` Jacob Sparre Andersen
2012-07-30  7:16     ` Keean Schupke
2012-07-30  9:20     ` Georg Bauhaus
2012-07-30 14:04       ` Keean Schupke
2012-07-22 10:09 ` robin.vowels
2012-07-22 16:02   ` Keean Schupke
2012-07-22 16:21 ` Florian Weimer
2012-07-22 16:46   ` Keean Schupke
2012-07-22 18:41     ` Florian Weimer
2012-07-24  8:21       ` Keean Schupke
2012-07-22 17:34   ` Niklas Holsti
2012-07-22 18:21     ` Keean Schupke
2012-07-30 14:18       ` Jacob Sparre Andersen
2012-07-24 16:00     ` robin.vowels
2012-07-25  7:09       ` Niklas Holsti
2012-07-25  9:03         ` Keean Schupke
2012-07-26  0:15           ` Randy Brukardt
2012-07-26  8:38             ` Keean Schupke
2012-07-26 10:10               ` Brian Drummond
2012-07-26 12:32                 ` Keean Schupke
2012-07-26 13:46                   ` Dmitry A. Kazakov
2012-07-26 17:40                     ` Shark8
2012-07-26 18:56                       ` Dmitry A. Kazakov
2012-07-27  5:25                         ` Shark8
2012-07-27  6:28                           ` Dmitry A. Kazakov
2012-07-27  7:01                             ` Vasiliy Molostov
2012-07-27  8:48                               ` Dmitry A. Kazakov
2012-07-27 12:01                                 ` Georg Bauhaus
2012-07-27 16:49                                 ` Vasiliy Molostov
2012-07-27 19:38                                   ` Dmitry A. Kazakov
2012-07-28  5:32                             ` Shark8
2012-07-28  7:37                               ` Dmitry A. Kazakov
2012-07-28 18:32                                 ` Shark8
     [not found]                     ` <6ov218tnkbqu3vpkuo4t77rd7de0a3aesf@invalid.netcom.com>
2012-07-26 18:49                       ` Dmitry A. Kazakov
     [not found]                         ` <86d31898ne39maimbl24knds7rf38qg7vc@invalid.netcom.com>
2012-07-27  6:45                           ` Dmitry A. Kazakov
2012-07-27  8:21                   ` Keean Schupke
2012-07-27  8:50                     ` Dmitry A. Kazakov
2012-07-27  9:17                       ` Keean Schupke
2013-02-25 21:18                     ` Eryndlia Mavourneen
2012-07-26 13:08               ` Georg Bauhaus
2012-07-26 19:37                 ` stefan-lucks
2012-07-26 19:21               ` stefan-lucks
2012-07-31  3:12               ` Randy Brukardt
2012-07-26  7:11           ` Markus Schöpflin
2012-07-26 14:47         ` Robin Vowels
2012-07-26 15:18           ` Martin
replies disabled

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