Hi Gilles,

thank you very much for your reply.

I must admit I am having a hard time understanding why MPI.DOUBLE.getSize() returns 1 instead of 8 ... Anyway, for the time being, I think you can get the expected result by createResized(..., ..., 8).

I did that before. Unfortunately, MPI.DOUBLE.getSize() returns 1 and I will use size 8 in createResized() which is hard to explain to students. If I
remember right, Oscar (who implemented the Java interface) told me years ago
that "size" in Java is not measured in bytes but in data items. In this case
"1" would make sense for size and extent, because both describe one data item
(getSize() and getExtent() return "1" for all basic data types).


If there is a consensus that your program is correct, I will be happy to issue a PR (Simply multiply lb and extent by baseSize before passing them to the native function)

I'm not sure if that will break something else, if you want to broadcast or
scatter a structure for example. Hopefully, you will find a solution.


Best regards and thank you very much for your help

Siegmar



Cheers,

Gilles

On Thursday, July 19, 2018, Siegmar Gross <siegmar.gr...@informatik.hs-fulda.de <mailto:siegmar.gr...@informatik.hs-fulda.de>> wrote:

    Hi,

    I've installed openmpi-3.1.0 on my "SUSE Linux Enterprise Server
    12.3 (x86_64)" with gcc-6.4.0. Why do I get "extent: 0" instead of
    "extent: 1" for my small program. In my opinion the extent of the
    old data type and the resized extent of the new data type should
    be the same. Am I wrong, is something wrong with my program, or
    results the unexpected value from an error of the MPI Java method
    getExtent() for a derived data type? I get the value 1, if I use
    MPI.DOUBLE.getSize() or MPI.DOUBLE.getExtent().

    loki java 130 which \mpijavac
    /usr/local/openmpi-3.1.0_64_gcc/bin/mpijavac
    loki java 131 \mpijavac SizeExtentMain.java
    loki java 132 mpiexec -np 1 java SizeExtentMain
    strided vector:
       size of old data type: 1
       count:                 2
       blocklength:           2
       stride:                4
       size:                  4
       lower bound:           0
       extent:                0
       true lower bound:      0
       true extent:           6
    loki java 133

    I would be grateful, if somebody can fix the problem, if it is a
    problem of the MPI Java method or if somebody knows, what I'm doing
    wrong in my program. Thank you very much for any help in advance.


    Kind regards

    Siegmar



_______________________________________________
users mailing list
users@lists.open-mpi.org
https://lists.open-mpi.org/mailman/listinfo/users
/* A small MPI Java program that prints the sizes of MPI data types.
 *
 * "mpijavac" and Java-bindings are available in "Open MPI
 * version 1.7.4" or newer.
 *
 *
 * Class file generation:
 *   mpijavac MpiDatatypeSizesMain.java
 *
 * Usage:
 *   mpiexec [parameters] java [parameters] MpiDatatypeSizesMain
 *
 * Examples:
 *   mpiexec java MpiDatatypeSizesMain
 *   mpiexec java -cp $HOME/mpi_classfiles MpiDatatypeSizesMain
 *
 *
 * File: MpiDatatypeSizesMain.java      Author: S. Gross
 * Date: 19.07.2018
 *
 */

import mpi.*;

