@@ -23,7 +23,7 @@ layer on top of the C implementation. This is the same approach as in
23
23
mpiJava [#mpijava ]_; in fact, mpiJava was taken as a starting point
24
24
for Open MPI Java bindings, but they were later totally rewritten.
25
25
26
- Building the Java Bindings
26
+ Building the Java bindings
27
27
--------------------------
28
28
29
29
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
37
37
platform as the JDK headers are located in a non-typical location. Two
38
38
options are available for this purpose:
39
39
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 ``
42
42
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.
47
46
48
47
In summary, therefore, you can configure the system using the
49
48
following Java-related options::
@@ -58,15 +57,50 @@ or simply::
58
57
59
58
$ ./configure --enable-mpi-java ...
60
59
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.
62
62
63
- Running Java MPI Applications
64
- -----------------------------
63
+ Building Java MPI applications
64
+ ------------------------------
65
65
66
66
The ``mpijavac `` wrapper compiler is available for compiling
67
67
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
+ -----------------------------
70
104
71
105
Once your application has been compiled, you can run it with the
72
106
standard ``mpirun `` command line::
@@ -76,10 +110,10 @@ standard ``mpirun`` command line::
76
110
``mpirun `` will detect the ``java `` token and ensure that the required
77
111
MPI libraries and class paths are defined to support execution. You
78
112
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
80
114
required for your application should be specified either on the
81
115
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
83
117
specified.
84
118
85
119
.. note :: The ``java`` executable, all required libraries, and your
@@ -90,15 +124,15 @@ Basic usage of the Java bindings
90
124
91
125
There is an MPI package that contains all classes of the MPI Java
92
126
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
94
128
primitives are just methods included in these classes. The convention
95
129
used for naming Java methods and classes is the usual camel-case
96
130
convention, e.g., the equivalent of ``MPI_File_set_info(fh,info) `` is
97
131
``fh.setInfo(info) ``, where ``fh `` is an object of the class ``File ``.
98
132
99
133
Apart from classes, the MPI package contains predefined public
100
134
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
102
136
as ``MPI.DOUBLE ``. Also, MPI initialization and finalization are methods
103
137
of the ``MPI `` class and must be invoked by all MPI Java
104
138
applications. The following example illustrates these concepts:
@@ -128,7 +162,9 @@ applications. The following example illustrates these concepts:
128
162
129
163
MPI. COMM_WORLD . reduce(sBuf, rBuf, 1 , MPI. DOUBLE , MPI. SUM , 0 );
130
164
131
- if (rank == 0 ) System . out. println(" PI: " + rBuf[0 ]);
165
+ if (rank == 0 ) {
166
+ System . out. println(" PI: " + rBuf[0 ]);
167
+ }
132
168
MPI . Finalize();
133
169
}
134
170
}
@@ -183,18 +219,22 @@ be necessary to allocate the buffer and free it later.
183
219
The default capacity of pool buffers can be modified with an Open MPI
184
220
MCA parameter::
185
221
186
- shell $ mpirun --mca mpi_java_eager SIZE ...
222
+ $ mpirun --mca ompi_mpi_java_eager SIZE ...
187
223
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
190
229
191
230
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:
198
238
199
239
.. code-block :: java
200
240
@@ -220,20 +260,22 @@ the number of elements in the buffer can be obtained with the method
220
260
}
221
261
222
262
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.
225
266
226
267
Direct buffers are not a replacement for arrays, because they have
227
268
higher allocation and deallocation costs than arrays. In some cases
228
269
arrays will be a better choice. You can easily convert a buffer into
229
270
an array and vice versa.
230
271
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.
233
275
234
276
The above example also illustrates that it is necessary to call the
235
277
``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 .
237
279
238
280
Specifying offsets in buffers
239
281
-----------------------------
0 commit comments