@@ -103,9 +103,13 @@ class ReplicatedVertexView[VD: ClassTag](
103
103
// Update the view with shippedActives, setting activeness flags in the resulting
104
104
// VertexPartitions
105
105
get(includeSrc, includeDst).zipPartitions(shippedActives) { (viewIter, shippedActivesIter) =>
106
- val (pid, vPart) = viewIter.next()
107
- val newPart = vPart.replaceActives(shippedActivesIter.flatMap(_._2.iterator))
108
- Iterator ((pid, newPart))
106
+ if (viewIter.hasNext) {
107
+ val (pid, vPart) = viewIter.next()
108
+ val newPart = vPart.replaceActives(shippedActivesIter.flatMap(_._2.iterator))
109
+ Iterator ((pid, newPart))
110
+ } else {
111
+ Iterator .empty
112
+ }
109
113
}
110
114
}
111
115
@@ -126,30 +130,40 @@ class ReplicatedVertexView[VD: ClassTag](
126
130
// VertexPartitions
127
131
prevView.get(includeSrc, includeDst).zipPartitions(shippedVerts) {
128
132
(prevViewIter, shippedVertsIter) =>
129
- val (pid, prevVPart) = prevViewIter.next()
130
- val newVPart = prevVPart.innerJoinKeepLeftDestructive(shippedVertsIter.flatMap(_._2.iterator))
131
- Iterator ((pid, newVPart))
133
+ if (prevViewIter.hasNext) {
134
+ val (pid, prevVPart) = prevViewIter.next()
135
+ val newVPart =
136
+ if (destructiveLocal) prevVPart.innerJoinKeepLeftDestructive(shippedVertsIter.flatMap(_._2.iterator))
137
+ else prevVPart.innerJoinKeepLeft(shippedVertsIter.flatMap(_._2.iterator))
138
+ Iterator ((pid, newVPart))
139
+ } else {
140
+ Iterator .empty
141
+ }
132
142
}.cache().setName(" ReplicatedVertexView delta %s %s" .format(includeSrc, includeDst))
133
143
134
144
case None =>
135
145
// Within each edge partition, place the shipped vertex attributes into the correct
136
146
// locations specified in localVertexIdMap
137
147
localVertexIdMap.zipPartitions(shippedVerts) { (mapIter, shippedVertsIter) =>
138
- val (pid, vidToIndex) = mapIter.next()
139
- assert(! mapIter.hasNext)
140
- // Populate the vertex array using the vidToIndex map
141
- val vertexArray = vdTag.newArray(vidToIndex.capacity)
142
- for ((_, block) <- shippedVertsIter) {
143
- for (i <- 0 until block.vids.size) {
144
- val vid = block.vids(i)
145
- val attr = block.attrs(i)
146
- val ind = vidToIndex.getPos(vid)
147
- vertexArray(ind) = attr
148
+ if (mapIter.hasNext) {
149
+ val (pid, vidToIndex) = mapIter.next()
150
+ assert(! mapIter.hasNext)
151
+ // Populate the vertex array using the vidToIndex map
152
+ val vertexArray = vdTag.newArray(vidToIndex.capacity)
153
+ for ((_, block) <- shippedVertsIter) {
154
+ for (i <- 0 until block.vids.size) {
155
+ val vid = block.vids(i)
156
+ val attr = block.attrs(i)
157
+ val ind = vidToIndex.getPos(vid)
158
+ vertexArray(ind) = attr
159
+ }
148
160
}
161
+ val newVPart = new VertexPartition (
162
+ vidToIndex, vertexArray, vidToIndex.getBitSet)(vdTag)
163
+ Iterator ((pid, newVPart))
164
+ } else {
165
+ Iterator .empty
149
166
}
150
- val newVPart = new VertexPartition (
151
- vidToIndex, vertexArray, vidToIndex.getBitSet)(vdTag)
152
- Iterator ((pid, newVPart))
153
167
}.cache().setName(" ReplicatedVertexView %s %s" .format(includeSrc, includeDst))
154
168
}
155
169
}
@@ -159,47 +173,55 @@ private object ReplicatedVertexView {
159
173
protected def buildBuffer [VD : ClassTag ](
160
174
pid2vidIter : Iterator [Array [Array [VertexId ]]],
161
175
vertexPartIter : Iterator [VertexPartition [VD ]]) = {
162
- val pid2vid : Array [Array [VertexId ]] = pid2vidIter.next()
163
- val vertexPart : VertexPartition [VD ] = vertexPartIter.next()
164
-
165
- Iterator .tabulate(pid2vid.size) { pid =>
166
- val vidsCandidate = pid2vid(pid)
167
- val size = vidsCandidate.length
168
- val vids = new PrimitiveVector [VertexId ](pid2vid(pid).size)
169
- val attrs = new PrimitiveVector [VD ](pid2vid(pid).size)
170
- var i = 0
171
- while (i < size) {
172
- val vid = vidsCandidate(i)
173
- if (vertexPart.isDefined(vid)) {
174
- vids += vid
175
- attrs += vertexPart(vid)
176
+ if (pid2vidIter.hasNext && vertexPartIter.hasNext) {
177
+ val pid2vid : Array [Array [VertexId ]] = pid2vidIter.next()
178
+ val vertexPart : VertexPartition [VD ] = vertexPartIter.next()
179
+
180
+ Iterator .tabulate(pid2vid.size) { pid =>
181
+ val vidsCandidate = pid2vid(pid)
182
+ val size = vidsCandidate.length
183
+ val vids = new PrimitiveVector [VertexId ](pid2vid(pid).size)
184
+ val attrs = new PrimitiveVector [VD ](pid2vid(pid).size)
185
+ var i = 0
186
+ while (i < size) {
187
+ val vid = vidsCandidate(i)
188
+ if (vertexPart.isDefined(vid)) {
189
+ vids += vid
190
+ attrs += vertexPart(vid)
191
+ }
192
+ i += 1
176
193
}
177
- i += 1
194
+ (pid, new VertexAttributeBlock (vids.trim().array, attrs.trim().array))
178
195
}
179
- (pid, new VertexAttributeBlock (vids.trim().array, attrs.trim().array))
196
+ } else {
197
+ Iterator .empty
180
198
}
181
199
}
182
200
183
201
protected def buildActiveBuffer (
184
202
pid2vidIter : Iterator [Array [Array [VertexId ]]],
185
203
activePartIter : Iterator [VertexPartition [_]])
186
204
: Iterator [(Int , Array [VertexId ])] = {
187
- val pid2vid : Array [Array [VertexId ]] = pid2vidIter.next()
188
- val activePart : VertexPartition [_] = activePartIter.next()
189
-
190
- Iterator .tabulate(pid2vid.size) { pid =>
191
- val vidsCandidate = pid2vid(pid)
192
- val size = vidsCandidate.length
193
- val actives = new PrimitiveVector [VertexId ](vidsCandidate.size)
194
- var i = 0
195
- while (i < size) {
196
- val vid = vidsCandidate(i)
197
- if (activePart.isDefined(vid)) {
198
- actives += vid
205
+ if (pid2vidIter.hasNext && activePartIter.hasNext) {
206
+ val pid2vid : Array [Array [VertexId ]] = pid2vidIter.next()
207
+ val activePart : VertexPartition [_] = activePartIter.next()
208
+
209
+ Iterator .tabulate(pid2vid.size) { pid =>
210
+ val vidsCandidate = pid2vid(pid)
211
+ val size = vidsCandidate.length
212
+ val actives = new PrimitiveVector [VertexId ](vidsCandidate.size)
213
+ var i = 0
214
+ while (i < size) {
215
+ val vid = vidsCandidate(i)
216
+ if (activePart.isDefined(vid)) {
217
+ actives += vid
218
+ }
219
+ i += 1
199
220
}
200
- i += 1
221
+ (pid, actives.trim().array)
201
222
}
202
- (pid, actives.trim().array)
223
+ } else {
224
+ Iterator .empty
203
225
}
204
226
}
205
227
}
0 commit comments