Raspberry Pi 4Bは1.5GHzで動作していますから1,800MIPS/core以上の処理能力があるはずです。GILがありインタープリターのRaspberry PiのPythonでも17MB/sのTCP送受信ができます。MIPSというのは最近あまり使わないのでマイナーですがアセンブラ言語では意識されます。シリアル通信は29Kbps、57Kbps、115Kbpsの速度です。Windowsはハイパーターミナルが消えましたが、今でもダメな時はまずシリアルです。一方、LANの速度は普通で1Gbpsです。そしてTCP/IP、USB2以上、さらにSDカードではアセンブラのライブラリーは見かけることはありません。特にTCP/IPスタックは膨大です。また出だしから脈絡のない話で何を言っているのか分からなくなりましたが、今回の主題は、複数台を使う分散処理により、整数型で高次方程式を解くプログラムです。
100次、1000次の高次方程式では1台の4core並列処理だけでは長時間かかります。そこで2台で分散処理すれば計算時間は1/2、3台では1/3、4台では1/4になります。プログラムは高次方程式の計算部分本体が律速です。この部分を複数台に分ければ、台数分で計算時間は短縮されます。またこの計算部分本体の計算時間が数時間であることに対して、LAN通信の遅延は数秒です。複数台のLAN通信での分散処理が、計算時間の短縮に大きなメリットがあります。次に今回の分散処理で使った複数台のLAN構成を示します。
* 今回の予定は「整数型で高次方程式を解く=分散並列処理=」でしたが、タイトルだけ変更しました。内容は同じです。
#分散処理LANの基本ユニット
5ポートのギガビットスイッチングハブでLANを構成しています。
計算結果 → → File Size
┌──────────────┳━┓ 60MB
│ ┌───────────┨P┃
│ │ ┌────────┨O┃ Speed
│ │ │ ┌─────┨R┃ 17MB/s
┌┴┐┌┴┐┌┴┐┌┴┐ ┃T┃
│1││2││3││4│ ┃5┃
└┬┘└┬┘└┬┘└┬┘ ┗┯┛
│ │ │ │ ├───┬───┬───┐
│ │ │ │ │ │ │ │
┌┴┐┌┴┐┌┴┐┌┴┐ ┌┴┐ ┌┴┐ ┌┴┐ ┌┴┐
│2││2││2││2│ │A│ │B│ │C│ │D│
│1││2││3││4│ ┣━┷━┷━┷━┷━┷━┷━┫
└─┘└─┘└─┘└─┘ ┃ 集計用RPi4B 20 ┃
計算用 RPi4B 4台 ┗━━━━━━━━━━━━━┛
各1core送受信 4core送受信
Core To Core
固定IPアドレスを使い、OSのアップグレード時以外はハブでLANを構成しています。計算用4台と集計用1台です。TCPのsocket通信は、同じRaspberry Pi 4B同士のCoreToCoreです。同じ機種でのCoreToCore通信ですから送受信のタイムミングが大変よく合います。ただ受信側では受信バッファーを別変数(大容量)に追記する重いステップがあるのと比較して、送信側では小さな14400byteを送信バッファーへ書き込むだけの軽いステップですから、受信側に1タイムラグの遅延があるようです。次に作成した分散処理のプログラムを示します。
#分散並列処理のプログラム簡易版
計算用1台と集計用1台の最小構成です。
②計算結果 --> ┏━┓ File Size
┌─────────────┨P┃ 4MB
│ <-- ①パラメーター ┃O┃
│ ┃R┃ Speed
┌┴┐ ┃T┃ 10MB/s
│1│ ┃5┃
└┬┘ ┗┯┛
│ │
┌┴┐ ┌┴┐
│2│ │A│
│1│ ┣━┷━━━━━━━━━━━┓
└─┘ ┃ 集計用RPi4B 20 ┃
計算用RPi4B 1台 ┗━━━━━━━━━━━━━┛
1core送受信 1core送受信
(4core計算)
計算用が1台しかないので分散処理とは言えないですが、台数を増やす前の確認のために作成したプログラムです。Raspberry Pi 4B メモリー2GB 1台とPC Windows 10版Python IDLE 1台の混成でも、さらに計算用と集計用を入れ替えても、動きました。試行はしていませんが、Mac版Python IDLEでも動くかもしれません。Pythonプログラムが動けば、あとはノード間のTCP通信ですから、LANケーブルが接続されLEDが点灯していて、IPaddressとportが合っていれば、基本的には通信できるはずです。固定IPアドレスです。
プログラム上、TCP通信はmultiprocessingの1プロセスで送受信します。計算部分は4coreを使う4プロセスです。以下にプログラムを示します。最初が計算用のプログラムtrib-calc1.pyです。その次が集計用のプログラムtrib-total1.pyです。(後日記:Mac OSではプログラム中の14400を8192へ変更した方がいいかもしれません。送受信速度が遅いだけで他に支障はないと思いますが。TCPはOSに依存していますから。)
import time
import socket
from multiprocessing import Manager, Process
def f1(List1, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
Ypre=0
print(f" core 1 start")
for X in range( int(X_init), int(X_end)+1 ):
Y=1
for j in range(0, Ji_su):
Y *= (X-Ksu[j])
#Y=0
#for j in range(0, Ji_su+1):
# Y += Ksu[j]*(X**j)
if X == int(X_init):
Ypre=Y
List1.pop(0)
if Ypre * Y > 0:
Ypre=Y
else:
if Y == 0:
Y=Y
List1.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)), Y ))
else:
Ypre=Y
List1.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)), Y ))
def f2(List2, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
Ypre=0
print(f" core 2 start")
for X in range( int(X_init), int(X_end)+1 ):
Y=1
for j in range(0, Ji_su):
Y *= (X-Ksu[j])
#Y=0
#for j in range(0, Ji_su+1):
# Y += Ksu[j]*(X**j)
if X == int(X_init):
Ypre=Y
List2.pop(0)
if Ypre * Y > 0:
Ypre=Y
else:
if Y == 0:
Y=Y
List2.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)), Y ))
else:
Ypre=Y
List2.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)), Y ))
def f3(List3, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
Ypre=0
print(f" core 3 start")
for X in range( int(X_init), int(X_end)+1 ):
Y=1
for j in range(0, Ji_su):
Y *= (X-Ksu[j])
#Y=0
#for j in range(0, Ji_su+1):
# Y += Ksu[j]*(X**j)
if X == int(X_init):
Ypre=Y
List3.pop(0)
if Ypre * Y > 0:
Ypre=Y
else:
if Y == 0:
Y=Y
List3.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)), Y ))
else:
Ypre=Y
List3.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)), Y ))
def f4(List4, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
Ypre=0
print(f" core 4 start")
for X in range( int(X_init), int(X_end)+1 ):
Y=1
for j in range(0, Ji_su):
Y *= (X-Ksu[j])
#Y=0
#for j in range(0, Ji_su+1):
# Y += Ksu[j]*(X**j)
if X == int(X_init):
Ypre=Y
List4.pop(0)
if Ypre * Y > 0:
Ypre=Y
else:
if Y == 0:
Y=Y
List4.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)), Y ))
else:
Ypre=Y
List4.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)), Y ))
if __name__=="__main__":
ipaddressAcceptFrom = '192.168.2.21'#IP address
portAcceptFrom = 60021
ipaddressSendTo = '192.168.2.20'#total IP address
portSendTo = 60021
## Parameter Accept
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ipaddressAcceptFrom, portAcceptFrom))
s.listen(5)
clientsocket, address = s.accept()
print(f"Connection from {address}")
tmp0en = b''
tmp0en = clientsocket.recv(1046)
tmp0str = tmp0en.decode("utf-8")
tmp0str = tmp0str.replace('[', '')
tmp0str = tmp0str.replace(']', '')
list_tmp0str = []
list_tmp0str = tmp0str.split(', ')
list0int = int(list_tmp0str[0])
xx_from = int(list_tmp0str[1])
xx_to = int(list_tmp0str[2])
r_f = int(list_tmp0str[3])
ji_su = int(list_tmp0str[4])
y_zoom = int(list_tmp0str[5])
print(f"Parameters accepted")
print(f"from :")
print(xx_from)
print(f"to :")
print(xx_to)
print(f"resolution :")
print(r_f)
print(f"oder :")
print(ji_su)
print(f"y axis zoom :")
print(y_zoom)
list0str = str(list0int)
clientsocket.send(bytes(list0str, 'utf-8'))
q, mod = divmod(list0int, 14400)
list1stren1 = b''
list1stren2 = b''
list1stren3 = b''
list1stren4 = b''
list1stren5 = b''
if mod > 0:
q += 1
while True:
if len(list1stren1)+len(list1stren2)+len(list1stren3)+\
len(list1stren4)+len(list1stren5) >= list0int:
break
if len(list1stren1) < 2500000:
list1stren1 += clientsocket.recv(14400)
elif len(list1stren2) < 2500000:
list1stren2 += clientsocket.recv(14400)
elif len(list1stren3) < 2500000:
list1stren3 += clientsocket.recv(14400)
elif len(list1stren4) < 2500000:
list1stren4 += clientsocket.recv(14400)
else :
list1stren5 += clientsocket.recv(14400)
print('recv finished')
list1str1 = list1stren1.decode("utf-8")
list1str2 = list1stren2.decode("utf-8")
list1str3 = list1stren3.decode("utf-8")
list1str4 = list1stren4.decode("utf-8")
list1str5 = list1stren5.decode("utf-8")
list1str = list1str1
list1str += list1str2
list1str += list1str3
list1str += list1str4
list1str += list1str5
if list0int==len(list1str):
print('length OK')
clientsocket.close()
s.close()
print('server closed')
print(' ')
list1str = list1str.replace('[', '')
list1str = list1str.replace(']', '')
ksu_init = []
ksu_init = list1str.split(', ')
## Calculation Start
with Manager() as manager:
list1 = manager.list(range(1))
list2 = manager.list(range(1))
list3 = manager.list(range(1))
list4 = manager.list(range(1))
initial_time=time.time()
print(f"Calcilation Start")
print(f" Please wait for 1 minute.")
Xfrom = xx_from
Xto = xx_to
Xrange = Xto - Xfrom
ksu=[]
for i in range(len(ksu_init)):
ksu.append( int(ksu_init[i]) )
p1 = Process(target=f1, args=(list1,r_f,ji_su,y_zoom,Xfrom+0*Xrange/4,Xfrom+1*Xrange/4,ksu))
p1.start()
p2 = Process(target=f2, args=(list2,r_f,ji_su,y_zoom,Xfrom+1*Xrange/4,Xfrom+2*Xrange/4,ksu))
p2.start()
p3 = Process(target=f3, args=(list3,r_f,ji_su,y_zoom,Xfrom+2*Xrange/4,Xfrom+3*Xrange/4,ksu))
p3.start()
p4 = Process(target=f4, args=(list4,r_f,ji_su,y_zoom,Xfrom+3*Xrange/4,Xfrom+4*Xrange/4,ksu))
p4.start()
print(f" 4 core start")
p1.join()
p2.join()
p3.join()
p4.join()
print(f" 4 core finished")
end_time=time.time()
list00str = ''
list00str += str(list1)+str(list2)+str(list3)+str(list4)
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.connect((ipaddressSendTo, portSendTo))
len_list00str = len(list00str)
len_list00str_str = str(len_list00str)
s1.send(bytes(len_list00str_str, 'utf-8'))
re_len0en = b''
re_len0en = s1.recv(1046)
re_len0str = re_len0en.decode("utf-8")
if re_len0str == len_list00str_str:
print(' length OK')
print(' sending start')
time.sleep(1)
q, mod = divmod(len_list00str, 14400)
for i in range(q):
temp_00str = list00str[14400*i:14400*(i+1)]
s1.send(bytes(temp_00str, 'utf-8'))
time.sleep(0.0001)
if mod > 0:
temp_00str = list00str[14400*q:]
s1.send(bytes(temp_00str, 'utf-8'))
s1.close()
print(f"Calcilation Finished")
print(f"")
print(f"Time :")
print(end_time - initial_time)
if re_len0str == len_list00str_str:
print('length OK')
print('sending finished')
print('server closed')
time.sleep(10)
次が集計用のプログラムです。selectを使う予定だったのですができませんでした。またいつか試行しようと思っています。
import time
import socket
from multiprocessing import Manager, Process
def f1p(List1p,IPaddress1p,Port1p,X1p_from,X1p_to,R_f,Ji_su,Y_zoom):
List1p_str = str(List1p)
len_List1p_str = len(List1p_str)
list_tmp=[len_List1p_str, X1p_from, X1p_to, R_f, Ji_su, Y_zoom]
list_tmp_str = str(list_tmp)
s1p = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1p.connect((IPaddress1p, Port1p))
s1p.send(bytes(list_tmp_str, 'utf-8'))
time.sleep(1)
re_len0en = b''
re_len0en = s1p.recv(1046)
int_re_len0str = int(re_len0en.decode("utf-8"))
time.sleep(1)#splitting
q, mod = divmod(len_List1p_str, 14400)
for i in range(q):
temp_00str = List1p_str[14400*i:14400*(i+1)]
s1p.send(bytes(temp_00str, 'utf-8'))
time.sleep(0.0001)
if mod > 0:
temp_00str = List1p_str[14400*q:]
s1p.send(bytes(temp_00str, 'utf-8'))
if int_re_len0str == len_List1p_str:
print('Process 0 Sending Complite')
s1p.close()
def f1r(List1r, IPaddress1r, Port1r):
s1r = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1r.bind((IPaddress1r, Port1r))
s1r.listen(5)
clientsocket, address = s1r.accept()
print(f"Connection from {address}")
list1en = b''
list1en = clientsocket.recv(1046)
list1str = list1en.decode("utf-8")
clientsocket.send(bytes(list1str, 'utf-8'))
len_list1str = int(list1str)
q, mod = divmod(len_list1str, 14400)
list1stren1 = b''
list1stren2 = b''
list1stren3 = b''
list1stren4 = b''
list1stren5 = b''
if mod > 0:
q += 1
while True:
if len(list1stren1)+len(list1stren2)+len(list1stren3)+\
len(list1stren4)+len(list1stren5) >= len_list1str:
break
if len(list1stren1) < 2500000:
list1stren1 += clientsocket.recv(14400)
elif len(list1stren2) < 2500000:
list1stren2 += clientsocket.recv(14400)
elif len(list1stren3) < 2500000:
list1stren3 += clientsocket.recv(14400)
elif len(list1stren4) < 2500000:
list1stren4 += clientsocket.recv(14400)
else :
list1stren5 += clientsocket.recv(14400)
print('recv finished')
list1str1 = list1stren1.decode("utf-8")
list1str2 = list1stren2.decode("utf-8")
list1str3 = list1stren3.decode("utf-8")
list1str4 = list1stren4.decode("utf-8")
list1str5 = list1stren5.decode("utf-8")
list1str = list1str1
list1str += list1str2
list1str += list1str3
list1str += list1str4
list1str += list1str5
if len_list1str==len(list1str):
print('length OK')
clientsocket.close()
s1r.close()
print('server closed')
List1r.pop(0)
List1r.append(list1str)
if __name__=="__main__":
ipaddress1p = '192.168.2.21'
port1p = 60021
ipaddress1r = '192.168.2.20'
port1r = 60021
RPi_number = 1
xx_from = 0.949
xx_to = 1.051
r_f = 1000000
ji_su = 1000
y_zoom = 200
ksu_init = []
ksu_temp = 0.9499
for i in range(ji_su+1):
ksu_temp += 0.0001
ksu_init.append(int(ksu_temp*r_f))
with Manager() as manager:
## Parameter Sending Start
Xfrom = int(r_f*xx_from)
Xto = int(r_f*xx_to)
Xrange = Xto - Xfrom
list1p = manager.list(range(1))
list1p.pop(0)
for i in range(len(ksu_init)):
list1p.append(ksu_init[i])
x1p_from = int(Xfrom+0*Xrange/RPi_number)#*
x1p_to = int(Xfrom+1*Xrange/RPi_number)#*
p1p = Process(target=f1p, args=(list1p,ipaddress1p,port1p,x1p_from,x1p_to,r_f,ji_su,y_zoom))
p1p.start()
p1p.join()
## Result Accepting Start
list1r = manager.list(range(1))
p1r = Process(target=f1r, args=(list1r, ipaddress1r, port1r))
p1r.start()
p1r.join()
print(list1r)
time.sleep(10)
計算用trib-calc1.pyを先に実行します。後で集計用trib-total1.pyを実行するとパラメーターを送信して計算が開始されます。計算側の台数を2台、3台、4台と増やすと、計算時間は1/2、1/3、1/4になります。次に計算側2台と集計側1台でのプログラムを示します。
#分散並列処理のプログラム2台構成
計算用を1台増やし、計算用2台と集計用1台の3台構成です。
②計算結果 --> ┏━┓ File Size
┌─────────────┨P┃ 4MB
│ <-- ①パラメーター ┃O┃
│ ┌──────────┨R┃ Speed
┌┴┐┌┴┐ ②計算結果 ->┃T┃ 10MB/s
│1││2│ ┃5┃
└┬┘└┬┘ ┗┯┛
│ │ ├───┐
┌┴┐┌┴┐ ┌┴┐ ┌┴┐
│2││2│ │A│ │B│
│1││2│ ┣━┷━┷━┷━━━━━━━┓
└─┘└─┘ ┃ 集計用RPi4B 20 ┃
計算用RPi4B 2台 ┗━━━━━━━━━━━━━┛
1core送受信 1core送受信
(4core計算)
これもPC Windows 10版Python IDLE との混成でも動きます。試行はしていませんが、Mac版Python IDLEでも動くかもしれません。固定IPアドレスです。(後日記:Mac OSではプログラム中の14400を8192へ変更した方がいいかもしれません。送受信速度が遅いだけで他に支障はないと思いますが。TCPはOSに依存していますから。)
計算用の1台目と2台目のプログラムtrib-calc2-1.pyとtrib-calc2-2.pyです。最後が計算用2台から結果を受信する集計用のプログラムtrib-total2.pyです。ここでは、整数型で高次方程式を解くManager編の1000次方程式16core版と同じ10次方程式を解いています。
import time
import socket
from multiprocessing import Manager, Process
ipaddressAcceptFrom = '192.168.2.21'#IP address
portAcceptFrom = 60021
ipaddressSendTo = '192.168.2.20'#total IP address
portSendTo = 60021
def f0(List0, List0b, List0c, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
Ypre =0
YYpre =0
YYYpre =0
for X in range( int(X_init), int(X_end)+1 ):
Y=0
for j in range(0, Ji_su+1):
Y += Ksu[j]*(X**j)
YY=0
for j in range(0, Ji_su):
YY += (j+1)*Ksu[j+1]*(X**j)
YYY=0
for j in range(0, Ji_su-1):
YYY += (j+1)*(j+2)*Ksu[j+2]*(X**j)
if X == int(X_init):
Ypre =Y
YYpre =YY
YYYpre =YYY
List0.pop(0)
List0b.pop(0)
List0c.pop(0)
## Y : Simple x axis cross method ##
if Ypre * Y > 0:
Ypre=Y
else:
if Y == 0:
Y=Y
List0.append(( X/R_f, X, Y/(R_f**(Ji_su-Y_zoom)), Y ,333 ))
else:
X_tmp = X-1
Y_tmp = 0
for k in range(0, Ji_su+1):
Y_tmp += Ksu[k]*(X_tmp**k)
List0.append(( X_tmp/R_f, X_tmp, Y_tmp/(R_f**(Ji_su-Y_zoom)), Y_tmp, 666 ))
Ypre=Y
## YY even: Simple x axias cross method ##
if YYpre * YY > 0:
YYpre=YY
else:
if YY == 0:
YY=YY
List0b.append(( X/R_f, X, YY/(R_f**(Ji_su-Y_zoom)), YY, 333 ))
else:
X_tmp = X-1
YY_tmp = 0
for k in range(0, Ji_su):
YY_tmp += (k+1)*Ksu[k+1]*(X_tmp**k)
List0b.append(( X_tmp/R_f, X_tmp, YY_tmp/(R_f**(Ji_su-Y_zoom)), YY_tmp, 666 ))
YYpre=YY
## YYY odd: Simple x axias cross method ##
if YYYpre * YYY > 0:
YYYpre=YYY
else:
if YYY == 0:
YYY=YYY
List0c.append(( X/R_f, X, YYY/(R_f**(Ji_su-Y_zoom)), YYY, 333 ))
else:
X_tmp = X-1
YYY_tmp = 0
for k in range(0, Ji_su-1):
YYY_tmp += (k+1)*(k+2)*Ksu[k+2]*(X_tmp**k)
List0c.append(( X_tmp/R_f, X_tmp, YYY_tmp/(R_f**(Ji_su-Y_zoom)), YYY_tmp, 666 ))
YYYpre=YYY
if __name__=="__main__":
## Parameter recv
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ipaddressAcceptFrom, portAcceptFrom))
s.listen(5)
clientsocket, address = s.accept()
print(f"Connection from {address}")
tmp0en = b''
tmp0en = clientsocket.recv(1046)
tmp0str = tmp0en.decode("utf-8")
tmp0str = tmp0str.replace('[', '')
tmp0str = tmp0str.replace(']', '')
list_tmp0str = []
list_tmp0str = tmp0str.split(', ')
list0int = int(list_tmp0str[0])
xx_from = int(list_tmp0str[1])
xx_to = int(list_tmp0str[2])
r_f = int(list_tmp0str[3])
ji_su = int(list_tmp0str[4])
y_zoom = int(list_tmp0str[5])
print(f"Parameters accepted")
print(f"from :")
print(xx_from)
print(f"to :")
print(xx_to)
print(f"resolution :")
print(r_f)
print(f"oder :")
print(ji_su)
print(f"y axis zoom :")
print(y_zoom)
list0str = str(list0int)
clientsocket.send(bytes(list0str, 'utf-8'))
q, mod = divmod(list0int, 14400)
list1stren1 = b''
list1stren2 = b''
list1stren3 = b''
list1stren4 = b''
list1stren5 = b''
if mod > 0:
q += 1
while True:
if len(list1stren1)+len(list1stren2)+len(list1stren3)+\
len(list1stren4)+len(list1stren5) >= list0int:
break
if len(list1stren1) < 2500000:
list1stren1 += clientsocket.recv(14400)
elif len(list1stren2) < 2500000:
list1stren2 += clientsocket.recv(14400)
elif len(list1stren3) < 2500000:
list1stren3 += clientsocket.recv(14400)
elif len(list1stren4) < 2500000:
list1stren4 += clientsocket.recv(14400)
else :
list1stren5 += clientsocket.recv(14400)
print('recv finished')
list1str1 = list1stren1.decode("utf-8")
list1str2 = list1stren2.decode("utf-8")
list1str3 = list1stren3.decode("utf-8")
list1str4 = list1stren4.decode("utf-8")
list1str5 = list1stren5.decode("utf-8")
list1str = list1str1
list1str += list1str2
list1str += list1str3
list1str += list1str4
list1str += list1str5
if list0int==len(list1str):
print('length OK')
clientsocket.close()
s.close()
print('server closed')
print(' ')
list1str = list1str.replace('[', '')
list1str = list1str.replace(']', '')
ksu_init = []
ksu_init = list1str.split(', ')
## Calculation Start
with Manager() as manager:
list1 = manager.list(range(1))
list1b = manager.list(range(1))
list1c = manager.list(range(1))
list2 = manager.list(range(1))
list2b = manager.list(range(1))
list2c = manager.list(range(1))
list3 = manager.list(range(1))
list3b = manager.list(range(1))
list3c = manager.list(range(1))
list4 = manager.list(range(1))
list4b = manager.list(range(1))
list4c = manager.list(range(1))
initial_time=time.time()
print(f"Calcilation Start")
print(f" Please wait for 1 minute.")
Xfrom = xx_from
Xto = xx_to
Xrange = Xto - Xfrom
ksu=[]
for i in range(len(ksu_init)):
ksu.append( (r_f**(ji_su-i))*int(float(ksu_init[i])) )
p1 = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom,Xfrom+0*Xrange/4,Xfrom+1*Xrange/4,ksu))
p1.start()
p2 = Process(target=f0, args=(list2,list2b,list2c,r_f,ji_su,y_zoom,Xfrom+1*Xrange/4,Xfrom+2*Xrange/4,ksu))
p2.start()
p3 = Process(target=f0, args=(list3,list3b,list3c,r_f,ji_su,y_zoom,Xfrom+2*Xrange/4,Xfrom+3*Xrange/4,ksu))
p3.start()
p4 = Process(target=f0, args=(list4,list4b,list4c,r_f,ji_su,y_zoom,Xfrom+3*Xrange/4,Xfrom+4*Xrange/4,ksu))
p4.start()
print(f" 4 core start")
p1.join()
p2.join()
p3.join()
p4.join()
print(f" 4 core finished")
print(f"Calcilation Finished")
print(f"")
print(f"Time :")
print(str(time.time() - initial_time))
list00 =[]
print(f"Answers Y:")
str_AnsY=("Answers Y:",)
list00.append(str_AnsY)
for i in range(len(list1)):
print(list1[i])
list00.append(list1[i])
for i in range(len(list2)):
print(list2[i])
list00.append(list2[i])
for i in range(len(list3)):
print(list3[i])
list00.append(list3[i])
for i in range(len(list4)):
print(list4[i])
list00.append(list4[i])
print(f"Answers YY even:")
str_AnsYY=("Answers YY even:",)
list00.append(str_AnsYY)
for i in range(len(list1b)):
print(list1b[i])
list00.append(list1b[i])
for i in range(len(list2b)):
print(list2b[i])
list00.append(list2b[i])
for i in range(len(list3b)):
print(list3b[i])
list00.append(list3b[i])
for i in range(len(list4b)):
print(list4b[i])
list00.append(list4b[i])
print(f"Answers YYY odd:")
str_AnsYYY=("Answers YYY odd:",)
list00.append(str_AnsYYY)
for i in range(len(list1c)):
print(list1c[i])
list00.append(list1c[i])
for i in range(len(list2c)):
print(list2c[i])
list00.append(list2c[i])
for i in range(len(list3c)):
print(list3c[i])
list00.append(list3c[i])
for i in range(len(list4c)):
print(list4c[i])
list00.append(list4c[i])
list00str = str(list00)
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.connect((ipaddressSendTo, portSendTo))
len_list00str = len(list00str)
len_list00str_str = str(len_list00str)
s1.send(bytes(len_list00str_str, 'utf-8'))
re_len0en = b''
re_len0en = s1.recv(1046)
re_len0str = re_len0en.decode("utf-8")
if re_len0str == len_list00str_str:
print(' length OK')
print(' sending start')
time.sleep(1)
q, mod = divmod(len_list00str, 14400)
for i in range(q):
temp_00str = list00str[14400*i:14400*(i+1)]
s1.send(bytes(temp_00str, 'utf-8'))
time.sleep(0.0001)
if mod > 0:
temp_00str = list00str[14400*q:]
s1.send(bytes(temp_00str, 'utf-8'))
s1.close()
if re_len0str == len_list00str_str:
print('length OK')
print('sending finished')
print('server closed')
time.sleep(10)
import time
import socket
from multiprocessing import Manager, Process
ipaddressAcceptFrom = '192.168.2.22'#IP address
portAcceptFrom = 60022
ipaddressSendTo = '192.168.2.20'#total IP address
portSendTo = 60022
def f0(List0, List0b, List0c, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
Ypre =0
YYpre =0
YYYpre =0
for X in range( int(X_init), int(X_end)+1 ):
Y=0
for j in range(0, Ji_su+1):
Y += Ksu[j]*(X**j)
YY=0
for j in range(0, Ji_su):
YY += (j+1)*Ksu[j+1]*(X**j)
YYY=0
for j in range(0, Ji_su-1):
YYY += (j+1)*(j+2)*Ksu[j+2]*(X**j)
if X == int(X_init):
Ypre =Y
YYpre =YY
YYYpre =YYY
List0.pop(0)
List0b.pop(0)
List0c.pop(0)
## Y : Simple x axis cross method ##
if Ypre * Y > 0:
Ypre=Y
else:
if Y == 0:
Y=Y
List0.append(( X/R_f, X, Y/(R_f**(Ji_su-Y_zoom)), Y ,333 ))
else:
X_tmp = X-1
Y_tmp = 0
for k in range(0, Ji_su+1):
Y_tmp += Ksu[k]*(X_tmp**k)
List0.append(( X_tmp/R_f, X_tmp, Y_tmp/(R_f**(Ji_su-Y_zoom)), Y_tmp, 666 ))
Ypre=Y
## YY even: Simple x axias cross method ##
if YYpre * YY > 0:
YYpre=YY
else:
if YY == 0:
YY=YY
List0b.append(( X/R_f, X, YY/(R_f**(Ji_su-Y_zoom)), YY, 333 ))
else:
X_tmp = X-1
YY_tmp = 0
for k in range(0, Ji_su):
YY_tmp += (k+1)*Ksu[k+1]*(X_tmp**k)
List0b.append(( X_tmp/R_f, X_tmp, YY_tmp/(R_f**(Ji_su-Y_zoom)), YY_tmp, 666 ))
YYpre=YY
## YYY odd: Simple x axias cross method ##
if YYYpre * YYY > 0:
YYYpre=YYY
else:
if YYY == 0:
YYY=YYY
List0c.append(( X/R_f, X, YYY/(R_f**(Ji_su-Y_zoom)), YYY, 333 ))
else:
X_tmp = X-1
YYY_tmp = 0
for k in range(0, Ji_su-1):
YYY_tmp += (k+1)*(k+2)*Ksu[k+2]*(X_tmp**k)
List0c.append(( X_tmp/R_f, X_tmp, YYY_tmp/(R_f**(Ji_su-Y_zoom)), YYY_tmp, 666 ))
YYYpre=YYY
if __name__=="__main__":
## Parameter recv
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ipaddressAcceptFrom, portAcceptFrom))
s.listen(5)
clientsocket, address = s.accept()
print(f"Connection from {address}")
tmp0en = b''
tmp0en = clientsocket.recv(1046)
tmp0str = tmp0en.decode("utf-8")
tmp0str = tmp0str.replace('[', '')
tmp0str = tmp0str.replace(']', '')
list_tmp0str = []
list_tmp0str = tmp0str.split(', ')
list0int = int(list_tmp0str[0])
xx_from = int(list_tmp0str[1])
xx_to = int(list_tmp0str[2])
r_f = int(list_tmp0str[3])
ji_su = int(list_tmp0str[4])
y_zoom = int(list_tmp0str[5])
print(f"Parameters accepted")
print(f"from :")
print(xx_from)
print(f"to :")
print(xx_to)
print(f"resolution :")
print(r_f)
print(f"oder :")
print(ji_su)
print(f"y axis zoom :")
print(y_zoom)
list0str = str(list0int)
clientsocket.send(bytes(list0str, 'utf-8'))
q, mod = divmod(list0int, 14400)
list1stren1 = b''
list1stren2 = b''
list1stren3 = b''
list1stren4 = b''
list1stren5 = b''
if mod > 0:
q += 1
while True:
if len(list1stren1)+len(list1stren2)+len(list1stren3)+\
len(list1stren4)+len(list1stren5) >= list0int:
break
if len(list1stren1) < 2500000:
list1stren1 += clientsocket.recv(14400)
elif len(list1stren2) < 2500000:
list1stren2 += clientsocket.recv(14400)
elif len(list1stren3) < 2500000:
list1stren3 += clientsocket.recv(14400)
elif len(list1stren4) < 2500000:
list1stren4 += clientsocket.recv(14400)
else :
list1stren5 += clientsocket.recv(14400)
print('recv finished')
list1str1 = list1stren1.decode("utf-8")
list1str2 = list1stren2.decode("utf-8")
list1str3 = list1stren3.decode("utf-8")
list1str4 = list1stren4.decode("utf-8")
list1str5 = list1stren5.decode("utf-8")
list1str = list1str1
list1str += list1str2
list1str += list1str3
list1str += list1str4
list1str += list1str5
if list0int==len(list1str):
print('length OK')
clientsocket.close()
s.close()
print('server closed')
print(' ')
list1str = list1str.replace('[', '')
list1str = list1str.replace(']', '')
ksu_init = []
ksu_init = list1str.split(', ')
## Calculation Start
with Manager() as manager:
list1 = manager.list(range(1))
list1b = manager.list(range(1))
list1c = manager.list(range(1))
list2 = manager.list(range(1))
list2b = manager.list(range(1))
list2c = manager.list(range(1))
list3 = manager.list(range(1))
list3b = manager.list(range(1))
list3c = manager.list(range(1))
list4 = manager.list(range(1))
list4b = manager.list(range(1))
list4c = manager.list(range(1))
initial_time=time.time()
print(f"Calcilation Start")
print(f" Please wait for 1 minute.")
Xfrom = xx_from
Xto = xx_to
Xrange = Xto - Xfrom
ksu=[]
for i in range(len(ksu_init)):
ksu.append( (r_f**(ji_su-i))*int(float(ksu_init[i])) )
p1 = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom,Xfrom+0*Xrange/4,Xfrom+1*Xrange/4,ksu))
p1.start()
p2 = Process(target=f0, args=(list2,list2b,list2c,r_f,ji_su,y_zoom,Xfrom+1*Xrange/4,Xfrom+2*Xrange/4,ksu))
p2.start()
p3 = Process(target=f0, args=(list3,list3b,list3c,r_f,ji_su,y_zoom,Xfrom+2*Xrange/4,Xfrom+3*Xrange/4,ksu))
p3.start()
p4 = Process(target=f0, args=(list4,list4b,list4c,r_f,ji_su,y_zoom,Xfrom+3*Xrange/4,Xfrom+4*Xrange/4,ksu))
p4.start()
print(f" 4 core start")
p1.join()
p2.join()
p3.join()
p4.join()
print(f" 4 core finished")
print(f"Calcilation Finished")
print(f"")
print(f"Time :")
print(str(time.time() - initial_time))
list00 =[]
print(f"Answers Y:")
str_AnsY=("Answers Y:",)
list00.append(str_AnsY)
for i in range(len(list1)):
print(list1[i])
list00.append(list1[i])
for i in range(len(list2)):
print(list2[i])
list00.append(list2[i])
for i in range(len(list3)):
print(list3[i])
list00.append(list3[i])
for i in range(len(list4)):
print(list4[i])
list00.append(list4[i])
print(f"Answers YY even:")
str_AnsYY=("Answers YY even:",)
list00.append(str_AnsYY)
for i in range(len(list1b)):
print(list1b[i])
list00.append(list1b[i])
for i in range(len(list2b)):
print(list2b[i])
list00.append(list2b[i])
for i in range(len(list3b)):
print(list3b[i])
list00.append(list3b[i])
for i in range(len(list4b)):
print(list4b[i])
list00.append(list4b[i])
print(f"Answers YYY odd:")
str_AnsYYY=("Answers YYY odd:",)
list00.append(str_AnsYYY)
for i in range(len(list1c)):
print(list1c[i])
list00.append(list1c[i])
for i in range(len(list2c)):
print(list2c[i])
list00.append(list2c[i])
for i in range(len(list3c)):
print(list3c[i])
list00.append(list3c[i])
for i in range(len(list4c)):
print(list4c[i])
list00.append(list4c[i])
list00str = str(list00)
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.connect((ipaddressSendTo, portSendTo))
len_list00str = len(list00str)
len_list00str_str = str(len_list00str)
s1.send(bytes(len_list00str_str, 'utf-8'))
re_len0en = b''
re_len0en = s1.recv(1046)
re_len0str = re_len0en.decode("utf-8")
if re_len0str == len_list00str_str:
print(' length OK')
print(' sending start')
time.sleep(1)
q, mod = divmod(len_list00str, 14400)
for i in range(q):
temp_00str = list00str[14400*i:14400*(i+1)]
s1.send(bytes(temp_00str, 'utf-8'))
time.sleep(0.0001)
if mod > 0:
temp_00str = list00str[14400*q:]
s1.send(bytes(temp_00str, 'utf-8'))
s1.close()
if re_len0str == len_list00str_str:
print('length OK')
print('sending finished')
print('server closed')
time.sleep(10)
計算用2台の時の集計側プログラムを以下に示します。
import time
import socket
from multiprocessing import Manager, Process
#### Input Start ####
RPi_number = 2
ipaddress1p = '192.168.2.21'
port1p = 60021
ipaddress2p = '192.168.2.22'
port2p = 60022
#ipaddress3p = '192.168.2.23'
#port3p = 60023
#ipaddress4p = '192.168.2.24'
#port4p = 60024
ipaddress1r = '192.168.2.20'
port1r = 60021
ipaddress2r = '192.168.2.20'
port2r = 60022
#ipaddress3r = '192.168.2.20'
#port3r = 60023
#ipaddress4r = '192.168.2.20'
#port4r = 60024
xx_from = 0.5
xx_to = 8.5
r_f = 10000
y_zoom = 0
ji_su = 10
ksu_init = [1481760,-4512312,5699652,-4003042,1752225,-503860,97027,-12418,1015,-48,1,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
#### Input End ####
def f0p(List0p,IPaddress0p,Port0p,X0p_from,X0p_to,R_f,Ji_su,Y_zoom):
List0p_str = str(List0p)
len_List0p_str = len(List0p_str)
list_tmp=[len_List0p_str, X0p_from, X0p_to, R_f, Ji_su, Y_zoom]
list_tmp_str = str(list_tmp)
s0p = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s0p.connect((IPaddress0p, Port0p))
s0p.send(bytes(list_tmp_str, 'utf-8'))
time.sleep(1)
re_len0en = b''
re_len0en = s0p.recv(1046)
int_re_len0str = int(re_len0en.decode("utf-8"))
time.sleep(1)#splitting
q, mod = divmod(len_List0p_str, 14400)
for i in range(q):
temp_00str = List0p_str[14400*i:14400*(i+1)]
s0p.send(bytes(temp_00str, 'utf-8'))
time.sleep(0.0001)
if mod > 0:
temp_00str = List0p_str[14400*q:]
s0p.send(bytes(temp_00str, 'utf-8'))
if int_re_len0str == len_List0p_str:
print('Process 0 Sending Complite')
s0p.close()
def f0r(List0r, IPaddress0r, Port0r):
s0r = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s0r.bind((IPaddress0r, Port0r))
s0r.listen(5)
clientsocket, address = s0r.accept()
print(f"Connection from {address}")
list1en = b''
list1en = clientsocket.recv(1046)
list1str = list1en.decode("utf-8")
clientsocket.send(bytes(list1str, 'utf-8'))
len_list1str = int(list1str)
q, mod = divmod(len_list1str, 14400)
list1stren1 = b''
list1stren2 = b''
list1stren3 = b''
list1stren4 = b''
list1stren5 = b''
if mod > 0:
q += 1
while True:
if len(list1stren1)+len(list1stren2)+len(list1stren3)+\
len(list1stren4)+len(list1stren5) >= len_list1str:
break
if len(list1stren1) < 2500000:
list1stren1 += clientsocket.recv(14400)
elif len(list1stren2) < 2500000:
list1stren2 += clientsocket.recv(14400)
elif len(list1stren3) < 2500000:
list1stren3 += clientsocket.recv(14400)
elif len(list1stren4) < 2500000:
list1stren4 += clientsocket.recv(14400)
else :
list1stren5 += clientsocket.recv(14400)
print('recv finished')
list1str1 = list1stren1.decode("utf-8")
list1str2 = list1stren2.decode("utf-8")
list1str3 = list1stren3.decode("utf-8")
list1str4 = list1stren4.decode("utf-8")
list1str5 = list1stren5.decode("utf-8")
list1str = list1str1
list1str += list1str2
list1str += list1str3
list1str += list1str4
list1str += list1str5
if len_list1str==len(list1str):
print('length OK')
clientsocket.close()
s0r.close()
print('server closed')
List0r.pop(0)
List0r.append(list1str)
if __name__=="__main__":
with Manager() as manager:
## Parameter Send Start
Xfrom = int(r_f*xx_from)
Xto = int(r_f*xx_to)
Xrange = Xto - Xfrom
list1p = manager.list(range(1))
list1p.pop(0)
for i in range(len(ksu_init)):
list1p.append(ksu_init[i])
x1p_from = int(Xfrom+0*Xrange/RPi_number)#*
x1p_to = int(Xfrom+1*Xrange/RPi_number)#*
p1p = Process(target=f0p, args=(list1p,ipaddress1p,port1p,x1p_from,x1p_to,r_f,ji_su,y_zoom))
p1p.start()
list2p = manager.list(range(1))
list2p.pop(0)
for i in range(len(ksu_init)):
list2p.append(ksu_init[i])
x2p_from = int(Xfrom+1*Xrange/RPi_number)#*
x2p_to = int(Xfrom+2*Xrange/RPi_number)#*
p2p = Process(target=f0p, args=(list2p,ipaddress2p,port2p,x2p_from,x2p_to,r_f,ji_su,y_zoom))
p2p.start()
#
#
p1p.join()
p2p.join()
#
#
## Result Accept Start
list1r = manager.list(range(1))
list2r = manager.list(range(1))
p1r = Process(target=f0r, args=(list1r, ipaddress1r, port1r))
p1r.start()
p2r = Process(target=f0r, args=(list2r, ipaddress2r, port2r))
p2r.start()
#
#
p1r.join()
list1rStr = str(list1r)
list1rStr = list1rStr.replace('["[(', '')
list1rStr = list1rStr.replace(')]"]', '')
list1rStrS =[]
list1rStrS =list1rStr.split('), (')
for i in range(len(list1rStrS)):
print(list1rStrS[i])
p2r.join()
list2rStr = str(list2r)
list2rStr = list2rStr.replace('["[(', '')
list2rStr = list2rStr.replace(')]"]', '')
list2rStrS =[]
list2rStrS =list2rStr.split('), (')
for i in range(len(list2rStrS)):
print(list2rStrS[i])
#
#
#
#
time.sleep(10)
これも計算用trib-calc2-1.py、trib-calc2-2.pyを先に実行して待機します。後で集計用trib-total2.pyを実行すると計算用2台へパラメーターを送信して計算が開始されます。計算時間は1/2になります。
#さらに多台数での分散処理
計算用を8台さらに16台へと増やすことが可能です。
┌──────────┬─┐ ┌─┬──────────┐
│ ┌───────┤P│ │P├───────┐ │
│ │ ┌────┤O│ │O├────┐ │ │
│ │ │ ┌─┤R│ │R├─┐ │ │ │
┌┴┐┌┴┐┌┴┐┌┴┐│T│ │T│┌┴┐┌┴┐┌┴┐┌┴┐
│1││2││3││4││5│ │5││4││3││2││1│
└┬┘└┬┘└┬┘└┬┘└┬┘ └┬┘└┬┘└┬┘└┬┘└┬┘
│ │ │ │ └──┐┌──┘ │ │ │ │
┏┷┓┏┷┓┏┷┓┏┷┓ ││ ┏┷┓┏┷┓┏┷┓┏┷┓
┃2┃┃2┃┃2┃┃2┃ ││ ┃3┃┃3┃┃3┃┃3┃
┃6┃┃7┃┃8┃┃9┃ ││ ┃7┃┃6┃┃5┃┃4┃
┗━┛┗━┛┗━┛┗━┛ ││ ┗━┛┗━┛┗━┛┗━┛
││
┌──────────┬─┐ ││ ┌─┬──────────┐
│ ┌───────┤P│ ││ │P├───────┐ │
│ │ ┌────┤O│ ││ │O├────┐ │ │
│ │ │ ┌─┤R│ ││ │R├─┐ │ │ │
┌┴┐┌┴┐┌┴┐┌┴┐│T│ ││ │T│┌┴┐┌┴┐┌┴┐┌┴┐
│1││2││3││4││5│ ││ │5││4││3││2││1│
└┬┘└┬┘└┬┘└┬┘└┬┘ ││ └┬┘└┬┘└┬┘└┬┘└┬┘
│ │ │ │ └─┐││┌─┘ │ │ │ │
┏┷┓┏┷┓┏┷┓┏┷┓ ││││ ┏┷┓┏┷┓┏┷┓┏┷┓
┃4┃┃4┃┃4┃┃4┃ ││││ ┃5┃┃5┃┃5┃┃5┃
┃2┃┃3┃┃4┃┃5┃ ││││ ┃3┃┃2┃┃1┃┃0┃
┗━┛┗━┛┗━┛┗━┛ ││││ ┗━┛┗━┛┗━┛┗━┛
││││
┏━━━━━━━━━━━━┓ ││││
┃TOTAL SERVER┃ ││││
┣━━━━━━━━━━━━┫ ││││
┃ FILE SERVER┃ ││││
┗━━━━━┯━━┯━━━┛ ││││
│ │ ┌──┘││└──┐
│ │ │ ┌┘└┐ │
┌┴┐┌┴┐┌┴┐┌┴┐┌┴┐┌┴┐┌┴┐┌┴┐
│1││2││3││4││5││6││7││8│
└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘
そうすれば計算時間は1/8、1/16と短縮されていきます。図は16台構成の分散処理の1例を示しました。セグメントを分けるにはRUTERを使うのが一般的ですが、今回の用途では小セグメントに分けるのにシンプルなSWITCHを使っても同じ機能をします。16台、数十台、数百台と構成台数が増えても、セグメントに分ければブロードキャストは気になりません。
ただ整数型で計算した場合、生データの桁数は大きくなり、今回のプログラムを実行すればわかりますが1000次方程式でさえ4MBでした。10000次方程式の整数型の生データは100MBを超えそうです。Raspberry Pi 4BのPythonの今回のプログラムでは17MB/sの受信処理が可能ですから、100MBでも6秒ほどで送受信は可能です。4coreでは4台からも受信可能です。さらに台数が8台、16台と増え、計算結果送信が併発すると、さすがに混雑したLANとなります。ただ計算結果送信の一時期だけです。ゆえに送信前に、一極集中する集計用の受信側の空きを、送信側プログラム上で事前確認するだけで解決できそうです。数時間計算して、わずか数秒の送信待機の待ち時間です。また一極集中する計算結果の受信バッファーとしてファイルサーバーを併設することも一案です。
最後までご覧いただいて、ありがとうございました。
今回はQiitaの主旨に同意して投稿していますので、公開したプログラムはコピー、改変などでのご使用は自由です。著作権に関する問題も発生しません。
ただし、Raspberry Pi 4Bを使う場合にはCPUに特に大きめのヒートシンクが必須です。LAN通信の頻度の少ない今回のプログラムのような場合、LANチップは熱くなりません。しかし計算時間が継続するとCPUの激しい発熱で分かるように相当電力を使っています。電源UCB Cタイプの後ろにある黒い小さなチップも熱くなりますので、ファンでの風流も必要です。
#16core用20次方程式
以下は、後日追加したプログラムです。16coreのPC向けです。集計用のサーバーを想定しています。単体で動くプログラムです。x=1と14に3重解、x=2と13に2重解がある20次方程式です。グラフは次のようになります。
因数分解型の展開に、次のような小さなプログラムを作り、係数を取得しました。
kai = [1,1,2,2,3,4,5,6,7,8,9,10,11,12,13,13,14,14,14]
#((x-1)**3)*((x-2)**2)*(x-3)*(x-4)*(x-5)*(x-6)*(x-7)*(x-8)*(x-9)*(x-10)*(x-11)*(x-12)*((x-13)**2)*((x-14)**3)
ji_su = 20 # > 2
keisu = [1,-1] # (x-1) 1次式
PreKeisu = keisu.copy()
for i in range(ji_su-1):
for j in range(len(keisu)-1):
keisu[j+1] += -kai[i]*PreKeisu[j]
keisu.append(-kai[i]*PreKeisu[len(keisu)-1])
PreKeisu.clear()
PreKeisu=keisu.copy()
keisu.reverse()
for i in range(len(keisu)):
print(keisu[i],f",\\")
# Please copy & paste directly from IDLE, and delete space before ','.
#444260571955200 ,\
#-2652832054978560 ,\
#7067033893269504 ,\
#-11161579926967680 ,\
#11730774309288256 ,\
#-8737764247363680 ,\
#4799101239329104 ,\
#-1996645873992360 ,\
#641287103894956 ,\
#-161134278901050 ,\
#31955605427239 ,\
#-5026741278390 ,\
#627983806021 ,\
#-62139346620 ,\
#4834833694 ,\
#-291921420 ,\
#13385566 ,\
#-450090v
#10459 ,\
#-150 ,\
#1 ,\
得られた係数を使って以下のプログラムで20次方程式を解きました。Core_suを16にすると16コアで動きます。
import time
from multiprocessing import Manager, Process
#### Input Start
Core_su = 4 # 2 or 4 or 8 or 16
x_from = 0.7 # only > 0
x_to = 14.2
r_f = 100000 # resolution 100 - 10000000
y_zoom = 0
ji_suu = 20
#((x-1)**3)*((x-2)**2)*(x-3)*(x-4)*(x-5)*(x-6)*(x-7)*(x-8)*(x-9)*(x-10)*(x-11)*(x-12)*((x-13)**2)*((x-14)**3)
ksu_0 = [444260571955200,\
-2652832054978560,\
7067033893269504,\
-11161579926967680,\
11730774309288256,\
-8737764247363680,\
4799101239329104,\
-1996645873992360,\
641287103894956,\
-161134278901050,\
31955605427239,\
-5026741278390,\
627983806021,\
-62139346620,\
4834833694,\
-291921420,\
13385566,\
-450090,\
10459,\
-150,\
1]
#### Input End
def f0(List0, List0b, List0c, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
Ypre =0
YYpre =0
YYYpre =0
for X in range( int(X_init), int(X_end)+1 ):
Y=0
for j in range(0, Ji_su+1):
Y += Ksu[j]*(X**j)
YY=0
for j in range(0, Ji_su):
YY += (j+1)*Ksu[j+1]*(X**j)
YYY=0
for j in range(0, Ji_su-1):
YYY += (j+1)*(j+2)*Ksu[j+2]*(X**j)
if X == int(X_init):
Ypre =Y
YYpre =YY
YYYpre =YYY
List0.pop(0)
List0b.pop(0)
List0c.pop(0)
#### Y : Simple x axis cross method ####
if Ypre * Y > 0:
Ypre=Y
else:
if Y == 0:
Y=Y
List0.append(( X/R_f, X, Y/(R_f**(Ji_su-Y_zoom)), Y ,333 )) # If float error appear around 100ji, please switch to below.
#List0.append(( X/R_f, X, Y , 333 ))
else:
X_tmp = X-1
Y_tmp = 0
for k in range(0, Ji_su+1):
Y_tmp += Ksu[k]*(X_tmp**k)
List0.append(( X_tmp/R_f, X_tmp, Y_tmp/(R_f**(Ji_su-Y_zoom)), Y_tmp, 666 )) # If float error appear around 100ji, please switch to below.
#List0.append(( X_tmp/R_f, X_tmp, Y_tmp, 666 ))
Ypre=Y
#### YY even: Simple x axias cross method ####
if YYpre * YY > 0:
YYpre=YY
else:
if YY == 0:
YY=YY
List0b.append(( X/R_f, X, YY/(R_f**(Ji_su-Y_zoom)), YY, 333 )) # If float error appear around 100ji, please switch to below.
#List0b.append(( X/R_f, X, YY, 333 ))
else:
X_tmp = X-1
YY_tmp = 0
for k in range(0, Ji_su):
YY_tmp += (k+1)*Ksu[k+1]*(X_tmp**k)
List0b.append(( X_tmp/R_f, X_tmp, YY_tmp/(R_f**(Ji_su-Y_zoom)), YY_tmp, 666 )) # If float error appear around 100ji, please switch to below.
#List0b.append(( X_tmp/R_f, X_tmp, YY_tmp, 666 ))
YYpre=YY
#### YYY odd: Simple x axias cross method ####
if YYYpre * YYY > 0:
YYYpre=YYY
else:
if YYY == 0:
YYY=YYY
List0c.append(( X/R_f, X, YYY/(R_f**(Ji_su-Y_zoom)), YYY, 333 )) # If float error appear around 100ji, please switch to below.
#List0c.append(( X/R_f, X, YYY, 333 ))
else:
X_tmp = X-1
YYY_tmp = 0
for k in range(0, Ji_su-1):
YYY_tmp += (k+1)*(k+2)*Ksu[k+2]*(X_tmp**k)
List0c.append(( X_tmp/R_f, X_tmp, YYY_tmp/(R_f**(Ji_su-Y_zoom)), YYY_tmp, 666 )) # If float error appear around 100ji, please switch to below.
#List0c.append(( X_tmp/R_f, X_tmp, YYY_tmp, 666 ))
YYYpre=YYY
if __name__=="__main__":
if Core_su >=16:
core_su = 16
elif Core_su < 16 and Core_su >=8:
core_su = 8
elif Core_su < 8 and Core_su >=4:
core_su = 4
else:
core_su = 2
ji_su =int(ji_suu)
with Manager() as manager:
if core_su>=2:
list1 = manager.list(range(1))
list1b = manager.list(range(1))
list1c = manager.list(range(1))
list2 = manager.list(range(1))
list2b = manager.list(range(1))
list2c = manager.list(range(1))
if core_su>=4:
list3 = manager.list(range(1))
list3b = manager.list(range(1))
list3c = manager.list(range(1))
list4 = manager.list(range(1))
list4b = manager.list(range(1))
list4c = manager.list(range(1))
if core_su>=8:
list5 = manager.list(range(1))
list5b = manager.list(range(1))
list5c = manager.list(range(1))
list6 = manager.list(range(1))
list6b = manager.list(range(1))
list6c = manager.list(range(1))
list7 = manager.list(range(1))
list7b = manager.list(range(1))
list7c = manager.list(range(1))
list8 = manager.list(range(1))
list8b = manager.list(range(1))
list8c = manager.list(range(1))
if core_su>=16:
list9 = manager.list(range(1))
list9b = manager.list(range(1))
list9c = manager.list(range(1))
list10 = manager.list(range(1))
list10b = manager.list(range(1))
list10c = manager.list(range(1))
list11 = manager.list(range(1))
list11b = manager.list(range(1))
list11c = manager.list(range(1))
list12 = manager.list(range(1))
list12b = manager.list(range(1))
list12c = manager.list(range(1))
list13 = manager.list(range(1))
list13b = manager.list(range(1))
list13c = manager.list(range(1))
list14 = manager.list(range(1))
list14b = manager.list(range(1))
list14c = manager.list(range(1))
list15 = manager.list(range(1))
list15b = manager.list(range(1))
list15c = manager.list(range(1))
list16 = manager.list(range(1))
list16b = manager.list(range(1))
list16c = manager.list(range(1))
initial_time=time.time()
print(f"Calcilation Start")
Xfrom = int(r_f*x_from)
Xto = int(r_f*x_to)
Xrange = Xto - Xfrom
ksu=[]
for i in range(len(ksu_0)):
ksu.append( int(ksu_0[i]*r_f**(ji_su-i)) )
if core_su==2:
p1 = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom,Xfrom+0*Xrange/2,Xfrom+1*Xrange/2,ksu))
p1.start()
p2 = Process(target=f0, args=(list2,list2b,list1c,r_f,ji_su,y_zoom,Xfrom+1*Xrange/2,Xfrom+2*Xrange/2,ksu))
p2.start()
elif core_su==4:
p1 = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom,Xfrom+0*Xrange/4,Xfrom+1*Xrange/4,ksu))
p1.start()
p2 = Process(target=f0, args=(list2,list2b,list2c,r_f,ji_su,y_zoom,Xfrom+1*Xrange/4,Xfrom+2*Xrange/4,ksu))
p2.start()
p3 = Process(target=f0, args=(list3,list3b,list3c,r_f,ji_su,y_zoom,Xfrom+2*Xrange/4,Xfrom+3*Xrange/4,ksu))
p3.start()
p4 = Process(target=f0, args=(list4,list4b,list4c,r_f,ji_su,y_zoom,Xfrom+3*Xrange/4,Xfrom+4*Xrange/4,ksu))
p4.start()
elif core_su==8:
p1 = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom,Xfrom+0*Xrange/8,Xfrom+1*Xrange/8,ksu))
p1.start()
p2 = Process(target=f0, args=(list2,list2b,list2c,r_f,ji_su,y_zoom,Xfrom+1*Xrange/8,Xfrom+2*Xrange/8,ksu))
p2.start()
p3 = Process(target=f0, args=(list3,list3b,list3c,r_f,ji_su,y_zoom,Xfrom+2*Xrange/8,Xfrom+3*Xrange/8,ksu))
p3.start()
p4 = Process(target=f0, args=(list4,list4b,list4c,r_f,ji_su,y_zoom,Xfrom+3*Xrange/8,Xfrom+4*Xrange/8,ksu))
p4.start()
p5 = Process(target=f0, args=(list5,list5b,list5c,r_f,ji_su,y_zoom,Xfrom+4*Xrange/8,Xfrom+5*Xrange/8,ksu))
p5.start()
p6 = Process(target=f0, args=(list6,list6b,list6c,r_f,ji_su,y_zoom,Xfrom+5*Xrange/8,Xfrom+6*Xrange/8,ksu))
p6.start()
p7 = Process(target=f0, args=(list7,list7b,list7c,r_f,ji_su,y_zoom,Xfrom+6*Xrange/8,Xfrom+7*Xrange/8,ksu))
p7.start()
p8 = Process(target=f0, args=(list8,list8b,list8c,r_f,ji_su,y_zoom,Xfrom+7*Xrange/8,Xfrom+8*Xrange/8,ksu))
p8.start()
elif core_su==16:
p1 = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom, Xfrom+0*Xrange/16, Xfrom+1*Xrange/16,ksu))
p1.start()
p2 = Process(target=f0, args=(list2,list2b,list2c,r_f,ji_su,y_zoom, Xfrom+1*Xrange/16, Xfrom+2*Xrange/16,ksu))
p2.start()
p3 = Process(target=f0, args=(list3,list3b,list3c,r_f,ji_su,y_zoom, Xfrom+2*Xrange/16, Xfrom+3*Xrange/16,ksu))
p3.start()
p4 = Process(target=f0, args=(list4,list4b,list4c,r_f,ji_su,y_zoom, Xfrom+3*Xrange/16, Xfrom+4*Xrange/16,ksu))
p4.start()
p5 = Process(target=f0, args=(list5,list5b,list5c,r_f,ji_su,y_zoom, Xfrom+4*Xrange/16, Xfrom+5*Xrange/16,ksu))
p5.start()
p6 = Process(target=f0, args=(list6,list6b,list6c,r_f,ji_su,y_zoom, Xfrom+5*Xrange/16, Xfrom+6*Xrange/16,ksu))
p6.start()
p7 = Process(target=f0, args=(list7,list7b,list7c,r_f,ji_su,y_zoom, Xfrom+6*Xrange/16, Xfrom+7*Xrange/16,ksu))
p7.start()
p8 = Process(target=f0, args=(list8,list8b,list8c,r_f,ji_su,y_zoom, Xfrom+7*Xrange/16, Xfrom+8*Xrange/16,ksu))
p8.start()
p9 = Process(target=f0, args=(list9,list9b,list9c,r_f,ji_su,y_zoom, Xfrom+8*Xrange/16, Xfrom+9*Xrange/16,ksu))
p9.start()
p10 = Process(target=f0, args=(list10,list10b,list10c,r_f,ji_su,y_zoom, Xfrom+9*Xrange/16,Xfrom+10*Xrange/16,ksu))
p10.start()
p11 = Process(target=f0, args=(list11,list11b,list11c,r_f,ji_su,y_zoom,Xfrom+10*Xrange/16,Xfrom+11*Xrange/16,ksu))
p11.start()
p12 = Process(target=f0, args=(list12,list12b,list12c,r_f,ji_su,y_zoom,Xfrom+11*Xrange/16,Xfrom+12*Xrange/16,ksu))
p12.start()
p13 = Process(target=f0, args=(list13,list13b,list13c,r_f,ji_su,y_zoom,Xfrom+12*Xrange/16,Xfrom+13*Xrange/16,ksu))
p13.start()
p14 = Process(target=f0, args=(list14,list14b,list14c,r_f,ji_su,y_zoom,Xfrom+13*Xrange/16,Xfrom+14*Xrange/16,ksu))
p14.start()
p15 = Process(target=f0, args=(list15,list15b,list15c,r_f,ji_su,y_zoom,Xfrom+14*Xrange/16,Xfrom+15*Xrange/16,ksu))
p15.start()
p16 = Process(target=f0, args=(list16,list16b,list16c,r_f,ji_su,y_zoom,Xfrom+15*Xrange/16,Xfrom+16*Xrange/16,ksu))
p16.start()
if core_su>=2:
p1.join()
p2.join()
if core_su>=4:
p3.join()
p4.join()
if core_su>=8:
p5.join()
p6.join()
p7.join()
p8.join()
if core_su>=16:
p9.join()
p10.join()
p11.join()
p12.join()
p13.join()
p14.join()
p15.join()
p16.join()
print(f"Calcilation Finished")
print(f"Time :")
print(str(time.time() - initial_time))
print(f"Answers Y:")
kai_su=0
if core_su>=2:
for i in range(len(list1)):
print(list1[i])
for i in range(len(list2)):
print(list2[i])
kai_su += len(list1) + len(list2)
if core_su>=4:
for i in range(len(list3)):
print(list3[i])
for i in range(len(list4)):
print(list4[i])
kai_su += len(list3) + len(list4)
if core_su>=8:
for i in range(len(list5)):
print(list5[i])
for i in range(len(list6)):
print(list6[i])
for i in range(len(list7)):
print(list7[i])
for i in range(len(list8)):
print(list8[i])
kai_su += len(list5) + len(list6) + len(list7) + len(list8)
if core_su>=16:
for i in range(len(list9)):
print(list9[i])
for i in range(len(list10)):
print(list10[i])
for i in range(len(list11)):
print(list11[i])
for i in range(len(list12)):
print(list12[i])
for i in range(len(list13)):
print(list13[i])
for i in range(len(list14)):
print(list14[i])
for i in range(len(list15)):
print(list15[i])
for i in range(len(list16)):
print(list16[i])
kai_su += len(list9) + len(list10) + len(list11) + len(list12) + len(list13) + len(list14) + len(list15) + len(list16)
print(f"Answers YY even:")
if core_su>=2:
for i in range(len(list1b)):
print(list1b[i])
for i in range(len(list2b)):
print(list2b[i])
if core_su>=4:
for i in range(len(list3b)):
print(list3b[i])
for i in range(len(list4b)):
print(list4b[i])
if core_su>=8:
for i in range(len(list5b)):
print(list5b[i])
for i in range(len(list6b)):
print(list6b[i])
for i in range(len(list7b)):
print(list7b[i])
for i in range(len(list8b)):
print(list8b[i])
if core_su>=16:
for i in range(len(list9b)):
print(list9b[i])
for i in range(len(list10b)):
print(list10b[i])
for i in range(len(list11b)):
print(list11b[i])
for i in range(len(list12b)):
print(list12b[i])
for i in range(len(list13b)):
print(list13b[i])
for i in range(len(list14b)):
print(list14b[i])
for i in range(len(list15b)):
print(list15b[i])
for i in range(len(list16b)):
print(list16b[i])
print(f"Answers YYY odd:")
if core_su>=2:
for i in range(len(list1c)):
print(list1c[i])
for i in range(len(list2c)):
print(list2c[i])
if core_su>=4:
for i in range(len(list3c)):
print(list3c[i])
for i in range(len(list4c)):
print(list4c[i])
if core_su>=8:
for i in range(len(list5c)):
print(list5c[i])
for i in range(len(list6c)):
print(list6c[i])
for i in range(len(list7c)):
print(list7c[i])
for i in range(len(list8c)):
print(list8c[i])
if core_su>=16:
for i in range(len(list9c)):
print(list9c[i])
for i in range(len(list10c)):
print(list10c[i])
for i in range(len(list11c)):
print(list11c[i])
for i in range(len(list12c)):
print(list12c[i])
for i in range(len(list13c)):
print(list13c[i])
for i in range(len(list14c)):
print(list14c[i])
for i in range(len(list15c)):
print(list15c[i])
for i in range(len(list16c)):
print(list16c[i])
time.sleep(10)
#Calcilation Start
#Calcilation Finished
#Time :
#30....
#Answers Y:
#(1.0, 100000, 0.0, 0, 333)
#(1.0, 100000, 0.0, 0, 666)
#(2.0, 200000, 0.0, 0, 333)
#(3.0, 300000, 0.0, 0, 333)
#(3.0, 300000, 0.0, 0, 666)
#(4.0, 400000, 0.0, 0, 333)
#(4.0, 400000, 0.0, 0, 666)
#(5.0, 500000, 0.0, 0, 333)
#(5.0, 500000, 0.0, 0, 666)
#(6.0, 600000, 0.0, 0, 333)
#(6.0, 600000, 0.0, 0, 666)
#(7.0, 700000, 0.0, 0, 333)
#(7.0, 700000, 0.0, 0, 666)
#(8.0, 800000, 0.0, 0, 333)
#(8.0, 800000, 0.0, 0, 666)
#(9.0, 900000, 0.0, 0, 333)
#(9.0, 900000, 0.0, 0, 666)
#(10.0, 1000000, 0.0, 0, 333)
#(10.0, 1000000, 0.0, 0, 666)
#(11.0, 1100000, 0.0, 0, 333)
#(11.0, 1100000, 0.0, 0, 666)
#(12.0, 1200000, 0.0, 0, 333)
#(12.0, 1200000, 0.0, 0, 666)
#(13.0, 1300000, 0.0, 0, 333)
#(14.0, 1400000, 0.0, 0, 333)
#(14.0, 1400000, 0.0, 0, 666)
#Answers YY even:
#(1.0, 100000, 0.0, 0, 333)
#(1.46352, 146352, -51.259020882557394, -512590208825573924941721417374101568543884660343461787745537606134111910199333204475153172014552842240, 666)
#(2.0, 200000, 0.0, 0, 333)
#(2.0, 200000, 0.0, 0, 666)
#(2.5927, 259270, -5.738733207406932, -57387332074069319734389954282838148394996599976668989012972573874072617421031107400000000000000000000, 666)
#(3.48788, 348788, 113.16630121407185, 1131663012140718540797147503929665235552395080534594293029745689353156172487330622567011027120071639040, 666)
#(4.47265, 447265, -76.00395187210451, -760039518721045037546567328535966006575245059521180272030233517458621852961548851814683151245117187500, 666)
#(5.47703, 547703, 45.13210669235468, 451321066923546814838051101774473458467390580890294818723773360803846645128083540342750682231077243340, 666)
#(6.48751, 648751, -31.03814760009142, -310381476000914210024737090846882293840382681056334195033207564769373732399385238411711686108757224980, 666)
#(7.5, 750000, 0.0, 0, 333)
#(7.5, 750000, 0.0, 0, 666)
#(8.51248, 851248, -31.536879292138362, -315368792921383635378716192992689122954550698694290953008987752993024589418348413684941387930020085760, 666)
#(9.52296, 952296, 30.157885830483018, 301578858304830166727350497262086679394657455696272137975182747352928616573031232207560657360513925120, 666)
#(10.52734, 1052734, -22.522438051936504, -225224380519365045531660330416070531460250634359892043160666535494650753716976117392470391017932062720, 666)
#(11.51211, 1151211, 13.812632261512157, 138126322615121558295483752702790628312131767950969307413266916916582109150550280757062519754619061820, 666)
#(12.40729, 1240729, -127.30599876071821, -1273059987607182137044249956858295159166145024091227056395837942372560477833581459514979419441989780620, 666)
#(13.0, 1300000, 0.0, 0, 333)
#(13.0, 1300000, 0.0, 0, 666)
#(13.53647, 1353647, -187.97527498134596, -1879752749813459585909241239515942428067009313053316602619186792605174321517662035484806299720513336340, 666)
#(14.0, 1400000, 0.0, 0, 333)
#Answers YYY odd:
#(1.0, 100000, 0.0, 0, 333)
#(1.0, 100000, 0.0, 0, 666)
#(1.23288, 123288, -0.02197592315455411, -219759231545541089678655821956879198286655700596120524609061470170469376517897648954366098910740480, 666)
#(1.70423, 170423, 0.004340698083147923, 43406980831479229785984190109106881081807903038182891533245291654986044089499873593936500496748220, 666)
#(2.28578, 228578, -0.003412033602952443, -34120336029524426414305255154298403686276061076805277619617507996105622013985857559243126006087680, 666)
#(3.03081, 303081, 0.0032685826714762586, 32685826714762585516935246823503881316036259990365959512956080222113105771373220259472965851323580, 666)
#(3.95335, 395335, -0.002534724517226041, -25347245172260410717194656328725129623352656684826438558894621287353931687608161211318969726562500, 666)
#(4.94677, 494677, 0.0020776101459824064, 20776101459824065868983940489565067463146432807884249221564450687816533870180310784258086198696220, 666)
#(5.96292, 596292, -0.0014687643740594794, -14687643740594793652460271276338273049534061576588852899499354608761800726770406543294229202862080, 666)
#(6.98697, 698697, 0.0004360935304089328, 4360935304089327944687376648794456699083542502777639923008436275562502200345023951991910423781820, 666)
#(8.01302, 801302, -0.001390999353065438, -13909993530654379144202009914436773164517580538100596340539429480481459375970264171804204366561280, 666)
#(9.03707, 903707, 0.0006246588714060029, 6246588714060028046802654111429723879803905200581248885038716229095339759328516511230180839326620, 666)
#(10.05322, 1005322, -0.0006165362184569625, -6165362184569625094809943130920537129898108427785849419086469092309696936539983766589732610375680, 666)
#(11.04664, 1104664, 0.0011607774315889605, 11607774315889605833695271806776699954810131541676154811472487592418906333612050975834355563233280, 666)
#(11.96918, 1196918, -0.0016869814212306339, -16869814212306338677971825974176346417532521128778450882212462309327237979698278113617778316410880, 666)
#(12.71421, 1271421, 0.0033152737103085616, 33152737103085616033287198087477050149668955304906755284379054217110677186420957398862892871049180, 666)
#(13.29576, 1329576, -0.00685359723375656, -68535972337565593627377049251979914539011459057940968624089699490604643370675821517315469601669120, 666)
#(13.76711, 1376711, 0.0016898396618776157, 16898396618776156728931696843675416608437132846921485046953055205884254454135347147425863242750780, 666)
#(14.0, 1400000, 0.0, 0, 333)
#(14.0, 1400000, 0.0, 0, 666)
今回は因数分解型から整数の係数で解きましたからきれいにY値が0.0になります。x=2とx=13はYの符号が反転していません。YYは符号が反転しています。そしてYYYはありません。evenの重解でありYYYが無いので2重解です。x=1とx=14はYの符号が反転しています。YYは符号が反転していません。さらにYYYがあり符号が反転しています。Oddの重解でありYYYがありますからさらに5重解かもしれません。しかし20次方程式で既に20個解が求まっていますから3重解です。
実際の高次方程式を解くと、きれいにY値が0.0になることはなかなかありません。ゆえに4次および5次微分、さらにmatplotlibなどのグラフの併用、そして有効数字を増やして少し時間をかけて再計算し、最終的な解を確定しています。