Bill Allombert on Sat, 13 May 2023 16:36:15 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Question about random() and threads...
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: Question about random() and threads...
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Sat, 13 May 2023 16:31:18 +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=1683988273; c=relaxed/relaxed; bh=hSvi/scdoJNRIGmD6hrPlqCNseQK9Kbu+6zfztqBIPQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:Mail-Followup-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; b=HjfybVcX9nJaV9abEcx/jppC7ZEgaYfI96xuMKG3wrqLv59qqDowIA43tYLlfbyShGPdUSbeL/U7ZNTEk4l+uRbcF5nWCoI6vPpYmAQ2BaVC38PxCrIDYjsa7cvnmZeyegVB0AYS3EMzIbSiSo8qKLPEMp3p4ItzLOWbCkL+CLhFhhEwX6Tt0ECwCRamepwE7//E5J20BOOiCjBeScY4vsFCBYua0NsoLGa3X1+6+MZwOupw9EdeAWnGPHvmj6/wpqDjYrK9jTjvYK5xHy3gQeZ7YKba21K/4QBbwqik6RYvxhvSkGh/xlDM9XNHYsDM/1chnh1v/azFMQdb/VuVO30KtsM5/UCREIJ86admNYwCrkm9RCRKgDWtj5qnvijj/fTg36V6we2rJvexXlZwDkubIRlmM0oxK7GoZf9fN04WW4yViNOkYUJjd5XWXYPzZiynpVr6eaSX+6d293Qsj8ln1uznFu4YzI+II8mAj78hffG0hgLvL9mZMWzshFkLIk9CK/I5oIHUxN76NkjmH/QdketrFfifng9dLcVhpH2rGcEyncwBdG/XpaLpgWBPGaSfFdKH5Z1aMxzkkGtlCZqprdObuJsfAuBc5M8toa20LGBpjEzs9f/lNWD+hTedRcnDhmkQsicylNOGGqeRfZ3q4OUvdzy7ONHSAeJ//2g=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1683988273; cv=none; b=K3Q6fwhM1mlBhjpT+IavDwMvEU12ZmlwZ25XwIC02aQLB9fMEkkMoTEtaFzqgmDcUgHaEtuFEXEk6xwzrIGVNM0wwFqcXreRW7QRoAtyiyqtNhqymxxEefCWH8DM2RywfQ53mtpldmf/MDjgWbCzsZ8f4PFjvjOh4tOanM8eTvPkGMPLDTn3+cIl8FmVX/gSLhyNSvdVStNrgvO2O7ZOJkUT1o2RuMVzLS/Yqqju849zNnk0gfWtoNDkOn0ylMVJRRMcGGXU5Xad8b2uUuYuNR8xsbT1e7/iiZOBRVng+3X6eAM8janj76FVzQXwoKDD+2zBQZArqPHMdI9cQDMxGJqyhLSO2FPuKqDUlfNSi0IxEr+wtaS4+a4R8/UoE8xOmpVmAkoOrP3Uaga2iqBryDvdDkXoTSjVbGt/nayvuOmUiApRjS8RudMFChkEOMTrQGVvU+UhaIxSSe4dw06e4AOOBak/8UfNK2q0JxFVlUZeErSsqwk0CrKeFLy3J6Mv21D+i2vElIR6j1j2sQRumLabYpVfkz2hA/byvNoDAt+Jkd5ok2Q3Boy4GMOcJfkkIVpUU7mjcDI4UmX2/nI1grmCyiMtamtuBBJpQaKCw23sxi8bHi6naxHUOncHtSlHOkysxiF1igf8aitcVH8TbNwUiEm6OFhxE8JZtPMrsAc=
- Authentication-results: smail; arc=none
- Delivery-date: Sat, 13 May 2023 16:36:15 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=math.u-bordeaux.fr; s=2022; t=1683988273; bh=hSvi/scdoJNRIGmD6hrPlqCNseQK9Kbu+6zfztqBIPQ=; h=Date:From:To:Subject:References:In-Reply-To:From; b=efWPXN+Ps8NkPOK3NPOf7ABSaVlI7z904A5M/jHVrCoM6/mjRLMk8ZoWwEuc/dVs8 G+1MyPN2W5IZkiZsER+udBuntQn/v2/V/Ms3jNLiS++5Fjk4H20GaIFyx3XyNTVWKO cEyc3VqSt+9OwHU//TRMIRiegY7kkjVN6h9qzBCxRM2w/t/MOe7k0vqIQegqG97+l8 6Bsnau+/dbmJpcGPFltL3cD0yq3aEBHuw5TNtvkpbc8rav2RQE5l0yniOI2WN2fvFf JpqAqOP+RoOKBNNluPKa4mwo2aKmr8LmjYVm4GPgFKUBMIaSQXktKJqZ/H3oFLdMNJ 8GPcBvcgH/Edm6ZajoJ5aDV4y3pvgk7sAYyq9DMBJ7uckhKvI9b54w4X0NGFfDal9v HmQBw86t4GFelYOo2hM4k8d39J6anCm1HCfLhWxwrU+KBo3j3VkdqwVh/i4NVvUUXr oD6EH3AUFTWbAONuKdjNglfUViZMo9/ii26RDoJ91Qbi2q4d/A0FD6rmfSRFy7UIqW DXE+rJYavdcxrabKRIL/fL4Q7K+HHjBBpFFsdGRFSlVLe29TXd2kRlrNnG/OwP9VVc A+HyD9uhfjK5fjKnCxh0XsDCZ5pL5kj8r8rl86+jDPb+dnNzcqI2t8zuiG+LGzavrV o7WUDkLJTdtkee5RUV0mBtjk=
- In-reply-to: <645F92AC.4020603@morpheus.net>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <645F92AC.4020603@morpheus.net>
On Sat, May 13, 2023 at 08:37:48AM -0500, wraithx@morpheus.net wrote:
> Hello,
>
> I was wondering how the random() function was implemented? I see in the
> documentation it mentions "a single internal generator", but if I use
> threads, with parfor() or similar, then I was wondering:
>
> 1) Is there a unique internal generator per thread? ie Each thread can have
> it's own starting seed and produce it's own sequence of random values?
Yes. Each thread has a separate generator that starts in the same state (setrand(1))
For example if you have 8 threads:
parisizemax = 4000002048, primelimit = 500000, nbthreads = 8
? parvector(8,i,random())
%1 = [1546275796,1546275796,1546275796,1546275796,1546275796,1546275796,1546275796,1546275796]
? parvector(8,i,random())
%2 = [1546275796,1546275796,1546275796,1546275796,1546275796,1546275796,1546275796,1546275796]
? parvector(8,i,random())
%3 = [1546275796,1546275796,1546275796,1546275796,1546275796,1546275796,1546275796,1546275796]
? parvector(8,i,random())
%4 = [1546275796,1546275796,1546275796,1546275796,1546275796,1546275796,1546275796,1546275796]
(here each threads is used exactly one)
If you have only 4 threads:
? default(nbthreads,4)
? parvector(8,i,random())
%6 = [1546275796,1546275796,1546275796,1546275796,879788114,879788114,879788114,1745191708]
? parvector(8,i,random())
%7 = [1546275796,1546275796,1546275796,1546275796,879788114,879788114,879788114,879788114]
? parvector(8,i,random())
%8 = [1546275796,1546275796,1546275796,1546275796,879788114,879788114,879788114,1745191708]
? parvector(8,i,random())
%9 = [1546275796,1546275796,1546275796,1546275796,879788114,879788114,879788114,1745191708]
(some threads are reused, so the random state is reused).
As rule, nothing is shared between threads, because we also support MPI (where threads do not share
memory).
To avoid this, you can use setrand to provides different starting state to each threads:
? my(V=vector(8,i,random()));parvector(8,i,setrand(V[i]);random())
%13 = [1834362136,1880444699,481818904,410565656,466627378,2013381622,67736138,1882161884]
Cheers,
Bill.