Got ArgumentError: Type must be isbitstype when code with MPI

Hi guys,

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

Here is a piece of code:

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!

You probably got that error because the element type of the array is not isbitstype, not the array itself.

What is eltype(send_mesg)?

It is Union{Missing, Float64}.

I have some NaN in the DataFrame…

In that particular case, if you don’t mind the extra allocations, you can convert missings to actual NaNs, which are Float64.

For example:

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 NaNs back to missing after receiving the data.

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 missings were converted to NaNs, and eltype(send_mesg) became Real.

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

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

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

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 Ints and Float64s. In that case, you can try the following:

send_mesg = Float64[ismissing(x) ? NaN : x for x in row]
1 Like

It solved the problem, thank you very much!