-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlockMap.jl
752 lines (590 loc) · 22.9 KB
/
BlockMap.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
export BlockMap
export remoteIDList, lid, gid
export minAllGID, maxAllGID, minMyGID, maxMyGID, minLID, maxLID
export numGlobalElements, myGlobalElements
export uniqueGIDs, globalIndicesType, sameBlockMapDataAs, sameAs
export linearMap, myGlobalElementIDs
export myGID, myLID, distributedGlobal, numMyElements
# methods and docs based straight off Epetra_BlockMap to match Comm
# ignoring indexBase methods and sticking with 1-based indexing
# ignoring elementSize methods since, type information is carried anyways
# ignoring point-related code, since elementSize is ignored
# TODO figure out expert users and developers only functions
"""
A type for partitioning block element vectors and matrices
"""
struct BlockMap{GID <: Integer, PID <:Integer, LID <: Integer}
data::BlockMapData{GID, PID, LID}
function BlockMap{GID, PID, LID}(data::BlockMapData) where {GID <: Integer, PID <:Integer, LID <: Integer}
new(data)
end
end
"""
BlockMap(numGlobalElements, comm)
Constructor for petra-defined uniform linear distribution of elements
"""
function BlockMap(numGlobalElements::Integer, comm::Comm{GID, PID, LID}) where GID <: Integer where PID <: Integer where LID <: Integer
BlockMap(GID(numGlobalElements), comm)
end
function BlockMap(numGlobalElements::GID, comm::Comm{GID, PID, LID}) where GID <: Integer where PID <: Integer where LID <: Integer
if numGlobalElements < 0
throw(InvalidArgumentError("NumGlobalElements = $(numGlobalElements). Should be >= 0"))
end
data = BlockMapData(numGlobalElements, comm)
map = BlockMap{GID, PID, LID}(data)
numProcVal = numProc(comm)
data.linearMap = true
myPIDVal = myPid(comm) - 1
data.numMyElements = floor(typeof(data.numGlobalElements),
data.numGlobalElements/numProcVal)
remainder = data.numGlobalElements % numProcVal
startIndex = myPIDVal * (data.numMyElements+1)
if myPIDVal < remainder
data.numMyElements += 1
else
startIndex -= (myPIDVal - remainder)
end
data.minAllGID = 1
data.maxAllGID = data.minAllGID + data.numGlobalElements - 1
data.minMyGID = startIndex + 1
data.maxMyGID = data.minMyGID + data.numMyElements - 1
data.distributedGlobal = isDistributedGlobal(map, data.numGlobalElements,
data.numMyElements)
EndOfConstructorOps(map)
map
end
"""
BlockMap(numGlobalElements, numMyElements, comm)
Constructor for user-defined linear distribution of elements
"""
function BlockMap(numGlobalElements::Integer, numMyElements::Integer, comm::Comm{GID, PID, LID}) where GID <: Integer where PID <: Integer where LID <: Integer
BlockMap(GID(numGlobalElements), LID(numMyElements), comm)
end
function BlockMap(numGlobalElements::GID, numMyElements::LID, comm::Comm{GID, PID, LID}) where GID <: Integer where PID <: Integer where LID <: Integer
if numGlobalElements < -1
throw(InvalidArgumentError("NumGlobalElements = $(numGlobalElements). Should be >= -1"))
end
if numMyElements < 0
throw(InvalidArgumentError("NumMyElements = $(numMyElements). Should be >= 0"))
end
data = BlockMapData(numGlobalElements, comm)
map = BlockMap{GID, PID, LID}(data)
data.numMyElements = numMyElements
data.linearMap = true
data.distributedGlobal = isDistributedGlobal(map, numGlobalElements, numMyElements)
#Local Map and uniprocessor case: Each processor gets a complete copy of all elements
if !data.distributedGlobal || numProc(comm) == 1
data.numGlobalElements = data.numMyElements
data.minAllGID = 1
data.maxAllGID = data.minAllGID + data.numGlobalElements - 1
data.minMyGID = 1
data.maxMyGID = data.minMyGID + data.numMyElements - 1
else
tmp_numMyElements = data.numMyElements
data.numGlobalElements = sumAll(data.comm, tmp_numMyElements)
data.minAllGID = 1
data.maxAllGID = data.minAllGID + data.numGlobalElements - 1
tmp_numMyElements = data.numMyElements
data.maxMyGID = scanSum(data.comm, tmp_numMyElements)
startIndex = data.maxMyGID - data.numMyElements
data.minMyGID = startIndex + 1
data.maxMyGID = data.minMyGID + data.numMyElements - 1
end
checkValidNGE(map, numGlobalElements)
EndOfConstructorOps(map)
map
end
"""
BlockMap(numGlobalElements, myGlobalElements, comm)
Constructor for user-defined arbitrary distribution of elements
"""
function BlockMap(numGlobalElements::Integer, myGlobalElements::AbstractArray{<:Integer}, comm::Comm{GID, PID,LID}
) where GID <: Integer where PID <: Integer where LID <: Integer
BlockMap(numGlobalElements, Array{GID}(myGlobalElements), comm)
end
function BlockMap(numGlobalElements::Integer, myGlobalElements::UnitRange{GID}, comm::Comm{GID, PID, LID}
) where {GID <: Integer, PID <: Integer, LID <: Integer}
numMyElements = LID(length(myGlobalElements))
data = BlockMapData(GID(0), comm)
map = BlockMap{GID, PID, LID}(data)
data.numMyElements = numMyElements
data.myGlobalElements = collect(myGlobalElements)
data.minMyGID = first(myGlobalElements)
data.maxMyGID = last(myGlobalElements)
#TODO this doesn't check if there is overlap between processors
# call the reduce to allow mixing this version with the abstract version
data.linearMap = Bool(minAll(data.comm, 1))
if numProc(comm) == 1
data.numGlobalElements = data.numMyElements
data.minAllGID = data.minMyGID
data.maxAllGID = data.maxMyGID
else
tmp_send = [
-((data.numMyElements > 0) ?
data.minMyGID : Inf)
, data.maxMyGID]
tmp_recv = maxAll(data.comm, tmp_send)
@assert typeof(tmp_recv[1]) <: Integer "Result type is $(typeof(tmp_recv[1])), should be subtype of Integer"
data.minAllGID = -tmp_recv[1]
data.maxAllGID = tmp_recv[2]
if numGlobalElements != -1
data.numGlobalElements = numGlobalElements
else
if data.linearMap
data.numGlobalElements = sumAll(data.comm, data.numMyElements)
else
#if 1+ GIDs shared between processors, need to total that correctly
allIDs = gatherAll(data.comm, myGlobalElements)
indexModifier = 1 - data.minAllGID
maxGID = data.maxAllGID
count = 0
arr = falses(maxGID + indexModifier)
for id in allIDs
if !arr[GID(id + indexModifier)]
arr[GID(id + indexModifier)] = true
count += 1
end
end
data.numGlobalElements = count
end
end
end
data.distributedGlobal = isDistributedGlobal(map, data.numGlobalElements, numMyElements)
EndOfConstructorOps(map)
map
end
function BlockMap(numGlobalElements::Integer, myGlobalElements::AbstractArray{GID}, comm::Comm{GID, PID,LID}
) where GID <: Integer where PID <: Integer where LID <: Integer
numMyElements = LID(length(myGlobalElements))
data = BlockMapData(GID(0), comm)
map = BlockMap{GID, PID, LID}(data)
data.numMyElements = numMyElements
linear = 1
if numMyElements > 0
data.myGlobalElements = Array{GID, 1}(undef, numMyElements)
data.myGlobalElements[1] = myGlobalElements[1]
data.minMyGID = myGlobalElements[1]
data.maxMyGID = myGlobalElements[1]
for i = 2:numMyElements
data.myGlobalElements[i] = myGlobalElements[i]
data.minMyGID = min(data.minMyGID, myGlobalElements[i])
data.maxMyGID = max(data.maxMyGID, myGlobalElements[i])
if myGlobalElements[i] != myGlobalElements[i-1] + 1
linear = 0
end
end
else
data.minMyGID = 1
data.maxMyGID = 0
end
#=
this doesn't check if there is overlap between processors
data.linearMap = Bool(minAll(data.comm, linear))
=#
if numProc(comm) == 1
data.numGlobalElements = data.numMyElements
data.minAllGID = data.minMyGID
data.maxAllGID = data.maxMyGID
else
tmp_send = [
-((data.numMyElements > 0) ?
data.minMyGID : Inf)
, data.maxMyGID]
tmp_recv = maxAll(data.comm, tmp_send)
@assert typeof(tmp_recv[1]) <: Integer "Result type is $(typeof(tmp_recv[1])), should be subtype of Integer"
data.minAllGID = -tmp_recv[1]
data.maxAllGID = tmp_recv[2]
if numGlobalElements != -1
data.numGlobalElements = numGlobalElements
else
if data.linearMap
data.numGlobalElements = sumAll(data.comm, data.numMyElements)
else
#if 1+ GIDs shared between processors, need to total that correctly
allIDs = gatherAll(data.comm, myGlobalElements)
indexModifier = 1 - data.minAllGID
maxGID = data.maxAllGID
count = 0
arr = falses(maxGID + indexModifier)
for id in allIDs
if !arr[GID(id + indexModifier)]
arr[GID(id + indexModifier)] = true
count += 1
end
end
data.numGlobalElements = count
end
end
end
data.distributedGlobal = isDistributedGlobal(map, data.numGlobalElements, numMyElements)
EndOfConstructorOps(map)
map
end
"""
BlockMap(numGlobalElements, numMyElements, myGlobalElements, isDistributedGlobal, userminAllGID, usermaxAllGID, comm)
Constructor for user-defined arbitrary distribution of elements with all information on globals provided by the user
"""
function BlockMap(numGlobalElements::Integer, numMyElements::Integer,
myGlobalElements::AbstractArray{GID}, userIsDistributedGlobal::Bool,
userMinAllGID::Integer, userMaxAllGID::Integer, comm::Comm{GID, PID, LID}) where GID <: Integer where PID <: Integer where LID <: Integer
BlockMap(GID(numGlobalElements), LID(numMyElements), Array{GID}(myGlobalElements), userIsDistributedGlobal,
GID(userMinAllGID), GID(userMaxAllGID), comm)
end
function BlockMap(numGlobalElements::GID, numMyElements::LID,
myGlobalElements::AbstractArray{GID}, userIsDistributedGlobal::Bool,
userMinAllGID::GID, userMaxAllGID::GID, comm::Comm{GID, PID, LID}) where GID <: Integer where PID <: Integer where LID <: Integer
if numGlobalElements < -1
throw(InvalidArgumentError("NumGlobalElements = $(numGlobalElements). Should be >= -1"))
end
if numMyElements < 0
throw(InvalidArgumentError("NumMyElements = $(numMyElements). Should be >= 0"))
end
if userMinAllGID < 1
throw(InvalidArgumentError("Minimum global element index = $(data.minAllGID). Should be >= 1"))
end
data = BlockMapData(numGlobalElements, comm)
map = BlockMap{GID, PID, LID}(data)
data.numMyElements = numMyElements
linear = 1
if numMyElements > 0
data.myGlobalElements = Vector{GID}(undef, numMyElements)
data.myGlobalElements[1] = myGlobalElements[1]
data.minMyGID = myGlobalElements[1]
data.maxMyGID = myGlobalElements[1]
for i = 2:numMyElements
data.myGlobalElements[i] = myGlobalElements[i]
data.minMyGID = min(data.minMyGID, myGlobalElements[i])
data.maxMyGID = max(data.maxMyGID, myGlobalElements[i])
if myGlobalElements[i] != myGlobalElements[i-1] + 1
linear = 0
end
end
else
data.minMyGID = 1
data.maxMyGID = 0
end
data.linearMap = Bool(minAll(comm, linear))
data.distributedGlobal = userIsDistributedGlobal
if !data.distributedGlobal || numProc(comm) == 1
data.numGlobalElements = data.numMyElements
checkValidNGE(map, numGlobalElements)
data.minAllGID = data.minMyGID
data.maxAllGID = data.maxMyGID
else
if numGlobalElements == -1
data.numGlobalElements = sumAll(data.comm, data.numMyElements)
else
data.numGlobalElements = numGlobalElements
end
checkValidNGE(data.numGlobalELements)
data.minAllGID = userMinAllGID
data.maxAllGID = userMaxAllGID
end
EndOfConstructorOps(map)
map
end
##### internal construction methods #####
function isDistributedGlobal(map::BlockMap{GID, PID, LID}, numGlobalElements::GID,
numMyElements::LID) where GID <: Integer where PID <: Integer where LID <: Integer
data = map.data
if numProc(data.comm) > 1
localReplicated = numGlobalElements == numMyElements
!Bool(minAll(data.comm, localReplicated))
else
false
end
end
function EndOfConstructorOps(map::BlockMap)
map.data.minLID = 1
map.data.maxLID = max(map.data.numMyElements, 1)
GlobalToLocalSetup(map);
end
function GlobalToLocalSetup(map::BlockMap)
data = map.data
numMyElements = data.numMyElements
myGlobalElements = data.myGlobalElements
if data.linearMap || numMyElements == 0
return map
end
if length(data.numGlobalElements) == 0
return map
end
val = myGlobalElements[1]
i = 1
while i < numMyElements
if val+1 != myGlobalElements[i+1]
break
end
val += 1
end
data.lastContiguousGIDLoc = i
if data.lastContiguousGIDLoc <= 1
data.lastContiguousGID = myGlobalElements[1]
else
data.lastContiguousGID = myGlobalElements[data.lastContiguousGIDLoc]
end
if i < numMyElements
data.lidHash = empty!(data.lidHash)
sizehint!(data.lidHash, numMyElements - i + 2)
for i = i:numMyElements
data.lidHash[myGlobalElements[i]] = i
end
end
map
end
function checkValidNGE(map::BlockMap{GID, PID, LID}, numGlobalElements::GID) where GID <: Integer where PID <: Integer where LID <: Integer
if (numGlobalElements != -1) && (numGlobalElements != map.data.numGlobalElements)
throw(InvalidArgumentError("Invalid NumGlobalElements. "
* "NumGlobalElements = $(numGlobalElements)"
* ". Should equal $(map.data.numGlobalElements)"
* ", or be set to -1 to compute automatically"))
end
end
##### external methods #####
getComm(map::BlockMap) = map.data.comm
"""
myGID(map::BlockMap, gidVal::Integer)
Return true if the GID passed in belongs to the calling processor in this
map, otherwise returns false.
"""
myGID(map::BlockMap, gidVal) = lid(map, gidVal) != 0
"""
myLID(map::BlockMap, lidVal::Integer)
Return true if the LID passed in belongs to the calling processor in this
map, otherwise returns false.
"""
@inline myLID(map::BlockMap, lidVal) = gid(map, lidVal) != 0
"""
distributedGlobal(map::BlockMap)
Return true if map is defined across more than one processor
"""
distributedGlobal(map::BlockMap) = map.data.distributedGlobal
"""
numMyElements(map::BlockMap{GID, PID, LID})::LID
Return the number of elements across the calling processor
"""
numMyElements(map::BlockMap) = map.data.numMyElements
"""
minMyGID(map::BlockMap{GID, PID, LID})::GID
Return the minimum global ID owned by this processor
"""
minMyGID(map::BlockMap) = map.data.minMyGID
"""
maxMyGID(map::BlockMap{GID, PID, LID})::GID
Return the maximum global ID owned by this processor
"""
maxMyGID(map::BlockMap) = map.data.maxMyGID
"""
getLocalMap(::BlockMap{GID, PID, LID})::BlockMap{GID, PID, LID}
Creates a copy of the given map that doesn't support any inter-process actions
"""
function getLocalMap(map::BlockMap{GID, PID, LID})::BlockMap{GID, PID, LID} where {GID, PID, LID}
oldData = map.data
data = BlockMapData(oldData.numGlobalElements, LocalComm(oldData.comm))
data.directory = nothing
data.lid = copy(oldData.lid)
#maps shouldn't be modified anyways, may as well share array
#data.myGlobalElements = copy(oldData.myGlobalElements)
data.myGlobalElements = oldData.myGlobalElements
data.numMyElements = oldData.numMyElements
data.minAllGID = oldData.minAllGID
data.maxAllGID = oldData.maxAllGID
data.minMyGID = oldData.minMyGID
data.maxMyGID = oldData.maxMyGID
data.minLID = oldData.minLID
data.maxLID = oldData.maxLID
data.linearMap = oldData.linearMap
data.distributedGlobal = oldData.distributedGlobal
data.oneToOneIsDetermined = oldData.oneToOneIsDetermined
data.oneToOne = oldData.oneToOne
data.lastContiguousGID = oldData.lastContiguousGID
data.lastContiguousGIDLoc = oldData.lastContiguousGIDLoc
data.lidHash = copy(oldData.lidHash)
BlockMap{GID, PID, LID}(data)
end
##local/global ID accessor methods##
"""
remoteIDList(map::BlockMap{GID, PID, LID}, gidList::AbstractArray{<: Integer}::Tuple{AbstractArray{PID}, AbstractArray{LID}}
Return the processor ID and local index value for a given list of global indices.
The returned value is a tuple containing
1. an Array of processors owning the global ID's in question
2. an Array of local IDs of the global on the owning processor
"""
function remoteIDList(map::BlockMap{GID, PID, LID}, gidList::AbstractArray{<:Integer}
)::Tuple{AbstractArray{PID}, AbstractArray{LID}} where GID <: Integer where PID <: Integer where LID <: Integer
remoteIDList(map, Vector{GID}(gidList))
end
function remoteIDList(map::BlockMap{GID, PID, LID}, gidList::AbstractArray{GID}
)::Tuple{AbstractArray{PID}, AbstractArray{LID}} where GID <: Integer where PID <: Integer where LID <: Integer
data = map.data
if data.directory === nothing
data.directory = createDirectory(data.comm, map)
end
getDirectoryEntries(data.directory, map, gidList)
end
"""
lid(map::BlockMap{GID, PID, LID}, gid::Integer)::LID
Return local ID of global ID, or 0 if not found on this processor
"""
@inline function lid(map::BlockMap{GID, PID, LID}, gid::Integer) where GID <: Integer where PID <: Integer where LID <: Integer
data = map.data
if (gid < data.minMyGID) || (gid > data.maxMyGID)
LID(0)
elseif data.linearMap
LID(gid - data.minMyGID + 1)
elseif gid >= data.myGlobalElements[1] && gid <= data.lastContiguousGID
LID(gid - data.myGlobalElements[1] + 1)
elseif haskey(data.lidHash, GID(gid))
data.lidHash[gid]
else
LID(0)
end
end
"""
gid(map::BlockMap{GID, PID, LID}, lid::Integer)::GID
Return global ID of local ID, or 0 if not found on this processor
"""
@inline function gid(map::BlockMap{GID, PID, LID}, lid::Integer) where GID <: Integer where PID <: Integer where LID <: Integer
data = map.data
if (data.numMyElements == LID(0)) || (lid < data.minLID) || (lid > data.maxLID)
GID(0)
elseif data.linearMap
GID(lid + data.minMyGID - 1)
else
GID(data.myGlobalElements[lid])
end
end
"""
minAllGID(map::BlockMap{GID, PID, LID})::GID
Return the minimum global ID across the entire map
"""
minAllGID(map::BlockMap) = map.data.minAllGID
"""
maxAllGID(map::BlockMap{GID, PID, LID})::GID
Return the maximum global ID across the entire map
"""
maxAllGID(map::BlockMap) = map.data.maxAllGID
"""
minLID(map::BlockMap{GID, PID, LID})::LID
Return the mimimum local index value on the calling processor
"""
minLID(map::BlockMap) = map.data.minLID
"""
maxLID(map::BlockMap{GID, PID, LID})::LID
Return the maximum local index value on the calling processor
"""
maxLID(map::BlockMap) = map.data.maxLID
##size/dimension accessor functions##
"""
numGlobalElements(map::BlockMap{GID, PID, LID})::GID
Return the number of elements across all processors
"""
numGlobalElements(map::BlockMap) = map.data.numGlobalElements
"""
myGlobalElements(map::BlockMap{GID, PID, LID})::AbstractArray{GID}
Return a list of global elements on this processor
"""
function myGlobalElements(map::BlockMap{GID})::AbstractArray{GID} where GID <: Integer
data = map.data
if length(data.myGlobalElements) == 0
myGlobalElements = Vector{GID}(undef, data.numMyElements)
@inbounds for i = GID(1):GID(data.numMyElements)
myGlobalElements[i] = data.minMyGID + i - 1
end
data.myGlobalElements = myGlobalElements
else
data.myGlobalElements
end
end
##Miscellaneous boolean tests##
"""
uniqueGIDs(map::BlockMap)::Bool
Return true if each map GID exists on at most 1 processor
"""
uniqueGIDs(map::BlockMap) = isOneToOne(map)
"""
globalIndicesType(map::BlockMap{GID, PID, LID})::Type{GID}
Return the type used for global indices in the map
"""
globalIndicesType(map::BlockMap{GID}) where GID <: Integer = GID
"""
sameBlockMapDataAs(this::BlockMap, other::BlockMap)::Bool
Return true if the maps have the same data
"""
sameBlockMapDataAs(this::BlockMap, other::BlockMap) = this.data == other.data
"""
sameAs(this::BlockMap, other::BlockMap)::Bool
Return true if this and other are identical maps
"""
sameAs(this::BlockMap, other::BlockMap) = false
# behavior by specification
function sameAs(this::BlockMap{GID, PID, LID}, other::BlockMap{GID, PID, LID})::Bool where GID <: Integer where PID <: Integer where LID <: Integer
tData = this.data
oData = other.data
if tData == oData
return true
end
if ((tData.minAllGID != oData.minAllGID)
|| (tData.maxAllGID != oData.maxAllGID)
|| (tData.numGlobalElements != oData.numGlobalElements))
return false
end
mySameMap = 1
if tData.numMyElements != oData.numMyElements
mySameMap = 0
end
if tData.linearMap && oData.linearMap
# For linear maps, just need to check whether lower bound is the same
if tData.minMyGID != oData.minMyGID
mySameMap = 0
end
else
for i = 1:tData.numMyElements
if gid(this, i) != gid(other, i)
mySameMap = 0
break
end
end
end
Bool(minAll(tData.comm, mySameMap))
end
"""
linearMap(map::BlockMap)::Bool
Return true if the global ID space is contiguously divided (but
not necessarily uniformly) across all processors
"""
linearMap(map::BlockMap) = map.data.linearMap
##Array accessor functions##
"""
myGlobalElementsIDs map::BlockMap{GID, PID, LID})::AbstractArray{GID}
Return list of global IDs assigned to the calling processor
"""
function myGlobalElementIDs(map::BlockMap{GID})::AbstractArray{GID} where GID <: Integer
data = map.data
if length(data.myGlobalElements) == 0
base = 0:data.numMyElements-1
rng = data.minMyGID .+ base
collect(rng)
else
copy(data.myGlobalElements)
end
end
function isOneToOne(map::BlockMap)::Bool
data = map.data
if !(data.oneToOneIsDetermined)
data.oneToOne = determineIsOneToOne(map)
data.oneToOneIsDetermined = true
end
data.oneToOne
end
function determineIsOneToOne(map::BlockMap)::Bool
data = map.data
if numProc(data.comm) < 2
true
else
if data.directory === nothing
data.directory = createDirectory(data.comm, map)
end
gidsAllUniquelyOwned(data.directory)
end
end