Beispiel #1
0
 private void getTrueLbExtent() throws MPIException {
   MPI.check();
   int lbExt[] = new int[2];
   getTrueLbExtent(handle, lbExt);
   trueLb = lbExt[0] / baseSize;
   trueExtent = lbExt[1] / baseSize;
 }
  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();
  }
Beispiel #3
0
 /**
  * Retrieves attribute value by key.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_GET_ATTR}.
  *
  * @param keyval attribute key
  * @return attribute value or null if no attribute is associated with the key.
  * @throws MPIException
  */
 public Object getAttr(int keyval) throws MPIException {
   MPI.check();
   Object obj = getAttr(handle, keyval);
   return obj instanceof byte[] ? MPI.attrGet((byte[]) obj) : obj;
 }
Beispiel #4
0
 /**
  * Deletes an attribute value associated with a key.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_DELETE_ATTR}.
  *
  * @param keyval attribute key
  * @throws MPIException
  */
 public void deleteAttr(int keyval) throws MPIException {
   MPI.check();
   deleteAttr(handle, keyval);
 }
Beispiel #5
0
 /**
  * Frees an attribute key.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_FREE_KEYVAL}.
  *
  * @param keyval attribute key
  * @throws MPIException
  */
 public static void freeKeyval(int keyval) throws MPIException {
   MPI.check();
   freeKeyval_jni(keyval);
 }
Beispiel #6
0
 /**
  * Stores attribute value associated with a key.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_SET_ATTR}.
  *
  * @param keyval attribute key
  * @param value attribute value
  * @throws MPIException
  */
 public void setAttr(int keyval, Object value) throws MPIException {
   MPI.check();
   setAttr(handle, keyval, MPI.attrSet(value));
 }
Beispiel #7
0
 /**
  * Return the print name from the datatype.
  *
  * @return name of the datatype
  * @throws MPIException
  */
 public String getName() throws MPIException {
   MPI.check();
   return getName(handle);
 }
Beispiel #8
0
 /**
  * Create a new attribute key.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_CREATE_KEYVAL}.
  *
  * @return attribute key for future access
  * @throws MPIException
  */
 public static int createKeyval() throws MPIException {
   MPI.check();
   return createKeyval_jni();
 }
Beispiel #9
0
 /**
  * Returns the total size of a datatype - the number of buffer elements it represents.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_SIZE}.
  *
  * @return datatype size
  * @throws MPIException
  */
 public int getSize() throws MPIException {
   MPI.check();
   return getSize(handle) / baseSize;
 }
Beispiel #10
0
 /**
  * Frees the datatype.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_FREE}.
  *
  * @throws MPIException
  */
 @Override
 public void free() throws MPIException {
   MPI.check();
   handle = free(handle);
 }
Beispiel #11
0
 /**
  * Identical to {@code createIndexed} except that the displacements are expressed directly in
  * terms of the buffer index, rather than the units of the old type.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_HINDEXED}.
  *
  * @param blockLengths number of elements per block
  * @param displacements byte displacement in buffer for each block
  * @param oldType old datatype
  * @return new datatype
  * @throws MPIException
  */
 public static Datatype createHIndexed(int[] blockLengths, int[] displacements, Datatype oldType)
     throws MPIException {
   MPI.check();
   long handle = getHIndexed(blockLengths, displacements, oldType.handle);
   return new Datatype(oldType, handle);
 }
Beispiel #12
0
 /**
  * The most general type constructor.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_STRUCT}.
  *
  * <p>The number of blocks is taken to be size of the {@code blockLengths} argument. The second
  * and third arguments, {@code displacements}, and {@code types}, should be the same size.
  *
  * @param blockLengths number of elements in each block
  * @param displacements byte displacement of each block
  * @param types type of elements in each block
  * @return new datatype
  * @throws MPIException
  */
 public static Datatype createStruct(int[] blockLengths, int[] displacements, Datatype[] types)
     throws MPIException {
   MPI.check();
   long handle = getStruct(blockLengths, displacements, types);
   return new Datatype(MPI.BYTE, handle);
 }
Beispiel #13
0
 /**
  * Identical to {@code createVector} except that the stride is expressed directly in terms of the
  * buffer index, rather than the units of the old type.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_HVECTOR}.
  *
  * @param count number of blocks
  * @param blockLength number of elements in each
  * @param stride number of bytes between start of each block
  * @param oldType old datatype
  * @return new datatype
  * @throws MPIException
  */
 public static Datatype createHVector(int count, int blockLength, int stride, Datatype oldType)
     throws MPIException {
   MPI.check();
   long handle = getHVector(count, blockLength, stride, oldType.handle);
   return new Datatype(oldType, handle);
 }
