Search in sources :

Example 1 with Status

use of mpi.Status in project twister2 by DSC-SPIDAL.

the class TWSMPIChannel method progress.

/**
 * Progress the communications that are pending
 */
public void progress() {
    // we should rate limit here
    while (pendingSends.size() > 0) {
        // post the message
        MPISendRequests sendRequests = pendingSends.poll();
        // post the send
        if (sendRequests != null) {
            postMessage(sendRequests);
            waitForCompletionSends.add(sendRequests);
        }
    }
    for (int i = 0; i < registeredReceives.size(); i++) {
        MPIReceiveRequests receiveRequests = registeredReceives.get(i);
        if (debug) {
            LOG.info(String.format("%d available receive %d %d %s", executor, receiveRequests.rank, receiveRequests.availableBuffers.size(), receiveRequests.availableBuffers.peek()));
        }
        // okay we have more buffers to be posted
        if (receiveRequests.availableBuffers.size() > 0) {
            postReceive(receiveRequests);
        }
    }
    Iterator<MPISendRequests> sendRequestsIterator = waitForCompletionSends.iterator();
    boolean canProgress = true;
    while (sendRequestsIterator.hasNext() && canProgress) {
        MPISendRequests sendRequests = sendRequestsIterator.next();
        Iterator<MPIRequest> requestIterator = sendRequests.pendingSends.iterator();
        while (requestIterator.hasNext()) {
            MPIRequest r = requestIterator.next();
            try {
                Status status = r.request.testStatus();
                // this request has finished
                if (status != null) {
                    completedSendCount++;
                    requestIterator.remove();
                } else {
                    canProgress = false;
                    break;
                }
            } catch (MPIException e) {
                throw new RuntimeException("Failed to complete the send to: " + sendRequests.rank, e);
            }
        }
        // ideally we should be able to call for each finish of the buffer
        if (sendRequests.pendingSends.size() == 0) {
            sendRequests.callback.onSendComplete(sendRequests.rank, sendRequests.edge, sendRequests.message);
            sendRequestsIterator.remove();
        }
    }
    if (false) {
        LOG.info(String.format("%d sending - sent %d comp send %d receive %d pend recv %d pending sends %d waiting %d", executor, sendCount, completedSendCount, receiveCount, pendingReceiveCount, pendingSends.size(), waitForCompletionSends.size()));
    }
    for (int i = 0; i < registeredReceives.size(); i++) {
        MPIReceiveRequests receiveRequests = registeredReceives.get(i);
        try {
            Iterator<MPIRequest> requestIterator = receiveRequests.pendingRequests.iterator();
            while (requestIterator.hasNext()) {
                MPIRequest r = requestIterator.next();
                Status status = r.request.testStatus();
                if (status != null) {
                    if (!status.isCancelled()) {
                        // LOG.info(String.format("%d Receive completed: from %d size %d %d",
                        // executor, receiveRequests.rank, status.getCount(MPI.BYTE), ++receiveCount));
                        ++receiveCount;
                        // lets call the callback about the receive complete
                        r.buffer.setSize(status.getCount(MPI.BYTE));
                        receiveRequests.callback.onReceiveComplete(receiveRequests.rank, receiveRequests.edge, r.buffer);
                        // LOG.info(String.format("%d finished calling the on complete method", executor));
                        requestIterator.remove();
                    } else {
                        throw new RuntimeException("MPI receive request cancelled");
                    }
                } else {
                    break;
                }
            }
        // this request has completed
        } catch (MPIException e) {
            LOG.log(Level.SEVERE, "Twister2Network failure", e);
            throw new RuntimeException("Twister2Network failure", e);
        }
    }
}
Also used : Status(mpi.Status) MPIException(mpi.MPIException)

Example 2 with Status

use of mpi.Status in project beast-mcmc by beast-dev.

the class MPIServices method receiveDouble.

public static double receiveDouble(int source) {
    double[] msg = new double[1];
    Status status = MPI.COMM_WORLD.Recv(msg, 0, 1, MPI.DOUBLE, source, ServiceRequest.MSG_REQUEST_TYPE);
    return msg[0];
}
Also used : Status(mpi.Status)

