Search in sources :

Example 1 with DataBuffer

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

the class TWSMPIChannel method postReceive.

private void postReceive(MPIReceiveRequests requests) {
    DataBuffer byteBuffer = requests.availableBuffers.poll();
    while (byteBuffer != null) {
        // post the receive
        pendingReceiveCount++;
        Request request = postReceive(requests.rank, requests.edge, byteBuffer);
        requests.pendingRequests.add(new MPIRequest(request, byteBuffer));
        byteBuffer = requests.availableBuffers.poll();
    }
}
Also used : Request(mpi.Request) DataBuffer(edu.iu.dsc.tws.api.comms.packing.DataBuffer)

Example 2 with DataBuffer

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

the class TWSTCPChannel method postReceive.

private void postReceive(TCPReceiveRequests requests) {
    DataBuffer byteBuffer = requests.availableBuffers.poll();
    if (byteBuffer != null) {
        // post the receive
        TCPMessage request = postReceive(requests.rank, requests.edge, byteBuffer);
        requests.pendingRequests.add(new Request(request, byteBuffer));
    }
}
Also used : TCPMessage(edu.iu.dsc.tws.common.net.tcp.TCPMessage) DataBuffer(edu.iu.dsc.tws.api.comms.packing.DataBuffer)

Example 3 with DataBuffer

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

the class TWSTCPChannel method postMessage.

/**
 * Send a message to the given rank.
 *
 * @param requests the message
 */
private void postMessage(TCPSendRequests requests) {
    ChannelMessage message = requests.message;
    for (int i = 0; i < message.getNormalBuffers().size(); i++) {
        sendCount++;
        DataBuffer buffer = message.getNormalBuffers().get(i);
        TCPMessage request = channel.iSend(buffer.getByteBuffer(), buffer.getSize(), requests.rank, message.getHeader().getEdge());
        // register to the loop to make communicationProgress on the send
        requests.pendingSends.add(new Request(request, buffer));
    }
}
Also used : TCPMessage(edu.iu.dsc.tws.common.net.tcp.TCPMessage) ChannelMessage(edu.iu.dsc.tws.api.comms.messaging.ChannelMessage) DataBuffer(edu.iu.dsc.tws.api.comms.packing.DataBuffer)

Example 4 with DataBuffer

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

the class ControlledChannelOperation method setupReceiveGroups.

/**
 * Start receiving from the next set of ids
 */
public void setupReceiveGroups(List<IntArrayList> receivingIds) {
    this.receiveIdGroups = receivingIds;
    int max = Integer.MIN_VALUE;
    // first lets validate
    for (int i = 0; i < receivingIds.size(); i++) {
        List<Integer> group = receivingIds.get(i);
        if (group.size() > max) {
            max = group.size();
        }
    }
    // we put max group size equal buffers
    int receiveBufferSize = CommunicationContext.bufferSize(config);
    this.freeReceiveBuffers = new ArrayBlockingQueue<>(max);
    for (int i = 0; i < max; i++) {
        ByteBuffer byteBuffer = channel.createBuffer(receiveBufferSize);
        this.freeReceiveBuffers.offer(new DataBuffer(byteBuffer));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteBuffer(java.nio.ByteBuffer) DataBuffer(edu.iu.dsc.tws.api.comms.packing.DataBuffer)

Example 5 with DataBuffer

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

the class ControlledChannelOperation method receiveProgress.

/**
 * Progress the receive
 *
 * @param receiveId
 */
public void receiveProgress(int receiveId) {
    Queue<InMessage> pendingReceiveMessages = pendingReceiveMessagesPerSource.get(receiveId);
    boolean canProgress = true;
    while (pendingReceiveMessages.size() > 0 && canProgress) {
        InMessage currentMessage = pendingReceiveMessages.peek();
        lock.lock();
        try {
            // lets keep track that we have completed a receive from this executor
            int workerId = currentMessage.getOriginatingId();
            int count = currentReceives.get(workerId);
            int expected = expectedReceivePerWorker.get(workerId);
            InMessage.ReceivedState receivedState = currentMessage.getReceivedState();
            if (receivedState == InMessage.ReceivedState.BUILT) {
                // if this message is built, we need to check how many we are expecting
                count++;
                currentReceives.put(workerId, count);
            }
            if (receivedState == InMessage.ReceivedState.BUILDING || receivedState == InMessage.ReceivedState.BUILT) {
                while (currentMessage.getBuiltMessages().size() > 0) {
                    // get the first channel message
                    ChannelMessage msg = currentMessage.getBuiltMessages().peek();
                    if (msg != null) {
                        if (!receiver.handleReceivedChannelMessage(msg)) {
                            canProgress = false;
                            break;
                        }
                        ChannelMessage releaseMsg = currentMessage.getBuiltMessages().poll();
                        Objects.requireNonNull(releaseMsg).release();
                        if (receivedState == InMessage.ReceivedState.BUILDING) {
                            DataBuffer buffer = freeReceiveBuffers.poll();
                            Queue<DataBuffer> list = receiveBuffers.get(workerId);
                            if (buffer == null) {
                                throw new RuntimeException("Free buffers doesn't have any buffer");
                            }
                            // we get a free buffer and offer
                            list.offer(buffer);
                        } else {
                            if (expected > count) {
                                DataBuffer buffer = freeReceiveBuffers.poll();
                                Queue<DataBuffer> list = receiveBuffers.get(workerId);
                                if (buffer == null) {
                                    throw new RuntimeException("Free buffers doesn't have any buffer");
                                }
                                // we get a free buffer and offer
                                list.offer(buffer);
                            }
                        }
                    }
                }
                if (receivedState == InMessage.ReceivedState.BUILT && currentMessage.getBuiltMessages().size() == 0 && canProgress) {
                    currentMessage.setReceivedState(InMessage.ReceivedState.RECEIVE);
                }
            }
            if (receivedState == InMessage.ReceivedState.RECEIVE) {
                Object object = currentMessage.getDeserializedData();
                if (!receiver.receiveMessage(currentMessage.getHeader(), object)) {
                    break;
                }
                currentMessage.setReceivedState(InMessage.ReceivedState.DONE);
                pendingReceiveMessages.poll();
            } else {
                break;
            }
        } finally {
            lock.unlock();
        }
    }
}
Also used : ChannelMessage(edu.iu.dsc.tws.api.comms.messaging.ChannelMessage) DataBuffer(edu.iu.dsc.tws.api.comms.packing.DataBuffer)

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