Detecting how many CPUs to use automatically

This commit is contained in:
Adrien Bourmault 2021-04-10 23:14:59 +02:00
parent 4486026d23
commit cbcd402c4c
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
2 changed files with 12 additions and 5 deletions

View File

@ -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

View File

@ -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
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.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):