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

Reply via email to