Bill Allombert on Thu, 19 Sep 2024 19:53:09 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: concurrent computation of a function
|
- To: Max Alekseyev <maxale@gmail.com>
- Subject: Re: concurrent computation of a function
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Thu, 19 Sep 2024 19:53:02 +0200
- Cc: pari-users@pari.math.u-bordeaux.fr
- Delivery-date: Thu, 19 Sep 2024 19:53:10 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=math.u-bordeaux.fr; s=2022; t=1726768387; bh=84jB0KukycVtVW3WwN4EjmTRCshCQF8fWMGfkKmkzZ4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Cw70lNnVhJL8RDrLyUwDX4w5zVqlAvjhwhJdPOkuIypyQ6ju7bIwUk0kJnS4D3Bpf fjvgnIFCz13sW/VbMixg8R63zAUACrJZ/FpgD3tOFrEtxoIXfoOSzmST7masNg2AVU 918XRaA/HyYOKCaUZtmlXnH9H16OJiScz+KKPGnNo9t7cWIMqDf3IYY9hHZwRBTXOd 1FmlUxANNwP6YUgOT0cydlxm1EnrfCOcPJbLLHYrydbFGj2aegrAUuGga1D7Kaqk+I z+hYhbWFOPwprEiw5mDU/6894Vcy7pTQODO5p7fPBEXMt2f3a2MT2BSpkkuB6975wi DFb0+51+TTFcswNQ68UoYhoBtTTOGJh1Nx4bG6zCG8HOrWC2Pke9f5DIOwQvGAhh9j cqinCri0uq3s6g4Vpcc5eeyh5j8OdMWSOlRlNzw8TDxTX0xP1NA7ro0Yb4Un55rN25 opixJvB7d79NQvkA9rTKqaCkPVDKJ4z56D0slXubg6VfjQRRNI8/HXoQBlKlwOOwCw Vu6WbXv3BnQ/dxpF3ULfNUte+xPpy4lV+N6FUkuI0cMZEjNmyM/FXIG2NZ7/+JRYNT 7BHx+IsV+QJVY8OMIeylnXyqSC0uyRCYEuFR6pShE5FggoK471LWRhZnOdDnlU85kh dzmmS+NTiA7+3Eb+6ryzVmIs=
- In-reply-to: <CAJkPp5MMFr=AG2=fOhrhX-DvdAnwstQg9VOAh3eMxnauvKvf+g@mail.gmail.com>
- Mail-followup-to: Max Alekseyev <maxale@gmail.com>, pari-users@pari.math.u-bordeaux.fr
- References: <CAJkPp5NVqG51fQ_UiGFc1MbVLUiV6QhY5fCg1O67R-SkhhG-5g@mail.gmail.com> <ZuxJ2hm6tHJAMZQ3@seventeen> <CAJkPp5MMFr=AG2=fOhrhX-DvdAnwstQg9VOAh3eMxnauvKvf+g@mail.gmail.com>
On Thu, Sep 19, 2024 at 01:11:24PM -0400, Max Alekseyev wrote:
> Hi Bill,
>
> Thank you for the elegant solution!
> Could you please elaborate on why the use of error() is not recommended? Is
> it because of side effects related to garbage collection or alike?
This is not related to error. The problem is with interrupting
a runnning thread at an arbitrary point. Using ^C has the same issue.
While PARI has some minimal protection against this, if the interruption
occurs at the wrong time, the system state might become inconsistent
and GP will crash.
> And is there a recommended alternative?
Only if you can change the inner loop of your program.
In that case you can check some shared state and stop when requested.
But there is no facility in GP for that, because that can lead to
race conditions.
The less ugly I could come up with is with using the fairly useless
seriesprecision:
fun(N)=
{
while(1,
if(default(seriesprecision)>16,return(0)); /*check signal */
if(random(2^16)==0, /*Finish! */
default(seriesprecision,17); /* signal other threads to stop */
return(N)))
}
default(seriesprecision,16);parapply(fun,[1..20])
%5 = [0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Cheers,
Bill.