Bill Allombert on Wed, 14 Jun 2023 21:34:48 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Give up with MT, need help!!!
|
- To: pari-dev@pari.math.u-bordeaux.fr
- Subject: Re: Give up with MT, need help!!!
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Wed, 14 Jun 2023 21:30:04 +0200
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1686770997; c=relaxed/relaxed; bh=C5Wrk2uUGQhOtLCYFXCx/JFhxV70Sp/1hnQfk3IAewM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; b=JDhnkLynxwDxmwYzs0LaywYSwKMEf2HiI+fP7duws8Q4zqX/CHV01MHeXE2mUKIFA3dkyHWWDo80EL0+wocsMnFnF0oXy3ie7Px+lH9IQKqatpUFARWcExVdV2upMF6RvR/blpqrrIHaOMec+Gjg+8pNoopCAAMCVJpKqf7X7A4SxaLNKlrcCHaS/uaArowgqsoyvP2SizMTKS8vCElWsPBRdJOBkoYQiOcm3VlaXgu52dqTQWOLvH3GgHFzszp4X9S8yG+bqwLMo8YWukK75aKZvlx7FRSN2do5ytMTxH9lvrUGSescCuxLCALBmRk3QNJZX2SYL2mZ75QLKQaqlIpSkEGnZQhCyxvNL/Kuq9NYZTLnneG5IT1X0//EP37nx64nUYmgpnwiEt1Uuklqvg349SnYaYEMXqCxEUfvXTYeGTHmFoPHKoYXgAJofZMSMAXnAoAune5P7BReEOW6VdzGRVHCvq4qwcwkMoYwGKQGNaXfRohNmmMDM7Kn3kYffem8ubBSwfpJoBkR7Jb1Jze5ukbXnZwxZyasAQw6FLBB1D0Z6ELQnVJWO+PPfpg1QAohwjVeoX1BQ/ezgSjxYHp2Z8eJgD6eD3IWpKJw7rO09b9OA0vB6ST9oEJ/HYnWlIzzgOwfCKlZfhEFy8JC/UWrTMNSYPA/uvsNRLIhp7A=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1686770997; cv=none; b=RwhWjMdHYlr4eJwchCyPDVNHNGiQrfBRVJXkoGEcd0MQ9NW8zHygCrBhvOsH1uKSt3tHgeTnE77VVwfuYOI0nrn7+4rbXZmD/MM3gvfR+S1Ji0+FUsOs5NHs5uQ4PVWUX+qQJNqxaJmIgDT2sXiM8L6Bx9YyCs3GXPJy0cvSJK5sACS6QDPcvwVot9/6zA9CDgkJv72ygJ8jWMgm09SEm69XZW22SE4b+e/bngRhJg86peL2i1UEXHi54VobmpVfWGIOzXLFJLUmcuK02fX8dJovD2LBI8QnFBiGctek6ktRt2LKqX1a7erHAPMCWS8sTp6Fm5d2NOi+kcGnxN6e+Vwv+M5BXqigFSe+R/d8a3sw/qB+jrqLKzuIr+hcaSjaK2nqCdeSZZPxMP3WYYLty7gwYJ9+VbRb/+3xOq+3Y5/LdVMtaRZ/lfTo0M3Px68sIPQV7vWEbMqbNJLwAEp2rTdWVIJNJ6rvbR6s9rzuZdf3xWARGOmU0N2ZIQy+NssfyQzHKOxr0CGlT9OTyx776KGbvWmln0TG2NFfSbVANYrNGylNEJm/k5cAGu5vNTRzyicbf45QWEVjS8NwOGHixi750eqIpF+eoduYCVtbJSj9pfcKAOfbdEp9sSqtWmC1tcOhJ/nO3R58JQscOiNBrbWK+0/WnsF2zFIhTrTX4J0=
- Authentication-results: smail; arc=none
- Delivery-date: Wed, 14 Jun 2023 21:34:48 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1686770997; bh=C5Wrk2uUGQhOtLCYFXCx/JFhxV70Sp/1hnQfk3IAewM=; h=Date:From:To:Subject:References:In-Reply-To:From; b=L1iPyL09/kmE0LNEbOKIAHhPmD6ijOKWnhowuOzLaXghK73skDmM/idPwHCiqC6S3 2/oKeVv6zW+3A82x59RDcTKH5QjweTdWI9VYCyCl/ctOMF+4RxH9MwWQzB9JK1x70F gbiBrKh47GIjdPLBokpfFyNiDaMrKT747MbLp4ylvME1LP+OGAPs90OZOy7/nvxQfE Z1vf8rhFxTN9JW/nvwfkftt0jeZ8QgHZ3JanlRJL3pAK3moitaXfL01JJBBCJQMzZ9 09BFK1nLyWDEFEA3M9vjCruCa2fqHkQcy5KUdmENbJZEsssYCFqVnwtO/rEIKomfPP WzGdMr7LM6VFJWwxj7UPlNnzKzq2X6ovsaGy/715+Be3O0Fyf2FPyoLdq7kR302sUZ 3IrNrkLwD8S+HGT/YDeQhkUWONDq2siBaR1SfQmuIraoGX4fSuefYFDIyAdazwZwNJ CDT9uLcE1Mg934bPGpbXFRmAvZkJfusfahiPIEWBhm9c+1LZJOY0NJjDAOsePQ1z1f ZAKzqKovDO5BleFFyIqrlgrJaUKRP2XGoxn0D25g4DilpEVh3+/MAUue4nzEwR+nLZ PuUGm16P6dMLlyOGE4xSmVxoQKwwmG6Ij7b40AKk7RaGKpy5TMFeYKfIqmLc2F0F12 H2DUWyMpmBcnfkgsqers5gUQ=
- In-reply-to: <2d27a45d-8fec-c98a-645c-c235dec5274e@free.fr>
- Mail-followup-to: pari-dev@pari.math.u-bordeaux.fr
- References: <2d27a45d-8fec-c98a-645c-c235dec5274e@free.fr>
On Wed, Jun 14, 2023 at 05:56:38PM +0200, Jean-Luc ARNAUD wrote:
> Hi all,
>
> As a newby to PARI/GP, I'm trying to understand how it works in MT
> environment.
> And I'm getting a lot of difficulties.
>
> As an example, how could I replace the for ... loop by a parfor ... one in
> the chudnovsky_parallel(n) function ?
>
> After many and many tries, getting always either "Please export ..." or
> "Impossible div ..." error message, I give up ...
>
> Would somebody be so kind as to modify the below script in order to use
> parfor loop instead of for?
>
> |chudnovsky_parallel(n) = {||
> || my(k, res, Result);||
> ||
> || for(k = 0, ceil(n/14),||
> || Result=pareval([||
> || ()-> (-1)^k *(6*k)! * (13591409 + 545140134*k),||
> || ()-> (3*k)! *k!^3 * (640320^(3*k + 3 / 2))]); /* +3/2 -> 583 ms,
> +1.5 -> 18,536 s !!! */||
> || res += Result[1] / Result[2];||
> || );||
> ||
> || res = 1 / (res * 12);||
> ||
> ||};||
You can do this (using parfor)
chudnovsky_parsum(n) =
{
my(res);
parfor(k = 0, ceil(n/14),
my(d,n);
d = (-1)^k *(6*k)! * (13591409 + 545140134*k);
n = (3*k)! *k!^3 * (640320^(3*k + 3 / 2));
d/n,
dn,
res += dn
);
res = 1 / (res * 12);
}
You could also use parsum:
chudnovsky_parsum(n) =
{
my(res);
res = parsum(k = 0, ceil(n/14),
my(d,n);
d = (-1)^k *(6*k)! * (13591409 + 545140134*k);
n = (3*k)! *k!^3 * (640320^(3*k + 3 / 2));
d/n
);
res = 1 / (res * 12);
}
or parapply
chudnovsky_parapply(n) =
{
my(res);
res = vecsum(parapply(k->
my(d,n);
d = (-1)^k *(6*k)! * (13591409 + 545140134*k);
n = (3*k)! *k!^3 * (640320^(3*k + 3 / 2));
d/n,
[0..ceil(n/14)]
));
res = 1 / (res * 12);
}
But this is not the right way to compute this. You should use
the recurrence formula for the factorial
k! = k*(k-1)! and not recompute k!^3, (3*k)!, (6*k)! for all k from scratch.
(3*k)!= (3*k)*(3*k-1)*(3*k-2)*(3*(k-1))!
etc.
Also you should factor out 640320^(3/2) to avoid recomputing it.
Cheers,
Bill