public class MpiDatatypeSizesMain
{
  public static void main (String args[]) throws MPIException
  {
    int mytid,                          /* my task id                   */
        sizeMpiChar,                    /* size of MPI data types       */ 
        sizeMpiShort,
        sizeMpiInt,
        sizeMpiLong,
        sizeMpiByte,
        sizeMpiBoolean,
        sizeMpiFloat,
        sizeMpiDouble;

    MPI.Init (args);
    mytid  = MPI.COMM_WORLD.getRank ();
    sizeMpiChar    = MPI.CHAR.getSize ();
    sizeMpiShort   = MPI.SHORT.getSize ();
    sizeMpiInt     = MPI.INT.getSize ();
    sizeMpiLong    = MPI.LONG.getSize ();
    sizeMpiByte    = MPI.BYTE.getSize ();
    sizeMpiBoolean = MPI.BOOLEAN.getSize ();
    sizeMpiFloat   = MPI.FLOAT.getSize ();
    sizeMpiDouble  = MPI.DOUBLE.getSize ();
    if (mytid == 0)
    {
      System.out.printf ("  size of MPI.CHAR:    %d\n" +
                         "  size of MPI.SHORT:   %d\n" +
                         "  size of MPI.INT:     %d\n" +
                         "  size of MPI.LONG:    %d\n" +
                         "  size of MPI.BYTE:    %d\n" +
                         "  size of MPI.BOOLEAN: %d\n" +
                         "  size of MPI.FLOAT:   %d\n" +
                         "  size of MPI.DOUBLE:  %d\n",
                         sizeMpiChar,
                         sizeMpiShort,
                         sizeMpiInt,
                         sizeMpiLong,
                         sizeMpiByte,
                         sizeMpiBoolean,
                         sizeMpiFloat,
                         sizeMpiDouble);
    }
    MPI.Finalize ();
  }
}
/* A small MPI Java program that prints the extents of MPI data types.
 *
 * "mpijavac" and Java-bindings are available in "Open MPI
 * version 1.7.4" or newer.
 *
 *
 * Class file generation:
 *   mpijavac MpiDatatypeExtentsMain.java
 *
 * Usage:
 *   mpiexec [parameters] java [parameters] MpiDatatypeExtentsMain
 *
 * Examples:
 *   mpiexec java MpiDatatypeExtentsMain
 *   mpiexec java -cp $HOME/mpi_classfiles MpiDatatypeExtentsMain
 *
 *
 * File: MpiDatatypeExtentsMain.java    Author: S. Gross
 * Date: 19.07.2018
 *
 */

import mpi.*;

public class MpiDatatypeExtentsMain
{
  public static void main (String args[]) throws MPIException
  {
    int mytid,                          /* my task id                   */
        extentMpiChar,                  /* extent of MPI data types     */ 
        extentMpiShort,
        extentMpiInt,
        extentMpiLong,
        extentMpiByte,
        extentMpiBoolean,
        extentMpiFloat,
        extentMpiDouble;

    MPI.Init (args);
    mytid  = MPI.COMM_WORLD.getRank ();
    extentMpiChar    = MPI.CHAR.getExtent ();
    extentMpiShort   = MPI.SHORT.getExtent ();
    extentMpiInt     = MPI.INT.getExtent ();
    extentMpiLong    = MPI.LONG.getExtent ();
    extentMpiByte    = MPI.BYTE.getExtent ();
    extentMpiBoolean = MPI.BOOLEAN.getExtent ();
    extentMpiFloat   = MPI.FLOAT.getExtent ();
    extentMpiDouble  = MPI.DOUBLE.getExtent ();
    if (mytid == 0)
    {
      System.out.printf ("  extent of MPI.CHAR:    %d\n" +
                         "  extent of MPI.SHORT:   %d\n" +
                         "  extent of MPI.INT:     %d\n" +
                         "  extent of MPI.LONG:    %d\n" +
                         "  extent of MPI.BYTE:    %d\n" +
                         "  extent of MPI.BOOLEAN: %d\n" +
                         "  extent of MPI.FLOAT:   %d\n" +
                         "  extent of MPI.DOUBLE:  %d\n",
                         extentMpiChar,
                         extentMpiShort,
                         extentMpiInt,
                         extentMpiLong,
                         extentMpiByte,
                         extentMpiBoolean,
                         extentMpiFloat,
                         extentMpiDouble);
    }
    MPI.Finalize ();
  }
}
/* Small program that distributes an array of structures with a
 * broadcast operation.
 *
 * "mpijavac" and Java-bindings are available in "Open MPI
 * version 1.7.4" or newer.
 *
 *
 * Class file generation:
 *   mpijavac BcastStructArrayMain.java
 *
 * Usage:
 *   mpiexec [parameters] java [parameters] BcastStructArrayMain
 *
 * Examples:
 *   mpiexec -np 2 java BcastStructArrayMain
 *   mpiexec -np 2 java -cp $HOME/mpi_classfiles BcastStructArrayMain
 *
 *
 * File: BcastStructArrayMain.java      Author: S. Gross
 * Date: 12.09.2013
 *
 */

import java.nio.*;
import java.util.Random;
import mpi.*;

public class BcastStructArrayMain
{
  static final int SLEEP_FACTOR = 200;  /* 200 ms to get ordered output */
  static final int NUM_ITEMS = 4;
  static final String firstNames[] = {"John", "Elizabeth"};
  static final String lastNames[] = {"Smith", "Cooper", "Hill"};

