all cpu working
This commit is contained in:
parent
ffbd6d2d63
commit
fd78079ea2
|
@ -8,7 +8,7 @@ SPACE_SIZE = 10000
|
|||
PREEMPTION_GLOBAL_SPACE = [True] * SPACE_SIZE
|
||||
ARROW_LIST = [(random.randint(0,SPACE_SIZE - 1),0) for x in range(ARROW_NUMBER)]
|
||||
TRANSITIONS_TREE = None
|
||||
MAX_THREAD = 300
|
||||
MAX_THREAD = 10
|
||||
|
||||
|
||||
class CurrentlyComputing(Exception):
|
||||
|
@ -20,6 +20,8 @@ class SuccessfulOperation(Exception):
|
|||
class FailedOperation(Exception):
|
||||
pass
|
||||
|
||||
## Local Threads
|
||||
|
||||
class LocalThread(multiprocessing.Process):
|
||||
|
||||
def __init__(self, id, shared_memory, address, orientation, transitions):
|
||||
|
@ -37,15 +39,18 @@ class LocalThread(multiprocessing.Process):
|
|||
try:
|
||||
# Actual code
|
||||
print("Thread local n°{} parle depuis {} !".format(self.id, self.address))
|
||||
n = 1
|
||||
for i in range(1000):
|
||||
n *= i
|
||||
|
||||
L = [random.randint(0,3000) for x in range(random.randint(0, 300))]
|
||||
|
||||
for i in xrange(10000000):
|
||||
sum(range(100))
|
||||
|
||||
self.namespace.returncode = SuccessfulOperation()
|
||||
|
||||
except Exception as exception:
|
||||
self.namespace.returncode = exception
|
||||
|
||||
## Master Thread
|
||||
class GreatScheduler(threading.Thread):
|
||||
|
||||
def __init__(self, preemption_space, arrow_list, n_thread, nmax_cycles):
|
||||
|
|
33
src/test.pyx
33
src/test.pyx
|
@ -1,18 +1,19 @@
|
|||
from threading import Thread
|
||||
import time
|
||||
def countdown():
|
||||
n = 50
|
||||
while n > 0:
|
||||
n -= 1
|
||||
import multiprocessing
|
||||
|
||||
COUNT = 10000000
|
||||
def func():
|
||||
for i in range(10000000):
|
||||
sum(range(100))
|
||||
|
||||
with nogil:
|
||||
t1 = Thread(target=countdown)
|
||||
t2 = Thread(target=countdown)
|
||||
start = time.time()
|
||||
t1.start();t2.start()
|
||||
t1.join();t2.join()
|
||||
|
||||
end = time.time()
|
||||
print end-start
|
||||
procs = []
|
||||
for i in range(200):
|
||||
p = multiprocessing.Process(target=func)
|
||||
p.start()
|
||||
procs.append(p)
|
||||
|
||||
print 'started', len(procs), 'processes'
|
||||
|
||||
for p in procs:
|
||||
p.join()
|
||||
print 'process done'
|
||||
|
||||
print 'all done'
|
||||
|
|
Loading…
Reference in New Issue