@@ -23,7 +23,7 @@ layer on top of the C implementation. This is the same approach as in
2323mpiJava [#mpijava ]_; in fact, mpiJava was taken as a starting point
2424for Open MPI Java bindings, but they were later totally rewritten.
2525
26- Building the Java Bindings
26+ Building the Java bindings
2727--------------------------
2828
2929Java support requires that Open MPI be built at least with shared
@@ -37,13 +37,12 @@ specify the location. For example, this is required on the Mac
3737platform as the JDK headers are located in a non-typical location. Two
3838options are available for this purpose:
3939
40- 1 . ``--with-jdk-bindir=<foo> ``: the location of ``javac `` and ``javah ``
41- 1 . ``--with-jdk-headers=<bar> ``: the directory containing ``jni.h ``
40+ # . ``--with-jdk-bindir=<foo> ``: the location of ``javac `` and ``javah ``
41+ # . ``--with-jdk-headers=<bar> ``: the directory containing ``jni.h ``
4242
43- For simplicity, typical configurations are provided in platform files
44- under ``contrib/platform/hadoop ``. These will meet the needs of most
45- users, or at least provide a starting point for your own custom
46- configuration.
43+ Some example configurations are provided in Open MPI configuration
44+ platform files under ``contrib/platform/hadoop ``. These examples can
45+ provide a starting point for your own custom configuration.
4746
4847In summary, therefore, you can configure the system using the
4948following Java-related options::
@@ -58,15 +57,50 @@ or simply::
5857
5958 $ ./configure --enable-mpi-java ...
6059
61- if JDK is in a "standard" place that we automatically find.
60+ if JDK is in a "standard" place that ``configure `` can automatically
61+ find.
6262
63- Running Java MPI Applications
64- -----------------------------
63+ Building Java MPI applications
64+ ------------------------------
6565
6666The ``mpijavac `` wrapper compiler is available for compiling
6767Java-based MPI applications. It ensures that all required Open MPI
68- libraries and class paths are defined. You can see the actual command
69- line using the ``--showme `` option, if you are interested.
68+ libraries and classpaths are defined. For example:
69+
70+ .. code-block ::
71+
72+ $ mpijavac Hello.java
73+
74+ You can use the ``--showme `` option to see the full command line of
75+ the Java compiler that is invoked:
76+
77+ .. code-block ::
78+
79+ $ mpijavac Hello.java --showme
80+ /usr/bin/javac -cp /opt/openmpi/lib/mpi.jar Hello.java
81+
82+ Note that if you are specifying a ``-cp `` argument on the command line
83+ to pass your application-specific classpaths, Open MPI will *extend *
84+ that argument to include the ``mpi.jar ``:
85+
86+ .. code-block ::
87+
88+ $ mpijavac -cp /path/to/my/app.jar Hello.java --showme
89+ /usr/bin/javac -cp /path/to/my/app.jar:/opt/openmpi/lib/mpi.jar Hello.java
90+
91+ Similarly, if you have a ``CLASSPATH `` environment variable defined,
92+ ``mpijavac `` will convert that into a ``-cp `` argument and extend it
93+ to include the ``mpi.jar ``:
94+
95+ .. code-block ::
96+
97+ $ export CLASSPATH=/path/to/my/app.jar
98+ $ mpijavac Hello.java --showme
99+ /usr/bin/javac -cp /path/to/my/app.jar:/opt/openmpi/lib/mpi.jar Hello.java
100+
101+
102+ Running Java MPI applications
103+ -----------------------------
70104
71105Once your application has been compiled, you can run it with the
72106standard ``mpirun `` command line::
@@ -76,10 +110,10 @@ standard ``mpirun`` command line::
76110``mpirun `` will detect the ``java `` token and ensure that the required
77111MPI libraries and class paths are defined to support execution. You
78112therefore do **not ** need to specify the Java library path to the MPI
79- installation, nor the MPI classpath. Any class path definitions
113+ installation, nor the MPI classpath. Any classpath definitions
80114required for your application should be specified either on the
81115command line or via the ``CLASSPATH `` environment variable. Note that
82- the local directory will be added to the class path if nothing is
116+ the local directory will be added to the classpath if nothing is
83117specified.
84118
85119.. note :: The ``java`` executable, all required libraries, and your
@@ -90,15 +124,15 @@ Basic usage of the Java bindings
90124
91125There is an MPI package that contains all classes of the MPI Java
92126bindings: ``Comm ``, ``Datatype ``, ``Request ``, etc. These classes have a
93- direct correspondence with classes defined by the MPI standard. MPI
127+ direct correspondence with handle types defined by the MPI standard. MPI
94128primitives are just methods included in these classes. The convention
95129used for naming Java methods and classes is the usual camel-case
96130convention, e.g., the equivalent of ``MPI_File_set_info(fh,info) `` is
97131``fh.setInfo(info) ``, where ``fh `` is an object of the class ``File ``.
98132
99133Apart from classes, the MPI package contains predefined public
100134attributes under a convenience class ``MPI ``. Examples are the
101- predefined communicator ``MPI.COMM_WORLD `` or predefined datatypes such
135+ predefined communicator ``MPI.COMM_WORLD `` and predefined datatypes such
102136as ``MPI.DOUBLE ``. Also, MPI initialization and finalization are methods
103137of the ``MPI `` class and must be invoked by all MPI Java
104138applications. The following example illustrates these concepts:
@@ -128,7 +162,9 @@ applications. The following example illustrates these concepts:
128162
129163 MPI. COMM_WORLD . reduce(sBuf, rBuf, 1 , MPI. DOUBLE , MPI. SUM , 0 );
130164
131- if (rank == 0 ) System . out. println(" PI: " + rBuf[0 ]);
165+ if (rank == 0 ) {
166+ System . out. println(" PI: " + rBuf[0 ]);
167+ }
132168 MPI . Finalize();
133169 }
134170 }
@@ -183,18 +219,22 @@ be necessary to allocate the buffer and free it later.
183219The default capacity of pool buffers can be modified with an Open MPI
184220MCA parameter::
185221
186- shell $ mpirun --mca mpi_java_eager SIZE ...
222+ $ mpirun --mca ompi_mpi_java_eager SIZE ...
187223
188- Where ``SIZE `` is the number of bytes, or kilobytes if it ends with 'k',
189- or megabytes if it ends with 'm'.
224+ The value of ``SIZE `` can be:
225+
226+ * ``N ``: An integer number of bytes
227+ * ``Nk ``: An integer number (suffixed with ``k ``) of kilobytes
228+ * ``Nm ``: An integer number (suffixed with ``m ``) of megabytes
190229
191230An alternative is to use "direct buffers" provided by standard classes
192- available in the Java SDK such as ``ByteBuffer ``. For convenience we
193- provide a few static methods ``new[Type]Buffer `` in the ``MPI `` class to
194- create direct buffers for a number of basic datatypes. Elements of the
195- direct buffer can be accessed with methods ``put() `` and ``get() ``, and
196- the number of elements in the buffer can be obtained with the method
197- ``capacity() ``. This example illustrates its use:
231+ available in the Java SDK such as ``ByteBuffer ``. For convenience,
232+ Open MPI provides a few static methods ``new[Type]Buffer `` in the
233+ ``MPI `` class to create direct buffers for a number of basic
234+ datatypes. Elements of the direct buffer can be accessed with methods
235+ ``put() `` and ``get() ``, and the number of elements in the buffer can
236+ be obtained with the method ``capacity() ``. This example illustrates
237+ its use:
198238
199239.. code-block :: java
200240
@@ -220,20 +260,22 @@ the number of elements in the buffer can be obtained with the method
220260 }
221261
222262 Direct buffers are available for: ``BYTE ``, ``CHAR ``, ``SHORT ``,
223- ``INT ``, ``LONG ``, ``FLOAT ``, and ``DOUBLE ``. There is no direct
224- buffer for booleans.
263+ ``INT ``, ``LONG ``, ``FLOAT ``, and ``DOUBLE ``.
264+
265+ .. note :: There is no direct buffer for booleans.
225266
226267Direct buffers are not a replacement for arrays, because they have
227268higher allocation and deallocation costs than arrays. In some cases
228269arrays will be a better choice. You can easily convert a buffer into
229270an array and vice versa.
230271
231- All non-blocking methods must use direct buffers and only
232- blocking methods can choose between arrays and direct buffers.
272+ .. important :: All non-blocking methods *must* use direct buffers.
273+ Only blocking methods can choose between arrays and
274+ direct buffers.
233275
234276The above example also illustrates that it is necessary to call the
235277``free() `` method on objects whose class implements the ``Freeable ``
236- interface. Otherwise, a memory leak is produced .
278+ interface. Otherwise, a memory leak will occur .
237279
238280Specifying offsets in buffers
239281-----------------------------
0 commit comments