  public static void main (String args[]) throws MPIException,
                                                 InterruptedException
  {
    int    mytid,                       /* my task id                   */
           idx;
    String processorName;               /* name of local machine        */
    Random rand = new Random();
    ByteBuffer    dataItemBuffer;       /* buffer for structured data   */
    MyStruct      myStructType;
    MyStruct.Data dataItem;             /* one item from dataItemBuffer */
    Datatype      myStructDatatype;

    MPI.Init (args);
    processorName    = MPI.getProcessorName ();
    mytid            = MPI.COMM_WORLD.getRank ();
    myStructType     = new MyStruct ();
    myStructDatatype = new MyStruct().getType();
    dataItemBuffer   = MPI.newByteBuffer(myStructType.getExtent() *
                                         NUM_ITEMS);

    if (mytid == 0)
    {
      /* initialize data items                                          */
      for (int i = 0; i < NUM_ITEMS; ++i)
      {
        dataItem = myStructType.getData(dataItemBuffer, i);
        dataItem.setAge (20 + rand.nextInt (40));
        idx = rand.nextInt (firstNames.length);
        dataItem.setFirstName (firstNames[idx]);
        idx = rand.nextInt (lastNames.length);
        dataItem.setLastName (lastNames[idx]);
        dataItem.setSalary (1000.0 + (2000 * rand.nextDouble ()));
      }
    }
    MPI.COMM_WORLD.bcast (dataItemBuffer, NUM_ITEMS, myStructDatatype, 0);
    /* Each process prints its received data item. The outputs
     * can intermingle on the screen so that you must use
     * "-output-filename" in Open MPI.
     */
    Thread.sleep (SLEEP_FACTOR * mytid); /* sleep to get ordered output */      
    System.out.printf ("\nProcess %d running on %s.\n",
                       mytid, processorName);
    for (int i = 0; i < NUM_ITEMS; ++i)
    {
      dataItem = myStructType.getData(dataItemBuffer, i);
      System.out.printf ("  dataItem[" + i + "].Age:       %d\n" +
                         "  dataItem[" + i + "].FirstName: %s\n" +
                         "  dataItem[" + i + "].LastName:  %s\n" +
                         "  dataItem[" + i + "].Salary:    %.2f\n",
                         dataItem.getAge (),
                         dataItem.getFirstName (),
                         dataItem.getLastName (),
                         dataItem.getSalary ());
    }
    MPI.Finalize ();
  }
}
/* Small program that distributes an array of structures with a
 * scatter operation. It needs one process for each element of the
 * array.
 *
 * "mpijavac" and Java-bindings are available in "Open MPI
 * version 1.7.4" or newer.
 *
 *
 * Class file generation:
 *   mpijavac ScatterStructArrayMain.java
 *
 * Usage:
 *   mpiexec [parameters] java [parameters] ScatterStructArrayMain
 *
 * Examples:
 *   mpiexec -np 2 java ScatterStructArrayMain
 *   mpiexec -np 2 java -cp $HOME/mpi_classfiles ScatterStructArrayMain
 *
 *
 * File: ScatterStructArrayMain.java    Author: S. Gross
 * Date: 11.09.2013
 *
 */

import java.nio.*;
import java.util.Random;
import mpi.*;

public class ScatterStructArrayMain
{
  static final int SLEEP_FACTOR = 200;  /* 200 ms to get ordered output */
  static final int P = 3;               /* # of array elem to scatter   */
  static final String firstNames[] = {"John", "Elizabeth"};
  static final String lastNames[] = {"Smith", "Cooper", "Hill"};

