use of edu.iu.dsc.tws.comms.mpi.MPISendMessage in project twister2 by DSC-SPIDAL.
the class MPIMessageSerializer method build.
@Override
public Object build(Object message, Object partialBuildObject) {
MPISendMessage sendMessage = (MPISendMessage) partialBuildObject;
// we got an already serialized message, lets just return it
if (sendMessage.getMPIMessage().isComplete()) {
sendMessage.setSendState(MPISendMessage.SendState.SERIALIZED);
return sendMessage;
}
if (sendMessage.getSerializationState() == null) {
sendMessage.setSerializationState(new SerializeState());
}
while (sendBuffers.size() > 0 && sendMessage.serializedState() != MPISendMessage.SendState.SERIALIZED) {
MPIBuffer buffer = sendBuffers.poll();
if (buffer == null) {
break;
}
if (sendMessage.serializedState() == MPISendMessage.SendState.INIT || sendMessage.serializedState() == MPISendMessage.SendState.SENT_INTERNALLY) {
// build the header
buildHeader(buffer, sendMessage);
sendMessage.setSendState(MPISendMessage.SendState.HEADER_BUILT);
}
if (sendMessage.serializedState() == MPISendMessage.SendState.HEADER_BUILT || sendMessage.serializedState() == MPISendMessage.SendState.BODY_BUILT) {
// build the body
// first we need to serialize the body if needed
boolean complete = serializeBody(message, sendMessage, buffer);
if (complete) {
sendMessage.setSendState(MPISendMessage.SendState.SERIALIZED);
}
}
// okay we are adding this buffer
sendMessage.getMPIMessage().addBuffer(buffer);
if (sendMessage.serializedState() == MPISendMessage.SendState.SERIALIZED) {
MPIMessage mpiMessage = sendMessage.getMPIMessage();
SerializeState state = sendMessage.getSerializationState();
int totalBytes = state.getTotalBytes();
mpiMessage.getBuffers().get(0).getByteBuffer().putInt(12, totalBytes);
MessageHeader.Builder builder = MessageHeader.newBuilder(sendMessage.getSource(), sendMessage.getEdge(), totalBytes);
builder.destination(sendMessage.getDestintationIdentifier());
sendMessage.getMPIMessage().setHeader(builder.build());
state.setTotalBytes(0);
// mark the original message as complete
mpiMessage.setComplete(true);
} else {
LOG.fine("Message NOT FULLY serialized");
}
}
return sendMessage;
}
use of edu.iu.dsc.tws.comms.mpi.MPISendMessage in project twister2 by DSC-SPIDAL.
the class Test method serializeObject.
private MPIMessage serializeObject(List object, int source) {
MPIMessage mpiMessage = new MPIMessage(source, MessageType.OBJECT, MPIMessageDirection.OUT, new MessageListener());
mpiMessage.setKeyType(MessageType.INTEGER);
int di = -1;
MPISendMessage sendMessage = new MPISendMessage(source, mpiMessage, 0, di, 0, 0, null, null);
multiMessageSerializer.build(object, sendMessage);
return mpiMessage;
}
use of edu.iu.dsc.tws.comms.mpi.MPISendMessage in project twister2 by DSC-SPIDAL.
the class MPIMultiMessageSerializer method build.
@Override
public Object build(Object message, Object partialBuildObject) {
int noOfMessages = 1;
if (message instanceof List) {
noOfMessages = ((List) message).size();
}
MPISendMessage sendMessage = (MPISendMessage) partialBuildObject;
// we got an already serialized message, lets just return it
MPIMessage mpiMessage = sendMessage.getMPIMessage();
if (mpiMessage.isComplete()) {
sendMessage.setSendState(MPISendMessage.SendState.SERIALIZED);
return sendMessage;
}
// to keep track of the serialization progress of this message
if (sendMessage.getSerializationState() == null) {
sendMessage.setSerializationState(new SerializeState());
}
while (sendBuffers.size() > 0 && sendMessage.serializedState() != MPISendMessage.SendState.SERIALIZED) {
MPIBuffer buffer = sendBuffers.poll();
if (sendMessage.serializedState() == MPISendMessage.SendState.INIT || sendMessage.serializedState() == MPISendMessage.SendState.SENT_INTERNALLY) {
// build the header
buildHeader(buffer, sendMessage, noOfMessages);
sendMessage.setSendState(MPISendMessage.SendState.HEADER_BUILT);
}
if (sendMessage.serializedState() == MPISendMessage.SendState.HEADER_BUILT || sendMessage.serializedState() == MPISendMessage.SendState.BODY_BUILT) {
// first we need to serialize the body if needed
serializeBody(message, sendMessage, buffer);
}
// okay we are adding this buffer
mpiMessage.addBuffer(buffer);
if (sendMessage.serializedState() == MPISendMessage.SendState.SERIALIZED) {
SerializeState state = sendMessage.getSerializationState();
int totalBytes = state.getTotalBytes();
mpiMessage.getBuffers().get(0).getByteBuffer().putInt(12, totalBytes);
MessageHeader.Builder builder = MessageHeader.newBuilder(sendMessage.getSource(), sendMessage.getEdge(), totalBytes);
builder.destination(sendMessage.getDestintationIdentifier());
sendMessage.getMPIMessage().setHeader(builder.build());
state.setTotalBytes(0);
// mark the original message as complete
mpiMessage.setComplete(true);
}
}
return sendMessage;
}
Aggregations