Bill Allombert on Wed, 20 Mar 2024 11:26:59 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: How to efficiently count Proth primes with GP parfor?
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: How to efficiently count Proth primes with GP parfor?
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Wed, 20 Mar 2024 11:26:54 +0100
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1710930416; c=relaxed/relaxed; bh=UP0WASGbrsxmM5SIXc4iV3P5HFXuw5bKj4mQA9rFXes=; 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=E4Dc8wHJXJD+jcxe4chRZHCIhzDmzrILDW2Rm3ASKo0s80y5DrS02BqNZqhGgfSfhA1Bn3MKncM/POKSNf5mbYZqRanQK2ccmeyvcueHsR7B5jkRUxuSCK4KmDOXCsDly1K5VtBFhguTCyNhLVSsGzMv39U75lKDEMduGucjGlV21YNGrSJ+FzFPaFTX42WrUia8+F3z/VUZH52WiPLD95D1FDBIk1xXXyjBRPR9R0U8NJ3HtTm9rtORrhiOfYXSBqjHne1HAgjxFEhJoujDzMaVGVjB4WHnP/oGSLkmBzS7O0BlV9cnLT2VoSkmqsMdo5qu5QA0LZmseMQQsmVI+UXW6PPzev6LNO0ykJD5CqGT+UCgwPf0Z9tr40Mgx8+i5cJkDKFoFJsZhdkpvxBvw6OVTYG/VMUXl0qLEX0zAsAF6L2xfwCt6EXGD+sDpoSDxQUH/jo4o0Deob2+6IMdbPQ3qaUSF4ickQw0j6I16uJwlL84xavN3kmvwLp1RQKpfbJLv/WmxKPRG+7Hrc+IyALbenPvVv1Tn8WvQ44dZMHy6m7q64g9i9D+xOzjr95UdkcnYx1h4pGYWf5nsSbPC2xUMjGxkl7+2w0yYb9jDU9e67+hU4I2lTq7Yavr709XAy13WmB5i0f/llbkH+2QGnzCzkanqThJp7+LbCdrz0g=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1710930416; cv=none; b=lScEl57W9BsmxK0osHDy5hQLaVbwlowWb1RK/KYWw7xLBGZpOlR2W7FaUmsBg+K2gFZ+pzvM09494/erdENt73CyOw0x4XckL1rH7xUDrLKghk1/Lu9JiYDn9YD5wf7q4tPdiY8h5IoFSDxHpmvMN4Tjzx5YsQhlSw8sRUQoOLEJZBeehL7JuK5d77wDinmUc1DLfEwhTpaqutVlYtCKnhLHmWuVR4Yl1QRHReazwLGkCXNw6YNN5zAwmVKRy49/TWBQfHC3sbhdPSlY/DpgdQlVIv3k5cghHujM+n8C0SWU7N+c3Umxilt8NXfML5BfJzyVDjpPWK4MpUSUZNECSJeELTfbqvKlfkTWmKzzytIBxTn9+xkHUMAUYaxPgq0jH9Hw/6y4FQljQiWGQQASDm5AB9cFqdHbn80sbKQdpHGXz1sPGdtHXr4kYXKUhmPYM3VvW1aOFwS/tZkUcMlCSBFZ6taBdVNK8Ui57RWSSVRpacrAW6SRBHv7/GxXxh7qMWnRfD0YvT85YoaN7c91yv9TGxYFwB5xMmd78wNtKhouFwr7fKwTdHM2lDs5Mw3Aa7gFfIozhJvDJeGahURNZjvuNCvr/idyWfKjvvkTz8F4GBZBCE42Afz9cPHZD+iU+JOZj89XWzPAmNd8PtufaOMcXe/0EBFq9mqKo+VpbiM=
- Authentication-results: smail; dmarc=none header.from=math.u-bordeaux.fr
- Authentication-results: smail; arc=none
- Delivery-date: Wed, 20 Mar 2024 11:26:59 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1710930416; bh=UP0WASGbrsxmM5SIXc4iV3P5HFXuw5bKj4mQA9rFXes=; h=Date:From:To:Subject:References:In-Reply-To:From; b=f+BxbUZBYZxy+pXUD521dwgGqwJWqz4a+xPflB5knF2MV+a92NieLfX2ZGR37rMvV /TwYyD8KnICH0psu3u28yPMmiBTqRAph6NCZLDgM+wdJVgiyEm3cOl56rxsJf5ikEY o5Wfw19LqUr/ZQGkFxk0yqnKqYU1DzDAT+sfuEP+HZkamdB1Xgz4Lwngb7hLfxYl2h Yc/A7LvEtwLfIzAomQbkbt3NnGuEqbVQWv63FYM6H5lyXB7E3Rnq1FbRVPcyDY1QFG f78COB9lJwDu3OmWqh8NMGMzJXyb8Mx+FK/MOni+DTt8xA5z172XiqdxvitxIG7EFb GdqsIyfC1b2l15BQC2CYdfldGrccGQYWInmKD6HbRyLfyCdv2SSzaCw4q62GpHwhD+ z00XJ3eHZBIUrzEmEAEUQ3gE8NsYVP1NMeSB1a/uRFpgVhtMiziizFTQUGM0DMjMP8 K0di0ShA2SWC2q2CB8IzgzDYM0k0yrrax2OJIcOLxr4Z+scgpXDGPen5UPwsRLwO2b sX3M/P2kOk62Njz2a/5ZhcOAVdqtvj3RFM5rTcwGHSwc43WzXp4Y1xvS6rxrh7iCdc MpEpN+2YL6PYOC9gZ7w9TYW5b8zeAWT/gIhmcI2r0eNYohd/AE8L+ZhDx1n3j4ieX4 0S7wzx0GcfSiR+ivMiNKZcWc=
- In-reply-to: <55fecf62eb12a6076cc03e3ff0c06bce@stamm-wilbrandt.de>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <78df8c6fb5e60216469075d862f79735@stamm-wilbrandt.de> <55fecf62eb12a6076cc03e3ff0c06bce@stamm-wilbrandt.de>
> ? isProth(p)=my(v=valuation(p-1,2));p>>v<2^v;
> ? export(isProth)
> ?
>
> I tested the first 3,000 Proth primes:
>
> ? c=0;forprime(p=3,323092481,if(isProth(p),c+=1));c
> 3000
> ? ##
> *** last result: cpu time 5,545 ms, real time 5,545 ms.
> ? c=0;parforprime(p=3,323092481,isProth(p),C,if(C,c+=1));c
> 3000
> ? ##
> *** last result: cpu time 29,142 ms, real time 18,457 ms.
> ?
>
> 1) Why is sequential computation more than 5× faster than parallel?
> 2) Why does gp run with only 336% CPU and not wih more than 1500% or 3100% ?
The function isProth is too fast compared to the overhead of parallelism.
As you see, PARI only manage to schedule 3.36 job on average before the first
one complete, so most of the time is spent scheduling jobs.
You need to do work by batch.
isProth(p)=my(v=valuation(p-1,2));p>>v<2^v;
export(isProth);
{
my(nbt=default(nbthreads));
my(c=0,B=323092481\nbt);
parforstep(i=1,323092481,B,
my(cc=0);
forprime(p=i,min(i+B-1,323092481),cc+=isProth(p));cc
,C,c+=C);c
}
%3 = 3000
? ##
*** last result: cpu time 17,843 ms, real time 1,070 ms.
(with 20 cores).
The best value of nbt will depend on your system.
Cheers,
Bill.