# Got ArgumentError: Type must be isbitstype when code with MPI

**URL:** <https://discourse.julialang.org/t/got-argumenterror-type-must-be-isbitstype-when-code-with-mpi/44749>\
**Category:** General Usage\
**Tags:** question, mpi\
**Created:** [August 11, 2020, 4:11pm UTC](https://discourse.julialang.org/t/got-argumenterror-type-must-be-isbitstype-when-code-with-mpi/44749 "2020-08-11T16:11:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ke\_Gao](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@Ke\_Gao](https://discourse.julialang.org/u/Ke_Gao)\
**Post date:** [August 11, 2020, 4:11pm UTC](https://discourse.julialang.org/t/got-argumenterror-type-must-be-isbitstype-when-code-with-mpi/44749/1 "2020-08-11T16:11:44Z")

</div>

Hi guys,

I got an `ArgumentError: Type must be isbitstype ` when I tried to work with MPI.jl.

Here is a piece of code:

```nohighlight
for row in eachrow(init_ele)
    println(i)
    send_mesg = vec(convert(Array, row))
    println(send_mesg)
    MPI.Send(send_mesg, i, tag, comm)
    i += 1
end

```

The `init_ele` is a DataFrame, so send\_mesg is a 1D array.

I thought I got the error because Array is not isbitstype. If so, how could I send data in MPI?

Any help is welcome, thank you!

---

<div class="post-metadata">

**Author:** ![jipolanco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jipolanco/32/12129_2.png) [@jipolanco](https://discourse.julialang.org/u/jipolanco)\
**Post date:** [August 11, 2020, 4:25pm UTC](https://discourse.julialang.org/t/got-argumenterror-type-must-be-isbitstype-when-code-with-mpi/44749/2 "2020-08-11T16:25:33Z")

</div>

You probably got that error because the _element type_ of the array is not `isbitstype`, not the array itself.

What is `eltype(send_mesg)`?

---

<div class="post-metadata">

**Author:** ![Ke\_Gao](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@Ke\_Gao](https://discourse.julialang.org/u/Ke_Gao)\
**Post date:** [August 11, 2020, 4:37pm UTC](https://discourse.julialang.org/t/got-argumenterror-type-must-be-isbitstype-when-code-with-mpi/44749/3 "2020-08-11T16:37:33Z")

</div>

It is `Union{Missing, Float64}`.

I have some NaN in the DataFrame…

---

<div class="post-metadata">

**Author:** ![jipolanco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jipolanco/32/12129_2.png) [@jipolanco](https://discourse.julialang.org/u/jipolanco)\
**Post date:** [August 11, 2020, 5:02pm UTC](https://discourse.julialang.org/t/got-argumenterror-type-must-be-isbitstype-when-code-with-mpi/44749/4 "2020-08-11T17:02:03Z")

</div>

In that particular case, if you don’t mind the extra allocations, you can convert `missing`s to actual `NaN`s, which are `Float64`.

For example:

```julia
send_mesg = [ismissing(x) ? NaN : x for x in row]

```

It’s not very elegant, but it should work with MPI if your data is `Union{Missing, Float64}`.

Similarly, you may convert the `NaN`s back to `missing` after receiving the data.

---

<div class="post-metadata">

**Author:** ![Ke\_Gao](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@Ke\_Gao](https://discourse.julialang.org/u/Ke_Gao)\
**Post date:** [August 12, 2020, 9:27am UTC](https://discourse.julialang.org/t/got-argumenterror-type-must-be-isbitstype-when-code-with-mpi/44749/5 "2020-08-12T09:27:46Z")

</div>

That’s a good idea!

Just modify your code slightly to `send_mesg = Array([ismissing(x) ? x = NaN : x for x in row])` because I got `MethodError: Cannot `convert` an object of type Missing to an object of type Float64` if use oftype() function.

Then the `missing`s were converted to `NaN`s, and `eltype(send_mesg)` became `Real`.

But I still got `ArgumentError: Type must be isbitstype` even so… Any ideas?

---

<div class="post-metadata">

**Author:** ![jipolanco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jipolanco/32/12129_2.png) [@jipolanco](https://discourse.julialang.org/u/jipolanco)\
**Post date:** [August 12, 2020, 9:41am UTC](https://discourse.julialang.org/t/got-argumenterror-type-must-be-isbitstype-when-code-with-mpi/44749/6 "2020-08-12T09:41:17Z")

</div>

Sorry, `oftype` was used incorrectly. I just edited my previous post.

Still, if you have an array of `Union{Missing, Float64}`, say

```julia
row = [3.0, 1.2, missing, 3.1]

```

then the above code (that I just edited) should give you a `Vector{Float64}`.

If you got an array of `Real`, it’s probably because your original data is not `Float64`, but a different subtype of `Real` such as `Int`, and then you’re mixing `Int`s and `Float64`s. In that case, you can try the following:

```julia
send_mesg = Float64[ismissing(x) ? NaN : x for x in row]

```

---

<div class="post-metadata">

**Author:** ![Ke\_Gao](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@Ke\_Gao](https://discourse.julialang.org/u/Ke_Gao)\
**Post date:** [August 12, 2020, 9:49am UTC](https://discourse.julialang.org/t/got-argumenterror-type-must-be-isbitstype-when-code-with-mpi/44749/7 "2020-08-12T09:49:15Z")

</div>

> [@jipolanco](#):
>
> `send_mesg = Float64[ismissing(x) ? NaN : x for x in row]`

It solved the problem, thank you very much!
