# Speed issue with KahanSummation

**URL:** <https://discourse.julialang.org/t/speed-issue-with-kahansummation/75491>\
**Category:** Performance\
**Tags:** question, package, parallel\
**Created:** [January 31, 2022, 6:29am UTC](https://discourse.julialang.org/t/speed-issue-with-kahansummation/75491 "2022-01-31T06:29:26Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![HJW019](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hjw019/32/22102_2.png) [@HJW019](https://discourse.julialang.org/u/HJW019)\
**Post date:** [February 3, 2022, 9:35am UTC](https://discourse.julialang.org/t/speed-issue-with-kahansummation/75491/10 "2022-02-03T09:35:20Z")

</div>

> AccurateArithmetic is implemented in Julia using `llvmcall` , not C. If your definition of “pure Julia” allows for wrapping LLVM’s SIMD intrinsics with `llvmcall` , then it is “pure Julia”.

Thank you for the clarification. By “pure Julia” I meant in the sense of ForwardDiff.jl’s “generic Julia” explained [in the doc] ([Limitations of ForwardDiff · ForwardDiff](https://juliadiff.org/ForwardDiff.jl/stable/user/limitations/)). I tried using AccurateArithmetic’s `sum_oro()` and `sum_kbn()` in a maximum likelihood estimation using Optim.jl with the `autodiff = :forward` option, and it didn’t work. I am not sure whether it is because `sum_oro()` and `sum_kbn()` are not “generic Julia” to ForwardDiff. I started [another thread](https://discourse.julialang.org/t/high-precision-summation-functions-not-compatible-with-optim-jl-with-autodiff-forward/75714) to discuss the issue there, where I provided a MWE.

> b) Seems like there is almost certainly a better way to get gradients with respect to a sum. E.g., overload (type piracy…) to provide a specialized implementation that takes `ForwardDiff.Dual` as inputs.

I am afraid I have no clue here. The MWE in the new thread mentioned above is very simple, but my real work involves high dimension Monte Carlo integrations which make the whole thing more complicated, I think. If there is a straightforward approach, I’ll certainly try.

---

_[View the full topic](https://discourse.julialang.org/t/speed-issue-with-kahansummation/75491)._
