Search in sources :

Example 1 with MessageHeader

use of edu.iu.dsc.tws.comms.api.MessageHeader in project twister2 by DSC-SPIDAL.

the class MPIDirectDataFlowCommunication method receiveMessage.

@Override
public boolean receiveMessage(MPIMessage currentMessage, Object object) {
    MessageHeader header = currentMessage.getHeader();
    LOG.info("================================================");
    LOG.info("MessageHeader : " + header.toString());
    LOG.info("MPIMessage : " + currentMessage.toString());
    LOG.info("Message Object : " + object.toString());
    LOG.info("Source ID : " + header.getSourceId());
    LOG.info("Source ID : " + header.getSourceId());
    LOG.info("================================================");
    // check weather this message is for a sub task
    return finalReceiver.onMessage(header.getSourceId(), 0, destination, header.getFlags(), object);
}
Also used : MessageHeader(edu.iu.dsc.tws.comms.api.MessageHeader)

Example 2 with MessageHeader

use of edu.iu.dsc.tws.comms.api.MessageHeader in project twister2 by DSC-SPIDAL.

the class MPIDataFlowGather method receiveMessage.

/**
 * We can receive messages from internal tasks or an external task, we allways receive messages
 * to the main task of the executor and we go from there
 *
 * @param currentMessage
 * @param object
 */
@Override
public boolean receiveMessage(MPIMessage currentMessage, Object object) {
    MessageHeader header = currentMessage.getHeader();
    // we always receive to the main task
    int messageDestId = currentMessage.getHeader().getDestinationIdentifier();
    // check weather this message is for a sub task
    if (!isLast() && partialReceiver != null) {
        // LOG.info(String.format("%d calling PARTIAL receiver %d", executor, header.getSourceId()));
        return partialReceiver.onMessage(header.getSourceId(), MPIContext.DEFAULT_PATH, router.mainTaskOfExecutor(instancePlan.getThisExecutor(), MPIContext.DEFAULT_PATH), header.getFlags(), currentMessage);
    } else {
        // LOG.info(String.format("%d calling FINAL receiver %d", executor, header.getSourceId()));
        return finalReceiver.onMessage(header.getSourceId(), MPIContext.DEFAULT_PATH, router.mainTaskOfExecutor(instancePlan.getThisExecutor(), MPIContext.DEFAULT_PATH), header.getFlags(), object);
    }
}
Also used : MessageHeader(edu.iu.dsc.tws.comms.api.MessageHeader)

Example 3 with MessageHeader

use of edu.iu.dsc.tws.comms.api.MessageHeader in project twister2 by DSC-SPIDAL.

the class MPIDataFlowOperation method onReceiveComplete.

@Override
public void onReceiveComplete(int id, int e, MPIBuffer buffer) {
    // we need to try to build the message here, we may need many more messages to complete
    MPIMessage currentMessage = currentMessages.get(id);
    ByteBuffer byteBuffer = buffer.getByteBuffer();
    byteBuffer.position(buffer.getSize());
    byteBuffer.flip();
    receiveCount++;
    if (currentMessage == null) {
        currentMessage = new MPIMessage(id, type, MPIMessageDirection.IN, this);
        if (isKeyed) {
            currentMessage.setKeyType(keyType);
        }
        currentMessages.put(id, currentMessage);
        MessageHeader header = messageDeSerializer.get(id).buildHeader(buffer, e);
        currentMessage.setHeader(header);
        currentMessage.setHeaderSize(16);
    }
    currentMessage.addBuffer(buffer);
    currentMessage.build();
    if (currentMessage.isComplete()) {
        currentMessages.remove(id);
        Queue<MPIMessage> deserializeQueue = pendingReceiveDeSerializations.get(id);
        if (!deserializeQueue.offer(currentMessage)) {
            throw new RuntimeException(executor + " We should have enough space: " + deserializeQueue.size());
        }
    }
}
Also used : MessageHeader(edu.iu.dsc.tws.comms.api.MessageHeader) ByteBuffer(java.nio.ByteBuffer)

Example 4 with MessageHeader

