-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSerialComm.jl
133 lines (101 loc) · 3.73 KB
/
SerialComm.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
export SerialComm, SerialDistributor
"""
SerialDistributor()
Creates a distributor to work with SerialComm
"""
mutable struct SerialDistributor{GID <: Integer, PID <:Integer, LID <: Integer} <: Distributor{GID, PID, LID}
post::Union{AbstractArray, Nothing}
reversePost::Union{AbstractArray, Nothing}
function SerialDistributor{GID, PID, LID}() where GID <: Integer where PID <: Integer where LID <: Integer
new(nothing, nothing)
end
end
function createFromSends(dist::SerialDistributor{GID, PID, LID},
exportPIDs::AbstractArray{PID})::Integer where GID <: Integer where PID <: Integer where LID <: Integer
for id in exportPIDs
if id != 1
throw(InvalidArgumentError("SerialDistributor can only accept PID of 1"))
end
end
length(exportPIDs)
end
function createFromRecvs(
dist::SerialDistributor{GID, PID, LID}, remoteGIDs::AbstractArray{GID}, remotePIDs::AbstractArray{PID}
)::Tuple{AbstractArray{GID}, AbstractArray{PID}} where GID <: Integer where PID <: Integer where LID <: Integer
for id in remotePIDs
if id != 1
throw(InvalidArgumentError("SerialDistributor can only accept PID of 1"))
end
end
remoteGIDs,remotePIDs
end
function resolve(dist::SerialDistributor, exportObjs::AbstractArray{T})::AbstractArray{T} where T
exportObjs
end
function resolveReverse(dist::SerialDistributor, exportObjs::AbstractArray{T})::AbstractArray{T} where T
exportObjs
end
function resolvePosts(dist::SerialDistributor, exportObjs::AbstractArray)
dist.post = exportObjs
end
function resolveWaits(dist::SerialDistributor)::AbstractArray
if dist.post === nothing
throw(InvalidStateError("Must post before waiting"))
end
result = dist.post
dist.post = nothing
result
end
function resolveReversePosts(dist::SerialDistributor, exportObjs::AbstractArray)
dist.reversePost = exportObjs
end
function resolveReverseWaits(dist::SerialDistributor)::AbstractArray
if dist.reversePost === nothing
throw(InvalidStateError("Must reverse post before reverse waiting"))
end
result = dist.reversePost
dist.reversePost = nothing
result
end
"""
SerialComm()
Gets an serial communication instance.
Serial communication results in mostly no-ops for the communication operations
"""
struct SerialComm{GID <: Integer, PID <:Integer, LID <: Integer} <: Comm{GID, PID, LID}
end
# most of these functions are no-ops or identify functions since there is only
# one processor
function barrier(comm::SerialComm)
end
function broadcastAll(comm::SerialComm, myVals::AbstractArray{T}, root::Integer)::Array{T} where T
if root != 1
throw(InvalidArgumentError("SerialComm can only accept PID of 1"))
end
myVals
end
function gatherAll(comm::SerialComm, myVals::AbstractArray{T})::Array{T} where T
myVals
end
function sumAll(comm::SerialComm, partialsums::AbstractArray{T})::Array{T} where T
partialsums
end
function maxAll(comm::SerialComm, partialmaxes::AbstractArray{T})::Array{T} where T
partialmaxes
end
function minAll(comm::SerialComm, partialmins::AbstractArray{T})::Array{T} where T
partialmins
end
function scanSum(comm::SerialComm, myvals::AbstractArray{T})::Array{T} where T
myvals
end
function myPid(comm::SerialComm{GID, PID})::PID where GID <: Integer where PID <: Integer
1
end
function numProc(comm::SerialComm{GID, PID})::PID where GID <: Integer where PID <: Integer
1
end
function createDistributor(comm::SerialComm{GID, PID, LID})::SerialDistributor{GID, PID, LID} where GID <: Integer where PID <: Integer where LID <: Integer
SerialDistributor{GID, PID, LID}()
end
getComm(::SerialDistributor{GID, PID, LID}) where {GID, PID, LID} = SerialComm{GID, PID, LID}()