- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
REPL: null-values in parallel ranges?
Hi scalaists
this evening I started playing a little with the parallel collections and this
crossed my way...
This is most likely only a REPL display effect - but it felt disturbing
somehow (thinking about races and uninitialized values):
-----------------
bjo@noordx:~/Tools/scala-2.9.0.RC1> bin/scala -J-Xmx3000m
Welcome to Scala version 2.9.0.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java
1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val big = (1 to 10000000)
big: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132,
133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
163, 164, 165, 166, 167, 168, 169, 170,...
scala> val bigger = big.map(e => -e)
bigger: scala.collection.immutable.IndexedSeq[Int] = Vector(-1, -2, -3, -4,
-5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20,
-21, -22, -23, -24, -25, -26, -27, -28, -29, -30, -31, -32, -33, -34, -35,
-36, -37, -38, -39, -40, -41, -42, -43, -44, -45, -46, -47, -48, -49, -50,
-51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65,
-66, -67, -68, -69, -70, -71, -72, -73, -74, -75, -76, -77, -78, -79, -80,
-81, -82, -83, -84, -85, -86, -87, -88, -89, -90, -91, -92, -93, -94, -95,
-96, -97, -98, -99, -100, -101, -102, -103, -104, -105, -106, -107, -108,
-109, -110, -111, -112, -113, -114, -115, -116, -117, -118, -119, -120, -121,
-122, -123, -124, -125, -126, -127, -128, -129, -130, -131, -132, -133, -134,
-135, -136, -137, -138, -139, -140, -141,...
scala> val bigpar = big.par
bigpar: scala.collection.parallel.immutable.ParRange = ParRange(1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 251, 27, 252, 28, 253, 29, 30, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, 511, 261,
46, 512, 47, 513, 262, 48, 514, 49, 515, 50, 263, 51, 516, 52, 264, 53, 517,
54, 518, 55, 265, 520, 56, 521, 57, 522, 58, 523, 59, 524, 60, 525, 266, 61,
526, 62, 527, 267, 528, 529, 530, 268, 531, 63, 269, 532, 533, 64, 270, 534,
535, 65, 536, 271, 537, 66, 538, 272, 539, 67, 540, 273, 541, 68, 542, 274,
543, 69, 544, 545, 275, 546, 547, 70, 548, 276, 549, 71, 126, 550, 277, 551,
72, 552, 127, 278, 553, 73,...
------------------
needless to say that I cannot reproduce this faithfully... most of the time it
looks unsuspicious. But as I saw it once I retried several times - this was
the second time I got this - directly after the start of the REPL session (the
transcript is unaltered)
I'm not sure if this qualifies as bug, as I was not able to get a hold on the
"nulls" during range processing. So it's maybe only a REPL print thingy.
Greetings
Bernd










Re: Re: REPL: null-values in parallel ranges?
On Mon, Apr 4, 2011 at 3:43 PM, martin odersky wrote:
> Yes. Orderedness of sequence elements is orthogonal to parallel evaluation.
Great, that is what I expected.
Best,
Ismael
Re: Re: REPL: null-values in parallel ranges?
Matthew
On 4 April 2011 13:46, Aleksandar Prokopec <aleksandar [dot] prokopec [at] gmail [dot] com> wrote:
--
Matthew Pocockmailto: turingatemyhamster [at] gmail [dot] com gchat: turingatemyhamster [at] gmail [dot] commsn: matthew_pocock [at] yahoo [dot] co [dot] uk irc.freenode.net: drdozer(0191) 2566550
Re: REPL: null-values in parallel ranges?
On 04/04/11 16:00, Matthew Pocock wrote:
> This looks good to me. It will need clearly documenting - users may
> assume that Par* is parallel, but with this hierarchy, Par* has the
> option of being parallel, and it's the implementations that decide. I'd
> personally have introduced another trait for things which definitely are
> going to be parallel with the Par prefix, and named these 'may or may
> not be parallel' things something else. However, I see good modelling
> reasons to keep things as you have them. Either way, I think your
> hierarchy is a reasonable way to provide parallelism without breaking
> every single line of existing collections code in the wild :D
>
> Matthew
>
True, in the diagram ParIterable, ParSeq and others could be renamed to
something more precise, but I'm unsure what the name would be.
Re: Re: REPL: null-values in parallel ranges?
On Mon, Apr 4, 2011 at 2:46 PM, Aleksandar Prokopec
wrote:
> We're in the process of solving this.
> We're considering the following and will begin to experiment with the
> necessary refactorings.
This looks like the proposal 2a) from Martin from above. Perhaps one
should talk a bit more what this design implicates than how it is
actually implemented (I don't understand the details fully nor do I
want to have to):
I'll try an overview:
A sequential collection now inherits from a parallel collection, this means
0.) a parallel collection is not a sequential one any more
1.) therefore, old libraries by design can't handle parallel
collections as input per default.
2.) a library writer has to "enable" the use of parallel collections
at each method parameter by requiring "only" the more general parallel
collection type variant if it supports parallel collections
3.) a library writer should inform the users if he changes a return
type from e.g. Seq to ParSeq because it can be that the user's program
will still be compiling, but now lacks the guarantees the sequential
collection variants give
open questions:
* foreach stays parallel?
* how to write a library method that can be used both by users
understanding and using parallel collections and others who are
completely agnostic of parallelism concerns without putting the burden
on the user to use `.seq` everywhere to be on the safe side?
IMO the choice to use this design is a conservative one. Users are on
the safe side and old code shouldn't break (even if HOFs like map,
collect, etc. are safe even when they use side-effects) What I still
don't like is that the default `foreach` is parallel. In my
experience, executing side-effects concurrently will produce problems
in more cases than not. For me the parallel foreach is the special
case not the sequential one.
Contrast that to the current solution where the onus is on the user to
make sure to don't use side-effecting closures with parallel
collections.
Johannes
Re: REPL: null-values in parallel ranges?
>
> I'll try an overview:
> A sequential collection now inherits from a parallel collection, this means
> 0.) a parallel collection is not a sequential one any more
True. A sequential collection is now a parallel collection.
> 1.) therefore, old libraries by design can't handle parallel
> collections as input per default.
That's the idea with this redesign, yes. Since the (valid) complaint (it
seems to me from most people) is that old libraries would be
compromised, this would disallow old code to implicitly use them.
_Perhaps_ a solution to this requirement could be to provide a Iterable
wrapper around a ParIterable. If a client wants to violate things in
lust for performance at his own responsibility, he would be allowed to
do so. A risk would then be explicit in the code.
legacyCallImSureDoesntHaveSideeffects(someParallelCollection.wrapSeq)
> 2.) a library writer has to "enable" the use of parallel collections
> at each method parameter by requiring "only" the more general parallel
> collection type variant if it supports parallel collections
True. If the code within a method can use the parameter in parallel
ways, this is expressed through a weaker precondition in the type of the
method parameter.
> 3.) a library writer should inform the users if he changes a return
> type from e.g. Seq to ParSeq because it can be that the user's program
> will still be compiling, but now lacks the guarantees the sequential
> collection variants give
This is a good point.
If he uses a ParSeq as a return type, the code calling a method may
still compile due to type inference. Note, however, that this does not
hurt existing libraries, since there aren't any yet. Furthermore, we've
had issues like this and we've used migration warnings to make them more
detectable.
> open questions:
> * foreach stays parallel?
Yes, foreach stays parallel. In ParTraversable, ParIterable and ParSeq
its possibly parallel, in a concrete collection class like ParArray it's
surely parallel.
> * how to write a library method that can be used both by users
> understanding and using parallel collections and others who are
> completely agnostic of parallelism concerns without putting the burden
> on the user to use `.seq` everywhere to be on the safe side?
>
In the current proposal, if the library writer knows his method won't do
side-effects:
Library writer writes:
def libraryMethod(sq: ParSeq[Int]) = {
sq.map(_ * 2)
}
User writes:
libraryMethod(ParArray(1, 2, 3))
If the library writer knows his method will do sideeffects in closure
passed to the collection argument:
def libraryMethod(sq: Seq[Int]) = {
sq foreach {
x => println(x)
}
}
If the library writer writes a method which takes a closure argument, he
would have to assume the closure is side-effecting just to be on the
safe side:
def libraryMethod(sq: Seq[Int])(f: Int => Int) = sq.map(f)
> IMO the choice to use this design is a conservative one. Users are on
> the safe side and old code shouldn't break (even if HOFs like map,
> collect, etc. are safe even when they use side-effects) What I still
> don't like is that the default `foreach` is parallel. In my
> experience, executing side-effects concurrently will produce problems
> in more cases than not. For me the parallel foreach is the special
> case not the sequential one.
I agree with you that it's easier to make a mistake if a foreach
executes in parallel, especially in the presence of type inference.
However, if a reference is known at compile time to be executed
sequentially, then there are no risks whatsoever.
A ".seq" or ": Traversable[A]" can always be used to fight type inference.
Although an always sequential `foreach` and an always parallel `pareach`
would solve the `foreach` issue, this is just a rule of the thumb. 90%
of collection methods take closures and any closure can contain a
sideeffect. To be completely safe, all other HOFs would require parallel
counterparts as well.
> Contrast that to the current solution where the onus is on the user to
> make sure to don't use side-effecting closures with parallel
> collections.
In the current solution, the user must make sure closures are pure for
any collection.
In the proposed solution, the user must make sure closure are pure
unless he knows at compile time that his collections is a sequential one.
This seems like an improvement to me..
Alex
Re: REPL: null-values in parallel ranges?
Am Montag, 4. April 2011, 16:22:46 schrieb Aleksandar Prokopec:
...
> > 3.) a library writer should inform the users if he changes a return
> >
> > type from e.g. Seq to ParSeq because it can be that the user's program
> > will still be compiling, but now lacks the guarantees the sequential
> > collection variants give
>
> This is a good point.
>
> If he uses a ParSeq as a return type, the code calling a method may
> still compile due to type inference. Note, however, that this does not
> hurt existing libraries, since there aren't any yet. Furthermore, we've
> had issues like this and we've used migration warnings to make them more
> detectable.
Maybe users should be instructed to explicitly provide the type of collection
they intend to use if they don't want to code concurrent aware. Thus
tightening the contract for collection providers into sequencial behaviour.
val myXY: Seq[aType] = someCollectionBuilderWhichMayReturnParallels()
for (e <- myXY) {happily doing sequencial stuff}
This way they have a lifetime guarantee for myXY to never fall into the
concurrent execution trap.
Or am I missing something?
Greetings
Bernd
Re: Re: REPL: null-values in parallel ranges?
On Mon, Apr 4, 2011 at 4:22 PM, Aleksandar Prokopec <aleksandar [dot] prokopec [at] gmail [dot] com> wrote:
I'm more worried about visibility, races etc.
--
Viktor Klang,
Relentless is more
Work: Scalable Solutions
Code: github.com/viktorklang
Follow: twitter.com/viktorklang
Read: klangism.tumblr.com
Re: REPL: null-values in parallel ranges?
>
>
> I'm more worried about visibility, races etc.
>
>
Can you elaborate further?
If you are using a collection known to be sequential at compile time,
then there should be no problems with data races.
If the collection is not known to have sequential type at compile time,
that is, it's possibly parallel, then the closures should not have
side-effects, or have thread-safe side-effects.
For instance, instance, it's safe to use a concurrent map insertion in a
foreach, or some other HOF, while it isn't safe to use array buffer
appending.
Furthermore, once the parallel operation completes, threads are
synchronized. So it should be safe to use non-synchronized side-effects
too, as long as the changes monotonic (e.g. writing `true` to a
non-volatile boolean variable). Although I would not recommend this.
Re: Re: REPL: null-values in parallel ranges?
On Apr 4, 2011, at 15:50 , Johannes Rudolph wrote:
> On Mon, Apr 4, 2011 at 2:46 PM, Aleksandar Prokopec
> wrote:
>> We're in the process of solving this.
>> We're considering the following and will begin to experiment with the
>> necessary refactorings.
>
[snip]
> Contrast that to the current solution where the onus is on the user to
> make sure to don't use side-effecting closures with parallel
> collections.
>
Having parallel foreach on the parallel collections can come in quite handy if you know what you're doing, especially in space-constrained environments (i.e. when building a complete result collection would blow up).
Regards,
Roland
Re: REPL: null-values in parallel ranges - Seq.foreach acting un
I would just like to point out that this is a bit more general - it's
not only about order, it's also about thread-safety. The problem is
not inherent in parallel sequences, but in any kind of a parallel
collection - processing an element may occur concurrently with
processing some other element. An out of order execution is a
consequence of this. This is why the ParRange printing used to show
nulls.
Alex
On Apr 2, 4:50 pm, HamsterofDeath wrote:
> a parallel sequence can replace a sequencial sequence (feels weird
> writing that) for every method except foreach. maybe there should be an
> ordered-foreach-able trait and a foreachable-random-order-trait? then it
> could be added to any collection that can do it.
>
Re: REPL: null-values in parallel ranges?
Viktor, scala has no effect tracking. This is essentially what you said. This issue is not specific to parallel code. We all deal with this already, somehow.
That is not to say "parallel foreach" is a good idea. It isn't.
On 03/04/2011 6:11 AM, "√iktor Ҡlang" <viktor [dot] klang [at] gmail [dot] com> wrote:Re: REPL: null-values in parallel ranges?
I don't think parallel collections should "lie" and provide a leaky abstraction over concurrency. When someone asks for parallel execution I think it is best that they get what they are asking for. Sure it might break sequential code, but threads does that; they turn determinism into non-determinism. Let's embrace parallelism at its core and reap the benefits of it rather than trying to force it into something that it is not. It is a matter of education; documentation needs to be a lot better. People needs to understand that concurrency and parallelism is here to stay and a lot of the time it still ain't that pretty.
2011/4/2 Tony Morris <tmorris [at] tmorris [dot] net>
--
Jonas Bonér
Specialist at Large
work: http://scalablesolutions.se
code: http://akka.io
blog: http://jonasboner.com
twtr: @jboner
Re: REPL: null-values in parallel ranges - Seq.foreach acting u
On 2 April 2011 15:50, HamsterofDeath <h-star [at] gmx [dot] de> wrote:
Not exactly. If the function you pass to map or the predicate you pass to filter accesses shared mutable state or performs IO, then these are just as affected by out-of-order execution as foreach. In the pathological case where you call foreach with pure code, you won't notice any difference in sequential and parallel execution.
Matthew
--
Matthew Pocockmailto: turingatemyhamster [at] gmail [dot] comgchat: turingatemyhamster [at] gmail [dot] com msn: matthew_pocock [at] yahoo [dot] co [dot] ukirc.freenode.net: drdozer(0191) 2566550
Re: REPL: null-values in parallel ranges - Seq.foreach acting u
seriously:
if your function is not threadsafe, don't use it in a multithreading environment. when i said "could replace", i implicitly meant "if using side effect free functions"
Am 02.04.2011 18:22, schrieb Matthew Pocock:
Re: REPL: null-values in parallel ranges - Seq.foreach acting u
I would be very surprised if there isn't scala code 'in the wild' that does exactly this. It probably works just fine for them right now because collections are processed sequentially. I'd expect IO side-effects to be the most common case.
In the absence of an effects system, it isn't always immediately obvious if your code will give different orders if the collection is processed in a different order, particularly for less experienced programmers. If there is some legacy or 3rd party code that now gets pushed into a parallel collection method, how could we expect people to know if it is threadsafe or not?
Matthew
--
Matthew Pocockmailto: turingatemyhamster [at] gmail [dot] comgchat: turingatemyhamster [at] gmail [dot] com msn: matthew_pocock [at] yahoo [dot] co [dot] ukirc.freenode.net: drdozer(0191) 2566550
Re: REPL: null-values in parallel ranges?
On 02/04/11 18:24, Bernd Johannes wrote:
> Am Samstag, 2. April 2011, 00:13:39 schrieb Alex Cruise:
>> I think a lot of people have a mental model of parallel collections as
>> "just like sequential, only hopefully faster." Whether this is similar to
>> the intent of the designers of 2.9's parallel collections is an
>> interesting question.
> My first concern goes towards documentation: if foreach on Seq in a parallel
> context is going to be evaluated out of order (i.e. parallelized) there should
> be a reminder in the documentation for Seq.foreach(). I.e. if somebody is
> going to write something which accepts a Seq and is going to execute side
> effects on this Seq by means of foreach has to cope with out of order
> execution because the Seq might be a parallelized Seq.
>
>> But when side effects are the whole point, I think many people really will
>> care about the order in which the actions are taken, so for whatever it's
>> worth, I think I'll go along with the "keep foreach sequential, and come up
>> something new that works like foreach but makes you sign an explicit
>> waiver that you won't get upset when things happen out of order" camp. At
>> least until convinced otherwise. :)
When side-effects are the "whole point" (which is far, far, far, far,
far, far rarer than is often alleged), it would be wise to stop the
silly buggers and admit that you have just lost parallelisation.
Re: REPL: null-values in parallel ranges?
On Thu, Mar 31, 2011 at 11:03 PM, Paul Phillips wrote:
> It isn't taking me long trying .par in the repl to see all kinds of crazy
> stuff. The main thing is that foreach seems to return things in a random
> order and iterator doesn't. That doesn't sound like something intentional,
> but I try not to assume too much. But it is likely at the heart of what you
> are seeing too.
I came across this today too while playing with the REPL and intended
to investigate it before filing a bug (if it was indeed a bug). Seems
like you've already found the root cause of the issue. Good. :)
Best,
Ismael
Re: REPL: null-values in parallel ranges?
On 3/31/11 3:09 PM, Ismael Juma wrote:
> I came across this today too while playing with the REPL and intended
> to investigate it before filing a bug (if it was indeed a bug). Seems
> like you've already found the root cause of the issue. Good. :)
It's fixed in trunk now. I'm trying not to be nervous about what other
code I've written which might be vulnerable to surprises here.
Re: REPL: null-values in parallel ranges?
what happens if you do this inside a scala program and use tostring?
Am 31.03.2011 22:42, schrieb Bernd Johannes:
> Hi scalaists
>
> this evening I started playing a little with the parallel collections and this
> crossed my way...
> This is most likely only a REPL display effect - but it felt disturbing
> somehow (thinking about races and uninitialized values):
>
> -----------------
> bjo@noordx:~/Tools/scala-2.9.0.RC1> bin/scala -J-Xmx3000m
> Welcome to Scala version 2.9.0.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java
> 1.6.0_24).
> Type in expressions to have them evaluated.
> Type :help for more information.
>
> scala> val big = (1 to 10000000)
> big: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7,
> 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
> 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
> 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
> 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
> 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
> 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
> 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132,
> 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
> 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162,
> 163, 164, 165, 166, 167, 168, 169, 170,...
> scala> val bigger = big.map(e => -e)
> bigger: scala.collection.immutable.IndexedSeq[Int] = Vector(-1, -2, -3, -4,
> -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20,
> -21, -22, -23, -24, -25, -26, -27, -28, -29, -30, -31, -32, -33, -34, -35,
> -36, -37, -38, -39, -40, -41, -42, -43, -44, -45, -46, -47, -48, -49, -50,
> -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65,
> -66, -67, -68, -69, -70, -71, -72, -73, -74, -75, -76, -77, -78, -79, -80,
> -81, -82, -83, -84, -85, -86, -87, -88, -89, -90, -91, -92, -93, -94, -95,
> -96, -97, -98, -99, -100, -101, -102, -103, -104, -105, -106, -107, -108,
> -109, -110, -111, -112, -113, -114, -115, -116, -117, -118, -119, -120, -121,
> -122, -123, -124, -125, -126, -127, -128, -129, -130, -131, -132, -133, -134,
> -135, -136, -137, -138, -139, -140, -141,...
> scala> val bigpar = big.par
> bigpar: scala.collection.parallel.immutable.ParRange = ParRange(1, 2, 3, 4, 5,
> 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
> 26, 251, 27, 252, 28, 253, 29, 30, null, null, null, null, null, null, null,
> null, null, null, null, null, null, null, null, null, null, null, null, null,
> null, null, null, null, null, null, null, null, null, null, null, 511, 261,
> 46, 512, 47, 513, 262, 48, 514, 49, 515, 50, 263, 51, 516, 52, 264, 53, 517,
> 54, 518, 55, 265, 520, 56, 521, 57, 522, 58, 523, 59, 524, 60, 525, 266, 61,
> 526, 62, 527, 267, 528, 529, 530, 268, 531, 63, 269, 532, 533, 64, 270, 534,
> 535, 65, 536, 271, 537, 66, 538, 272, 539, 67, 540, 273, 541, 68, 542, 274,
> 543, 69, 544, 545, 275, 546, 547, 70, 548, 276, 549, 71, 126, 550, 277, 551,
> 72, 552, 127, 278, 553, 73,...
> ------------------
> needless to say that I cannot reproduce this faithfully... most of the time it
> looks unsuspicious. But as I saw it once I retried several times - this was
> the second time I got this - directly after the start of the REPL session (the
> transcript is unaltered)
>
> I'm not sure if this qualifies as bug, as I was not able to get a hold on the
> "nulls" during range processing. So it's maybe only a REPL print thingy.
>
> Greetings
> Bernd
>
>
Re: REPL: null-values in parallel ranges?
Am Donnerstag, 31. März 2011, 22:56:25 schrieb HamsterofDeath:
> what happens if you do this inside a scala program and use tostring?
>
That's the first thing I tried: test it inside a function in the REPL - and as
I said: I wasn't able to provoke a NPE or something alike in 1000 loops on 6
cores (each loop processed a range from 0 .. 10000000 with map and a ParRange
with map and foreach with toString)
And I am sure all of this has already seen severe testing from the scala team.
I suppose this to be a special behaviour from the REPL printout...
Greetings
Bernd
> Am 31.03.2011 22:42, schrieb Bernd Johannes:
> > Hi scalaists
> >
> > this evening I started playing a little with the parallel collections and
> > this crossed my way...
> > This is most likely only a REPL display effect - but it felt disturbing
> > somehow (thinking about races and uninitialized values):
> >
> > -----------------
> > bjo@noordx:~/Tools/scala-2.9.0.RC1> bin/scala -J-Xmx3000m
> > Welcome to Scala version 2.9.0.RC1 (Java HotSpot(TM) 64-Bit Server VM,
> > Java 1.6.0_24).
> > Type in expressions to have them evaluated.
> > Type :help for more information.
> >
> > scala> val big = (1 to 10000000)
> > big: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6,
> > 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
> > 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
...
> > 169, 170,...
> > scala> val bigger = big.map(e => -e)
> > bigger: scala.collection.immutable.IndexedSeq[Int] = Vector(-1, -2, -3,
> > -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18,
...
> > -139, -140, -141,...
> > scala> val bigpar = big.par
> > bigpar: scala.collection.parallel.immutable.ParRange = ParRange(1, 2, 3,
> > 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
> > 23, 24, 25, 26, 251, 27, 252, 28, 253, 29, 30, null, null, null, null,
> > null, null, null, null, null, null, null, null, null, null, null, null,
> > null, null, null, null, null, null, null, null, null, null, null, null,
> > null, null, null, 511, 261, 46, 512, 47, 513, 262, 48, 514, 49, 515, 50,
> > 263, 51, 516, 52, 264, 53, 517, 54, 518, 55, 265, 520, 56, 521, 57, 522,
...
> > 553, 73,...
> > ------------------
> > needless to say that I cannot reproduce this faithfully... most of the
> > time it looks unsuspicious. But as I saw it once I retried several times
> > - this was the second time I got this - directly after the start of the
> > REPL session (the transcript is unaltered)
> >
> > I'm not sure if this qualifies as bug, as I was not able to get a hold on
> > the "nulls" during range processing. So it's maybe only a REPL print
> > thingy.
> >
> > Greetings
> > Bernd