# EXCEPTION\_ACCESS\_VIOLATION on Windows but not MacOS

**URL:** <https://discourse.julialang.org/t/exception-access-violation-on-windows-but-not-macos/127653>\
**Category:** General Usage\
**Created:** [April 3, 2025, 1:38am UTC](https://discourse.julialang.org/t/exception-access-violation-on-windows-but-not-macos/127653 "2025-04-03T01:38:29Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![danielwe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielwe/32/35657_2.png) [@danielwe](https://discourse.julialang.org/u/danielwe)\
**Post date:** [April 24, 2025, 8:55pm UTC](https://discourse.julialang.org/t/exception-access-violation-on-windows-but-not-macos/127653/13 "2025-04-24T20:55:52Z")

</div>

EDIT: Reading your first post again it looks like you may eventually want this code to run on GPU. In that case, `dot` is probably the way to go, and if not, definitely `mapreduce` and not one of the `sum` variants below. But I don’t think having a zip in there is GPU friendly/compatible—I think the `mapreduce` invocation you want is the following:

```julia
mapreduce(*, +, local_patch, err)

```

~~The mapreduce expression is kind of obscure, and mapreduce is generally not as well optimized as it should be (it often creates unnecessary intermediate allocations). I’d recommend a simple and easy to understand generator sum:~~

```julia
sum(l * e for (l, e) in zip(local_patch, err))

```

~~or even~~

```julia
sum(local_patch[i] * err[i] for i in eachindex(local_patch, err))

```

~~Curious how they affect your benchmarks.~~

* * *

And to drive home the point from the thread above: `@inbounds` is _dangerous_, precisely because you can’t rely on anyone saving your bacon if the index is actually out of bounds. Sometimes you get a segfault, sometimes you corrupt some program state, and sometimes you simply get an arbitrary value, often but not always zero. Avoid `@inbounds` as much as you can, and if your benchmarks show that you really need it for performance, add a line of code in the same function, but outside the hot loop, that checks that all the indices that will be visited during the loop are inbounds. See this post for an example of how that might look: [When does @inbounds increase performance? - #3 by danielwe](https://discourse.julialang.org/t/when-does-inbounds-increase-performance/123827/3)

---

_[View the full topic](https://discourse.julialang.org/t/exception-access-violation-on-windows-but-not-macos/127653)._
