Exemplo n.º 1
0
  public static void main(String args[]) throws MPIException {
    int myself, tasks;
    IntBuffer in = MPI.newIntBuffer(MAXLEN);
    Request request;

    MPI.Init(args);
    myself = MPI.COMM_WORLD.getRank();
    tasks = MPI.COMM_WORLD.getSize();

    for (int j = 1; j <= MAXLEN; j *= 10) {
      for (int i = 0; i < j; i++) {
        in.put(i, i);
      }

      request = MPI.COMM_WORLD.iAllReduce(in, j, MPI.INT, MPI.SUM);
      request.waitFor();
      request.free();

      for (int k = 0; k < j; k++) {
        if (in.get(k) != k * tasks) {
          OmpitestError.ompitestError(
              OmpitestError.getFileName(),
              OmpitestError.getLineNumber(),
              " bad answer ("
                  + in.get(k)
                  + ") at index "
                  + k
                  + " of "
                  + j
                  + " (should be "
                  + (k * tasks)
                  + ")\n");
          break;
        }
      }
    }

    MPI.COMM_WORLD.barrier();
    MPI.Finalize();
  }
Exemplo n.º 2
0
  public static void main(String args[]) throws MPIException {
    int root, myself, tasks;
    int out[] = new int[MAXLEN], in[] = new int[MAXLEN];

    MPI.Init(args);
    myself = MPI.COMM_WORLD.getRank();
    tasks = MPI.COMM_WORLD.getSize();

    root = tasks / 2;
    for (int j = 1; j <= MAXLEN; j *= 10) {
      for (int i = 0; i < j; i++) {
        out[i] = i;
      }

      MPI.COMM_WORLD.reduce(out, in, j, MPI.INT, MPI.SUM, root);

      if (myself == root) {
        for (int k = 0; k < j; k++) {
          if (in[k] != k * tasks) {
            OmpitestError.ompitestError(
                OmpitestError.getFileName(),
                OmpitestError.getLineNumber(),
                " bad answer ("
                    + in[k]
                    + ") at index "
                    + k
                    + " of "
                    + j
                    + " (should be "
                    + (k * tasks)
                    + ")\n");
            break;
          }
        }
      }
    }
    MPI.COMM_WORLD.barrier();
    MPI.Finalize();
  }
Exemplo n.º 3
0
 private void mpiInit(String args[]) throws MPIException {
   MPI.Init(args);
   mpiRank = MPI.COMM_WORLD.getRank();
   mpiRanksTotal = MPI.COMM_WORLD.getSize();
 }