root/ompi/mpi/java/java/UserFunction.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. call
  2. call
  3. vCall
  4. vCall
  5. vCall
  6. vCall
  7. vCall
  8. vCall
  9. vCall

   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         : User_function.java
  40  * Author       : Xinying Li
  41  * Created      : Thu Apr  9 12:22:15 1998
  42  * Revision     : $Revision: 1.4 $
  43  * Updated      : $Date: 1999/09/13 16:14:30 $
  44  * Copyright: Northeast Parallel Architectures Center
  45  *            at Syracuse University 1998
  46  */
  47 
  48 package mpi;
  49 
  50 import java.nio.*;
  51 
  52 /**
  53  * Java equivalent of the {@code MPI_USER_FUNCTION}.
  54  */
  55 public abstract class UserFunction
  56 {
  57         /**
  58          * User-defined function for a new {@code Op}.
  59          * @param inVec                 array of values to combine with {@code inoutvec} elements
  60          * @param inOutVec              in-out array of accumulator locations
  61          * @param count                 number of items in arrays
  62          * @param datatype              type of each item
  63          * @throws MPIException Signals that an MPI exception of some sort has occurred.
  64          */
  65         public void call(Object inVec, Object inOutVec, int count, Datatype datatype)
  66                         throws MPIException
  67         {
  68                 throw new UnsupportedOperationException("Not supported yet.");
  69         }
  70 
  71         /**
  72          * User-defined function for a new {@code Op}.
  73          * @param in                    direct byte buffer to combine with {@code inOut} buffer
  74          * @param inOut                 in-out direct byte buffer of accumulator locations
  75          * @param count                 number of items in buffers
  76          * @param datatype              type of each item
  77          * @throws MPIException Signals that an MPI exception of some sort has occurred.
  78          */
  79         public void call(ByteBuffer in, ByteBuffer inOut, int count, Datatype datatype)
  80                         throws MPIException
  81         {
  82                 switch(datatype.baseType)
  83                 {
  84                 case Datatype.BYTE:
  85                         vCall(in, inOut, count, datatype);
  86                         break;
  87                 case Datatype.CHAR:
  88                         vCall(in.asCharBuffer(), inOut.asCharBuffer(), count, datatype);
  89                         break;
  90                 case Datatype.SHORT:
  91                         vCall(in.asShortBuffer(), inOut.asShortBuffer(), count, datatype);
  92                         break;
  93                 case Datatype.INT:
  94                         vCall(in.asIntBuffer(), inOut.asIntBuffer(), count, datatype);
  95                         break;
  96                 case Datatype.LONG:
  97                         vCall(in.asLongBuffer(), inOut.asLongBuffer(), count, datatype);
  98                         break;
  99                 case Datatype.FLOAT:
 100                         vCall(in.asFloatBuffer(), inOut.asFloatBuffer(), count, datatype);
 101                         break;
 102                 case Datatype.DOUBLE:
 103                         vCall(in.asDoubleBuffer(), inOut.asDoubleBuffer(), count, datatype);
 104                         break;
 105                 case Datatype.PACKED:
 106                         vCall(in, inOut, count, datatype);
 107                         break;
 108                 default:
 109                         throw new IllegalArgumentException("Unsupported datatype.");
 110                 }
 111         }
 112 
 113         private void vCall(ByteBuffer in, ByteBuffer inOut,
 114                         int count, Datatype datatype) throws MPIException
 115         {
 116                 int    extent   = datatype.getExtent();
 117                 byte[] inVec    = new byte[count * extent],
 118                                 inOutVec = new byte[count * extent];
 119 
 120                 in.get(inVec);
 121                 inOut.get(inOutVec);
 122                 call(inVec, inOutVec, count, datatype);
 123                 inOut.clear();
 124                 inOut.put(inOutVec);
 125         }
 126 
 127         private void vCall(CharBuffer inBuf, CharBuffer inOutBuf,
 128                         int count, Datatype datatype) throws MPIException
 129         {
 130                 int    extent   = datatype.getExtent();
 131                 char[] inVec    = new char[count * extent],
 132                                 inOutVec = new char[count * extent];
 133 
 134                 inBuf.get(inVec);
 135                 inOutBuf.get(inOutVec);
 136                 call(inVec, inOutVec, count, datatype);
 137                 inOutBuf.clear();
 138                 inOutBuf.put(inOutVec);
 139         }
 140 
 141         private void vCall(ShortBuffer inBuf, ShortBuffer inOutBuf,
 142                         int count, Datatype datatype) throws MPIException
 143         {
 144                 int     extent   = datatype.getExtent();
 145                 short[] inVec    = new short[count * extent],
 146                                 inOutVec = new short[count * extent];
 147 
 148                 inBuf.get(inVec);
 149                 inOutBuf.get(inOutVec);
 150                 call(inVec, inOutVec, count, datatype);
 151                 inOutBuf.clear();
 152                 inOutBuf.put(inOutVec);
 153         }
 154 
 155         private void vCall(IntBuffer inBuf, IntBuffer inOutBuf,
 156                         int count, Datatype datatype) throws MPIException
 157         {
 158                 int   extent   = datatype.getExtent();
 159                 int[] inVec    = new int[count * extent],
 160                                 inOutVec = new int[count * extent];
 161 
 162                 inBuf.get(inVec);
 163                 inOutBuf.get(inOutVec);
 164                 call(inVec, inOutVec, count, datatype);
 165                 inOutBuf.clear();
 166                 inOutBuf.put(inOutVec);
 167         }
 168 
 169         private void vCall(LongBuffer inBuf, LongBuffer inOutBuf,
 170                         int count, Datatype datatype) throws MPIException
 171         {
 172                 int    extent   = datatype.getExtent();
 173                 long[] inVec    = new long[count * extent],
 174                                 inOutVec = new long[count * extent];
 175 
 176                 inBuf.get(inVec);
 177                 inOutBuf.get(inOutVec);
 178                 call(inVec, inOutVec, count, datatype);
 179                 inOutBuf.clear();
 180                 inOutBuf.put(inOutVec);
 181         }
 182 
 183         private void vCall(FloatBuffer inBuf, FloatBuffer inOutBuf,
 184                         int count, Datatype datatype) throws MPIException
 185         {
 186                 int     extent   = datatype.getExtent();
 187                 float[] inVec    = new float[count * extent],
 188                                 inOutVec = new float[count * extent];
 189 
 190                 inBuf.get(inVec);
 191                 inOutBuf.get(inOutVec);
 192                 call(inVec, inOutVec, count, datatype);
 193                 inOutBuf.clear();
 194                 inOutBuf.put(inOutVec);
 195         }
 196 
 197         private void vCall(DoubleBuffer inBuf, DoubleBuffer inOutBuf,
 198                         int count, Datatype datatype) throws MPIException
 199         {
 200                 int      extent   = datatype.getExtent();
 201                 double[] inVec    = new double[count * extent],
 202                                 inOutVec = new double[count * extent];
 203 
 204                 inBuf.get(inVec);
 205                 inOutBuf.get(inOutVec);
 206                 call(inVec, inOutVec, count, datatype);
 207                 inOutBuf.clear();
 208                 inOutBuf.put(inOutVec);
 209         }
 210 
 211 } // UserFunction

/* [<][>][^][v][top][bottom][index][help] */