Bill Allombert on Fri, 05 Nov 2021 19:16:43 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: return statement from inside parfor does not work


On Fri, Nov 05, 2021 at 12:47:19PM -0400, Max Alekseyev wrote:
> The following function never terminates despite executing the 'return'
> statement:
> 
> f() = parfor(i=0,+oo, if(i==100,print(i);return(i)) );
> 
> Calling f() does print '100', but ignores the 'return' statement. What's
> wrong?

In parfor (etc.) the return statement only returns from the parallel
section. you need to call return in the sequential section.

You can do something like

f() =
{
  parfor(i=0,+oo, 
    if(i==100,return(i));
    'NOTFOUND
   ,E, 
   if(!(E===NOTFOUND),print(E);return(E)))
}

Cheers,
Bill