-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRowGraph.jl
360 lines (258 loc) · 10.3 KB
/
RowGraph.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
export RowGraph
#required methods
export getRowMap, getColMap, getDomainMap, getRangeMap, getImporter, getExporter
export getGlobalNumRows, getGlobalNumCols, getGlobalNumEntries, getGlobalNumDiags
export getLocalNumRows, getLocalNumCols, getLocalNumEntries, getLocalNumDiags
export getNumEntriesInGlobalRow, getNumEntriesInLocalRow
export getGlobalMaxNumRowEntries, getLocalMaxNumRowEntries
export hasColMap, isLowerTriangular, sUpperTriangular
export isLocallyIndexed, isGloballyIndexed, isFillComplete
export getGlobalRowCopy, getLocalRowCopy, pack
#implemented methods
export isFillActive
"""
RowGraph is the base "type" for all row oriented storage graphs
Instances of these types are required to implement the following submethods
getRowMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the row map for the graph
getColMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the column map for the graph
getDomainMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the domain map for the graph
getRangeMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the range map for the graph
getImporter(::RowGraph{GID, PID, LID})::Union{Import{GID, PID, LID}, Nothing}
Gets the graph's Import object
getExporter(::RowGraph{GID, PID, LID})::Union{Export{GID, PID, LID}, Nothing}
Gets the graph's Export object
getGlobalNumEntries(::RowGraph{GID, PID, LID})::GID
Returns the global number of entries in the graph
getLocalNumEntries(::RowGraph{GID, PID, LID})::LID
Returns the local number of entries in the graph
getNumEntriesInLocalRow(::RowGraph{GID, PID, LID}, row::LID)::LID
Returns the current number of local entries in the given row
getGlobalNumDiags(::RowGraph{GID, PID, LID})::GID
Returns the global number of diagonal entries
getLocalNumDiags(::RowGraph{GID, PID, LID})::LID
Returns the local number of diagonal entries
getGlobalMaxNumRowEntries(::RowGraph{GID, PID, LID})::LID
Returns the maximum number of entries across all rows/columns on all processors
getLocalMaxNumRowEntries(::RowGraph{GID, PID, LID})::LID
Returns the maximum number of entries across all rows/columns on this processor
hasColMap(::RowGraph{GID, PID, LID})::Bool
Whether the graph has a well-defined column map
isLowerTriangular(::RowGraph{GID, PID, LID})::Bool
Whether the graph is lower trianguluar
isUpperTriangular(::RowGraph{GID, PID, LID})::Bool
Whether the graph is upper trianguluar
isGloballyIndexed(::RowGraph)::Bool
Whether the graph is using global indices
isFillComplete(::RowGraph)
If the graph is fully build.
getLocalRowCopy!(copy::AbstractVector{<:Integer}, graph::RowGraph{GID, PID, LID}, row::LID)::Integer
Copies the given row of the graph into the provided array using local indices
For optimal performance, the following methods may need to be re-implemented for the specific type
`getGlobalRowCopy!(copy::AbstractVector{<:Integer}, graph::RowGraph{GID}, row::GID)::Integer` is implemented by calling `getLocalRowCopy!` and remapping the values using `gid(::BlockMap, ::Integer)`
`getNumEntriesInGlobalRow(graph::RowGraph{GID, PID, LID}, row::GID)` is implemented using `getNumEntriesInLocalRow`
"""
abstract type RowGraph{GID <: Integer, PID <: Integer, LID <: Integer}
end
"""
isFillActive(::RowGraph)
Whether the graph is being built
"""
isFillActive(graph::RowGraph) = !isFillComplete(graph)
"""
getNumEntriesInLocalRow(::RowGraph{GID, PID, LID}, row::Integer)::LID
Returns the current number of local entries in the given row
"""
Base.@propagate_inbounds function getNumEntriesInLocalRow(graph::RowGraph{GID, PID, LID},
row::Integer)::LID where{GID, PID, LID}
getNumEntriesInLocalRow(graph, LID(row))
end
"""
getGlobalRowCopy(graph::RowGraph{GID}, row::Integer)::AbstractVector{GID}
Creates a copy of the given row of the graph using global indices
"""
Base.@propagate_inbounds function getGlobalRowCopy(graph::RowGraph{GID}, row::Integer)::AbstractVector{GID} where GID
numElts = getNumEntriesInGlobalRow(graph, row)
copy = Vector{GID}(undef, numElts)
getGlobalRowCopy!(copy, graph, GID(row))
copy
end
"""
getLocalRowCopy(graph::RowGraph{GID}, row::Integer)::AbstractVector{GID}
Creates a copy of the given row of the graph using local indices
"""
Base.@propagate_inbounds function getLocalRowCopy(graph::RowGraph{GID, PID, LID}, row::Integer)::AbstractVector{LID} where {GID, PID, LID}
numElts = getNumEntriesInGlobalRow(graph, row)
copy = Vector{LID}(undef, numElts)
getLocalRowCopy!(copy, graph, LID(row))
copy
end
"""
getGlobalRowCopy!(copy::AbstractVector{GID}, graph::RowGraph{GID}, row::Integer)::Integer
Copies the given row of the graph into the provided array using global indices
"""
Base.@propagate_inbounds function getGlobalRowCopy!(copy::AbstractVector{<:Integer}, graph::RowGraph{GID},
row::Integer)::Integer where GID
getGlobalRowCopy!(graph, GID(row))
end
Base.@propagate_inbounds function getGlobalRowCopy!(copy::AbstractVector{<:Integer},
matrix::RowGraph{GID}, globalRow::GID) where {GID}
rowMap = getRowMap(matrix)
numElts = getLocalRowCopy!(copy, matrix, lid(rowMap, globalRow))
@. copy = gid(rowMap, copy)
numElts
end
"""
getLocalRowCopy!(copy::AbstractVector{<:Integer}, graph::RowGraph{GID, PID, LID}, row::Integer)::Integer
Copies the given row of the graph into the provided array using global indices
"""
Base.@propagate_inbounds function getLocalRowCopy!(copy::AbstractVector{<:Integer}, graph::RowGraph{GID, PID, LID},
row::Integer)::Integer where {GID, PID, LID}
getLocalRowCopy!(graph, LID(row))
end
"""
isLocallyIndexed(::RowGraph)::Bool
Whether the graph is using local indices.
The default implementation uses the row graph
"""
isLocallyIndexed(graph::RowGraph) = !isGloballyIndexed(graph)
"""
getGlobalNumRows(::RowGraph{GID})::GID
Returns the number of global rows in the graph
The default implementation uses the row graph
"""
getGlobalNumRows(graph::RowGraph) = numAllElements(getRowMap(graph))
"""
getGlobalNumCols(::RowGraph{GID})::GID
Returns the number of global columns in the graph
The default implementation uses the row graph
"""
getGlobalNumCols(graph::RowGraph) = numAllElements(getColMap(graph))
"""
getLocalNumRows(::RowGraph{GID, PID, LID})::LID
Returns the number of rows owned by the calling process
The default implementation uses the row graph
"""
getLocalNumRows(graph::RowGraph) = numMyElements(getRowMap(graph))
"""
getLocalNumCols(::RowGraph{GID, PID, LID})::LID
Returns the number of columns owned by the calling process
The default implementation uses the row graph
"""
getLocalNumCols(graph::RowGraph) = nulMyElements(getColMap(graph))
"""
getNumEntriesInGlobalRow(graph::RowGraph{GID, PID, LID}, row::Integer)::LID
Returns the current number of local entries in the given row
"""
function getNumEntriesInGlobalRow(graph::RowGraph{GID, PID, LID}, row::Integer
)::LID where {GID, PID, LID}
getNumEntriesInGlobalRow(graph, row::GID)
end
function getNumEntriesInGlobalRow(graph::RowGraph{GID, PID, LID}, row::GID
)::LID where {GID, PID, LID}
getNumEntriesInLocalRow(graph, lid(getRowMap(graph), row))
end
"""
pack(::RowGraph{GID, PID, LID}, exportLIDs::AbstractArray{LID, 1}, distor::Distributor{GID, PID, LID})::AbstractArray{AbstractArray{LID, 1}}
Packs this object's data for import or export
"""
function pack(source::RowGraph{GID, PID, LID}, exportLIDs::AbstractArray{LID, 1}, distor::Distributor{GID, PID, LID})::Array{Array{LID, 1}, 1} where {GID, PID, LID}
srcMap = getMap(source)
map(lid->getGlobalRowCopy(source, gid(srcMap, lid)), exportLIDs)
end
#### SrcDistObject methods ####
getMap(graph::RowGraph) = getRowMap(graph)
#### documentation for required methods ####
"""
isFillComplete(mat::RowGraph)
Whether `fillComplete(...)` has been called
"""
function isFillComplete end
"""
getRowMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the row map for the graph
"""
function getRowMap end
"""
getColMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the column map for the graph
"""
function getColMap end
"""
hasColMap(::RowGraph{GID, PID, LID})::Bool
Whether the graph has a well-defined column map
"""
function hasColMap end
"""
getDomainMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the domain map for the graph
"""
function getDomainMap end
"""
getRangeMap(::RowGraph{GID, PID, LID})::BlockMap{GID, PID, LID}
Gets the range map for the graph
"""
function getRangeMap end
"""
getImporter(::RowGraph{GID, PID, LID})::Union{Import{GID, PID, LID}, Nothing}
Gets the graph's Import object, or null if the import is trivial
"""
function getImporter end
"""
getExporter(::RowGraph{GID, PID, LID})::Union{Export{GID, PID, LID}, Nothing}
Gets the graph's Export object, or null if the export is trivial
"""
function getExporter end
"""
getGlobalNumEntries(::RowGraph{GID, PID, LID})::GID
Returns the global number of entries in the graph
"""
function getGlobalNumEntries end
"""
getLocalNumEntries(::RowGraph{GID, PID, LID})::LID
Returns the local number of entries in the graph
"""
function getLocalNumEntries end
"""
getNumEntriesInLocalRow(::RowGraph{GID, PID, LID}, row::LID)::LID
Returns the current number of local entries in the given row
"""
function getNumEntriesInLocalRow end
"""
getGlobalNumDiags(::RowGraph{GID, PID, LID})::GID
Returns the global number of diagonal entries
"""
function getGlobalNumDiags end
"""
getLocalNumDiags(::RowGraph{GID, PID, LID})::LID
Returns the local number of diagonal entries
"""
function getLocalNumDiags end
"""
getGlobalMaxNumRowEntries(::RowGraph{GID, PID, LID})::LID
Returns the maximum number of entries across all rows/columns on all processors
"""
function getGlobalMaxNumRowEntries end
"""
getLocalMaxNumRowEntries(::RowGraph{GID, PID, LID})::LID
Returns the maximum number of entries across all rows/columns on the calling processor
"""
function getLocalMaxNumRowEntries end
"""
isLowerTriangular(::RowGraph{GID, PID, LID})::Bool
Whether the graph is lower trianguluar
"""
function isLowerTriangular end
"""
isUpperTriangular(::RowGraph{GID, PID, LID})::Bool
Whether the graph is upper trianguluar
"""
function isUpperTriangular end
"""
isGloballyIndexed(::RowGraph)::Bool
Whether the graph is using global indices
"""
function isGloballyIndexed end