I have a working cocotb setup as below. I want to use multi-processing in Python to run iterations in the loop to parallelize the execution.
Current setup:
from cocotb.decorators import coroutine
factory = TestFactory(Run)
@coroutine
def Run(dut,arg1, arg2):
for i in range(N):
ret = yield host.run_test(arg1, arg2)
What I tried:
from cocotb.decorators import coroutine
from multiprocessing import Process, Queue, Manager, Value
factory = TestFactory(Run)
@coroutine
def run_thread(arg1, arg2):
for i in range(N/n_threads):
ret = yield host.run_test(arg1, arg2)
@coroutine
def Run(dut,arg1, arg2):
threads = []
for n in range(0, n_threads):
threads.append(Process(target=run_thread, args=(arg1, arg2)))
for n in range(0, n_threads):
threads[n].start()
for n in range(0, n_threads):
threads[n].join()
As shown above, I tried putting all the content of the loop into a function and calling it using multiprocessing.Process. But when I execute it this way, run_test is not getting called properly.
I believe this is because I have a yield command for run_test and run_thread function returns a generator because of that. However, I don't see any way to iterate through the output of run_thread function because I am calling it in a thread.
Is there any way that I can get this working? Any guidance is much appreciated.
PS: I made a slight mistake in the second code in run_thread function. We need to have a for loop there are well. I corrected it now.