Open semal opened 1 year ago
Hi!
So, this is a nice idea, I actually didn't do it on purpose because they are recursive calls (inside generateProteins) that need to use the same shared memory that stores previous recursive results, so I can of expected a mess if one recursive call in a thread wanted the stored results of another call in another thread, which should happen, (this is actually recusrive + dynamical programming since it stores previous computations). Overall since we do this step once per PDB/antigen, I didn't push to make it more efficient.
But your idea is great and might work, I am just not sure in term of practical efficiency, or it might require tricks to share memorz between the threads and make locks in this common memory. my feeling is that a multithreaded version like this will have separate memory and perform the same recursive calls for each thread separately without using the power of saving the already calculated results from the other threads. The only way to know would be to run it! I am in holidays and changing job now, but in case you tried and it worked, I would be impressed!
I realized I might not have been clear :) feel free to ask more Best, Philippe
Below is some response from gpt4 maybe helpful, but I can not sure it works.
To make the selected code multi-threaded, we can use the pthread library to create multiple threads that can execute the for loop in parallel.
First, we need to declare a function that will be executed by each thread. This function should take a void argument and return a void value. In our case, we can define a function generateReceptorsThread that takes a pointer to a set object as its argument and returns NULL. This function will execute the for loop in the original code, but only for the positions in the given set.
Next, we need to create multiple threads and pass the appropriate arguments to each thread. We can use the pthread_create function to create a new thread and pass the set of positions as its argument. We can store the thread IDs in an array so that we can join them later.
In the modified code, we create a fixed number of threads (NUM_THREADS) and join them after processing a fixed number of positions. This helps to limit the number of threads created and reduces the overhead of thread creation and destruction.
Note that we need to include the pthread.h header file and link against the pthread library to use the pthread functions.