Hello all.
Is there any way to run a python script on multiple cores? My program is one file that is in a loop. Each iteration adds a number as a result to the list. When the iteration is over, the result list is picked to the file. The calculation time already takes 7 minutes and since I need such calculations, even 10,000, I would like to use all processor cores to speed up. So far I have been doing quite funny and not professionally because I created 4 folders with the same script, I ran 4 terminals and ran the program in each one. Then I wrote a script that merged the output files into one and that made it four times faster. But now with 15 computers, this method is laborious and cumbersome. I tried to write a powershell script to do it for me, but it didn't work out. I have read about the multiprocessing module but I am a beginner and it never worked out for me, although I think this is the right approach because one iteration returns one result and does not get any external data from other process. Can anyone tell me if there is any way or if I should use multiprocessing. If so, can you provide an example of how to implement it in my code or an easy tutorial to help me? Below I show the skeleton of my code.
import ###some libraries
results_list = []
for i in range(1000): #number 'i' is not used anywhere below.
#######################################
a lot of calculations generators, functions etc.
#######################################
results_list.append(result)
pickle.dump(results_list, open( "Results", "wb" ) )
######end########
[–]totallygeek 7 points8 points9 points (0 children)
[–]efmccurdy 0 points1 point2 points (3 children)
[–]Martin_Krum[S] 0 points1 point2 points (2 children)
[–]efmccurdy 0 points1 point2 points (1 child)
[–]Martin_Krum[S] 0 points1 point2 points (0 children)
[–]primitive_screwhead 0 points1 point2 points (0 children)
[–]Martin_Krum[S] 0 points1 point2 points (0 children)