Search in sources :

Example 6 with Status

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

the class MPIServices method getRequest.

public static ServiceRequest getRequest(int master) {
    int[] msg = new int[1];
    Status status = MPI.COMM_WORLD.Recv(msg, 0, 1, MPI.INT, master, ServiceRequest.MSG_REQUEST_TYPE);
    // todo check status and throw exception if error
    return ServiceRequest.getByID(msg[0]);
}
Also used : Status(mpi.Status)

Example 7 with Status

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

the class MPIServices method receiveDoubleArray.

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

Example 8 with Status

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

the class MPIServices method receiveIntArray.

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

Example 9 with Status

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

the class MPIChannel method progressReceives.

/**
 * This method needs to be called to progress the receives
 */
public void progressReceives() {
    try {
        for (Map.Entry<Integer, PendingReceive> x : pendingReceives.entrySet()) {
            boolean flag;
            PendingReceive pendingReceive = x.getValue();
            if (pendingReceive.status == ReceiveStatus.RECEIVE_LENGTH_POSTED) {
                Status status = pendingReceive.request.testStatus();
                if (status != null) {
                    pendingReceive.request = null;
                    int count = status.getCount(MPI.INT);
                    // read the length from the header
                    int length = pendingReceive.headerBuf.get(0);
                    int finFlag = pendingReceive.headerBuf.get(1);
                    // check weather we are at the end
                    if (finFlag != TWISTERX_MSG_FIN) {
                        if (count > 8) {
                            LOG.log(Level.SEVERE, "Un-expected number of bytes expected: 8 or less received: " + count);
                        }
                        // malloc a buffer
                        pendingReceive.data = allocator.allocate(length);
                        pendingReceive.length = length;
                        pendingReceive.request = comm.iRecv(pendingReceive.data.getByteBuffer(), length, MPI.BYTE, pendingReceive.receiveId, edge);
                        // LOG(INFO) << rank << " ** POST RECEIVE " << length << " addr: " << x.second->data;
                        pendingReceive.status = ReceiveStatus.RECEIVE_POSTED;
                        // copy the count - 2 to the buffer
                        if (count > 2) {
                            for (int i = 2; i < count; i++) {
                                pendingReceive.userHeader[i - 2] = pendingReceive.headerBuf.get(i);
                            }
                        }
                        // notify the receiver
                        receiveCallback.receivedHeader(x.getKey(), finFlag, pendingReceive.userHeader, count - 2);
                    } else {
                        if (count != 2) {
                            LOG.log(Level.SEVERE, "Un-expected number of bytes expected: 2 received: " + count);
                        }
                        // we are not expecting to receive any more
                        pendingReceive.status = ReceiveStatus.RECEIVED_FIN;
                        // notify the receiver
                        receiveCallback.receivedHeader(x.getKey(), finFlag, null, 0);
                    }
                }
            } else if (pendingReceive.status == ReceiveStatus.RECEIVE_POSTED) {
                flag = pendingReceive.request.test();
                if (flag) {
                    pendingReceive.request = null;
                    // clear the array
                    pendingReceive.headerBuf.clear();
                    pendingReceive.request = comm.iRecv(pendingReceive.headerBuf, TWISTERX_CHANNEL_HEADER_SIZE, MPI.INT, pendingReceive.receiveId, edge);
                    // LOG(INFO) << rank << " ** POST HEADER " << 8 << " addr: " << x.second->headerBuf;
                    pendingReceive.status = ReceiveStatus.RECEIVE_LENGTH_POSTED;
                    // call the back end
                    receiveCallback.receivedData(x.getKey(), pendingReceive.data, pendingReceive.length);
                }
            } else {
            // we are at the end
            }
        }
    } catch (MPIException e) {
        LOG.log(Level.SEVERE, "Error in MPI", e);
        throw new Twister2RuntimeException(e);
    }
}
Also used : Status(mpi.Status) MPIException(mpi.MPIException) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) HashMap(java.util.HashMap) Map(java.util.Map)

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