New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SI-6998] Implement variants of 'par' method that allow user to set number of threads or thread pool in-line #5212
Conversation
I'd prefer (if we can't manage to overload |
collection.par(5).rest.of.expression Got interpreted by the compiler's operator precedence as: (collection.par)(5).rest... And so it failed to compile. However, I assume the |
* @param pool the number of threads to use for supporting parallelism | ||
* @return a parallel implementation of this collection using `n` threads | ||
*/ | ||
final def parWith(n: Int): ParRepr = parWith(new ForkJoinPool(n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get rid of this overload?
I can live with overloaded parWith
for ForkJoinPool
and TaskSupport
as the types are quite specific, but parWith(Int)
is not self-explanatory.
As you already provide parWith(ForkJoinPool)
I think we don't really need parWith(Int)
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose I could live without it, although I like the Int
overloading because it allows me to simply say "just give me n-fold parallelism", and not have to muck about with all the ForkJoinPool
or ForkJoinTaskSupport
.
It may be that the primary use case is experimenting with throughput as a function of number of threads, but it's a thing I do with some frequency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I admit an advantage is without the Int
overloading we could probably just overload par
Regarding the general approach, the last time I reviewed this code my main concern was that I think it would be better to return a new instance instead of mutating internal fields and deprecate |
I also agree with the mutable |
…umber of threads or thread pool in-line
I looked into the current roles played by My current view on fixing the design as it stands is that there are broadly 3 related but somewhat independent goals:
Assuming this approach, it might be worth an umbrella ticket, with jiras for 2 and 3. (3) itself might take the form of multiple stages. |
Hmm. since def withTaskSupport(taskSupport: TaskSupport): Repr = {
// construct copy of Repr, set task support ?
} |
Here is a question that will help clarify the problem: Is it a design contract that a combiner is always used to construct a new ParSeq? Specifically, if I do something like this pseudocode: val cb = this.newCombiner
this.foreach { x => cb += x }
cb.result() Will the result always adhere to the correct sub-class of collection, with any sub-class specific details? |
@soc, am I barking up the right tree with these questions, or just off in the weeds? |
@erikerlandson Sorry for the delay, things are pretty busy here. I think many people are traveling to/from ScalaDays this week. Maybe @som-snytt can have a look at your combiner question? |
I just had a look at This is the issue:
|
@soc, yes that was a concern for me as well. It is pretty easy to return new collections using the idiom val cb = this.newCombiner
this.foreach { x => cb += x }
cb.result() I think that works fine with any immutable collections, but currently Respecting both cases may require a lot of local overrides for I'm not sure how to unwind that knot. If the convention was changed so that the combiner logic above was the universal behavior, it would be nice but that is a higher-impact strategy, at least in the mutable container cases |
I regret that we didn't get this into 2.12, but we can no longer change the API here. With 2.13 being the library release (2.12 was a compiler focussed cycle), I'm moving this PR there. We'll create a branch for 2.13.x dev in the next few weeks. |
The |
this code has been relocated to https://github.com/scala/scala-parallel-collections ; this could be taken up there |
I'm sorry this didn't reach the point of I only just realized that when you turn it all the way up to eleven, and then double it, you get 22. OMG I have to step outside for some air. |
🤘 |
No description provided.