First scheme (preparing tools)
This commit is contained in:
parent
dd2a8044ea
commit
a7c44bfbad
|
@ -1,33 +1,73 @@
|
||||||
import threading
|
from threading import Thread
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
renew_length = 12
|
||||||
|
local_workers_number = 10
|
||||||
|
number_of_cycles = 20
|
||||||
|
renew = []
|
||||||
|
done = []
|
||||||
|
space = []
|
||||||
|
copy = []
|
||||||
|
|
||||||
|
def init():
|
||||||
|
for i in range(0, renew_length - 1):
|
||||||
|
renew.append(-1)
|
||||||
|
for j in range(0, local_workers_number):
|
||||||
|
space.append(random.randint(10,99))
|
||||||
|
copy.append(space[j])
|
||||||
|
print(' ',space,' < initial global state')
|
||||||
|
|
||||||
|
def disp(coord, id, start, prev, next):
|
||||||
|
print(' {} at [{}] {} > {} by thread n°{:>3} {!s:.4} {}'.format(
|
||||||
|
space,
|
||||||
|
coord,
|
||||||
|
prev,
|
||||||
|
next,
|
||||||
|
str(id),
|
||||||
|
datetime.now().timestamp() - start,
|
||||||
|
renew
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def local_worker(coord, id):
|
def local_worker(coord, id):
|
||||||
start = datetime.now().timestamp()
|
start = datetime.now().timestamp()
|
||||||
val = random.randint(1,1000)
|
val = random.randint(1,1000)
|
||||||
time.sleep(val / 1000)
|
time.sleep(val / 1000)
|
||||||
prev = space[coord]
|
prev = space[coord]
|
||||||
next = space[coord] = 10 + val % 89
|
next = space[coord] = 10 + val % 89
|
||||||
print('{} on [{}] : {} > {} by local thread n°{:>3} {!s:.4}'.format(
|
done.append(id)
|
||||||
space,
|
for i in renew:
|
||||||
coord,
|
if renew[i] == id:
|
||||||
prev,
|
renew[i] = -1
|
||||||
next,
|
break
|
||||||
str(id),
|
disp(coord, id, start, prev, next)
|
||||||
datetime.now().timestamp() - start
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
from threading import Thread
|
init()
|
||||||
space = []
|
for k in range (1, number_of_cycles):
|
||||||
for i in range(0,10):
|
n = 0
|
||||||
space.append(random.randint(10,99))
|
while renew[n] == -1: # a diagonal of zeros is expected !
|
||||||
print(space,' < initialglobal state')
|
renew[n] = 0
|
||||||
for k in range (1,20):
|
if n < renew_length - 2:
|
||||||
t = Thread(target=local_worker, args=(random.randint(0,len(space) - 1), k))
|
n += 1
|
||||||
|
break
|
||||||
|
# for n in range(0, renew_length - 1):
|
||||||
|
# if renew[n] == -1:
|
||||||
|
# renew[n] = 0
|
||||||
|
# break
|
||||||
|
t = Thread(target=local_worker, args=(random.randint(0, len(space) - 1), k))
|
||||||
t.start()
|
t.start()
|
||||||
|
time.sleep(1)
|
||||||
|
print(' ',copy,' < initial global state (to compare)')
|
||||||
|
print(done)
|
||||||
|
done.sort()
|
||||||
|
print(done)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -60,5 +100,4 @@ Il délègue à la **CLI** les fonctions de communications avec les modules pér
|
||||||
|
|
||||||
3. mesures / recueil des commandes / retour d'information
|
3. mesures / recueil des commandes / retour d'information
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue