0
(0)

とある方から、 CUDA が CPU より高速計算可能なら superpi (スーパーπ)も高速計算できるのではないか?と打診があった。

[amazon_enhanced asin=”6131235538″ container=”” container_class=”” price=”All” background_color=”FFFFFF” link_color=”000000″ text_color=”0000FF” /]   [amazon_enhanced asin=”B00264YQ80″ container=”” container_class=”” price=”All” background_color=”FFFFFF” link_color=”000000″ text_color=”0000FF” /]

が、並列計算用に書き直しが発生すること、現状の superpi は GMP(任意精度計算関数・ライブラリ)を主とするものがメジャー。

まずは GMP 環境用の superpi cpp ソースを見直して、

書き直してみることに。

■環境: Windows 7 Professional x64 SP1
+ cygwin CYGWIN_NT-6.1-WOW64 Lets-note 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin

■gmp 導入 http://gmplib.org/ から Download でソースパッケージ入手する。

GNU libraries
* gmp: (gmp). GNU Multiple Precision Arithmetic Library.
http://gmplib.org/
http://gmplib.org/

■ ソース入手 → ftp://ftp.gmplib.org/pub/gmp-5.0.2/gmp-5.0.2.tar.gz

入手後 gzip -dc gmp-5.0.2.tar.gz | tar xvf – で tar ball を解凍したものを 適当なワークスペース (/home/yukio/gmpなど) へ配置し

そこで、

./configure ⇒ make ⇒ make check ⇒ make install

そして、(必要に応じ LIB_PATH を) 通してあげて、 /usr/local/libgmp-5.0.2/ をコンパイル時に参照できるようにする。

メモ:make してるときに、マシンが SandyBridge 等であっても C2D としか認識できないので (拘るなら、intel 純正コンパイラを買えよ!って話。買ったところで、もっと難解な世界しかありませんがw)、

gmp-mparam.h -> mpn/x86/p6/sse2/gmp-mparam.h こんな感じにヘッダ配置されます。

ーーー

■導入した様子

gmp-5.0.2
gmp-5.0.2

オマケ: perl でも gmp 使いたい場合は、/gmp-5.0.2/demos/perl/ から perl Malefile.pl, make が必要。

perl での実行結果:

$ perl -Iblib/arch sample.pl
$# is no longer supported at GMP/Mpf.pm line 75.
using GMP module 2.00 and GMP library 5.0.2
the 200th fibonacci number is 280571172992510140037611932413038677189525
next prime after 10**30 is (probably) 1000000000000000000000000000057
the 7th harmonic number is 363/140
a sample mpf is 1.0000000000000000000000000000000000000000000000000000006525

↑↑あまり精度が高くないやん。。。

■ superpi 実行結果の検証サイト

金田研究室を使うのが一番です。

http://www.super-computing.org/index.html

(1) First 500 digits (1 - 500)
3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 0628620899 8628034825 3421170679 8214808651 3282306647 0938446095 5058223172 5359408128 4811174502 8410270193 8521105559 6446229489 5493038196 4428810975 6659334461 2847564823 3786783165 2712019091 4564856692 3460348610 4543266482 1339360726 0249141273 7245870066 0631558817 4881520920 9628292540 9171536436 7892590360 0113305305 4882046652 1384146951 9415116094 3305727036 5759591953 0921861173 8193261179 3105118548 0744623799 6274956735 1885752724 8912279381 8301194912
(2) 500 digits ending Trillion-th (American) or Billion-th (British) (999,999,999,501 - 1,000,000,000,000) 3055541549 8630733226 9301895353 2800395568 4100135112 3018054466 7139616326 7123847333 9482691454 3860916430 1625543455 2814410067 9794539929 7396506499 6259579620 9832690772 9598209368 0476885637 4803576440 0887706440 9994610239 6615201174 0666595802 7919531531 8903915600 4823850597 7919334089 3525800653 2108289606 0294989554 9184899441 7318925720 9460412978 6725653700 4298366088 7081085596 4376680868 4559824388 6457656156 6050890585 2962457053 9070959679 6673211870 6342459769 2128529850 2976735807 0882130902 2460461146 5810642210 6680122702
(3) 500 digits ending 1,241,100,000,000-th (1,241,099,999,501 - 1,241,100,000,000) 3716787169 6567692125 2797286901 8503557537 6530193499 3533850167 1616469990 5984454421 7623131551 5483436562 7806800557 0748706663 5108659327 6579461496 7987525534 7689068277 7037671632 7753867760 1776471900 9279382597 6527339324 6948904759 2872702485 4618972965 3547547082 4504016840 2350653293 6254205392 4502959326 3809170954 8310279798 7965959470 8455199922 4435552002 5054585883 0997016164 9607402417 5296690907 5622217705 1785600450 0707455198 1744551596 6313820124 4825046054 2311034186 5591198918 2262704528 2696896699 2856706487 3410311045

で、検証できますね。
時間計測もお忘れなく。

さてと、cpp から cuda 移植を考えましょうか。

以上

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

投稿者 斉藤之雄 (Yukio Saito)

Global Information and Communication Technology OTAKU / Sports volunteer / Social Services / Master of Technology in Innovation for Design and Engineering, AIIT / BA, Social Welfare, NFU / twitter@yukio_saitoh