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 * IMPLEMENTATION DETAILS 22 * 23 * All methods with buffers that can be direct or non direct have 24 * a companion argument 'db' which is true if the buffer is direct. 25 * 26 * Checking if a buffer is direct is faster in Java than C. 27 */ 28 29 package mpi; 30 31 import java.nio.*; 32 import static mpi.MPI.assertDirectBuffer; 33 34 /** 35 * This class represents {@code MPI_Message}. 36 */ 37 public final class Message 38 { 39 protected long handle; 40 private static long NULL, NO_PROC; 41 42 static 43 { init()44 init(); 45 } 46 init()47 private static native void init(); 48 49 /** 50 * Creates a {@code MPI_MESSAGE_NULL}. 51 */ Message()52 public Message() 53 { 54 handle = NULL; 55 } 56 57 /** 58 * Tests if the message is {@code MPI_MESSAGE_NULL}. 59 * @return true if the message is {@code MPI_MESSAGE_NULL}. 60 */ isNull()61 public boolean isNull() 62 { 63 return handle == NULL; 64 } 65 66 /** 67 * Tests if the message is {@code MPI_MESSAGE_NO_PROC}. 68 * @return true if the message is {@code MPI_MESSAGE_NO_PROC}. 69 */ isNoProc()70 public boolean isNoProc() 71 { 72 return handle == NO_PROC; 73 } 74 75 /** 76 * Java binding of {@code MPI_MPROBE}. 77 * @param source rank of the source 78 * @param tag message tag 79 * @param comm communicator 80 * @return status object 81 * @throws MPIException Signals that an MPI exception of some sort has occurred. 82 */ mProbe(int source, int tag, Comm comm)83 public Status mProbe(int source, int tag, Comm comm) throws MPIException 84 { 85 MPI.check(); 86 Status status = new Status(); 87 handle = mProbe(source, tag, comm.handle, status.data); 88 return status; 89 } 90 mProbe(int source, int tag, long comm, long[] status)91 private native long mProbe(int source, int tag, long comm, long[] status) 92 throws MPIException; 93 94 /** 95 * Java binding of {@code MPI_IMPROBE}. 96 * @param source rank of the source 97 * @param tag message tag 98 * @param comm communicator 99 * @return status object if there is a message, {@code null} otherwise 100 * @throws MPIException Signals that an MPI exception of some sort has occurred. 101 */ imProbe(int source, int tag, Comm comm)102 public Status imProbe(int source, int tag, Comm comm) throws MPIException 103 { 104 MPI.check(); 105 return imProbe(source, tag, comm.handle); 106 } 107 imProbe(int source, int tag, long comm)108 private native Status imProbe(int source, int tag, long comm) 109 throws MPIException; 110 111 /** 112 * Java binding of {@code MPI_MRECV}. 113 * @param buf receive buffer 114 * @param count number of elements in receve buffer 115 * @param type datatype of each receive buffer element 116 * @return status object 117 * @throws MPIException Signals that an MPI exception of some sort has occurred. 118 */ mRecv(Object buf, int count, Datatype type)119 public Status mRecv(Object buf, int count, Datatype type) throws MPIException 120 { 121 MPI.check(); 122 int off = 0; 123 boolean db = false; 124 Status status = new Status(); 125 126 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) 127 { 128 off = type.getOffset(buf); 129 buf = ((Buffer)buf).array(); 130 } 131 132 handle = mRecv(handle, buf, db, off, count, 133 type.handle, type.baseType, status.data); 134 135 return status; 136 } 137 mRecv( long message, Object buf, boolean db, int offset, int count, long type, int baseType, long[] status)138 private native long mRecv( 139 long message, Object buf, boolean db, int offset, int count, 140 long type, int baseType, long[] status) throws MPIException; 141 142 /** 143 * Java binding of {@code MPI_IMRECV}. 144 * @param buf receive buffer 145 * @param count number of elements in receve buffer 146 * @param type datatype of each receive buffer element 147 * @return request object 148 * @throws MPIException Signals that an MPI exception of some sort has occurred. 149 */ imRecv(Buffer buf, int count, Datatype type)150 public Request imRecv(Buffer buf, int count, Datatype type) 151 throws MPIException 152 { 153 MPI.check(); 154 assertDirectBuffer(buf); 155 Request req = new Request(imRecv(handle, buf, count, type.handle)); 156 req.addRecvBufRef(buf); 157 return req; 158 } 159 imRecv(long message, Object buf, int count, long type)160 private native long imRecv(long message, Object buf, int count, long type) 161 throws MPIException; 162 163 } // Message 164