Search in sources :

Example 1 with THashSet

use of gnu.trove.set.hash.THashSet in project scheduler by btrplace.

the class FixedNodeSetsPartitioning method split.

@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
    Model mo = i.getModel();
    SynchronizedElementBuilder eb = new SynchronizedElementBuilder(mo);
    List<Instance> parts = new ArrayList<>(partitions.size());
    // nb of VMs
    int nbVMs = i.getModel().getMapping().getNbVMs();
    int nbNodes = i.getModel().getMapping().getNbNodes();
    TIntIntHashMap vmPosition = new TIntIntHashMap(nbVMs);
    TIntIntHashMap nodePosition = new TIntIntHashMap(nbNodes);
    int partNumber = 0;
    Set<VM> toLaunch = getVMsToLaunch(i);
    for (Collection<Node> s : partitions) {
        SubModel partModel = new SubModel(mo, eb, s, new HashSet<>(toLaunch.size() / partitions.size()));
        parts.add(new Instance(partModel, new THashSet<>(), i.getOptConstraint()));
        // VM Index
        partModel.getMapping().fillVMIndex(vmPosition, partNumber);
        // Node index
        for (Node n : s) {
            nodePosition.put(n.id(), partNumber);
        }
        partNumber++;
    }
    // Round-robin placement for the VMs to launch
    int p = 0;
    for (VM v : toLaunch) {
        if (!parts.get(p).getModel().getMapping().addReadyVM(v)) {
            throw new SplitException(parts.get(p).getModel(), "Unable to dispatch the VM to launch '" + v + "'");
        }
        vmPosition.put(v.id(), p);
        p = (p + 1) % parts.size();
    }
    // Split the constraints
    for (SatConstraint cstr : i.getSatConstraints()) {
        if (!cstrMapper.split(cstr, i, parts, vmPosition, nodePosition)) {
            throw new SplitException(i.getModel(), "Unable to split " + cstr);
        }
    }
    return parts;
}
Also used : Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ArrayList(java.util.ArrayList) SatConstraint(org.btrplace.model.constraint.SatConstraint) THashSet(gnu.trove.set.hash.THashSet) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) SynchronizedElementBuilder(org.btrplace.model.SynchronizedElementBuilder)

Example 2 with THashSet

use of gnu.trove.set.hash.THashSet in project scheduler by btrplace.

the class FixedNodeSetsPartitioning method getVMsToLaunch.

private Set<VM> getVMsToLaunch(Instance i) {
    Mapping m = i.getModel().getMapping();
    Set<VM> toLaunch = new THashSet<>();
    for (SatConstraint cstr : i.getSatConstraints()) {
        // Extract the VMs to launch
        if (cstr instanceof Running) {
            for (VM v : cstr.getInvolvedVMs()) {
                if (m.isReady(v)) {
                    m.remove(v);
                    toLaunch.add(v);
                }
            }
        }
    }
    return toLaunch;
}
Also used : VM(org.btrplace.model.VM) SatConstraint(org.btrplace.model.constraint.SatConstraint) Running(org.btrplace.model.constraint.Running) Mapping(org.btrplace.model.Mapping) THashSet(gnu.trove.set.hash.THashSet)

Aggregations

THashSet (gnu.trove.set.hash.THashSet)2 VM (org.btrplace.model.VM)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)1 ArrayList (java.util.ArrayList)1 Instance (org.btrplace.model.Instance)1 Mapping (org.btrplace.model.Mapping)1 Model (org.btrplace.model.Model)1 Node (org.btrplace.model.Node)1 SynchronizedElementBuilder (org.btrplace.model.SynchronizedElementBuilder)1 Running (org.btrplace.model.constraint.Running)1 SubModel (org.btrplace.scheduler.runner.disjoint.model.SubModel)1