Search in sources :

Example 1 with ResourcePlan

use of edu.iu.dsc.tws.rsched.spi.resource.ResourcePlan in project twister2 by DSC-SPIDAL.

the class MPIProcess method createResourcePlan.

private static ResourcePlan createResourcePlan(Config config) {
    try {
        int rank = MPI.COMM_WORLD.getRank();
        ResourcePlan resourcePlan = new ResourcePlan(MPIContext.clusterType(config), MPI.COMM_WORLD.getRank());
        String processName = MPI.getProcessorName();
        char[] processNameChars = new char[processName.length()];
        int length = processNameChars.length;
        processName.getChars(0, length, processNameChars, 0);
        IntBuffer countSend = MPI.newIntBuffer(1);
        int worldSize = MPI.COMM_WORLD.getSize();
        IntBuffer countReceive = MPI.newIntBuffer(worldSize);
        // now calculate the total number of characters
        countSend.put(length);
        MPI.COMM_WORLD.allGather(countSend, 1, MPI.INT, countReceive, 1, MPI.INT);
        int[] receiveSizes = new int[worldSize];
        int[] displacements = new int[worldSize];
        int sum = 0;
        for (int i = 0; i < worldSize; i++) {
            receiveSizes[i] = countReceive.get(i);
            displacements[i] = sum;
            sum += receiveSizes[i];
        }
        // first we need to send the expected number of characters
        // MPI.COMM_WORLD.allGather(countSend, 1, MPI.INT, countReceive, worldSize, MPI.INT);
        // now we need to send this to all the nodes
        CharBuffer sendBuffer = MPI.newCharBuffer(length);
        CharBuffer receiveBuffer = MPI.newCharBuffer(sum);
        sendBuffer.append(processName);
        // now lets receive the process names of each rank
        MPI.COMM_WORLD.allGatherv(sendBuffer, length, MPI.CHAR, receiveBuffer, receiveSizes, displacements, MPI.CHAR);
        Map<Integer, String> processNames = new HashMap<>();
        for (int i = 0; i < receiveSizes.length; i++) {
            char[] c = new char[receiveSizes[i]];
            receiveBuffer.get(c);
            processNames.put(i, new String(c));
            LOG.log(Level.FINE, String.format("Process %d name: %s", i, processNames.get(i)));
        }
        // now lets add the containers
        addContainers(config, resourcePlan, processNames);
        return resourcePlan;
    } catch (MPIException e) {
        throw new RuntimeException("Failed to communicate", e);
    }
}
Also used : MPIException(mpi.MPIException) HashMap(java.util.HashMap) ResourcePlan(edu.iu.dsc.tws.rsched.spi.resource.ResourcePlan) IntBuffer(java.nio.IntBuffer) CharBuffer(java.nio.CharBuffer)

Example 2 with ResourcePlan

use of edu.iu.dsc.tws.rsched.spi.resource.ResourcePlan in project twister2 by DSC-SPIDAL.

the class MPIProcess method worker.

private static void worker(Config config, int rank) {
    // lets create the resource plan
    ResourcePlan resourcePlan = createResourcePlan(config);
    String containerClass = MPIContext.containerClass(config);
    IContainer container;
    try {
        Object object = ReflectionUtils.newInstance(containerClass);
        container = (IContainer) object;
        LOG.log(Level.FINE, "loaded container class: " + containerClass);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        LOG.log(Level.SEVERE, String.format("failed to load the container class %s", containerClass), e);
        throw new RuntimeException(e);
    }
    // lets do a barrier here so everyone is synchronized at the start
    try {
        MPI.COMM_WORLD.barrier();
        LOG.log(Level.FINE, String.format("Worker %d: the cluster is ready...", rank));
    } catch (MPIException e) {
        LOG.log(Level.SEVERE, "Failed to synchronize the workers at the start");
        throw new RuntimeException(e);
    }
    // now initialize the container
    container.init(config, rank, resourcePlan);
}
Also used : MPIException(mpi.MPIException) ResourcePlan(edu.iu.dsc.tws.rsched.spi.resource.ResourcePlan) IContainer(edu.iu.dsc.tws.rsched.spi.container.IContainer)

Aggregations

ResourcePlan (edu.iu.dsc.tws.rsched.spi.resource.ResourcePlan)2 MPIException (mpi.MPIException)2 IContainer (edu.iu.dsc.tws.rsched.spi.container.IContainer)1 CharBuffer (java.nio.CharBuffer)1 IntBuffer (java.nio.IntBuffer)1 HashMap (java.util.HashMap)1