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 (c) 2018 FUJITSU LIMITED. All rights reserved.
15 * $COPYRIGHT$
16 *
17 * Additional copyrights may follow
18 *
19 * $HEADER$
20 *
21 *
22 * This file is almost a complete re-write for Open MPI compared to the
23 * original mpiJava package. Its license and copyright are listed below.
24 * See <path to ompi/mpi/java/README> for more information.
25 *
26 *
27 * Licensed under the Apache License, Version 2.0 (the "License");
28 * you may not use this file except in compliance with the License.
29 * You may obtain a copy of the License at
30 *
31 * http://www.apache.org/licenses/LICENSE-2.0
32 *
33 * Unless required by applicable law or agreed to in writing, software
34 * distributed under the License is distributed on an "AS IS" BASIS,
35 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 * See the License for the specific language governing permissions and
37 * limitations under the License.
38 *
39 *
40 * File : Op.java
41 * Author : Xinying Li, Sang LIm
42 * Created : Thu Apr 9 12:22:15 1998
43 * Revision : $Revision: 1.11 $
44 * Updated : $Date: 2003/01/16 16:39:34 $
45 * Copyright: Northeast Parallel Architectures Center
46 * at Syracuse University 1998
47 */
48
49 package mpi;
50
51 import java.nio.*;
52
53 /**
54 * This class represents {@code MPI_Op}.
55 */
56 public final class Op implements Freeable
57 {
58 protected final UserFunction uf;
59 private boolean commute;
60 private Datatype datatype;
61 protected long handle;
62
63 static
64 {
65 init();
66 }
67
68 private static native void init();
69
70 protected Op(int type)
71 {
72 getOp(type);
73 uf = null;
74 commute = true;
75 }
76
77 private native void getOp(int type);
78
79 /**
80 * Bind a user-defined global reduction operation to an {@code Op} object.
81 * <p>Java binding of the MPI operation {@code MPI_OP_CREATE}.
82 * @param function user defined function
83 * @param commute {@code true} if commutative, {@code false} otherwise
84 */
85 public Op(UserFunction function, boolean commute)
86 {
87 handle = 0; // When JNI code gets the handle it will be initialized.
88 uf = function;
89 this.commute = commute;
90 }
91
92 protected void setDatatype(Datatype t)
93 {
94 datatype = t;
95 }
96
97 protected void call(Object invec, Object inoutvec, int count)
98 throws MPIException
99 {
100 if(datatype.baseType == Datatype.BOOLEAN)
101 {
102 uf.call(invec, inoutvec, count, datatype);
103 }
104 else
105 {
106 uf.call(((ByteBuffer)invec).order(ByteOrder.nativeOrder()),
107 ((ByteBuffer)inoutvec).order(ByteOrder.nativeOrder()),
108 count, datatype);
109 }
110 }
111
112 /**
113 * Test if the operation is commutative.
114 * <p>Java binding of the MPI operation {@code MPI_OP_COMMUTATIVE}.
115 * @return {@code true} if commutative, {@code false} otherwise
116 */
117 public boolean isCommutative()
118 {
119 return commute;
120 }
121
122 /**
123 * Java binding of the MPI operation {@code MPI_OP_FREE}.
124 * @throws MPIException Signals that an MPI exception of some sort has occurred.
125 */
126 @Override public native void free() throws MPIException;
127
128 /**
129 * Test if operation object is null.
130 * @return true if the operation object is null, false otherwise
131 */
132 public native boolean isNull();
133
134 } // Op