client.py 761 Bytes
Newer Older
Samuel Kemmler's avatar
Samuel Kemmler committed
1
import zmq
Samuel Kemmler's avatar
Samuel Kemmler committed
2
3
4
5
6
7
8
9
import json
import random


def jacobi_iteration(u):
	for i in range(1, len(u) - 1):
		u[i] = 0.5 * (u[i - 1] + u[i + 1])

Samuel Kemmler's avatar
Samuel Kemmler committed
10
11
12
13
14
15

context = zmq.Context()

socket = context.socket(zmq.REQ)
socket.connect("tcp://192.168.2.110:5555")

Samuel Kemmler's avatar
Samuel Kemmler committed
16
17
18
19
20
21
22
23
24
25
print("Requesting parameters…")
socket.send(b"jacobi_request")
message = socket.recv().decode("ascii")
params = json.loads(message)

# initialize domain
u = [random.random() for i in range(params["n_unknowns"])]
u[0] = 0.0
u[len(u) - 1] = 0.0
socket.send("-".join(str(x) for x in u).encode("ascii"))
Samuel Kemmler's avatar
Samuel Kemmler committed
26

Samuel Kemmler's avatar
Samuel Kemmler committed
27
28
29
30
31
32
33
while True:
	# if requested, perform jacobi iteration and send result
	message = socket.recv().decode("ascii")
	if message != "next":
		break
	jacobi_iteration(u)
	socket.send("-".join(str(x) for x in u).encode("ascii"))