  public static void main (String args[]) throws MPIException,
                                                 InterruptedException
  {
    int    mytid,                       /* my task id                   */
           ntasks,                      /* number of tasks              */
           idx;
    String processorName;               /* name of local machine        */
    Random rand = new Random();
    ByteBuffer    dataItemBuffer,       /* buffer for structured data   */
                  recvBuffer;
    MyStruct      myStructType;
    MyStruct.Data dataItem;             /* one item from dataItemBuffer */
    Datatype      myStructDatatype;

    MPI.Init (args);
    mytid  = MPI.COMM_WORLD.getRank ();
    ntasks = MPI.COMM_WORLD.getSize ();
    myStructType     = new MyStruct ();
    myStructDatatype = new MyStruct().getType();
    dataItemBuffer   = MPI.newByteBuffer(myStructType.getExtent() * P);
    recvBuffer       = MPI.newByteBuffer(myStructType.getExtent());
    dataItem         = myStructType.getData(dataItemBuffer, 0);

    if (ntasks != P)
    {
      /* wrong number of processes                                      */
      if (mytid == 0)
      {
        String className =
          new ScatterStructArrayMain().getClass().getName();
        System.err.printf ("\nI need %d processes.\n" +
                           "Usage:\n" +
                           "  mpiexec -np %d java %s\n\n",
                           P, P, className);
      }
      MPI.Finalize ();
      System.exit (0);
    }

    processorName = MPI.getProcessorName ();
    if (mytid == 0)
    {
      /* initialize data items                                          */
      for (int i = 0; i < P; ++i)
      {
        dataItem = myStructType.getData(dataItemBuffer, i);
        dataItem.setAge (20 + rand.nextInt (40));
        idx = rand.nextInt (firstNames.length);
        dataItem.setFirstName (firstNames[idx]);
        idx = rand.nextInt (lastNames.length);
        dataItem.setLastName (lastNames[idx]);
        dataItem.setSalary (1000.0 + (2000 * rand.nextDouble ()));
      }
    }
    MPI.COMM_WORLD.scatter (dataItemBuffer, 1, myStructDatatype,
                            recvBuffer, 1, myStructDatatype, 0);
    /* Each process prints its received data item. The outputs
     * can intermingle on the screen so that you must use
     * "-output-filename" in Open MPI.
     */
    Thread.sleep (SLEEP_FACTOR * mytid); /* sleep to get ordered output */      
    dataItem = myStructType.getData(recvBuffer, 0);
    System.out.printf ("\nProcess %d running on %s.\n" +
                       "  Age:       %d\n" +
                       "  Firstname: %s\n" +
                       "  Lastname:  %s\n" +
                       "  Salary:    %.2f\n",
                       mytid, processorName,
                       dataItem.getAge (),
                       dataItem.getFirstName (),
                       dataItem.getLastName (),
                       dataItem.getSalary ());
    MPI.Finalize ();
  }
}
/* Data structure and methods for a small data object.
 *
 *
 * File: MyStruct.java                  Author: S. Gross
 * Date: 12.09.2013
 *
 */

import mpi.*;

public class MyStruct extends Struct
{
  private final static int MAX_NAME = 32;

  /* define buffer positions and the structure of the buffer            */
  private final int age       = addInt (),
                    fNameLen  = addInt (),
                    firstName = addChar (MAX_NAME),
                    lNameLen  = addInt (),
                    lastName  = addChar (MAX_NAME),
                    salary    = addDouble ();


  /* This method tells the super class how to create a data object      */
  @Override protected Data newData ()
  {
    return new Data ();
  }


  /* Read or write "structure components"                               */
  public class Data extends Struct.Data
  {
    public int getAge ()
    {
      return getInt (age);
    }


    public String getFirstName ()
    {
      int length = getInt (fNameLen);
      StringBuilder sb = new StringBuilder ();

      for (int i = 0; i < length; ++i)
      {
        sb.append(getChar (firstName, i));
      }
      return sb.toString ();
    }


    public String getLastName ()
    {
      int length = getInt (lNameLen);
      StringBuilder sb = new StringBuilder ();

      for (int i = 0; i < length; ++i)
      {
        sb.append(getChar (lastName, i));
      }
      return sb.toString ();
    }


    public double getSalary ()
    {
      return getDouble (salary);
    }


    public void setAge (int newAge)
    {
      putInt (age, newAge);
    }


    public void setFirstName (String newFirstName)
    {
      int length = Math.min (newFirstName.length (), MAX_NAME);

      putInt (fNameLen, length);
      for(int i = 0; i < length; ++i)
      {
        putChar (firstName, i, newFirstName.charAt (i));
      }
    }


    public void setLastName (String newLastName)
    {
      int length = Math.min (newLastName.length (), MAX_NAME);

      putInt (lNameLen, length);
      for (int i = 0; i < length; ++i)
      {
        putChar (lastName, i, newLastName.charAt (i));
      }
    }


    public void setSalary (double newSalary)
    {
      putDouble (salary, newSalary);
    }
  }
}
_______________________________________________
users mailing list
users@lists.open-mpi.org
https://lists.open-mpi.org/mailman/listinfo/users

Reply via email to