Commit f905fd4d authored by Thomas Vincent's avatar Thomas Vincent

Use default n_proc instead of cpu_count during merge

parent b3eec347
...@@ -38,13 +38,14 @@ import os.path ...@@ -38,13 +38,14 @@ import os.path
import ctypes import ctypes
from threading import Thread from threading import Thread
import multiprocessing.sharedctypes as mp_sharedctypes import multiprocessing.sharedctypes as mp_sharedctypes
from multiprocessing import Pool, cpu_count, Manager from multiprocessing import Pool, Manager
import h5py import h5py
import numpy as np import numpy as np
import fabio import fabio
from ...io import XsocsH5 from ...io import XsocsH5
from ... import config
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
...@@ -121,7 +122,7 @@ class KmapMerger(object): ...@@ -121,7 +122,7 @@ class KmapMerger(object):
self.__spec_h5 = spec_h5 self.__spec_h5 = spec_h5
self.__callback = callback self.__callback = callback
self.__n_proc = None self.__n_proc = config.DEFAULT_PROCESS_NUMBER
self.__compression = 'lzf' self.__compression = 'lzf'
self.__prefix = 'prefix' self.__prefix = 'prefix'
self.__overwrite = False self.__overwrite = False
...@@ -254,15 +255,10 @@ class KmapMerger(object): ...@@ -254,15 +255,10 @@ class KmapMerger(object):
with XsocsH5.XsocsH5MasterWriter(master_f, mode=mode): with XsocsH5.XsocsH5MasterWriter(master_f, mode=mode):
pass pass
if self.__n_proc is None:
n_proc = cpu_count()
else:
n_proc = self.__n_proc
# setting progress to 0 # setting progress to 0
np.frombuffer(self.__shared_progress, dtype='int32')[:] = 0 np.frombuffer(self.__shared_progress, dtype='int32')[:] = 0
pool = Pool(n_proc, pool = Pool(self.n_proc,
initializer=_init_process, initializer=_init_process,
initargs=(term_evt, initargs=(term_evt,
self.__shared_progress), self.__shared_progress),
...@@ -530,15 +526,13 @@ class KmapMerger(object): ...@@ -530,15 +526,13 @@ class KmapMerger(object):
@n_proc.setter @n_proc.setter
def n_proc(self, n_proc): def n_proc(self, n_proc):
if n_proc is None: if n_proc is None: # Use default
self.__n_proc = None n_proc = config.DEFAULT_PROCESS_NUMBER
return
n_proc = int(n_proc) n_proc = int(n_proc)
if n_proc <= 0: if n_proc <= 0:
self.__n_proc = None raise ValueError('n_proc must be strictly positive')
else: self.__n_proc = n_proc
self.__n_proc = n_proc
image_roi = property(lambda self: self.__image_roi) image_roi = property(lambda self: self.__image_roi)
......
...@@ -90,10 +90,10 @@ def merge_scan_data(output_dir, ...@@ -90,10 +90,10 @@ def merge_scan_data(output_dir,
headers. headers.
:type img_dir: *optional* str :type img_dir: *optional* str
:param n_proc: Number of threads to use when merging files. If None, the :param Union[int,None] n_proc:
number of threads used will be the value returned by the function Number of threads to use when merging files.
`multiprocessing.cpu_count()` If None, the number of processes used will be the
:type n_proc: *optional* str default config value (usually the number of cores).
:param version: version of the spec file. It is currently used to get :param version: version of the spec file. It is currently used to get
the offset and padding to apply to the nextNr value found in the spec scan the offset and padding to apply to the nextNr value found in the spec scan
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment