Max Alekseyev on Thu, 19 Sep 2024 21:21:59 +0200


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

Re: concurrent computation of a function


I've tried to use the error() approach extensively in my code and immediately got a "real" error:

free(): double free detected in tcache 2
Aborted (core dumped)

Can it be fixed?

Regards,
Max


On Thu, Sep 19, 2024 at 11:57 AM Bill Allombert <Bill.Allombert@math.u-bordeaux.fr> wrote:
On Thu, Sep 19, 2024 at 10:40:45AM -0400, Max Alekseyev wrote:
> Hello,
>
> Suppose I have two functions func1(x) and func2(x) computing the same
> entity, where depending on the input one may be much faster than the other
> (or vice versa).
> For the same input x, I'd like to compute them in parallel and return the
> result as soon as one of them completes, and terminate execution of the
> other.
> Is there a way to achieve this in PARI/GP?

The issue to terminate the second computation safely.
You can do that with pthread using error() but this is not recommended.

f1(a,b)=a+b
f2(a,b)=a*b

export(f1,f2);
{
  iferr(pareval([
       ()->error(f1(5,6)),
       ()->error(f2(5,6))
  ]),E,return(component(E,1)[1]),err_name(E)="e_USER")
}

Cheers,
Bill.