Last active
January 22, 2017 19:38
-
-
Save artificialsoph/2dad5ebed45c50543e10bdcb6f1224f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
list_of_inputs = [0, 1, 2, 3] | |
def calculate_function(ind_input): | |
return ind_input**2 | |
results = [] | |
####### as a for loop (option 1, not parallel) | |
for ind_input in list_of_inputs: | |
results.append(calculate_function(ind_input)) | |
####### as a starmap | |
num_cpu = 4 # use multiprocessing.cpu_count() to see how many are available | |
pool = multiprocessing.Pool(processes=num_cpu) | |
results = pool.map(calculate_function,list_of_inputs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment