mirror of https://github.com/KLayout/klayout.git
adding multithreaded extension build for setup.py
This commit is contained in:
parent
98a6b39e68
commit
98d66725eb
20
setup.py
20
setup.py
|
|
@ -60,6 +60,26 @@ import os
|
|||
import platform
|
||||
import distutils.sysconfig as sysconfig
|
||||
|
||||
|
||||
# monkey-patch for parallel compilation
|
||||
# from https://stackoverflow.com/questions/11013851/speeding-up-build-process-with-distutils
|
||||
def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None):
|
||||
# those lines are copied from distutils.ccompiler.CCompiler directly
|
||||
macros, objects, extra_postargs, pp_opts, build = self._setup_compile(output_dir, macros, include_dirs, sources, depends, extra_postargs)
|
||||
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
|
||||
# parallel code
|
||||
N=2 # number of parallel compilations
|
||||
import multiprocessing.pool
|
||||
def _single_compile(obj):
|
||||
try: src, ext = build[obj]
|
||||
except KeyError: return
|
||||
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
|
||||
# convert to list, imap is evaluated on-demand
|
||||
list(multiprocessing.pool.ThreadPool(N).imap(_single_compile,objects))
|
||||
return objects
|
||||
import distutils.ccompiler
|
||||
distutils.ccompiler.CCompiler.compile=parallelCCompile
|
||||
|
||||
# ----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue