I've got this program:
def optimal(t0, tf, frequences, delay, ratio = 0):
First = True
for s in delay:
delay = 0
timelines = list()
for i in range(len(frequences)):
timelines.append(time_builder(frequences[i], t0+delay, tf))
delay += s
It takes in input an initial time t0, a final time tf, a list of 5 frequencies, and this `
If the value s meets the requirements, i.e valid = True and optim_param_1 < optimal[3], then optimal is replaced with optimal = (s, _overlap, __trio_overlap, optim_param_1).
The problem is that there are many possibilities for s to be tested and that the computation within is quite long. I would like to use several threads to speed up the process. I've never actually done it and I've been read there are limitations and algorithm design choices to make to avoid false results.
First question, is it possible to modify this algorithm into a multithread one?
Second question, is from threading import Thread the right solution?
Third question, since optimal is shared between threads (comparison to find out if the solution is better than the previous best one), should I create one optimal per thread and then compare which one of the optimal is the best, or is there another way?
Thanks for the tips, I really don't know where to start with multithreading....
EDIT: Some s value computation might be fast, and some quite long. There is not 2 with the same duration.