-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExport.jl
238 lines (189 loc) · 7.58 KB
/
Export.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
export Export
export sourceMap, targetMap, distributor, isLocallyComplete
export permuteToLIDs, permuteFromLIDs, exportLIDs, remoteLIDs, remotePIDs, numSameIDs
"""
Communication plan for data rekg.ribution from a (possibly) multiple-owned to a uniquely owned distribution
"""
struct Export{GID <: Integer, PID <:Integer, LID <: Integer}
exportData::ImportExportData{GID, PID, LID}
end
## Constructors ##
"""
Export(source::BlockMap, target::BlockMap, remotePIDs::Union{AbstractArray, Nothing}, plist...)
"""
function Export(source::BlockMap{GID, PID, LID}, target::BlockMap{GID, PID, LID}, remotePIDs::Union{AbstractArray{PID}, Nothing}=nothing; plist...) where {GID <: Integer, PID <: Integer, LID <: Integer}
Export(source, target,
Dict(Tuple{Symbol, Any}[pair for pair in plist]))
end
"""
Export(source::BlockMap, target::BlockMap, remotePIDs::Union{AbstractArray, Nothing}, plist::Dict)
"""
function Export(source::BlockMap{GID, PID, LID}, target::BlockMap{GID, PID, LID}, remotePIDs::Union{AbstractArray{PID}, Nothing}, plist::Dict{Symbol}) where {
GID <: Integer, PID <: Integer, LID <: Integer}
expor = Export(ImportExportData(source, target))
exportGIDs = setupSamePermuteExport(expor)
if distributedGlobal(source)
setupRemote(expor, exportGIDs)
end
expor
end
"""
Export(source::BlockMap, target::BlockMap, plist::Dict)
"""
function Export(source::BlockMap{GID, PID, LID}, target::BlockMap{GID, PID, LID},
plist::Dict{Symbol}) where {GID <: Integer, PID <: Integer, LID <: Integer}
Export(source, target, nothing, plist)
end
## internal construction methods ##
function setupSamePermuteExport(expor::Export{GID, PID, LID})::AbstractArray{GID} where {GID <: Integer, PID <: Integer, LID <: Integer}
data = expor.exportData
source = sourceMap(expor)
target = targetMap(expor)
sourceGIDs = myGlobalElements(source)
targetGIDs = myGlobalElements(target)
numSrcGIDs = length(sourceGIDs)
numTgtGIDs = length(targetGIDs)
numGIDs = min(numSrcGIDs, numTgtGIDs)
numSameGIDs = 1
while numSameGIDs <= numGIDs && sourceGIDs[numSameGIDs] == targetGIDs[numSameGIDs]
numSameGIDs += 1
end
numSameGIDs -= 1
numSameIDs(data, numSameGIDs)
exportGIDs = Array{GID, 1}(undef, 0)
permuteToLIDs = JuliaPetra.permuteToLIDs(data)
permuteFromLIDs = JuliaPetra.permuteFromLIDs(data)
exportLIDs = JuliaPetra.exportLIDs(data)
for srcLID = (numSameGIDs+1):numSrcGIDs
curSrcGID = sourceGIDs[srcLID]
tgtLID = lid(target, curSrcGID)
if tgtLID != 0
push!(permuteToLIDs, tgtLID)
push!(permuteFromLIDs, srcLID)
else
push!(exportGIDs, curSrcGID)
push!(exportLIDs, srcLID)
end
end
if length(exportLIDs) != 0 && !distributedGlobal(source)
isLocallyComplete(data, false)
warn("Source has export LIDs but source not distributed globally. " *
"Exporting to a submap of the target map.")
end
if distributedGlobal(source)
#resize!(JuliaPetra.exportPIDs(data), length(exportGIDs))
(exportPIDs, exportLIDs) = remoteIDList(target, exportGIDs)
JuliaPetra.exportPIDs(data, exportPIDs)
missingGIDs = 0
for i = 1:length(exportPIDs)
if exportPIDs[i] == 0
missingGIDs += 1
end
end
if missingGIDs != 0
warn("The source Map has GIDs not found in the target Map")
isLocallyComplete(data, false)
numInvalidExports = missingGIDs
totalNumExports = length(exportPIDs)
if numInvalidExports == totalNumExports
# all exports invalid, can delete all exports
resize!(exportGIDs, 0)
resize!(exportLIDs, 0)
resize!(exportPIDs, 0)
else
#some exports are valid, need to keep the valid exports
numValidExports = 1
for e = 1:totalNumExports
if exportPIDs[e] != 0
exportGIDs[numValidExports] = exportGIDs[e]
exportLIDs[numValidExports] = exportLIDs[e]
exportPIDs[numValidExports] = exportPIDs[e]
numValidExports += 1
end
end
numValidExports -= 1
resize!(exportGIDs, numValidExports)
resize!(exportLIDs, numValidExports)
resize!(exportPIDs, numValidExports)
end
end
end
exportGIDs
end
function setupRemote(expor::Export{GID, PID, LID}, exportGIDs::AbstractArray{GID, 1}) where {GID <: Integer, PID <: Integer, LID <: Integer}
data = expor.exportData
target = targetMap(data)
exportPIDs = JuliaPetra.exportPIDs(data)
order = sortperm(exportPIDs)
permute!(exportPIDs, order)
permute!(exportLIDs(data), order)
permute!(exportGIDs, order)
numRemoteIDs = createFromSends(distributor(data), exportPIDs)
remoteGIDs = resolve(distributor(data), exportGIDs)
remoteLIDs = JuliaPetra.remoteLIDs(data)
resize!(remoteLIDs, numRemoteIDs)
for i in 1:length(remoteGIDs)
remoteLIDs[i] = lid(target, remoteGIDs[i])
end
end
## Getters ##
"""
Get the source map for the given ImportExportData
"""
function sourceMap(impor::Export{GID, PID, LID})::BlockMap{GID, PID, LID} where GID <: Integer where PID <:Integer where LID <: Integer
impor.exportData.source
end
"""
Get the target map for the given ImportExportData
"""
function targetMap(impor::Export{GID, PID, LID})::BlockMap{GID, PID, LID} where GID <: Integer where PID <:Integer where LID <: Integer
impor.exportData.target
end
"""
List of elements in the target map that are permuted.
"""
function permuteToLIDs(impor::Export{GID, PID, LID})::Array{LID} where GID <: Integer where PID <:Integer where LID <: Integer
impor.exportData.permuteToLIDs
end
"""
List of elements in the source map that are permuted.
"""
function permuteFromLIDs(impor::Export{GID, PID, LID})::Array{LID} where GID <: Integer where PID <:Integer where LID <: Integer
impor.exportData.permuteFromLIDs
end
"""
List of elements in the target map that are coming from other processors
"""
function remoteLIDs(impor::Export{GID, PID, LID})::Array{LID} where GID <: Integer where PID <: Integer where LID <: Integer
impor.exportData.remoteLIDs
end
"""
List of elements that will be sent to other processors
"""
function exportLIDs(impor::Export{GID, PID, LID})::Array{LID} where GID <: Integer where PID <: Integer where LID <: Integer
impor.exportData.exportLIDs
end
"""
List of processors to which elements will be sent `exportLID[i]` will be sent to processor `exportPIDs[i]`
"""
function exportPIDs(impor::Export{GID, PID, LID})::Array{PID} where GID <: Integer where PID <: Integer where LID <: Integer
impor.exportData.exportPIDs
end
"""
Returns the number of elements that are identical between the source and target maps, up to the first different ID
"""
function numSameIDs(impor::Export{GID, PID, LID})::LID where GID <: Integer where PID <: Integer where LID <: Integer
impor.exportData.numSameIDs
end
"""
Returns the distributor being used
"""
function distributor(impor::Export{GID, PID, LID})::Distributor{GID, PID, LID} where GID <: Integer where PID <: Integer where LID <: Integer
impor.exportData.distributor
end
"""
Returns whether the import or export is locally complete
"""
function isLocallyComplete(impor::Export{GID, PID, LID})::Bool where GID <: Integer where PID <: Integer where LID <: Integer
impor.exportData.isLocallyComplete
end