chapel icon indicating copy to clipboard operation
chapel copied to clipboard

[Feature Request]: Warning when a data-parallel loop over something distributed is not distributed

Open jabraham17 opened this issue 1 year ago • 3 comments

In Chapel its possible to think you are writing a distributed parallel loop but end up creating something that runs locally. The following code sample demonstrates this:

use BlockDist;
use CommDiagnostics;

var d = {1..100};
var A = blockDist.createArray(d, int);

startVerboseComm();
forall (i, elm) in zip(d, A) {
  elm = i;
}
stopVerboseComm();

Because d is not distributed, the forall is not going to result in distributed execution. This is because the data-parallel forall loop is driver by the leader iterator of d, which is a local domain. This results in a ton of extra communication because in most iterations of the loop elm is remote and the assignment elm = i results in a PUT. There are several ways to avoid this, two simple ones are to change zip(d, A) to zip(A.domain, A) or to change forall (i, elm) in zip(d, A) to forall (elm, i) in zip(A, d).

While this is expected Chapel behavior, I think a compiler/linter/static analyzer warning for this case would be good, warning users when a data-parallel loop over a distributed object is not going to result in distributed execution. This would give users an early warning that they may have poor performance due to the extra communication.

jabraham17 avatar Aug 02 '24 17:08 jabraham17

@jabraham17 : Is the concept here to warn whenever a loop zip iterates over distributed and non-distributed things where the non-distributed thing is the leader?

bradcray avatar Aug 12 '24 22:08 bradcray

Yes

jabraham17 avatar Aug 13 '24 13:08 jabraham17

It sounds reasonable to me. It's not the biggest issue IMO for a warning but I think it's reasonable to ask if there is a way for a user to indicate they really meant to do this thing.

This is related in concept to PR #10791 / issue #5657.

mppf avatar Aug 15 '24 12:08 mppf