I
- Vertex idV
- Vertex dataE
- Edge dataM1
- Incoming message typeM2
- Outgoing message typepublic abstract class AbstractComputation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable> extends WorkerAggregatorDelegator<I,V,E> implements Computation<I,V,E,M1,M2>
Computation
for explanation of the interface.
This is a abstract class helper for users to implement their computations.
It implements all of the methods required by the Computation
interface except for the compute(Vertex, Iterable)
which we leave
to the user to define.
In most cases users should inherit from this class when implementing their
algorithms with Giraph.Constructor and Description |
---|
AbstractComputation() |
Modifier and Type | Method and Description |
---|---|
void |
addEdgeRequest(I sourceVertexId,
Edge<I,E> edge)
Request to add an edge of a vertex in the graph
(processed just prior to the next superstep)
|
void |
addVertexRequest(I id,
V value)
Sends a request to create a vertex that will be available during the
next superstep.
|
void |
addVertexRequest(I id,
V value,
OutEdges<I,E> edges)
Sends a request to create a vertex that will be available during the
next superstep.
|
abstract void |
compute(Vertex<I,V,E> vertex,
Iterable<M1> messages)
Must be defined by user to do computation on a single Vertex.
|
org.apache.hadoop.mapreduce.Mapper.Context |
getContext()
Get the mapper context
|
int |
getMyWorkerIndex()
Get index for this worker
|
long |
getSuperstep()
Retrieves the current superstep.
|
long |
getTotalNumEdges()
Get the total (all workers) number of edges that
existed in the previous superstep.
|
long |
getTotalNumVertices()
Get the total (all workers) number of vertices that
existed in the previous superstep.
|
<W extends WorkerContext> |
getWorkerContext()
Get the worker context
|
int |
getWorkerCount()
Get number of workers
|
int |
getWorkerForVertex(I vertexId)
Get worker index which will contain vertex with given id,
if such vertex exists.
|
void |
initialize(GraphState graphState,
WorkerClientRequestProcessor<I,V,E> workerClientRequestProcessor,
CentralizedServiceWorker<I,V,E> serviceWorker,
WorkerGlobalCommUsage workerGlobalCommUsage)
Initialize, called by infrastructure before the superstep starts.
|
void |
postSuperstep()
Finish computation.
|
void |
preSuperstep()
Prepare for computation.
|
void |
removeEdgesRequest(I sourceVertexId,
I targetVertexId)
Request to remove all edges from a given source vertex to a given target
vertex (processed just prior to the next superstep).
|
void |
removeVertexRequest(I vertexId)
Request to remove a vertex from the graph
(applied just prior to the next superstep).
|
void |
sendMessage(I id,
M2 message)
Send a message to a vertex id.
|
void |
sendMessageToAllEdges(Vertex<I,V,E> vertex,
M2 message)
Send a message to all edges.
|
void |
sendMessageToMultipleEdges(Iterator<I> vertexIdIterator,
M2 message)
Send a message to multiple target vertex ids in the iterator.
|
aggregate, getAggregatedValue, getBroadcast, reduce, reduceMerge, setWorkerGlobalCommUsage
getConf, setConf
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConf
setConf
getBroadcast
reduce, reduceMerge
aggregate
getAggregatedValue
public abstract void compute(Vertex<I,V,E> vertex, Iterable<M1> messages) throws IOException
compute
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
vertex
- Vertexmessages
- Messages that were sent to this vertex in the previous
superstep. Each message is only guaranteed to have
a life expectancy as long as next() is not called.IOException
public void preSuperstep()
compute(Vertex, Iterable)
being called for any of the vertices
in the partition.preSuperstep
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
public void postSuperstep()
postSuperstep
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
public void initialize(GraphState graphState, WorkerClientRequestProcessor<I,V,E> workerClientRequestProcessor, CentralizedServiceWorker<I,V,E> serviceWorker, WorkerGlobalCommUsage workerGlobalCommUsage)
initialize
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
graphState
- Graph stateworkerClientRequestProcessor
- Processor for handling requestsserviceWorker
- Graph-wide BSP Mapper for this VertexworkerGlobalCommUsage
- Worker global communication usagepublic long getSuperstep()
getSuperstep
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
public long getTotalNumVertices()
getTotalNumVertices
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
public long getTotalNumEdges()
getTotalNumEdges
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
public void sendMessage(I id, M2 message)
sendMessage
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
id
- Vertex id to send the message tomessage
- Message data to sendpublic void sendMessageToAllEdges(Vertex<I,V,E> vertex, M2 message)
sendMessageToAllEdges
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
vertex
- Vertex whose edges to send the message to.message
- Message sent to all edges.public void sendMessageToMultipleEdges(Iterator<I> vertexIdIterator, M2 message)
sendMessageToMultipleEdges
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
vertexIdIterator
- An iterator to multiple target vertex ids.message
- Message sent to all targets in the iterator.public void addVertexRequest(I id, V value, OutEdges<I,E> edges) throws IOException
addVertexRequest
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
id
- Vertex idvalue
- Vertex valueedges
- Initial edgesIOException
public void addVertexRequest(I id, V value) throws IOException
addVertexRequest
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
id
- Vertex idvalue
- Vertex valueIOException
public void removeVertexRequest(I vertexId) throws IOException
removeVertexRequest
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
vertexId
- Id of the vertex to be removed.IOException
public void addEdgeRequest(I sourceVertexId, Edge<I,E> edge) throws IOException
addEdgeRequest
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
sourceVertexId
- Source vertex id of edgeedge
- Edge to addIOException
public void removeEdgesRequest(I sourceVertexId, I targetVertexId) throws IOException
removeEdgesRequest
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
sourceVertexId
- Source vertex idtargetVertexId
- Target vertex idIOException
public org.apache.hadoop.mapreduce.Mapper.Context getContext()
getContext
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
public <W extends WorkerContext> W getWorkerContext()
getWorkerContext
in interface Computation<I extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable,E extends org.apache.hadoop.io.Writable,M1 extends org.apache.hadoop.io.Writable,M2 extends org.apache.hadoop.io.Writable>
W
- WorkerContext classpublic final int getWorkerCount()
WorkerIndexUsage
getWorkerCount
in interface WorkerIndexUsage<I extends org.apache.hadoop.io.WritableComparable>
public final int getMyWorkerIndex()
WorkerIndexUsage
getMyWorkerIndex
in interface WorkerIndexUsage<I extends org.apache.hadoop.io.WritableComparable>
public final int getWorkerForVertex(I vertexId)
WorkerIndexUsage
getWorkerForVertex
in interface WorkerIndexUsage<I extends org.apache.hadoop.io.WritableComparable>
vertexId
- vertex idCopyright © 2011-2020 The Apache Software Foundation. All Rights Reserved.