# Segmentation fault using ArrayFire and @spawn

**URL:** <https://discourse.julialang.org/t/segmentation-fault-using-arrayfire-and-spawn/19266>\
**Category:** Julia at Scale\
**Created:** [January 4, 2019, 10:58am UTC](https://discourse.julialang.org/t/segmentation-fault-using-arrayfire-and-spawn/19266 "2019-01-04T10:58:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [January 4, 2019, 10:58am UTC](https://discourse.julialang.org/t/segmentation-fault-using-arrayfire-and-spawn/19266/1 "2019-01-04T10:58:47Z")

</div>

Hello beautiful people,

I have some process that can fit at my GPU memory, so to speed up, I was wondering if I could run parallel process (`using Distributed`). My hope was that Julia would do its magic, but I just got a segmentation fault. Here a dummy code:

```julia
using ArrayFire
function foo(N) # Just to be sure that something is working
    A = rand(N,N)
    b = rand(N)

    Af = AFArray(A)
    bf = AFArray(b)

    C = A*b
    Cf = Af*bf
    return Cf, C
end

foo(5) # OK

# --------------

using Distributed
addprocs(3)

@everywhere begin

    using ArrayFire
    function foo(N)
        A = rand(N,N)
        b = rand(N)

        Af = AFArray(A)
        bf = AFArray(b)

        C = A*b
        Cf = Af*bf
        return Cf, C
    end

end

# works as expected
r = @spawn rand(2,2)
fetch(r)

# does not works
s = @spawn foo(3)
fetch(s)

# also does not works
s = pmap(x->foo(x), 2:5)

```

The message that I get is:

```julia
signal (11): Segmentation fault
in expression starting at no file:0
unknown function (ip: 0x7f2fcb90fc2f)
Allocations: 70383902 (Pool: 70368264; Big: 15638); GC: 156

```

Is there clever/not clever way to do my code to run without use Julia’s parallel functions ?

Thank you

For reference:  
Julia version 1.0.1 (MKL), GPU Vega RX 64, ArrayFire 6.3.1
