Exemple #1
0
 public void run() throws DigestException {
   try {
     System.err.println(me + " starting");
     synchronized (this) {
       abort();
       state = -1;
     }
     while (bag.size > 0) {
       while (bag.size > 0) {
         for (int n = 500; (n > 0) && (bag.size > 0); --n) {
           bag.expand(md);
         }
         abort();
         distribute();
       }
       if (resilient) {
         map.set(me, bag.trim());
       }
       steal();
     }
     synchronized (this) {
       abort();
       state = -2;
     }
     distribute();
     lifelinesteal();
   } finally {
     System.err.println(me + " stopping");
   }
 }
Exemple #2
0
 static List<UTS> explode(UTS bag) {
   final List<UTS> bags = new ArrayList<>();
   for (int i = 0; i < bag.upper[0]; i++) {
     final UTS b = new UTS(64);
     b.merge(bag);
     if (i == 0) {
       b.count = 1;
     }
     b.lower[0] = i;
     b.upper[0] = i + 1;
     bags.add(b);
   }
   return bags;
 }
Exemple #3
0
 synchronized void deal(UTS loot) {
   if (state == -3) {
     return;
   }
   if (loot != null) {
     bag.merge(loot);
   }
   state = -1;
   notifyAll();
 }
Exemple #4
0
 void transfer(int thief, UTS loot) {
   final UTS bag = this.bag.trim();
   final int me = this.me;
   final int wave = ResilientUTS.this.wave;
   hz.executeTransaction(
       (TransactionalTaskContext context) -> {
         final TransactionalMap<Integer, UTS> map = context.getMap("map" + wave);
         map.set(me, bag);
         final UTS old = map.getForUpdate(thief);
         loot.count = old == null ? 0 : old.count;
         map.set(thief, loot);
         return null;
       });
 }
Exemple #5
0
 void distribute() {
   if (group.size() == 1 && power == 0) {
     return;
   }
   Integer thief;
   while ((thief = thieves.poll()) != null) {
     final UTS loot = bag.split();
     if (loot != null && resilient) {
       transfer(thief, loot);
     }
     myUncountedAsyncAt(thief, w -> w.deal(loot));
   }
   if (bag.size > 0 && lifeline.get()) {
     final UTS loot = bag.split();
     if (loot != null) {
       thief = next;
       if (resilient) {
         transfer(thief, loot);
       }
       lifeline.set(false);
       myAsyncAt(next, w -> w.lifelinedeal(loot));
     }
   }
 }
Exemple #6
0
  final class Worker { // not serializable
    final int me; // my index in the lifeline graph
    final int prev; // index of the predecessor in the lifeline graph
    final int next; // index of the successor in the lifeline graph
    final Random random;
    final MessageDigest md = UTS.encoder();
    final UTS bag = new UTS(64);
    // pending requests from thieves
    final ConcurrentLinkedQueue<Integer> thieves = new ConcurrentLinkedQueue<>();
    final AtomicBoolean lifeline; // pending lifeline request?
    int state = -2; // -3: abort, -2: inactive, -1: running, p: stealing from p

    Worker(int id, int size, int ratio) {
      me = (group.indexOf(here()) << power) + id;
      random = new Random(me);
      prev = (me + (group.size() << power) - 1) % (group.size() << power);
      next = (me + 1) % (group.size() << power);
      lifeline = new AtomicBoolean(((next % ratio) != 0) || ((next / ratio) >= size));
    }

    synchronized void abort() {
      if (state == -3) {
        throw new DeadPlaceException(here());
      }
    }

    public void run() throws DigestException {
      try {
        System.err.println(me + " starting");
        synchronized (this) {
          abort();
          state = -1;
        }
        while (bag.size > 0) {
          while (bag.size > 0) {
            for (int n = 500; (n > 0) && (bag.size > 0); --n) {
              bag.expand(md);
            }
            abort();
            distribute();
          }
          if (resilient) {
            map.set(me, bag.trim());
          }
          steal();
        }
        synchronized (this) {
          abort();
          state = -2;
        }
        distribute();
        lifelinesteal();
      } finally {
        System.err.println(me + " stopping");
      }
    }

    void lifelinesteal() {
      if (group.size() == 1 && power == 0) {
        return;
      }
      myUncountedAsyncAt(prev, w -> w.lifeline.set(true));
    }

    void steal() {
      if (group.size() == 1 && power == 0) {
        return;
      }
      final int me = this.me;
      int p = random.nextInt((group.size() << power) - 1);
      if (p >= me) {
        p++;
      }
      synchronized (this) {
        abort();
        state = p;
      }
      myUncountedAsyncAt(p, w -> w.request(me));
      synchronized (this) {
        while (state >= 0) {
          try {
            wait();
          } catch (final InterruptedException e) {
          }
        }
      }
    }

    void request(int thief) {
      synchronized (this) {
        if (state == -3) {
          return;
        }
        if (state == -1) {
          thieves.add(thief);
          return;
        }
      }
      myUncountedAsyncAt(thief, w -> w.deal(null));
    }

    void lifelinedeal(UTS b) throws DigestException {
      bag.merge(b);
      run();
    }

    synchronized void deal(UTS loot) {
      if (state == -3) {
        return;
      }
      if (loot != null) {
        bag.merge(loot);
      }
      state = -1;
      notifyAll();
    }

    synchronized void unblock(Place p) {
      state = -3;
      notifyAll();
    }

    void transfer(int thief, UTS loot) {
      final UTS bag = this.bag.trim();
      final int me = this.me;
      final int wave = ResilientUTS.this.wave;
      hz.executeTransaction(
          (TransactionalTaskContext context) -> {
            final TransactionalMap<Integer, UTS> map = context.getMap("map" + wave);
            map.set(me, bag);
            final UTS old = map.getForUpdate(thief);
            loot.count = old == null ? 0 : old.count;
            map.set(thief, loot);
            return null;
          });
    }

    void distribute() {
      if (group.size() == 1 && power == 0) {
        return;
      }
      Integer thief;
      while ((thief = thieves.poll()) != null) {
        final UTS loot = bag.split();
        if (loot != null && resilient) {
          transfer(thief, loot);
        }
        myUncountedAsyncAt(thief, w -> w.deal(loot));
      }
      if (bag.size > 0 && lifeline.get()) {
        final UTS loot = bag.split();
        if (loot != null) {
          thief = next;
          if (resilient) {
            transfer(thief, loot);
          }
          lifeline.set(false);
          myAsyncAt(next, w -> w.lifelinedeal(loot));
        }
      }
    }
  }
Exemple #7
0
  public static void main(String[] args) {
    int depth = 13;
    try {
      depth = Integer.parseInt(args[0]);
    } catch (final Exception e) {
    }
    int _power = 1;
    try {
      _power = Integer.parseInt(args[1]);
    } catch (final Exception e) {
    }
    final int power = _power;

    if (System.getProperty(Configuration.APGAS_PLACES) == null) {
      System.setProperty(Configuration.APGAS_PLACES, "2");
    }
    System.setProperty(Configuration.APGAS_THREADS, "" + ((1 << power) + 1));

    final boolean resilient = Boolean.getBoolean(Configuration.APGAS_RESILIENT);

    final int maxPlaces = places().size();

    final MessageDigest md = UTS.encoder();

    System.out.println("Warmup...");

    final UTS tmp = new UTS(64);
    tmp.seed(md, 19, depth - 2);
    finish(() -> ResilientUTS.step(explode(tmp), -1, power, resilient));

    System.out.println("Starting...");
    Long time = -System.nanoTime();

    final UTS bag = new UTS(64);
    bag.seed(md, 19, depth);
    List<UTS> bags = explode(bag);

    int wave = 0;
    while (bags.get(0).size > 0) {
      final int w = wave++;
      final List<UTS> b = bags;
      System.out.println("Wave: " + w);
      try {
        bags = finish(() -> ResilientUTS.step(b, w, power, resilient));
      } catch (final DeadPlacesException e) {
      }
    }

    time += System.nanoTime();
    System.out.println("Finished.");

    System.out.println(
        "Depth: "
            + depth
            + ", Places: "
            + maxPlaces
            + ", Waves: "
            + wave
            + ", Performance: "
            + bags.get(0).count
            + "/"
            + UTS.sub("" + time / 1e9, 0, 6)
            + " = "
            + UTS.sub("" + (bags.get(0).count / (time / 1e3)), 0, 6)
            + "M nodes/s");
  }
