chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.78k stars 420 forks source link

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

Open jabraham17 opened 2 months ago

jabraham17 commented 2 months ago

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.

bradcray commented 2 months ago

@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?

jabraham17 commented 2 months ago

Yes

mppf commented 2 months ago

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.