我正在使用 CURAND 库在 CUDA 中编写随机生成代码。我读到的关于随机生成的内容让我相信,如果我使用相同的种子,我将得到相同的随机数集。但是当我测试它时,情况并非如此。请解释我做错了什么。我粘贴下面的代码以供参考:
curandGenerator_t rand_gen;
status = curandCreateGenerator (&rand_gen ,CURAND_RNG_PSEUDO_DEFAULT );
if(status != CURAND_STATUS_SUCCESS){
printf("Error encountered in generating handle\n");
}
status = curandSetPseudoRandomGeneratorSeed (rand_gen ,1234ULL);
if(status != CURAND_STATUS_SUCCESS){
printf("Error encountered in setting seed\n");
}
for(j=0; j<2; j++){
status = curandGenerate(rand_gen,a_d,N);
if(status != CURAND_STATUS_SUCCESS){
printf("Error encountered in generating random numbers\n");
}
cudaMemcpy ( a_h , a_d , N * sizeof(unsigned int),cudaMemcpyDeviceToHost);
for(i = 0; i < N; i++){
printf("%d : %u\n",i,a_h[i]);
}
printf("-----------%d----------------------\n",j);
}
status = curandDestroyGenerator(rand_gen);
if(status != CURAND_STATUS_SUCCESS){
printf("Error encountered in destroying handle\n");
}
输出:
0:624778773
1:3522650202
2:2363946444
3:3:326286439
4: 3:326286439 4:3:
3732235839 7:
3382235839
7:322599309
8: 1225999309
8 :
1225999208 - - - - - - - - -
------
4
:2220575578
_
_
_
_
_
_
_
_ ------1------------------------