New Issue: Design question: Should the serial loop order over a rectangular domain reflect the storage order?

17333, "mstrout", "Design question: Should the serial loop order over a rectangular domain reflect the storage order?", "2021-03-04T01:37:56Z"

@bradcray quotes:
“Should a for loop on a dense 2D domain/array always iterate over the indices/elements in the same order (“to make the science of a code independent of the data structure order”), or should a domain map be able to define its own order (“for efficiency”) such that a RMO array would return in RMO, a CMO array in CMO, and an array using tiled memory or a space-filling curve would reveal that order. And similarly, if the 2D array is printed out, should that printout be independent of its memory layout, or reflect it? In practice, we’ve usually said “the same order” for productivity and postulated that there could be a .naturalOrder() iterator method if the user didn’t care about the order and wanted whatever serial ordering was faster.

"Should a for loop (or writeln) over a dense multidimensional domain reflect the storage order”, I believe that in the spec and in the code, the answer is “no” (and that this is the answer I like). But that it comes up in conversation just frequently enough with some people expressing hesitancy about it that I think it’s worthy of an actual conversation to put to bed. "

For rectangular domains, the for loop documentation, for-loops: structured serial iteration — Chapel Documentation 1.23, strongly implies lexical order and so does the use of ranges in for loops (Ranges — Chapel Documentation 1.23). However, neither of those pages have multi-dimensional examples. Here (Domains — Chapel Documentation 1.23) I found "If the domain defines an iteration order of its indices, then the indices are visited in that order." It seems like first and last, if supported at all, should align with the default order or the order specified for the domain.

I believe what [the "if the ..." sentence] is saying is that some domain types, by nature, do not define a natural iteration order, where our associative domains are currently the key such example. And that other domain types do, like dense rectangular domains (where, as Michelle says, the order is lexicographic, or RMO).

Tangentially related to the question about sparse first and last, Propose not supporting first and last methods on sparse domains · Issue #17327 · chapel-lang/chapel · GitHub.