Example #1
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");
  }
Example #2
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;
 }