Detecting how many CPUs to use automatically
This commit is contained in:
parent
4486026d23
commit
cbcd402c4c
|
@ -30,7 +30,7 @@ PREEMPTION_GLOBAL_SPACE = [True] * SPACE_SIZE
|
||||||
DRAWING_GLOBAL_SPACE = []
|
DRAWING_GLOBAL_SPACE = []
|
||||||
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 = 10
|
MAX_THREAD = 0
|
||||||
|
|
||||||
masterThread = scheduler.GreatScheduler(PREEMPTION_GLOBAL_SPACE, TRANSITIONS_TREE, ARROW_LIST, MAX_THREAD, MAX_CYCLES)
|
masterThread = scheduler.GreatScheduler(PREEMPTION_GLOBAL_SPACE, TRANSITIONS_TREE, ARROW_LIST, MAX_THREAD, MAX_CYCLES)
|
||||||
|
|
||||||
|
@ -38,4 +38,4 @@ masterThread.start()
|
||||||
server.ServerCLI.start()
|
server.ServerCLI.start()
|
||||||
|
|
||||||
## Exiting
|
## Exiting
|
||||||
scheduler.masterThread = True
|
masterThread.stopped = True
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
#=----------------------------------------------------------------------------=#
|
#=----------------------------------------------------------------------------=#
|
||||||
|
|
||||||
import multiprocessing, threading
|
import os, multiprocessing, threading
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import localthread
|
import localthread
|
||||||
|
@ -34,10 +34,17 @@ class GreatScheduler(threading.Thread):
|
||||||
self.preemption_space = preemption_space
|
self.preemption_space = preemption_space
|
||||||
self.transition_tree = transitions_tree
|
self.transition_tree = transitions_tree
|
||||||
self.arrow_list = arrow_list
|
self.arrow_list = arrow_list
|
||||||
self.n_thread = n_thread
|
|
||||||
|
if n_thread == 0: # No limit
|
||||||
|
# Use number of usable CPUs multiplied by 3
|
||||||
|
self.n_thread = len(os.sched_getaffinity(0)) * 3
|
||||||
|
else:
|
||||||
|
self.n_thread = n_thread
|
||||||
|
|
||||||
self.cur_id = -1
|
self.cur_id = -1
|
||||||
self.n_cycle = -1
|
self.n_cycle = -1
|
||||||
self.nmax_cycles = nmax_cycles
|
self.nmax_cycles = nmax_cycles
|
||||||
|
|
||||||
self.stopped = False
|
self.stopped = False
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
Loading…
Reference in New Issue