use of edu.iu.dsc.tws.comms.api.MessageHeader in project twister2 by DSC-SPIDAL.

the class MPIDataFlowReduce method receiveMessage.

/**
 * We can receive messages from internal tasks or an external task, we allways receive messages
 * to the main task of the executor and we go from there
 *
 * @param currentMessage
 * @param object
 */
public boolean receiveMessage(MPIMessage currentMessage, Object object) {
    MessageHeader header = currentMessage.getHeader();
    // we always receive to the main task
    int messageDestId = currentMessage.getHeader().getDestinationIdentifier();
    // check weather this message is for a sub task
    if (!isLast(header.getSourceId(), header.getFlags(), messageDestId) && partialReceiver != null) {
        return partialReceiver.onMessage(header.getSourceId(), MPIContext.DEFAULT_PATH, router.mainTaskOfExecutor(instancePlan.getThisExecutor(), MPIContext.DEFAULT_PATH), header.getFlags(), object);
    } else {
        return finalReceiver.onMessage(header.getSourceId(), MPIContext.DEFAULT_PATH, router.mainTaskOfExecutor(instancePlan.getThisExecutor(), MPIContext.DEFAULT_PATH), header.getFlags(), object);
    }
}
Also used : MessageHeader(edu.iu.dsc.tws.comms.api.MessageHeader)

Example 5 with MessageHeader

use of edu.iu.dsc.tws.comms.api.MessageHeader in project twister2 by DSC-SPIDAL.

the class MPIMultiMessageDeserializer method getDataBuffers.

@Override
public Object getDataBuffers(Object partialObject, int edge) {
    MPIMessage currentMessage = (MPIMessage) partialObject;
    int readLength = 0;
    int bufferIndex = 0;
    List<MPIBuffer> buffers = currentMessage.getBuffers();
    List<Object> returnList = new ArrayList<>();
    MessageHeader header = currentMessage.getHeader();
    if (header == null) {
        throw new RuntimeException("Header must be built before the message");
    }
    // LOG.info(String.format("%d deserilizing message", executor));
    while (readLength < header.getLength()) {
        List<MPIBuffer> messageBuffers = new ArrayList<>();
        MPIBuffer mpiBuffer = buffers.get(bufferIndex);
        ByteBuffer byteBuffer = mpiBuffer.getByteBuffer();
        // now read the length
        int length = byteBuffer.getInt();
        int tempLength = 0;
        int tempBufferIndex = bufferIndex;
        while (tempLength < length) {
            mpiBuffer = buffers.get(tempBufferIndex);
            messageBuffers.add(mpiBuffer);
            tempLength += mpiBuffer.getByteBuffer().remaining();
            tempBufferIndex++;
        // LOG.info(String.format("%d temp %d length %d readLength %d header %d buf_pos %d",
        // executor, tempLength, length, readLength, header.getLength(),
        // mpiBuffer.getByteBuffer().position()));
        }
        Object object = getSingleDataBuffers(currentMessage, messageBuffers, length);
        readLength += length + 4;
        if (keyed && !MessageTypeUtils.isPrimitiveType(currentMessage.getKeyType())) {
            // adding 4 to the length since the key length is also kept
            readLength += 4;
        }
        byteBuffer = mpiBuffer.getByteBuffer();
        if (byteBuffer.remaining() > 0) {
            bufferIndex = tempBufferIndex - 1;
        } else {
            bufferIndex = tempBufferIndex;
        }
        returnList.add(object);
    }
    return returnList;
}
Also used : MPIMessage(edu.iu.dsc.tws.comms.mpi.MPIMessage) ArrayList(java.util.ArrayList) MessageHeader(edu.iu.dsc.tws.comms.api.MessageHeader) MPIBuffer(edu.iu.dsc.tws.comms.mpi.MPIBuffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

MessageHeader (edu.iu.dsc.tws.comms.api.MessageHeader)7 MPIBuffer (edu.iu.dsc.tws.comms.mpi.MPIBuffer)3 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 MPIMessage (edu.iu.dsc.tws.comms.mpi.MPIMessage)2 List (java.util.List)1