Skip to content

Commit 98c2db3

Browse files
committed
add type dictionary to __init__
1 parent 6b63242 commit 98c2db3

File tree

2 files changed

+34
-42
lines changed

2 files changed

+34
-42
lines changed

src/MPI.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,34 @@ function __init__()
3030
eval(:(const $jname = Libdl.dlsym(libmpi_handle, $fname)))
3131
end
3232
end
33+
34+
global const mpitype_dict = Dict{DataType, Cint}(
35+
# Older versions of OpenMPI (such as those used by default in
36+
# Travis) do not define MPI_WCHAR and the MPI_*INT*_T types for
37+
# Fortran. We thus don't require them (yet).
38+
# Char => MPI_WCHAR,
39+
# Int8 => MPI_INT8_T,
40+
# UInt8 => MPI_UINT8_T,
41+
# Int16 => MPI_INT16_T,
42+
# UInt16 => MPI_UINT16_T,
43+
# Int32 => MPI_INT32_T,
44+
# UInt32 => MPI_UINT32_T,
45+
# Int64 => MPI_INT64_T,
46+
# UInt64 => MPI_UINT64_T,
47+
Char => MPI_INTEGER4,
48+
Int8 => MPI_INTEGER1,
49+
UInt8 => MPI_INTEGER1,
50+
Int16 => MPI_INTEGER2,
51+
UInt16 => MPI_INTEGER2,
52+
Int32 => MPI_INTEGER4,
53+
UInt32 => MPI_INTEGER4,
54+
Int64 => MPI_INTEGER8,
55+
UInt64 => MPI_INTEGER8,
56+
Float32 => MPI_REAL4,
57+
Float64 => MPI_REAL8,
58+
Complex64 => MPI_COMPLEX8,
59+
Complex128 => MPI_COMPLEX16)
60+
3361
end
3462

3563
end

src/mpi-base.jl

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,12 @@ typealias MPIDatatype Union{Char,
77
# for a given type T<:MPIDatatype. This works better with precompilation
88
# than a dictionary (since DataType keys need to be re-hashed at runtime),
99
# and also allows the datatype code to be inlined at compile-time.
10-
let _int_datatypes = Dict{Int, Cint}(
11-
1 => MPI_INTEGER1,
12-
2 => MPI_INTEGER2,
13-
4 => MPI_INTEGER4,
14-
8 => MPI_INTEGER8),
15-
_real_datatypes = Dict{Int, Cint}(
16-
4 => MPI_REAL4,
17-
8 => MPI_REAL8)
18-
_complex_datatypes = Dict{Int, Cint}(
19-
8 => MPI_COMPLEX8,
20-
16 => MPI_COMPLEX16)
21-
_datatypes = Dict{DataType, Cint}(
22-
# Older versions of OpenMPI (such as those used by default in
23-
# Travis) do not define MPI_WCHAR and the MPI_*INT*_T types for
24-
# Fortran. We thus don't require them (yet).
25-
# Char => MPI_WCHAR,
26-
# Int8 => MPI_INT8_T,
27-
# UInt8 => MPI_UINT8_T,
28-
# Int16 => MPI_INT16_T,
29-
# UInt16 => MPI_UINT16_T,
30-
# Int32 => MPI_INT32_T,
31-
# UInt32 => MPI_UINT32_T,
32-
# Int64 => MPI_INT64_T,
33-
# UInt64 => MPI_UINT64_T,
34-
Char => _int_datatypes[sizeof(Char)],
35-
Int8 => _int_datatypes[sizeof(Int8)],
36-
UInt8 => _int_datatypes[sizeof(UInt8)],
37-
Int16 => _int_datatypes[sizeof(Int16)],
38-
UInt16 => _int_datatypes[sizeof(UInt16)],
39-
Int32 => _int_datatypes[sizeof(Int32)],
40-
UInt32 => _int_datatypes[sizeof(UInt32)],
41-
Int64 => _int_datatypes[sizeof(Int64)],
42-
UInt64 => _int_datatypes[sizeof(UInt64)],
43-
Float32 => _real_datatypes[sizeof(Float32)],
44-
Float64 => _real_datatypes[sizeof(Float64)],
45-
Complex64 => _complex_datatypes[sizeof(Complex64)],
46-
Complex128 => _complex_datatypes[sizeof(Complex128)])
47-
48-
global mpitype
49-
for (T,t) in _datatypes
50-
@eval mpitype(::Type{$T}) = $t
51-
end
10+
11+
12+
# accessor function for getting MPI datatypes
13+
# use a function in case more behavior is needed later
14+
function mpitype{T}(::Type{T})
15+
return mpitype_dict[T]
5216
end
5317

5418
type Comm

0 commit comments

Comments
 (0)