-
-
Save AruniRC/49b87469e45358ca571594752908ba0a to your computer and use it in GitHub Desktop.
Example code to demonstrate parallel for (parfor) loop implementation using joblib
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
# Example code to demonstrate parallel for loop implementation using joblib | |
from joblib import Parallel, delayed | |
import multiprocessing | |
# Vars | |
my_list = range(10) | |
squares = [] | |
# Function to parallelize | |
def find_square(i): | |
return i ** 2 | |
# Without parallel processing | |
for index, element in enumerate(my_list): | |
squares.append(find_square(element)) | |
# With parallel processing | |
num_cores = multiprocessing.cpu_count() | |
squares = Parallel(n_jobs=num_cores, verbose=50)(delayed( | |
find_square)(i)for i in my_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment