|
ヘルプとsample program を参考にして、手探り状態です。
DECLARE STRUCTURE struct1: 1 OF NUMERIC
DECLARE STRUCTURE struct2: NUMERIC(3401)
DECLARE SHARED shar OF struct2
DECLARE MESSAGE mess1 OF struct1
DECLARE MESSAGE mess2 OF struct1
DECLARE MESSAGE mess3 OF struct1
paract par1
OPTION ARITHMETIC NATIVE
DECLARE NUMERIC A(3401)
LET k6=31607
LET k2=3401
DECLARE EXTERNAL SUB prime
CALL prime(k6)
WAIT EVENT ok1
GET from shar TO A
START par2
START par3
START par4
PRINT A(1);"par1"
!DECLARE NUMERIC x,y,z
RECEIVE FROM mess1 TO x
PRINT x;"par2 mess1"
RECEIVE FROM mess2 TO y
PRINT y;"par3 mess2"
RECEIVE FROM mess3 TO z
PRINT z;"par4 mess3"
PRINT A(8);"par1"
END PARACT
paract par2
OPTION ARITHMETIC NATIVE
DECLARE NUMERIC A(3401)
!DECLARE NUMERIC B
GET FROM shar TO A
PRINT A(2);"par2"
LET B=A(5)
SEND TO mess1 FROM B
END paract
paract par3
OPTION ARITHMETIC NATIVE
DECLARE NUMERIC A(3401)
!DECLARE NUMERIC B
GET from shar TO A
PRINT A(3);"par3"
LET B=A(6)
SEND TO mess2 FROM B
END paract
paract par4
OPTION ARITHMETIC NATIVE
DECLARE NUMERIC A(3401)
!DECLARE NUMERIC B
GET from shar TO A
PRINT A(4);"par4"
LET B=A(7)
SEND TO mess3 FROM B
END paract
EXTERNAL SUB prime(k6)!エラトステネスの篩
OPTION ARITHMETIC NATIVE
DECLARE NUMERIC A(3401)!素数
LET Fu=k6
DIM P(Fu)
MAT P=ZER
LET A(1)=2
LET H1=1
FOR I=3 TO SQR(Fu) STEP 2
IF P(I)=0 THEN
FOR J=I*I TO Fu STEP I
LET P(J)=1
NEXT J
END IF
NEXT I
FOR I=3 TO Fu STEP 2
IF P(I)=0 THEN
LET H1=H1+1
LET A(H1)=I
END IF
NEXT I
PUT TO shar FROM A
signal ok1
END SUB
------------------------------
paract par1
DECLARE EXTERNAL SUB prime
素数を共有配列に登録して
それから
START par2
START par3
START par4
色々試せます。
このプログラムを1コアCPUで実行すると
2 par1
3 par2
5 par3
7 par4
11 par2 mess1
13 par3 mess2
17 par4 mess3
19 par1
4コアCPUで実行すると
3 par2
2 par1
11 par2 mess1
5 par3
13 par3 mess2
7 par4
17 par4 mess3
19 par1
違いが出ます。
私のPCでは、それぞれのparact parから計算結果を集計する時
DECLARE MESSAGE mess1 OF struct1
SEND TO mess1 FROM B
RECEIVE FROM mess1 TO x
これがやさしい。と、思いました。
http://blogs.yahoo.co.jp/donald_stinger
|
|