Beispiel #14
0
 /**
  * Construct new datatype representing replication of old datatype into contiguous locations.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_CONTIGUOUS}.
  *
  * <p>The base type of the new datatype is the same as the base type of {@code oldType}.
  *
  * @param count replication count
  * @param oldType old datatype
  * @return new datatype
  * @throws MPIException
  */
 public static Datatype createContiguous(int count, Datatype oldType) throws MPIException {
   MPI.check();
   return new Datatype(oldType, getContiguous(count, oldType.handle));
 }
Beispiel #15
0
 /**
  * Java binding of {@code MPI_TYPE_DUP}.
  *
  * @return new datatype
  * @throws MPIException
  */
 public Datatype dup() throws MPIException {
   MPI.check();
   return new Datatype(this, dup(handle));
 }
Beispiel #16
0
  public static void main(String[] args) throws MPIException {
    Comm comm;
    IntBuffer sBuf, rBuf;
    int rank, size, extent;
    int[] sendCounts, recvCounts, rDispls, sDispls;
    Datatype[] sDTypes, rDTypes;
    Request req;

    MPI.Init(args);

    comm = MPI.COMM_WORLD;

    /* Create the buffer */
    size = comm.getSize();
    rank = comm.getRank();

    sBuf = MPI.newIntBuffer(size * size);
    rBuf = MPI.newIntBuffer(size * size);

    /* Load up the buffers */
    for (int i = 0; i < (size * size); i++) {
      sBuf.put(i, (i + 100 * rank));
      rBuf.put(i, -i);
    }

    /* Create and load the arguments to alltoallw */
    sendCounts = new int[size];
    recvCounts = new int[size];
    rDispls = new int[size];
    sDispls = new int[size];
    sDTypes = new Datatype[size];
    rDTypes = new Datatype[size];

    extent =
        4; // MPI.INT.getExtent(); //getExtent returns 1, but a 4 is needed for these calculations

    for (int i = 0; i < size; i++) {
      sendCounts[i] = i;
      recvCounts[i] = rank;
      rDispls[i] = (i * rank * extent);
      sDispls[i] = (((i * (i + 1)) / 2) * extent);
      sDTypes[i] = MPI.INT;
      rDTypes[i] = MPI.INT;
    }

    req = comm.iAllToAllw(sBuf, sendCounts, sDispls, sDTypes, rBuf, recvCounts, rDispls, rDTypes);
    req.waitFor();
    req.free();

    /* Check rbuf */
    for (int i = 0; i < size; i++) {
      int p = rDispls[i] / extent;
      for (int j = 0; j < rank; j++) {
        if (rBuf.get(p + j) != (i * 100 + (rank * (rank + 1)) / 2 + j)) {
          System.out.println(i + " " + j + " " + size + " " + rank + " " + extent);
          OmpitestError.ompitestError(
              OmpitestError.getFileName(),
              OmpitestError.getLineNumber(),
              "bad answer "
                  + rBuf.get(p + j)
                  + " (should be "
                  + (i * 100 + (rank * (rank + 1)) / 2 + j)
                  + ")\n");
        }
      }
    }

    MPI.COMM_WORLD.barrier();
    MPI.Finalize();
    if (rank == 0) {
      System.out.println("Test completed.");
    }
  }
Beispiel #17
0
 /**
  * Sets the print name for the datatype.
  *
  * @param name name for the datatype
  * @throws MPIException
  */
 public void setName(String name) throws MPIException {
   MPI.check();
   setName(handle, name);
 }
Beispiel #18
0
 /**
  * Create a datatype with a new lower bound and extent from an existing datatype.
  *
  * <p>Java binding of the MPI operation {@code MPI_TYPE_CREATE_RESIZED}.
  *
  * @param oldType input datatype
  * @param lb new lower bound of datatype (address integer)
  * @param extent new extent of datatype (address integer)
  * @return new datatype
  * @throws MPIException
  */
 public static Datatype createResized(Datatype oldType, int lb, int extent) throws MPIException {
   MPI.check();
   long handle = getResized(oldType.handle, lb, extent);
   return new Datatype(oldType, handle);
 }
Beispiel #19
0
 /**
  * Commits a derived datatype. Java binding of the MPI operation {@code MPI_TYPE_COMMIT}.
  *
  * @throws MPIException
  */
 public void commit() throws MPIException {
   MPI.check();
   commit(handle);
 }