Search in sources :

Example 1 with JobSchedulerException

use of edu.rit.pj.cluster.JobSchedulerException 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)

Aggregations

ChannelGroup (edu.rit.mp.ChannelGroup)1 JobBackend (edu.rit.pj.cluster.JobBackend)1 JobFrontend (edu.rit.pj.cluster.JobFrontend)1 JobSchedulerException (edu.rit.pj.cluster.JobSchedulerException)1 InetSocketAddress (java.net.InetSocketAddress)1