Hi - Yes,
var y = max reduce [i in 2..10] i*i; writeln(y); runs in parallel; the reduction is parallel and the [ ] syntax is a forall expression. You can think of the forall expression as yielding, in parallel, data to the reduce operator. I'm hoping that somebody else will chime in about reduce intents, but it would be nice to have a good example where reduce doesn't work. -michael On 7/15/15, 11:52 AM, "Brian Guarraci" <[email protected]> wrote: >Ah yes, for these simple cases reduce works. I forgot about reduce >because it has been slow and I've avoided it. > > >Does your example work in parallel? > > >I'll see if I can find an example which doesn't easily map to a reduce. > > >On Wed, Jul 15, 2015 at 8:43 AM, Michael Ferguson ><[email protected]> wrote: > >Hi Brian - > >> Is there an idiomatic way to find a max value in parallel iteration? > >I would have thought you'd use a reduction - like this: > > var y = max reduce [i in 2..10] i*i; > writeln(y); > > >We also have some ongoing work on reduce intents that might >help, but I'd have to let someone else explain that part. > >-michael > >On 7/15/15, 11:37 AM, "Brian Guarraci" <[email protected]> wrote: > >>Hi, >> >> >>Is there an idiomatic way to find a max value in parallel iteration? I >>may have missed something in existing runtime / examples, but because of >>intents, finding the max without some tricks doesn't seem obvious. >>Consider the following: >> >> >>use Random; >> >> >>var seed = 17; >>var rand = new RandomStream(seed); >> >> >>proc getNext(): real { >> return rand.getNext(); >>} >> >> >>// It would be nice if Chapel max took an array, as it can be smarter in >>different contexts >>proc _max(m): real { >> if (m.domain.low > m.domain.high) then return min(real); >> return max(m(m.domain.low), _max(m[m.domain.low+1..])); >>} >> >> >>var m: atomic real; >> >> >>// would like to have a way to get the max out of this forall w/o >>explicit atomic logic >>forall 1..100 { >> var n = getNext(); >> while (n > m.read()) { >> m.compareExchange(m.read(), n); >> } >>} >>writeln("max value is: ", m.read()); >> >> >>// works but not parallel and allocates memory >>rand = new RandomStream(seed); >>var res = [i in 1..100] getNext(); // bug: can't use array expression >>directly in _max() >>writeln("max value is: ", _max(res)); >> >> >> >>Thanks! >>Brian >> > > > > > > > > ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ Chapel-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/chapel-developers
