Search in sources :

Example 21 with DataBuffer

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

the class TWSMPIChannel method postMessage.

/**
 * Send a message to the given rank.
 *
 * @param requests the message
 */
private void postMessage(MPISendRequests requests) {
    ChannelMessage message = requests.message;
    for (int i = 0; i < message.getNormalBuffers().size(); i++) {
        try {
            sendCount++;
            DataBuffer buffer = message.getNormalBuffers().get(i);
            Request request = comm.iSend(buffer.getByteBuffer(), buffer.getSize(), MPI.BYTE, requests.rank, message.getHeader().getEdge());
            // register to the loop to make communicationProgress on the send
            requests.pendingSends.add(new MPIRequest(request, buffer));
        } catch (MPIException e) {
            throw new RuntimeException("Failed to send message to rank: " + requests.rank);
        }
    }
}
Also used : MPIException(mpi.MPIException) Request(mpi.Request) ChannelMessage(edu.iu.dsc.tws.api.comms.messaging.ChannelMessage) DataBuffer(edu.iu.dsc.tws.api.comms.packing.DataBuffer)

Example 22 with DataBuffer

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

the class TWSUCXChannel method sendMessage.

@Override
public boolean sendMessage(int id, ChannelMessage message, ChannelListener callback) {
    AtomicInteger buffersLeft = new AtomicInteger(message.getBuffers().size());
    for (DataBuffer buffer : message.getBuffers()) {
        buffer.getByteBuffer().limit(buffer.getSize());
        buffer.getByteBuffer().position(0);
        int tag = this.workerId * tagWIdOffset + message.getHeader().getEdge();
        LOG.log(Level.FINE, () -> String.format("SENDING to %d[%d] : %s, TAG[%d]", id, message.getHeader().getEdge(), buffer.getByteBuffer(), tag));
        this.endpoints.get(id).sendTaggedNonBlocking(buffer.getByteBuffer(), tag, new UcxCallback() {

            @Override
            public void onSuccess(UcpRequest request) {
                pendingSendRequests.decrementAndGet();
                if (buffersLeft.decrementAndGet() == 0) {
                    callback.onSendComplete(id, message.getHeader().getEdge(), message);
                }
            }

            @Override
            public void onError(int ucsStatus, String errorMsg) {
                // This is a catastrophic failure
                LOG.severe("UCX send request failed to worker " + id + " with status " + ucsStatus + ". Error : " + errorMsg);
                throw new Twister2RuntimeException("Send request to worker : " + id + " failed. " + errorMsg);
            }
        });
        this.pendingSendRequests.incrementAndGet();
    }
    return true;
}
Also used : Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UcpRequest(org.openucx.jucx.ucp.UcpRequest) UcpEndpoint(org.openucx.jucx.ucp.UcpEndpoint) DataBuffer(edu.iu.dsc.tws.api.comms.packing.DataBuffer) UcxCallback(org.openucx.jucx.UcxCallback)

Example 23 with DataBuffer

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

the class BaseSerializeTest method keyedSingleValueCase.

public InMessage keyedSingleValueCase(int numBuffers, int size, MessageType type, MessageType keyType, Object data) {
    BlockingQueue<DataBuffer> bufferQueue = createDataQueue(numBuffers, size);
    OutMessage outMessage = new OutMessage(0, 1, -1, 10, 0, null, null, type, keyType, null, data);
    KeyedDataSerializer serializer = new KeyedDataSerializer();
    serializer.init(Config.newBuilder().build(), bufferQueue);
    List<ChannelMessage> messages = new ArrayList<>();
    while (outMessage.getSendState() != OutMessage.SendState.SERIALIZED) {
        ChannelMessage ch = serializer.build(data, outMessage);
        messages.add(ch);
    }
    KeyedDataDeSerializer deserializer = new KeyedDataDeSerializer();
    deserializer.init(Config.newBuilder().build());
    MessageHeader header = deserializer.buildHeader(messages.get(0).getBuffers().get(0), 1);
    InMessage inMessage = new InMessage(0, type, null, header);
    inMessage.setKeyType(keyType);
    for (ChannelMessage channelMessage : messages) {
        for (DataBuffer dataBuffer : channelMessage.getBuffers()) {
            inMessage.addBufferAndCalculate(dataBuffer);
        }
    }
    deserializer.build(inMessage, 1);
    return inMessage;
}
Also used : OutMessage(edu.iu.dsc.tws.comms.dfw.OutMessage) ArrayList(java.util.ArrayList) InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) MessageHeader(edu.iu.dsc.tws.api.comms.messaging.MessageHeader) DataBuffer(edu.iu.dsc.tws.api.comms.packing.DataBuffer) ChannelMessage(edu.iu.dsc.tws.api.comms.messaging.ChannelMessage)

Aggregations

DataBuffer (edu.iu.dsc.tws.api.comms.packing.DataBuffer)23 ChannelMessage (edu.iu.dsc.tws.api.comms.messaging.ChannelMessage)14 MessageHeader (edu.iu.dsc.tws.api.comms.messaging.MessageHeader)10 InMessage (edu.iu.dsc.tws.comms.dfw.InMessage)10 ArrayList (java.util.ArrayList)9 OutMessage (edu.iu.dsc.tws.comms.dfw.OutMessage)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 DataPacker (edu.iu.dsc.tws.api.comms.packing.DataPacker)4 MessageType (edu.iu.dsc.tws.api.comms.messaging.types.MessageType)2 TCPMessage (edu.iu.dsc.tws.common.net.tcp.TCPMessage)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Request (mpi.Request)2 ChannelListener (edu.iu.dsc.tws.api.comms.channel.ChannelListener)1 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)1 DataDeserializer (edu.iu.dsc.tws.comms.dfw.io.DataDeserializer)1 DataSerializer (edu.iu.dsc.tws.comms.dfw.io.DataSerializer)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 ByteBuffer (java.nio.ByteBuffer)1 Queue (java.util.Queue)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1