Exemple #8
0
 public static List<UTS> step(List<UTS> bags, int wave, int power, boolean resilient) {
   final Place[] group = places().toArray(new Place[0]);
   while (bags.size() > (group.length << power)) {
     final UTS b = bags.remove(bags.size() - 1);
     bags.get(0).merge(b);
     bags.get(0).count += b.count;
   }
   final int s = bags.size();
   final int r = (group.length << power) / s;
   final ResilientUTS uts =
       PlaceLocalObject.make(
           Arrays.asList(group), () -> new ResilientUTS(wave, group, power, s, r, resilient));
   if (resilient) {
     for (int i = 0; i < s; i++) {
       uts.map.set(i * r, bags.get(i));
     }
   }
   try {
     finish(
         () -> {
           for (int i = 1; i < s; i++) {
             final UTS bag = bags.get(i);
             uts.myAsyncAt(
                 i * r,
                 w -> {
                   w.bag.count = bag.count;
                   w.lifelinedeal(bag);
                 });
           }
           uts.workers[0].bag.count = bags.get(0).count;
           uts.workers[0].lifelinedeal(bags.get(0));
         });
   } catch (final DeadPlacesException e) {
   }
   final UTS bag = new UTS();
   final List<UTS> l = new ArrayList<>();
   if (resilient) {
     final Collection<UTS> values =
         uts.hz.executeTransaction(
             (TransactionalTaskContext context) -> {
               return context.<Integer, UTS>getMap("map" + wave).values();
             });
     for (final UTS b : values) {
       if (b.size > 0) {
         l.add(b);
       } else {
         bag.count += b.count;
       }
     }
   } else {
     for (final Place p : group) {
       bag.count +=
           at(
               p,
               () -> {
                 long count = 0;
                 for (int i = 0; i < 1 << power; i++) {
                   count += uts.workers[i].bag.count;
                 }
                 return count;
               });
     }
   }
   if (!l.isEmpty()) {
     l.get(0).count += bag.count;
   } else {
     l.add(bag);
   }
   return l;
 }
Exemple #9
0
 void lifelinedeal(UTS b) throws DigestException {
   bag.merge(b);
   run();
 }
 static 
 {
     $SwitchMap$com$adobe$mediacore$MediaPlayer$Event = new int[().length];
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayer$Event[vent.l()] = 1;
     }
     catch (NoSuchFieldError nosuchfielderror53) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayer$Event[vent.l()] = 2;
     }
     catch (NoSuchFieldError nosuchfielderror52) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayer$Event[YBACK.l()] = 3;
     }
     catch (NoSuchFieldError nosuchfielderror51) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayer$Event[CK.l()] = 4;
     }
     catch (NoSuchFieldError nosuchfielderror50) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayer$Event[UTS.l()] = 5;
     }
     catch (NoSuchFieldError nosuchfielderror49) { }
     $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type = new int[lues().length];
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[SOURCE_LOADED.dinal()] = 1;
     }
     catch (NoSuchFieldError nosuchfielderror48) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[EM_CREATED.dinal()] = 2;
     }
     catch (NoSuchFieldError nosuchfielderror47) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[EM_UPDATED.dinal()] = 3;
     }
     catch (NoSuchFieldError nosuchfielderror46) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[EM_READY.dinal()] = 4;
     }
     catch (NoSuchFieldError nosuchfielderror45) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[BREAK_PLACEMENT_COMPLETED.dinal()] = 5;
     }
     catch (NoSuchFieldError nosuchfielderror44) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[BREAK_PLACEMENT_FAILED.dinal()] = 6;
     }
     catch (NoSuchFieldError nosuchfielderror43) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[BREAK_REMOVAL_COMPLETED.dinal()] = 7;
     }
     catch (NoSuchFieldError nosuchfielderror42) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[NTENT_PLACEMENT_COMPLETE.dinal()] = 8;
     }
     catch (NoSuchFieldError nosuchfielderror41) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_MANIFEST_LOAD_COMPLETE.dinal()] = 9;
     }
     catch (NoSuchFieldError nosuchfielderror40) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_MANIFEST_LOAD_FAILED.dinal()] = 10;
     }
     catch (NoSuchFieldError nosuchfielderror39) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_BREAK_MANIFEST_LOAD_COMPLETE.dinal()] = 11;
     }
     catch (NoSuchFieldError nosuchfielderror38) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[NTENT_CHANGED.dinal()] = 12;
     }
     catch (NoSuchFieldError nosuchfielderror37) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[NTENT_MARKER.dinal()] = 13;
     }
     catch (NoSuchFieldError nosuchfielderror36) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[OFILE_CHANGED.dinal()] = 14;
     }
     catch (NoSuchFieldError nosuchfielderror35) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[EK_STARTED.dinal()] = 15;
     }
     catch (NoSuchFieldError nosuchfielderror34) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[EK_COMPLETED.dinal()] = 16;
     }
     catch (NoSuchFieldError nosuchfielderror33) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[EK_ADJUST_COMPLETED.dinal()] = 17;
     }
     catch (NoSuchFieldError nosuchfielderror32) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[FFERING_STARTED.dinal()] = 18;
     }
     catch (NoSuchFieldError nosuchfielderror31) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[FFERING_COMPLETED.dinal()] = 19;
     }
     catch (NoSuchFieldError nosuchfielderror30) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[FFERING_FULL.dinal()] = 20;
     }
     catch (NoSuchFieldError nosuchfielderror29) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[DIO_TRACK_FAILED.dinal()] = 21;
     }
     catch (NoSuchFieldError nosuchfielderror28) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[AD_INFO.dinal()] = 22;
     }
     catch (NoSuchFieldError nosuchfielderror27) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[M_METADATA.dinal()] = 23;
     }
     catch (NoSuchFieldError nosuchfielderror26) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[DEO_STATE_CHANGED.dinal()] = 24;
     }
     catch (NoSuchFieldError nosuchfielderror25) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[DEO_ERROR.dinal()] = 25;
     }
     catch (NoSuchFieldError nosuchfielderror24) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[EW_CLICKED.dinal()] = 26;
     }
     catch (NoSuchFieldError nosuchfielderror23) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[PORTUNITY_COMPLETED.dinal()] = 27;
     }
     catch (NoSuchFieldError nosuchfielderror22) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[PORTUNITY_FAILED.dinal()] = 28;
     }
     catch (NoSuchFieldError nosuchfielderror21) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[EM_REPLACED.dinal()] = 29;
     }
     catch (NoSuchFieldError nosuchfielderror20) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[ERATION_FAILED.dinal()] = 30;
     }
     catch (NoSuchFieldError nosuchfielderror19) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[EPARED.dinal()] = 31;
     }
     catch (NoSuchFieldError nosuchfielderror18) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[DATED.dinal()] = 32;
     }
     catch (NoSuchFieldError nosuchfielderror17) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[MELINE_UPDATED.dinal()] = 33;
     }
     catch (NoSuchFieldError nosuchfielderror16) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[AY_START.dinal()] = 34;
     }
     catch (NoSuchFieldError nosuchfielderror15) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[AY_COMPLETE.dinal()] = 35;
     }
     catch (NoSuchFieldError nosuchfielderror14) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[ATE_CHANGED.dinal()] = 36;
     }
     catch (NoSuchFieldError nosuchfielderror13) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[ZE_CHANGED.dinal()] = 37;
     }
     catch (NoSuchFieldError nosuchfielderror12) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[MED_METADATA_ADDED.dinal()] = 38;
     }
     catch (NoSuchFieldError nosuchfielderror11) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[MED_METADATA_ADDED_IN_BACKGROUND.dinal()] = 39;
     }
     catch (NoSuchFieldError nosuchfielderror10) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_BREAK_START.dinal()] = 40;
     }
     catch (NoSuchFieldError nosuchfielderror9) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_BREAK_COMPLETE.dinal()] = 41;
     }
     catch (NoSuchFieldError nosuchfielderror8) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_BREAK_SKIPPED.dinal()] = 42;
     }
     catch (NoSuchFieldError nosuchfielderror7) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_START.dinal()] = 43;
     }
     catch (NoSuchFieldError nosuchfielderror6) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_PROGRESS.dinal()] = 44;
     }
     catch (NoSuchFieldError nosuchfielderror5) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_COMPLETE.dinal()] = 45;
     }
     catch (NoSuchFieldError nosuchfielderror4) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[_CLICK.dinal()] = 46;
     }
     catch (NoSuchFieldError nosuchfielderror3) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[TE_SELECTED.dinal()] = 47;
     }
     catch (NoSuchFieldError nosuchfielderror2) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[TE_PLAYING.dinal()] = 48;
     }
     catch (NoSuchFieldError nosuchfielderror1) { }
     try
     {
         $SwitchMap$com$adobe$mediacore$MediaPlayerEvent$Type[CKGROUND_MANIFEST_FAILED.dinal()] = 49;
     }
     catch (NoSuchFieldError nosuchfielderror)
     {
         return;
     }
 }