Skip to content
  • Ell's avatar
    gegl-parallel: improve optimal thread-count calculation · e1d01be8
    Ell authored
    Previously, the number of threads used by
    gegl_parallel_distribute_{range,area}() was proportional to the
    number of elements to be processed, such that each thread processed
    at least a user-provided minimal number of elements.  This,
    however, fails to take into account the fact that each additional
    thread lowers the effective cost of processing each additional
    element, since processing is spread over more threads, and
    therefore more elements are necessary to justify each additional
    thread.
    
    To find the optimal number of threads to use, we assume that the
    cost of processing the elements is proportional to the number of
    elements to be processed by each thread, and that each thread
    additional incurs a fixed cost.  This cost is specified by a user-
    provided parameter, relative to the cost of processing a single
    element, replacing the old minimal per-thread element-count
    paramter (it is expected, however, that this parameter will take
    the same value as the old parameter; in particular, the minimal
    number of per-thread elements for using two threads equals the the
    cost.)
    
    In other words, the cost of processing n elements, using t threads,
    with a fixed realtive per-thread cost c, is assumed to be
    proportional to:
    
      n / t + c * t
    
    The number of threads, t, that minimize this cost, for a given per-
    thread cost, c, is roughly proportional to the square root of the
    number of elements, n.
    e1d01be8