Skip to content

Commit c3d3797

Browse files
authored
Merge pull request #10256 from jsquyres/pr/moar-moar-moar-docs-updates
More documentation updates
2 parents 04f6142 + df9178d commit c3d3797

File tree

2 files changed

+78
-31
lines changed

2 files changed

+78
-31
lines changed

docs/features/java.rst

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ layer on top of the C implementation. This is the same approach as in
2323
mpiJava [#mpijava]_; in fact, mpiJava was taken as a starting point
2424
for Open MPI Java bindings, but they were later totally rewritten.
2525

26-
Building the Java Bindings
26+
Building the Java bindings
2727
--------------------------
2828

2929
Java 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
3737
platform as the JDK headers are located in a non-typical location. Two
3838
options 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

4847
In summary, therefore, you can configure the system using the
4948
following 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

6666
The ``mpijavac`` wrapper compiler is available for compiling
6767
Java-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

71105
Once your application has been compiled, you can run it with the
72106
standard ``mpirun`` command line::
@@ -76,10 +110,10 @@ standard ``mpirun`` command line::
76110
``mpirun`` will detect the ``java`` token and ensure that the required
77111
MPI libraries and class paths are defined to support execution. You
78112
therefore 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
80114
required for your application should be specified either on the
81115
command 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
83117
specified.
84118

85119
.. note:: The ``java`` executable, all required libraries, and your
@@ -90,15 +124,15 @@ Basic usage of the Java bindings
90124

91125
There is an MPI package that contains all classes of the MPI Java
92126
bindings: ``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
94128
primitives are just methods included in these classes. The convention
95129
used for naming Java methods and classes is the usual camel-case
96130
convention, 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

99133
Apart from classes, the MPI package contains predefined public
100134
attributes 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
102136
as ``MPI.DOUBLE``. Also, MPI initialization and finalization are methods
103137
of the ``MPI`` class and must be invoked by all MPI Java
104138
applications. 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.
183219
The default capacity of pool buffers can be modified with an Open MPI
184220
MCA 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

191230
An 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

226267
Direct buffers are not a replacement for arrays, because they have
227268
higher allocation and deallocation costs than arrays. In some cases
228269
arrays will be a better choice. You can easily convert a buffer into
229270
an 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

234276
The 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

238280
Specifying offsets in buffers
239281
-----------------------------

docs/to-do.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ Need to update these docs to reflect:
3636
functions are not declared in mpi.h unless Open MPI was compiled
3737
with ``--enable-mpi1-compatibility``.
3838

39+
* This is not really a change in v5.0, but it probably has changed
40+
(because of PRTE) since v4.x, so: we need to document how to use
41+
``MPI_Comm_join`` and ``MPI_Publish_name`` + ``MPI_Comm_accept`` /
42+
``MPI_Lookup_name`` + ``MPI_Comm_connect``. See
43+
https://github.com/open-mpi/ompi/issues/10222
3944

4045
Other random to-do items
4146
------------------------

0 commit comments

Comments
 (0)