We require an extra register in for_each because we maintain both the current agent index, i, as well as the parameter, first.
Each agent increments first by its index to find its iterator. That means if parallel agents happen to be implemented in sequence, then over the course of the sequential loop, we have to remember the value of the first parameter even though the next agent that gets scheduled in sequence could have gotten its value of first from the previous agent.
We could reclaim the register by explicitly targeting a par(seq) nesting instead of flat par. The idea would be for each parallel agent to find its index and then call for_each(seq, first + offset, last, f). offset would be something like i * grainsize.
We require an extra register in
for_eachbecause we maintain both the current agent index,i, as well as the parameter,first.Each agent increments
firstby its index to find its iterator. That means if parallel agents happen to be implemented in sequence, then over the course of the sequential loop, we have to remember the value of thefirstparameter even though the next agent that gets scheduled in sequence could have gotten its value offirstfrom the previous agent.We could reclaim the register by explicitly targeting a
par(seq)nesting instead of flatpar. The idea would be for each parallel agent to find its index and then callfor_each(seq, first + offset, last, f).offsetwould be something likei * grainsize.