In Chapel, it seems possible to declare an array by using the notation [][]. This looks very similar to "array of arrays" in other languages, so I am wondering whether it is a so-called "jagged array" with each sub-array allocated independently in memory? For example, in the following code, are a[0][..] and a[1][..] not necessarily contiguous in memory?
(My interest here is whether the use of such [][] may be less efficient than [,] because of non-contiguous memory.)
proc test( D1, D2 )
{
var a: [D1][D2] int; // "jagged" array?
var b: [D1, D2] int; // I assume this is a rectanguar (contiguous) array
for i in D1 do
for j in D2 do
a[i][j] = i * 100 + j;
for (i, j) in b.domain do
b[i, j] = i * 100 + j;
var lo = D1.low, hi = D1.high;
writeln( "a = ", a );
writeln( "a[ lo ] = ", a[ lo ] );
writeln( "a[ hi ] = ", a[ hi ] );
writeln();
writeln( "b = ", b );
writeln( "b[ lo, .. ] = ", b[ lo, .. ] );
writeln( "b[ hi, .. ] = ", b[ hi, .. ] );
}
test( 0..1, 1..3 );
$ chpl test.chpl
$ ./a.out
a = 1 2 3 101 102 103
a[ lo ] = 1 2 3
a[ hi ] = 101 102 103
b = 1 2 3
101 102 103
b[ lo, .. ] = 1 2 3
b[ hi, .. ] = 101 102 103
A related question is: Is there any way or command to know the memory location (address) of a given variable or array element (to get information on memory allocation)?