Example 3 with Status

use of mpi.Status in project twister2 by DSC-SPIDAL.

the class TWSMPIChannel method progressSends.

@Override
public void progressSends() {
    // we should rate limit here
    while (pendingSends.size() > 0) {
        // post the message
        MPISendRequests sendRequests = pendingSends.poll();
        // post the send
        if (sendRequests != null) {
            postMessage(sendRequests);
            waitForCompletionSends.add(sendRequests);
        }
    }
    IterativeLinkedList.ILLIterator sendRequestsIterator = waitForCompletionSends.iterator();
    while (sendRequestsIterator.hasNext()) {
        MPISendRequests sendRequests = (MPISendRequests) sendRequestsIterator.next();
        IterativeLinkedList.ILLIterator requestIterator = sendRequests.pendingSends.iterator();
        while (requestIterator.hasNext()) {
            MPIRequest r = (MPIRequest) requestIterator.next();
            try {
                Status status = r.request.testStatus();
                // this request has finished
                if (status != null) {
                    // completedSendCount++;
                    requestIterator.remove();
                } else {
                    break;
                }
            } catch (MPIException e) {
                throw new RuntimeException("Failed to complete the send to: " + sendRequests.rank, e);
            }
        }
        // ideally we should be able to call for each finish of the buffer
        if (sendRequests.pendingSends.size() == 0) {
            sendRequests.callback.onSendComplete(sendRequests.rank, sendRequests.edge, sendRequests.message);
            sendRequestsIterator.remove();
        }
    }
}
Also used : Status(mpi.Status) MPIException(mpi.MPIException) IterativeLinkedList(edu.iu.dsc.tws.common.util.IterativeLinkedList)

Example 4 with Status

use of mpi.Status in project twister2 by DSC-SPIDAL.

the class TWSMPIChannel method progressInternalReceives.

private void progressInternalReceives(List<MPIReceiveRequests> requests) {
    for (int i = 0; i < requests.size(); i++) {
        MPIReceiveRequests receiveRequests = requests.get(i);
        // okay we have more buffers to be posted
        if (receiveRequests.availableBuffers.size() > 0) {
            postReceive(receiveRequests);
        }
        try {
            IterativeLinkedList.ILLIterator requestIterator = receiveRequests.pendingRequests.iterator();
            while (requestIterator.hasNext()) {
                MPIRequest r = (MPIRequest) requestIterator.next();
                Status status = r.request.testStatus();
                if (status != null) {
                    if (!status.isCancelled()) {
                        // ++receiveCount;
                        // lets call the callback about the receive complete
                        r.buffer.setSize(status.getCount(MPI.BYTE));
                        // We do not have any buffers to receive messages so we need to free a buffer
                        receiveRequests.callback.onReceiveComplete(receiveRequests.rank, receiveRequests.edge, r.buffer);
                        pendingReceiveCount--;
                        requestIterator.remove();
                    } else {
                        throw new RuntimeException("MPI receive request cancelled");
                    }
                } else {
                    break;
                }
            }
        // this request has completed
        } catch (MPIException e) {
            LOG.log(Level.SEVERE, "Twister2Network failure", e);
            throw new RuntimeException("Twister2Network failure", e);
        }
    }
}
Also used : Status(mpi.Status) MPIException(mpi.MPIException) IterativeLinkedList(edu.iu.dsc.tws.common.util.IterativeLinkedList)

Example 5 with Status

use of mpi.Status in project beast-mcmc by beast-dev.

the class MPIServices method receiveInt.

public static int receiveInt(int source) {
    int[] msg = new int[1];
    Status status = MPI.COMM_WORLD.Recv(msg, 0, 1, MPI.INT, source, ServiceRequest.MSG_REQUEST_TYPE);
    return msg[0];
}
Also used : Status(mpi.Status)

Aggregations

Status (mpi.Status)9 MPIException (mpi.MPIException)4 IterativeLinkedList (edu.iu.dsc.tws.common.util.IterativeLinkedList)2 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1