Search in sources :

Example 1 with ObjectBuf

use of edu.rit.mp.ObjectBuf in project ffx by mjschnie.

the class Comm method createComm.

/**
 * Create a new communicator. <I>Every</I> process in this communicator must
 * call the <TT>createComm()</TT> method. Each process passes true or false
 * for the <TT>participate</TT> argument to state whether the process will
 * participate in the new communicator. At least one process must
 * participate in the new communicator. Messages to set up the new
 * communicator are sent to all processes in this communicator, using the
 * given message tag.
 * <P>
 * In processes participating in the new communicator, the new communicator
 * is returned. The participating processes appear in the same order by rank
 * in the new communicator as in this communicator. The process can call the
 * new communicator's <TT>rank()</TT> method to determine the process's rank
 * in the new communicator.
 * <P>
 * In processes not participating in the new communicator, null is returned.
 *
 * @param participate True if this process will participate in the new
 * communicator; false otherwise.
 * @param tag Message tag.
 *
 * @return New communicator if this process will participate in the new
 * communicator; null otherwise.
 *
 * @exception IOException Thrown if an I/O error occurred.
 */
public Comm createComm(boolean participate, int tag) throws IOException {
    // Set up array of socket addresses for all processes.
    InetSocketAddress[] address = new InetSocketAddress[mySize];
    ObjectBuf<InetSocketAddress>[] addressbuf = ObjectBuf.sliceBuffers(address, new Range(0, mySize - 1).subranges(mySize));
    // Create channel group for new communicator, if participating.
    ChannelGroup channelgroup = null;
    InetSocketAddress myaddress = null;
    if (participate) {
        channelgroup = new ChannelGroup(new InetSocketAddress(myChannelGroup.listenAddress().getAddress(), 0));
        myaddress = channelgroup.listenAddress();
        address[myRank] = myaddress;
    }
    // All-gather channel group socket addresses into every process.
    allGather(tag, addressbuf[myRank], addressbuf);
    // Close up gaps in the socket address array if any.
    int off = 0;
    int newsize = 0;
    int newrank = -1;
    for (int i = 0; i < mySize; ++i) {
        if (address[i] == null) {
            ++off;
        } else {
            if (i == myRank) {
                newrank = i - off;
            }
            address[i - off] = address[i];
            ++newsize;
        }
    }
    // Verify size of new communicator.
    if (newsize == 0) {
        throw new IOException("Comm.createComm(): No processes in communicator");
    }
    // Return new communicator if participating.
    if (participate) {
        return new Comm(newsize, newrank, myHost, channelgroup, address);
    } else // Return null if not participating.
    {
        return null;
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) ObjectBuf(edu.rit.mp.ObjectBuf) Range(edu.rit.util.Range) ChannelGroup(edu.rit.mp.ChannelGroup)

Aggregations

ChannelGroup (edu.rit.mp.ChannelGroup)1 ObjectBuf (edu.rit.mp.ObjectBuf)1 Range (edu.rit.util.Range)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 InetSocketAddress (java.net.InetSocketAddress)1