all cpu working

This commit is contained in:
Jean Sirmai 2021-04-09 18:14:56 +02:00
parent ffbd6d2d63
commit fd78079ea2
Signed by untrusted user who does not match committer: jean
GPG Key ID: FB3115C340E057E3
2 changed files with 26 additions and 20 deletions

View File

@ -8,7 +8,7 @@ SPACE_SIZE = 10000
PREEMPTION_GLOBAL_SPACE = [True] * SPACE_SIZE PREEMPTION_GLOBAL_SPACE = [True] * SPACE_SIZE
ARROW_LIST = [(random.randint(0,SPACE_SIZE - 1),0) for x in range(ARROW_NUMBER)] ARROW_LIST = [(random.randint(0,SPACE_SIZE - 1),0) for x in range(ARROW_NUMBER)]
TRANSITIONS_TREE = None TRANSITIONS_TREE = None
MAX_THREAD = 300 MAX_THREAD = 10
class CurrentlyComputing(Exception): class CurrentlyComputing(Exception):
@ -20,6 +20,8 @@ class SuccessfulOperation(Exception):
class FailedOperation(Exception): class FailedOperation(Exception):
pass pass
## Local Threads
class LocalThread(multiprocessing.Process): class LocalThread(multiprocessing.Process):
def __init__(self, id, shared_memory, address, orientation, transitions): def __init__(self, id, shared_memory, address, orientation, transitions):
@ -37,15 +39,18 @@ class LocalThread(multiprocessing.Process):
try: try:
# Actual code # Actual code
print("Thread local n°{} parle depuis {} !".format(self.id, self.address)) print("Thread local n°{} parle depuis {} !".format(self.id, self.address))
n = 1
for i in range(1000): L = [random.randint(0,3000) for x in range(random.randint(0, 300))]
n *= i
for i in xrange(10000000):
sum(range(100))
self.namespace.returncode = SuccessfulOperation() self.namespace.returncode = SuccessfulOperation()
except Exception as exception: except Exception as exception:
self.namespace.returncode = exception self.namespace.returncode = exception
## Master Thread
class GreatScheduler(threading.Thread): class GreatScheduler(threading.Thread):
def __init__(self, preemption_space, arrow_list, n_thread, nmax_cycles): def __init__(self, preemption_space, arrow_list, n_thread, nmax_cycles):

View File

@ -1,18 +1,19 @@
from threading import Thread import multiprocessing
import time
def countdown():
n = 50
while n > 0:
n -= 1
COUNT = 10000000 def func():
for i in range(10000000):
sum(range(100))
with nogil: procs = []
t1 = Thread(target=countdown) for i in range(200):
t2 = Thread(target=countdown) p = multiprocessing.Process(target=func)
start = time.time() p.start()
t1.start();t2.start() procs.append(p)
t1.join();t2.join()
print 'started', len(procs), 'processes'
end = time.time()
print end-start for p in procs:
p.join()
print 'process done'
print 'all done'