Search in sources :

Example 1 with ChannelGroup

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

the class Comm method init.

// Exported operations.
/**
 * Initialize the PJ message passing middleware. Certain Java system
 * properties specify the middleware's behavior; these properties are
 * typically given on the Java command line with the <TT>"-D"</TT> flag. For
 * further information, see class {@linkplain PJProperties}.
 *
 * @param args Command line arguments.
 *
 * @exception NullPointerException (unchecked exception) Thrown if
 * <TT>args</TT> is null.
 * @exception IllegalArgumentException (unchecked exception) Thrown if the
 * value of one of the Java system properties is illegal.
 * @exception IOException Thrown if an I/O error occurred.
 */
public static void init(String[] args) throws IOException {
    // Verify preconditions.
    if (args == null) {
        throw new NullPointerException("Comm.init(): args is null");
    }
    // Get the job backend object.
    JobBackend backend = JobBackend.getJobBackend();
    if (backend == null) {
        // We're running on the frontend processor.
        // Prepare constructor arguments for the Job Frontend object.
        String username = System.getProperty("user.name");
        int Nn = PJProperties.getPjNn();
        int Np = PJProperties.getPjNp();
        int Nt = PJProperties.getPjNt();
        boolean hasFrontendComm = false;
        // Examine the call stack to find the main program class name.
        StackTraceElement[] stack = Thread.currentThread().getStackTrace();
        StackTraceElement bottom = stack[stack.length - 1];
        if (!bottom.getMethodName().equals("main")) {
            throw new IllegalStateException("Comm.init(): Not called from main program");
        }
        String mainClassName = bottom.getClassName();
        // Set up the Job Frontend object.
        JobFrontend frontend = null;
        try {
            frontend = new JobFrontend(username, Nn, Np, Nt, hasFrontendComm, mainClassName, args);
            // We were able to contact the Job Scheduler.
            // Run the job frontend in this process, then exit.
            frontend.run();
            System.exit(0);
        } catch (JobSchedulerException exc) {
            // We were not able to contact the Job Scheduler.
            // System.err.println(" No Job Scheduler at " + PJProperties.getPjHost() + ":" + PJProperties.getPjPort() + ", running in this (one) process");
            // Set up world communicator.
            theWorldCommunicator = new Comm(/*size        */
            1, /*rank        */
            0, /*host        */
            "<unknown>", /*channelgroup*/
            new ChannelGroup(), /*address     */
            new InetSocketAddress[] { new InetSocketAddress(0) });
        }
    } else {
        // We're running on a backend processor.
        // Set up world communicator.
        theWorldCommunicator = new Comm(/*size        */
        backend.getK(), /*rank        */
        backend.getRank(), /*host        */
        backend.getBackendHost(), /*channelgroup*/
        backend.getWorldChannelGroup(), /*address     */
        backend.getWorldAddress());
    }
}
Also used : JobFrontend(edu.rit.pj.cluster.JobFrontend) JobSchedulerException(edu.rit.pj.cluster.JobSchedulerException) InetSocketAddress(java.net.InetSocketAddress) JobBackend(edu.rit.pj.cluster.JobBackend) ChannelGroup(edu.rit.mp.ChannelGroup)

Example 2 with ChannelGroup

use of edu.rit.mp.ChannelGroup 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)2 InetSocketAddress (java.net.InetSocketAddress)2 ObjectBuf (edu.rit.mp.ObjectBuf)1 JobBackend (edu.rit.pj.cluster.JobBackend)1 JobFrontend (edu.rit.pj.cluster.JobFrontend)1 JobSchedulerException (edu.rit.pj.cluster.JobSchedulerException)1 Range (edu.rit.util.Range)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1