Created
January 31, 2019 14:40
-
-
Save andersx/e9ceea9821c2dd6061b32657c279d3ae to your computer and use it in GitHub Desktop.
Multiprocessing loop example
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
| def multiprocessing_func(pids, compounds_list, rd): | |
| for i in pids: | |
| rep_out = generate_fchl_acsf( | |
| compounds[i].nuclear_charges, | |
| compounds[i].coordinates, | |
| **rep_params) | |
| rd[i] = rep_out | |
| manager = mp.Manager() | |
| return_dict = manager.dict() | |
| processes = [] | |
| nprocs = 24 | |
| pids = np.array_split(list(range(TOTAL)),nprocs) | |
| for i in range(nprocs): | |
| p = mp.Process(target=multiprocessing_func, args=(pids[i],compounds,return_dict)) | |
| processes.append(p) | |
| p.start() | |
| for process in processes: | |
| process.join() | |
| for i, c in enumerate(compounds): | |
| c.representation = return_dict[i] | |
| # for i, c in enumerate(compounds): | |
| # c.representation = generate_fchl_acsf(c.nuclear_charges, | |
| # c.coordinates, **rep_params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment