예제 #1
0
  /**
   * main method to be called from commandline <br>
   * Usage: RunSGB [seq|seq+|par|par+] [irr|left|right|two] &lt;file&gt; #procs
   */
  @SuppressWarnings("unchecked")
  public static void main(String[] args) {

    String[] allkinds =
        new String[] {
          "seq", "seq+",
          "par", "par+",
          // "dist", "dist+", ,
          // "disthyb", "disthyb+",
          // "cli"
        }; // must be last
    String[] allmeth = new String[] {"irr", "left", "right", "two"};

    String usage =
        "Usage: RunGB [ "
            + join(allkinds, " | ")
            // + "[port] ] "
            + " ] ["
            + join(allmeth, " | ")
            + "] <file> "
            + "#threads "
            // + "#procs/#threadsPerNode "
            // + "[machinefile] ";
            + "[check] [nolog]";

    if (args.length < 3) {
      System.out.println("args: " + Arrays.toString(args));
      System.out.println(usage);
      return;
    }

    boolean plusextra = false;
    String kind = args[0];
    boolean sup = false;
    int k = -1;
    for (int i = 0; i < args.length; i++) {
      int j = indexOf(allkinds, args[i]);
      if (j < 0) {
        continue;
      }
      sup = true;
      k = i;
      kind = args[k];
      break;
    }
    if (!sup) {
      System.out.println("args(sup): " + Arrays.toString(args));
      System.out.println(usage);
      return;
    }
    if (kind.indexOf("+") >= 0) {
      plusextra = true;
    }
    System.out.println("kind: " + kind + ", k = " + k);

    String action = args[k + 1];
    sup = false;
    int j = indexOf(allmeth, action);
    if (j < 0) {
      System.out.println(usage);
      return;
    }

    String filename = args[k + 2];

    int threads = 0;
    if (kind.startsWith("par")) {
      if (args.length < 4) {
        System.out.println("args(par): " + Arrays.toString(args));
        System.out.println(usage);
        return;
      }
      String tup = args[k + 3];
      String t = tup;
      try {
        threads = Integer.parseInt(t);
      } catch (NumberFormatException e) {
        e.printStackTrace();
        System.out.println("args(threads): " + Arrays.toString(args));
        System.out.println(usage);
        return;
      }
      if (threads < 1) {
        threads = 1;
      }
    }
    j = indexOf(args, "check");
    if (j >= 0) {
      doCheck = true;
    }
    j = indexOf(args, "nolog");
    if (j >= 0) {
      doLog = false;
    }

    Reader problem = RunGB.getReader(filename);
    if (problem == null) {
      System.out.println("args(file): " + filename);
      System.out.println("args(file): examples.jar(" + filename + ")");
      System.out.println("args(file): " + Arrays.toString(args));
      System.out.println(usage);
      return;
    }
    RingFactoryTokenizer rftok = new RingFactoryTokenizer(problem);
    GenSolvablePolynomialRing spfac = null;
    try {
      spfac = rftok.nextSolvablePolynomialRing();
      rftok = null;
    } catch (IOException e) {
      e.printStackTrace();
      return;
    }
    Reader polyreader = new CatReader(new StringReader("("), problem); // ( has gone
    // Reader polyreader = problem;
    GenPolynomialTokenizer tok = new GenPolynomialTokenizer(spfac, polyreader);
    PolynomialList S = null;
    try {
      S = new PolynomialList(spfac, tok.nextSolvablePolynomialList());
    } catch (IOException e) {
      e.printStackTrace();
      return;
    }
    System.out.println("S =\n" + S);

    if (doLog) {
      BasicConfigurator.configure();
    }

    if (kind.startsWith("seq")) {
      runSequential(S, action, plusextra);
    } else if (kind.startsWith("par")) {
      runParallel(S, threads, action, plusextra);
    }
    ComputerThreads.terminate();
  }
예제 #2
0
  /**
   * main method to be called from commandline <br>
   * Usage: RunSGB [seq|par|par+] [irr|left|right|two] &lt;file&gt; #procs
   */
  public static void main(java.lang.String[] args) {

    BasicConfigurator.configure();

    String usage =
        "Usage: RunSGB "
            + "[ seq | par | par+ ] "
            //        + "[ seq | par | dist | cli [port] ] "
            + "[ irr | left | right | two ] "
            + "<file> "
            + "#procs ";
    //  + "[machinefile]";
    if (args.length < 3) {
      System.out.println(usage);
      return;
    }

    boolean pairseq = false;
    String kind = args[0];
    String[] allkinds = new String[] {"seq", "par", "par+"};
    // String[] allkinds = new String[] { "seq", "par", "dist", "cli"  };
    boolean sup = false;
    for (int i = 0; i < allkinds.length; i++) {
      if (kind.equals(allkinds[i])) {
        sup = true;
        if (kind.indexOf("+") >= 0) {
          pairseq = true;
        }
      }
    }
    if (!sup) {
      System.out.println(usage);
      return;
    }
    String[] allmeth = new String[] {"irr", "left", "right", "two"};
    String action = args[1];
    sup = false;
    for (int i = 0; i < allmeth.length; i++) {
      if (action.equals(allmeth[i])) {
        sup = true;
      }
    }
    if (!sup) {
      System.out.println(usage);
      return;
    }

    String filename = args[2];

    int threads = 0;
    if (kind.startsWith("par")) {
      if (args.length < 4) {
        System.out.println(usage);
        return;
      }
      String tup = args[3];
      String t = tup;
      try {
        threads = Integer.parseInt(t);
      } catch (NumberFormatException e) {
        e.printStackTrace();
        System.out.println(usage);
        return;
      }
      if (threads < 1) {
        threads = 1;
      }
    }

    Reader problem = null;
    try {
      problem = new FileReader(filename);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      System.out.println(usage);
      return;
    }

    RingFactoryTokenizer rftok = new RingFactoryTokenizer(problem);
    GenSolvablePolynomialRing spfac = null;
    try {
      spfac = rftok.nextSolvablePolynomialRing();
      rftok = null;
    } catch (IOException e) {
      e.printStackTrace();
      return;
    }
    Reader polyreader = new CatReader(new StringReader("("), problem); // ( has gone
    GenPolynomialTokenizer tok = new GenPolynomialTokenizer(spfac, polyreader);
    PolynomialList S = null;
    try {
      S = new PolynomialList(spfac, tok.nextSolvablePolynomialList());
    } catch (IOException e) {
      e.printStackTrace();
      return;
    }
    System.out.println("S =\n" + S);

    if (kind.startsWith("seq")) {
      runSequential(S, action, pairseq);
    }

    if (kind.startsWith("par")) {
      runParallel(S, threads, action, pairseq);
    }
  }