I have some python code, which relies on a piece of c++ code that essentially does a large tree search. I need to run this tree search n times in a for loop and since each iteration was taking several second I figured this would be an obvious place to add some multiprocessing in python to speed things up. My multiprocessing is fairly standard: with Pool() as pool: probs = pool.starmap(self._probs_multi, zip(self.features, self.scales, repeat(labels), repeat(nr_classes))) I can see that when I run it, I get n cores that operate at 100% load (when n is smaller than my number of cores), as opposed to the sequential case where I had 1 core operating at 100% load. However the total runtime of the for loop is still taking the same amount of time! The c++ library is right now loaded using something like this: import ctypes import numpy.ctypeslib as ctl libfile = os.path.dirname(__file__) + '/km_dict_lib.so' lib = ctypes.cdll.LoadLibrary(libfile) py_km_tree_multi = lib.build_km_tree_multi # say which inputs the function expects py_km_tree_multi.argtypes = [ctl.ndpointer(ctypes.c_double, flags="C_CONTIGUOUS"), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_bool, ctl.ndpointer(ctypes.c_double, flags="C_CONTIGUOUS")] py_km_tree_multi(image, rows, cols, channels, n_im, self.patch_size, self.number_layers, self.branching_factor, number_training_patches, self.normalization, self.tree) I can think of two reasons why the sequential run is as fast as the multiprocessor run. The first reason is that the job is not actually cpu bound but memory bound instead, I guess this could be the case for a tree search I am not really that experienced with them, but if this is the case it seems strange to me that all n cores are having 100% load which to me suggest it should be cpu bound? The other option is that somehow the multiprocessing isn't actually working when the python script is calling an external c++ function or that my naive approach for this is insufficient. Does anyone have any insight into how I can move forward with this and figure out what is wrong? Continue reading...