-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.jl
66 lines (59 loc) · 1.41 KB
/
test.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Libdl
Libdl.dlopen("/opt/cray/pe/mpich/8.1.16/gtl/lib/libmpi_gtl_cuda.so.0.0.0", RTLD_GLOBAL)
using CUDA
using MPI
function init!(a::AbstractVector, comm::MPI.Comm)
rank = MPI.Comm_rank(comm)
if rank == 0
fill!(a, 1)
elseif rank == 1
fill!(a, 0)
else
error("Wrong rank $rank")
end
end
function check!(a::AbstractVector, comm::MPI.Comm)
rank = MPI.Comm_rank(comm)
if rank == 0
if !(all(a .== 1))
error("Wrong values on rank $rank with type $(typeof(a))")
else
println("Correct")
end
elseif rank == 1
if !(all(a .== 1))
error("Wrong values on rank $rank with type $(typeof(a))")
else
println("Correct")
end
else
error("Wrong rank $rank")
end
end
function sendrecv!(a::AbstractVector, comm::MPI.Comm)
rank = MPI.Comm_rank(comm)
if rank == 0
MPI.Send(a, 1, 0, comm)
elseif rank == 1
MPI.Recv!(a, 0, 0, comm)
else
error("Wrong rank $rank")
end
end
MPI.Init()
# Run with two ranks
println("MPI.has_cuda: $(MPI.has_cuda())")
comm = MPI.COMM_WORLD
rank = MPI.Comm_rank(comm)
size = MPI.Comm_size(comm)
println("Size: $size")
@assert size == 2
a = Vector{Int64}(undef, 1)
init!(a, comm)
sendrecv!(a, comm)
check!(a, comm)
cua = CuVector{Int64}(undef, 1)
init!(cua, comm)
sendrecv!(cua, comm)
check!(cua, comm)
MPI.Finalize()