1 /*
2 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2015 Los Alamos National Security, LLC. All rights
13 * reserved.
14 * $COPYRIGHT$
15 *
16 * Additional copyrights may follow
17 *
18 * $HEADER$
19 *
20 *
21 * This file is almost a complete re-write for Open MPI compared to the
22 * original mpiJava package. Its license and copyright are listed below.
23 * See <path to ompi/mpi/java/README> for more information.
24 *
25 *
26 * Licensed under the Apache License, Version 2.0 (the "License");
27 * you may not use this file except in compliance with the License.
28 * You may obtain a copy of the License at
29 *
30 * http://www.apache.org/licenses/LICENSE-2.0
31 *
32 * Unless required by applicable law or agreed to in writing, software
33 * distributed under the License is distributed on an "AS IS" BASIS,
34 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35 * See the License for the specific language governing permissions and
36 * limitations under the License.
37 *
38 *
39 * File : Status.java
40 * Author : Sang Lim, Sung-Hoon Ko, Xinying Li, Bryan Carpenter
41 * Created : Thu Apr 9 12:22:15 1998
42 * Revision : $Revision: 1.15 $
43 * Updated : $Date: 2003/01/16 16:39:34 $
44 * Copyright: Northeast Parallel Architectures Center
45 * at Syracuse University 1998
46 */
47
48 package mpi;
49
50 /**
51 * This class represents {@code MPI_Status}.
52 */
53 public final class Status
54 {
55 protected final long[] data;
56
57 static
58 {
59 init();
60 }
61
62 private static native void init();
63
64 /**
65 * Status objects must be created only by the MPI methods.
66 */
67 protected Status()
68 {
69 data = new long[6];
70 }
71
72 /**
73 * Returns the number of received entries.
74 * <p>Java binding of the MPI operation {@code MPI_GET_COUNT}.
75 * @param datatype datatype of each item in receive buffer
76 * @return number of received entries
77 * @throws MPIException Signals that an MPI exception of some sort has occurred.
78 */
79 public int getCount(Datatype datatype) throws MPIException
80 {
81 MPI.check();
82 int i = 0;
83 int source = (int)data[i++];
84 int tag = (int)data[i++];
85 int error = (int)data[i++];
86 int cancelled = (int)data[i++];
87 long ucount = data[i++];
88 return getCount(source, tag, error, cancelled, ucount, datatype.handle);
89 }
90
91 private native int getCount(
92 int source, int tag, int error,
93 int cancelled, long ucount, long datatype) throws MPIException;
94
95 /**
96 * Tests if the communication was cancelled.
97 * <p>Java binding of the MPI operation {@code MPI_TEST_CANCELLED}.
98 * @return true if the operation was succesfully cancelled, false otherwise
99 * @throws MPIException Signals that an MPI exception of some sort has occurred.
100 */
101 public boolean isCancelled() throws MPIException
102 {
103 MPI.check();
104 int i = 0;
105 int source = (int)data[i++];
106 int tag = (int)data[i++];
107 int error = (int)data[i++];
108 int cancelled = (int)data[i++];
109 long ucount = data[i++];
110 return isCancelled(source, tag, error, cancelled, ucount);
111 }
112
113 private native boolean isCancelled(
114 int source, int tag, int error, int cancelled, long ucount)
115 throws MPIException;
116
117 /**
118 * Retrieves the number of basic elements from status.
119 * <p>Java binding of the MPI operation {@code MPI_GET_ELEMENTS}.
120 * @param datatype datatype used by receive operation
121 * @return number of received basic elements
122 * @throws MPIException Signals that an MPI exception of some sort has occurred.
123 */
124 public int getElements(Datatype datatype) throws MPIException
125 {
126 MPI.check();
127 int i = 0;
128 int source = (int)data[i++];
129 int tag = (int)data[i++];
130 int error = (int)data[i++];
131 int cancelled = (int)data[i++];
132 long ucount = data[i++];
133 return getElements(source, tag, error, cancelled, ucount, datatype.handle);
134 }
135
136 private native int getElements(
137 int source, int tag, int error,
138 int cancelled, long ucount, long datatype) throws MPIException;
139
140 /**
141 * Retrieves the number of basic elements from status.
142 * <p>Java binding of the MPI operation {@code MPI_GET_ELEMENTS_X}.
143 * @param datatype datatype used by receive operation
144 * @return number of received basic elements
145 * @throws MPIException Signals that an MPI exception of some sort has occurred.
146 */
147 public Count getElementsX(Datatype datatype) throws MPIException
148 {
149 MPI.check();
150 int i = 0;
151 int source = (int)data[i++];
152 int tag = (int)data[i++];
153 int error = (int)data[i++];
154 int cancelled = (int)data[i++];
155 long ucount = data[i++];
156 return getElementsX(source, tag, error, cancelled, ucount, datatype.handle);
157 }
158
159 private native Count getElementsX(
160 int source, int tag, int error,
161 int cancelled, long ucount, long datatype) throws MPIException;
162
163 /**
164 * Sets the number of basic elements for this status object.
165 * <p>Java binding of the MPI operation {@code MPI_STATUS_SET_ELEMENTS}.
166 * @param datatype datatype used by receive operation
167 * @param count number of elements to associate with the status
168 * @throws MPIException Signals that an MPI exception of some sort has occurred.
169 */
170 public void setElements(Datatype datatype, int count) throws MPIException
171 {
172 MPI.check();
173 int i = 0;
174 int source = (int)data[i++];
175 int tag = (int)data[i++];
176 int error = (int)data[i++];
177 int cancelled = (int)data[i++];
178 long ucount = data[i++];
179 data[4] = setElements(source, tag, error, cancelled, ucount, datatype.handle, count);
180 }
181
182 private native int setElements(
183 int source, int tag, int error,
184 int cancelled, long ucount, long datatype, int count) throws MPIException;
185
186 /**
187 * Sets the number of basic elements for this status object.
188 * <p>Java binding of the MPI operation {@code MPI_STATUS_SET_ELEMENTS_X}.
189 * @param datatype datatype used by receive operation
190 * @param count number of elements to associate with the status
191 * @throws MPIException Signals that an MPI exception of some sort has occurred.
192 */
193 public void setElementsX(Datatype datatype, Count count) throws MPIException
194 {
195 MPI.check();
196 int i = 0;
197 int source = (int)data[i++];
198 int tag = (int)data[i++];
199 int error = (int)data[i++];
200 int cancelled = (int)data[i++];
201 long ucount = data[i++];
202 data[4] = setElementsX(source, tag, error, cancelled, ucount, datatype.handle, count.getCount());
203 }
204
205 private native long setElementsX(
206 int source, int tag, int error,
207 int cancelled, long ucount, long datatype, long count) throws MPIException;
208
209 /**
210 * Sets the cancelled flag.
211 * <p>Java binding of the MPI operation {@code MPI_STATUS_SET_CANCELLED}.
212 * @param flag if true indicates request was cancelled
213 * @throws MPIException Signals that an MPI exception of some sort has occurred.
214 */
215 public void setCancelled(boolean flag) throws MPIException
216 {
217 MPI.check();
218 int i = 0;
219 int source = (int)data[i++];
220 int tag = (int)data[i++];
221 int error = (int)data[i++];
222 int cancelled = (int)data[i++];
223 long ucount = data[i++];
224
225 if(flag) {
226 setCancelled(source, tag, error, cancelled, ucount, 1);
227 data[3] = 1;
228 } else {
229 setCancelled(source, tag, error, cancelled, ucount, 0);
230 data[3] = 0;
231 }
232
233 }
234
235 private native void setCancelled(
236 int source, int tag, int error,
237 int cancelled, long ucount, int flag) throws MPIException;
238
239 /**
240 * Returns the "source" of message.
241 * <p>Java binding of the MPI value {@code MPI_SOURCE}.
242 * @return source of message
243 */
244 public int getSource()
245 {
246 return (int)data[0];
247 }
248
249 /**
250 * Returns the "tag" of message.
251 * <p>Java binding of the MPI value {@code MPI_TAG}.
252 * @return tag of message
253 */
254 public int getTag()
255 {
256 return (int)data[1];
257 }
258
259 /**
260 * Returns the {@code MPI_ERROR} of message.
261 * @return error of message.
262 */
263 public int getError()
264 {
265 return (int)data[2];
266 }
267
268 /**
269 * Returns the index of message.
270 * @return index of message.
271 */
272 public int getIndex()
273 {
274 return (int)data[5];
275 }
276
277 } // Status