Bill Allombert on Thu, 19 Sep 2024 17:57:17 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: concurrent computation of a function
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: concurrent computation of a function
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Thu, 19 Sep 2024 17:57:14 +0200
- Delivery-date: Thu, 19 Sep 2024 17:57:18 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=math.u-bordeaux.fr; s=2022; t=1726761435; bh=iQxzj8oHI72L/SDMM7BAdr8mGPl4ldK2d38g93ucU+o=; h=Date:From:To:Subject:References:In-Reply-To:From; b=ZIjPhigUvyZzahbmsv9LTIsSci5yCd+Hj2svQoz/1jaoTPPBezYm45Sbwel4rWjYz MDFnyfOEjBtvw/Bkt1diALYMYwVESIX91c9XDas36MQDq95W5t0+XWoPNqQgrwDjpy F3jSCLvLWL9+ZsfbiThsmtGTgEyOwKwvwTUC1nak9W/rOb1Oc9guPchYXkIl2HdnBf Fj8LsD0Ll0rdoao6kthvivfgal28Z6EdJmzX0TVjZJ8vc03dRo+33TTP+RPYVajmEK 2wGvesY/I14JA831yv0K6cxE1ZCilyRP0IIkHUO5DkXP71M+4bpMO0+RwcaqWavJY3 FQOYlGDm28yf0be4T/pg2mSymOK+f5CRuekH2gFBlicOAORRHUdRt/NqQgLURBhyk9 1NsrYilmcgxvm+d9LDHfR43RKz2jacEIdRqjITwtumRJU7ZzUOm1UXn3iXBVNNfpWq oz8r1WZyIDHkCmfW1n6xXWWlTVN03xJ3CMqaWfis+fNZd+/4wpWofUtnELKnM/cgQC qegXJWI0nPACxCNSXrpanFKqYbW56F+Gsw7/qDzs+Wr7x1B9gXvM2WwBYTh05o3NDB WfuWOq+FT3pN3Vhh0TIVv13tgkkj29Kbz0Rie+9cXn1vMJ02WOqiUyX3AwrL/eaYeB rNJovky0Ucx3mfMteNc+fV2s=
- In-reply-to: <CAJkPp5NVqG51fQ_UiGFc1MbVLUiV6QhY5fCg1O67R-SkhhG-5g@mail.gmail.com>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <CAJkPp5NVqG51fQ_UiGFc1MbVLUiV6QhY5fCg1O67R-SkhhG-5g@mail.gmail.com>
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.