Separate compilation with Cython works !
This commit is contained in:
parent
fd78079ea2
commit
63c0b33451
49
src/Makefile
49
src/Makefile
|
@ -1,23 +1,48 @@
|
|||
.PHONY: all scheduler clean test
|
||||
#=----------------------------------------------------------------------------=#
|
||||
# Makefile #
|
||||
# #
|
||||
# Copyright © 2021 The Gem-graph Project #
|
||||
# #
|
||||
# This file is part of gem-graph. #
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU Affero General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU Affero General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Affero General Public License #
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
CCOPTS=-pthread -fPIC -fwrapv -Wall -fno-strict-aliasing
|
||||
CCFLAGS=-I /usr/include/python3.9
|
||||
LDFLAGS=-lpython3.9 -lpthread -lm -lutil
|
||||
LDFLAGS=-lpython3.9 -lpthread -lm -lutil -ldl
|
||||
|
||||
scheduler: scheduler.c
|
||||
gcc $(CCOPTS) $(CCFLAGS) -o scheduler scheduler.c $(LDFLAGS)
|
||||
DEPS=main.c scheduler.c server.c localthread.c
|
||||
|
||||
scheduler.c: scheduler.pyx
|
||||
cython3 scheduler.pyx --embed
|
||||
gem-graph-server: $(DEPS)
|
||||
$(CC) $(CCOPTS) $(CCFLAGS) -o $@ $(DEPS) $(LDFLAGS)
|
||||
|
||||
%.c: %.py
|
||||
cython3 $< -o $@
|
||||
|
||||
main.c: main.py
|
||||
cython3 $< -o $@ --embed
|
||||
|
||||
clean:
|
||||
rm -rf scheduler.c scheduler
|
||||
rm -rf test.c test
|
||||
rm -rf *.c *.o gem-graph-server test
|
||||
|
||||
all: scheduler
|
||||
all: gem-graph-server
|
||||
|
||||
test: test.c
|
||||
gcc $(CCOPTS) $(CCFLAGS) -o test test.c $(LDFLAGS)
|
||||
$(CC) $(CCOPTS) $(CCFLAGS) -o $@ $< $(LDFLAGS)
|
||||
|
||||
test.c: test.pyx
|
||||
cython3 test.pyx --embed
|
||||
test.c: test.py
|
||||
cython3 $< --embed
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,62 @@
|
|||
#=----------------------------------------------------------------------------=#
|
||||
# Local computing threads related functions #
|
||||
# #
|
||||
# Copyright © 2021 The Gem-graph Project #
|
||||
# #
|
||||
# This file is part of gem-graph. #
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU Affero General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU Affero General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Affero General Public License #
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
import random
|
||||
import multiprocessing
|
||||
|
||||
class CurrentlyComputing(Exception):
|
||||
pass
|
||||
|
||||
class SuccessfulOperation(Exception):
|
||||
pass
|
||||
|
||||
class FailedOperation(Exception):
|
||||
pass
|
||||
|
||||
## Local Threads
|
||||
|
||||
class LocalComputingUnit(multiprocessing.Process):
|
||||
|
||||
def __init__(self, id, shared_memory, address, orientation, transitions):
|
||||
|
||||
multiprocessing.Process.__init__(self)
|
||||
|
||||
self.id = id
|
||||
self.address = address
|
||||
self.orientation = orientation
|
||||
self.transitions = transitions
|
||||
self.namespace = shared_memory.Namespace()
|
||||
self.namespace.returncode = CurrentlyComputing()
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
# Actual code
|
||||
print("Thread local n°{} parle depuis {} !".format(self.id, self.address))
|
||||
|
||||
L = [random.randint(0,3000) for x in range(random.randint(0, 300))]
|
||||
|
||||
for i in range(10000000):
|
||||
sum(range(100))
|
||||
|
||||
self.namespace.returncode = SuccessfulOperation()
|
||||
|
||||
except Exception as exception:
|
||||
self.namespace.returncode = exception
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,41 @@
|
|||
#=----------------------------------------------------------------------------=#
|
||||
# Server interface related functions #
|
||||
# #
|
||||
# Copyright © 2021 The Gem-graph Project #
|
||||
# #
|
||||
# This file is part of gem-graph. #
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU Affero General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU Affero General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Affero General Public License #
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
import server
|
||||
import scheduler
|
||||
import random
|
||||
|
||||
ARROW_NUMBER = 150
|
||||
MAX_CYCLES = 20000
|
||||
SPACE_SIZE = 10000
|
||||
PREEMPTION_GLOBAL_SPACE = [True] * SPACE_SIZE
|
||||
DRAWING_GLOBAL_SPACE = []
|
||||
ARROW_LIST = [(random.randint(0,SPACE_SIZE - 1),0) for x in range(ARROW_NUMBER)]
|
||||
TRANSITIONS_TREE = None
|
||||
MAX_THREAD = 10
|
||||
|
||||
masterThread = scheduler.GreatScheduler(PREEMPTION_GLOBAL_SPACE, TRANSITIONS_TREE, ARROW_LIST, MAX_THREAD, MAX_CYCLES)
|
||||
|
||||
masterThread.start()
|
||||
server.ServerCLI.start()
|
||||
|
||||
## Exiting
|
||||
scheduler.masterThread = True
|
File diff suppressed because it is too large
Load Diff
|
@ -1,63 +1,38 @@
|
|||
#=----------------------------------------------------------------------------=#
|
||||
# Scheduler related functions #
|
||||
# #
|
||||
# Copyright © 2021 The Gem-graph Project #
|
||||
# #
|
||||
# This file is part of gem-graph. #
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU Affero General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU Affero General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Affero General Public License #
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
import multiprocessing, threading
|
||||
import time
|
||||
import random
|
||||
|
||||
ARROW_NUMBER = 150
|
||||
MAX_CYCLES = 20000
|
||||
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 = 10
|
||||
|
||||
|
||||
class CurrentlyComputing(Exception):
|
||||
pass
|
||||
|
||||
class SuccessfulOperation(Exception):
|
||||
pass
|
||||
|
||||
class FailedOperation(Exception):
|
||||
pass
|
||||
|
||||
## Local Threads
|
||||
|
||||
class LocalThread(multiprocessing.Process):
|
||||
|
||||
def __init__(self, id, shared_memory, address, orientation, transitions):
|
||||
|
||||
multiprocessing.Process.__init__(self)
|
||||
|
||||
self.id = id
|
||||
self.address = address
|
||||
self.orientation = orientation
|
||||
self.transitions = transitions
|
||||
self.namespace = shared_memory.Namespace()
|
||||
self.namespace.returncode = CurrentlyComputing()
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
# Actual code
|
||||
print("Thread local n°{} parle depuis {} !".format(self.id, self.address))
|
||||
|
||||
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
|
||||
import localthread
|
||||
|
||||
## Master Thread
|
||||
class GreatScheduler(threading.Thread):
|
||||
|
||||
def __init__(self, preemption_space, arrow_list, n_thread, nmax_cycles):
|
||||
def __init__(self, preemption_space, transitions_tree, arrow_list, n_thread, nmax_cycles):
|
||||
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
self.preemption_space = preemption_space
|
||||
self.transition_tree = transitions_tree
|
||||
self.arrow_list = arrow_list
|
||||
self.n_thread = n_thread
|
||||
self.cur_id = -1
|
||||
|
@ -91,11 +66,11 @@ class GreatScheduler(threading.Thread):
|
|||
self.cur_id += 1
|
||||
|
||||
thread_list.append(
|
||||
LocalThread(self.cur_id,
|
||||
localthread.LocalComputingUnit(self.cur_id,
|
||||
shared_memory,
|
||||
elected_arrow[0],
|
||||
elected_arrow[1],
|
||||
TRANSITIONS_TREE
|
||||
self.transition_tree
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -104,8 +79,8 @@ class GreatScheduler(threading.Thread):
|
|||
|
||||
for thread in thread_list:
|
||||
if not thread.is_alive():
|
||||
if not thread.namespace.returncode.__class__ is SuccessfulOperation:
|
||||
if thread.namespace.returncode.__class__ is FailedOperation:
|
||||
if not thread.namespace.returncode.__class__ is localthread.SuccessfulOperation:
|
||||
if thread.namespace.returncode.__class__ is localthread.FailedOperation:
|
||||
print("A optimiser : créer une règle")
|
||||
else:
|
||||
raise thread.namespace.returncode
|
||||
|
@ -119,23 +94,9 @@ class GreatScheduler(threading.Thread):
|
|||
|
||||
for thread in thread_list:
|
||||
thread.join()
|
||||
if not thread.namespace.returncode.__class__ is SuccessfulOperation:
|
||||
if thread.namespace.returncode.__class__ is FailedOperation:
|
||||
if not thread.namespace.returncode.__class__ is localthread.SuccessfulOperation:
|
||||
if thread.namespace.returncode.__class__ is localthread.FailedOperation:
|
||||
print("A optimiser : créer une règle")
|
||||
else:
|
||||
raise thread.namespace.returncode
|
||||
print("Thread local n°{} est terminé".format(thread.id))
|
||||
|
||||
class ServerCLI:
|
||||
|
||||
def start():
|
||||
stopped = False
|
||||
while not stopped:
|
||||
stopped = input()
|
||||
return
|
||||
|
||||
#multiprocessing.set_start_method('fork')
|
||||
scheduler = GreatScheduler(PREEMPTION_GLOBAL_SPACE, ARROW_LIST, MAX_THREAD, MAX_CYCLES)
|
||||
scheduler.start()
|
||||
ServerCLI.start()
|
||||
scheduler.stopped = True
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,28 @@
|
|||
#=----------------------------------------------------------------------------=#
|
||||
# Server interface related functions #
|
||||
# #
|
||||
# Copyright © 2021 The Gem-graph Project #
|
||||
# #
|
||||
# This file is part of gem-graph. #
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU Affero General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU Affero General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Affero General Public License #
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
class ServerCLI:
|
||||
|
||||
def start():
|
||||
stopped = False
|
||||
while not stopped:
|
||||
stopped = input()
|
||||
return
|
19
src/test.pyx
19
src/test.pyx
|
@ -1,19 +0,0 @@
|
|||
import multiprocessing
|
||||
|
||||
def func():
|
||||
for i in range(10000000):
|
||||
sum(range(100))
|
||||
|
||||
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