Hi Tomsy,
In this reply, I'm assuming the definition of "A" looks similar to:
var A: [1..1000, 1..1000] real;
When iterating over a data structure with a for loop, an iterator named
"these" is called implicitly. In your first example below, each for
loop calls a "these" iterator defined by the range type since
A.domain.dim(1) and A.domain.dim(2) are ranges. In the 1.12.0 release
you can find the definition of this iterator at
$CHPL_HOME/modules/internal/ChapelRange.chpl line 1419.
In your second example, the "these" iterator defined by a rectangular
domain is in control because A.domain is a rectangular domain. The
definition of this iterator is located at
$CHPL_HOME/modules/internal/DefaultRectangular.chpl line 154.
I'm surprised that you found that the latter is far faster than the
former. The two versions should generate code that is nearly
identical. I tried the following program on my Linux desktop and found
that the two sets of loops take about the same amount of time:
// ----------
use Time;
config const nTrials = 1000;
var A: [1..1000, 1..1000] int;
var t = new Timer();
t.start();
for trial in 1..nTrials {
for i in A.domain.dim(1) do
for j in A.domain.dim(2) do
A[i,j] = i*10000 + j;
}
t.stop();
writeln("First loop: ", t.elapsed(), " seconds");
t.clear();
t.start();
for trial in 1..nTrials {
for (i,j) in A.domain do
A[i,j] = i*10000 + j;
}
t.stop();
writeln("Second loop: ", t.elapsed(), " seconds");
// ----------
% chpl --fast testLoops.chpl
% ./a.out
First loop: 0.811924 seconds
Second loop: 0.812175 seconds
David
On 11/25/2015 02:08 AM, Tomsy Paul wrote:
Hello all,
I want to know about the implementation of tuple based array indexing.
Specifically I observe that there is considerable difference in
performance between
for i in A.domain.dim(1) do
for j in A.domain.dim(2) do
something
and
for (i,j) in A.domain do
something
with the latter far faster than former.
Why is this so?
------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741551&iu=/4140
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers
------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741551&iu=/4140
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers