フィルターのクリア

Speed up 3D rand

1 回表示 (過去 30 日間)
Basil Tsekenis
Basil Tsekenis 2022 年 12 月 12 日
コメント済み: Bruno Luong 2022 年 12 月 12 日
I was wondering if I could so anything to speed up the process of generating random matrices.
For instance,
tic
rand(1000, 1000, 1000)
toc
gives 7-9 sec as a result.
Using this line in a monte carlo simulation of 100000 repetitions means that the program will need at least 277 hours.. I read that CUDA could be handy but my GPU doesn't support it.
  8 件のコメント
Bora Eryilmaz
Bora Eryilmaz 2022 年 12 月 12 日
You must be accessing the elements of the random matrix in a for-loop or something. I can't imagine you would be doing direct array operations on the whole random array since that would quickly grind your computer to a halt. So assuming you are using some kind of loop to access "parts" of the random array, you could just generate random numbers for that part as needed, and not in advance.
Bruno Luong
Bruno Luong 2022 年 12 月 12 日
OP wants to speed up, not necessary to reduce memory.

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2022 年 12 月 12 日
tic
A = rand(1000, 1000, 1000);
t = toc
t = 9.4093
So on average rand generated 1 number every:
format longg
s = seconds(t/numel(A))
s = duration
9.409342e-09 sec
about 10 nanoseconds. What's your requirement for how fast generating a random number needs to be for your application? That will tell us if what you want to do is theoretically feasible.
The SIMD-oriented Fast Mersenne Twister may be a bit faster (see the rng function for how to enable this version) but if you're looking for this to take a millisecond to generate that whole array I think that's likely not achievable.

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by