summaryrefslogtreecommitdiff
path: root/ot/utils.py
diff options
context:
space:
mode:
authorkguerda-idris <84066930+kguerda-idris@users.noreply.github.com>2021-09-29 15:29:31 +0200
committerGitHub <noreply@github.com>2021-09-29 15:29:31 +0200
commit1c7e7ce2da8bb362c184fb6eae71fe7e36356494 (patch)
tree92fdc31870b6d5384c8ba83ff72d85a2d5a1eee6 /ot/utils.py
parent7dde9e8e4b6aae756e103d49198caaa4f24150e3 (diff)
[MRG] OpenMP support (#260)
* Added : OpenMP support Restored : Epsilon and Debug mode Replaced : parmap => multiprocessing is now replace by multithreading * Commit clean up * Number of CPUs correctly calculated on SLURM clusters * Corrected number of processes for cluster slurm * Mistake corrected * parmap is now deprecated * Now a different solver is used depending on the requested number of threads * Tiny mistake corrected * Folders are now in the ot library instead of at the root * Helpers is now correctly placed * Attempt to make compilation work smoothly * OS compatible path * NumThreads now defaults to 1 * Better flags * Mistake corrected in case of OpenMP unavailability * Revert OpenMP flags modification, which do not compile on Windows * Test helper functions * Helpers comments * Documentation update * File title corrected * Warning no longer using print * Last attempt for macos compilation * pls work * atempt * solving a type error * TypeError OpenMP * Compilation finally working on Windows * Bug solve, number of threads now correctly selected * 64 bits solver to avoid overflows for bigger problems * 64 bits EMD corrected Co-authored-by: kguerda-idris <ssos023@jean-zay3.idris.fr> Co-authored-by: ncassereau-idris <84033440+ncassereau-idris@users.noreply.github.com> Co-authored-by: ncassereau <nathan.cassereau@idris.fr> Co-authored-by: RĂ©mi Flamary <remi.flamary@gmail.com>
Diffstat (limited to 'ot/utils.py')
-rw-r--r--ot/utils.py38
1 files changed, 5 insertions, 33 deletions
diff --git a/ot/utils.py b/ot/utils.py
index 4dac0c5..6a782e6 100644
--- a/ot/utils.py
+++ b/ot/utils.py
@@ -7,7 +7,6 @@ Various useful functions
#
# License: MIT License
-import multiprocessing
from functools import reduce
import time
@@ -311,38 +310,11 @@ def label_normalization(y, start=0):
return y
-def fun(f, q_in, q_out):
- """ Utility function for parmap with no serializing problems """
- while True:
- i, x = q_in.get()
- if i is None:
- break
- q_out.put((i, f(x)))
-
-
-def parmap(f, X, nprocs=multiprocessing.cpu_count()):
- """ paralell map for multiprocessing (only map on windows)"""
-
- if not sys.platform.endswith('win32') and not sys.platform.endswith('darwin'):
-
- q_in = multiprocessing.Queue(1)
- q_out = multiprocessing.Queue()
-
- proc = [multiprocessing.Process(target=fun, args=(f, q_in, q_out))
- for _ in range(nprocs)]
- for p in proc:
- p.daemon = True
- p.start()
-
- sent = [q_in.put((i, x)) for i, x in enumerate(X)]
- [q_in.put((None, None)) for _ in range(nprocs)]
- res = [q_out.get() for _ in range(len(sent))]
-
- [p.join() for p in proc]
-
- return [x for i, x in sorted(res)]
- else:
- return list(map(f, X))
+def parmap(f, X, nprocs="default"):
+ """ paralell map for multiprocessing.
+ The function has been deprecated and only performs a regular map.
+ """
+ return list(map(f, X))
def check_params(**kwargs):