root/ompi/mpi/java/c/mpi_Status.c

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

DEFINITIONS

This source file includes following definitions.
  1. getStatus
  2. Java_mpi_Status_init
  3. Java_mpi_Status_getCount
  4. Java_mpi_Status_isCancelled
  5. Java_mpi_Status_getElements
  6. Java_mpi_Status_getElementsX
  7. Java_mpi_Status_setElements
  8. Java_mpi_Status_setElementsX
  9. Java_mpi_Status_setCancelled
  10. ompi_java_status_new
  11. ompi_java_status_newIndex
  12. ompi_java_status_set
  13. ompi_java_status_setIndex

   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$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 /*
  19  * This file is almost a complete re-write for Open MPI compared to the
  20  * original mpiJava package. Its license and copyright are listed below.
  21  * See <path to ompi/mpi/java/README> for more information.
  22  */
  23 /*
  24     Licensed under the Apache License, Version 2.0 (the "License");
  25     you may not use this file except in compliance with the License.
  26     You may obtain a copy of the License at
  27 
  28        http://www.apache.org/licenses/LICENSE-2.0
  29 
  30     Unless required by applicable law or agreed to in writing, software
  31     distributed under the License is distributed on an "AS IS" BASIS,
  32     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  33     See the License for the specific language governing permissions and
  34     limitations under the License.
  35 */
  36 /*
  37  * File         : mpi_Status.c
  38  * Headerfile   : mpi_Status.h
  39  * Author       : Sung-Hoon Ko, Xinying Li
  40  * Created      : Thu Apr  9 12:22:15 1998
  41  * Revision     : $Revision: 1.9 $
  42  * Updated      : $Date: 2003/01/16 16:39:34 $
  43  * Copyright: Northeast Parallel Architectures Center
  44  *            at Syracuse University 1998
  45  */
  46 
  47 #include "ompi_config.h"
  48 
  49 #include <stdlib.h>
  50 #ifdef HAVE_TARGETCONDITIONALS_H
  51 #include <TargetConditionals.h>
  52 #endif
  53 
  54 #include "mpi.h"
  55 #include "mpi_Status.h"
  56 #include "mpiJava.h"
  57 
  58 static void getStatus(MPI_Status *status, jint source, jint tag,
  59                       jint error, jint cancelled, jlong ucount)
  60 {
  61     /* Copy the whole thing to C */
  62     status->MPI_SOURCE = source;
  63     status->MPI_TAG    = tag;
  64     status->MPI_ERROR  = error;
  65     status->_cancelled = cancelled;
  66     status->_ucount    = ucount;
  67 }
  68 
  69 JNIEXPORT void JNICALL Java_mpi_Status_init(JNIEnv *env, jclass clazz)
  70 {
  71     ompi_java.StatusData = (*env)->GetFieldID(env, clazz, "data", "[J");
  72 }
  73 
  74 JNIEXPORT jint JNICALL Java_mpi_Status_getCount(
  75         JNIEnv *env, jobject jthis, jint source, jint tag,
  76         jint error, jint cancelled, jlong ucount, jlong jType)
  77 {
  78     int count;
  79     MPI_Status stat;
  80     getStatus(&stat, source, tag, error, cancelled, ucount);
  81     MPI_Datatype datatype = (MPI_Datatype)jType;
  82     int rc = MPI_Get_count(&stat, datatype, &count);
  83     ompi_java_exceptionCheck(env, rc);
  84     return count;
  85 }
  86 
  87 JNIEXPORT jboolean JNICALL Java_mpi_Status_isCancelled(
  88         JNIEnv *env, jobject jthis, jint source, jint tag,
  89         jint error, jint cancelled, jlong ucount)
  90 {
  91     int flag;
  92     MPI_Status stat;
  93     getStatus(&stat, source, tag, error, cancelled, ucount);
  94     int rc = MPI_Test_cancelled(&stat, &flag);
  95     ompi_java_exceptionCheck(env, rc);
  96     return flag==0 ? JNI_FALSE : JNI_TRUE;
  97 }
  98 
  99 JNIEXPORT jint JNICALL Java_mpi_Status_getElements(
 100         JNIEnv *env, jobject jthis, jint source, jint tag,
 101         jint error, jint cancelled, jlong ucount, jlong jType)
 102 {
 103     int count;
 104     MPI_Status stat;
 105     getStatus(&stat, source, tag, error, cancelled, ucount);
 106     MPI_Datatype datatype = (MPI_Datatype)jType;
 107     int rc = MPI_Get_elements(&stat, datatype, &count);
 108     ompi_java_exceptionCheck(env, rc);
 109     return count;
 110 }
 111 
 112 JNIEXPORT jobject JNICALL Java_mpi_Status_getElementsX(
 113         JNIEnv *env, jobject jthis, jint source, jint tag,
 114         jint error, jint cancelled, jlong ucount, jlong jType)
 115 {
 116     MPI_Count count;
 117     MPI_Status stat;
 118     getStatus(&stat, source, tag, error, cancelled, ucount);
 119     MPI_Datatype datatype = (MPI_Datatype)jType;
 120     int rc = MPI_Get_elements_x(&stat, datatype, &count);
 121     ompi_java_exceptionCheck(env, rc);
 122 
 123         return (*env)->NewObject(env, ompi_java.CountClass,
 124                                 ompi_java.CountInit, (jlong)count);
 125 }
 126 
 127 JNIEXPORT jint JNICALL Java_mpi_Status_setElements(
 128         JNIEnv *env, jobject jthis, jint source, jint tag,
 129         jint error, jint cancelled, jlong ucount, jlong jType, int count)
 130 {
 131     MPI_Status stat;
 132     getStatus(&stat, source, tag, error, cancelled, ucount);
 133     MPI_Datatype datatype = (MPI_Datatype)jType;
 134     int rc = MPI_Status_set_elements(&stat, datatype, count);
 135     ompi_java_exceptionCheck(env, rc);
 136     return stat._ucount;
 137 }
 138 
 139 JNIEXPORT jlong JNICALL Java_mpi_Status_setElementsX(
 140         JNIEnv *env, jobject jthis, jint source, jint tag,
 141         jint error, jint cancelled, jlong ucount, jlong jType, jlong jcount)
 142 {
 143     MPI_Status stat;
 144     MPI_Count count = (long)jcount;
 145     getStatus(&stat, source, tag, error, cancelled, ucount);
 146     MPI_Datatype datatype = (MPI_Datatype)jType;
 147     int rc = MPI_Status_set_elements_x(&stat, datatype, count);
 148     ompi_java_exceptionCheck(env, rc);
 149     return (jlong)stat._ucount;
 150 }
 151 
 152 JNIEXPORT void JNICALL Java_mpi_Status_setCancelled(
 153         JNIEnv *env, jobject jthis, jint source, jint tag,
 154         jint error, jint cancelled, jlong ucount, int flag)
 155 {
 156     MPI_Status stat;
 157     getStatus(&stat, source, tag, error, cancelled, ucount);
 158     int rc = MPI_Status_set_cancelled(&stat, flag);
 159     ompi_java_exceptionCheck(env, rc);
 160 }
 161 
 162 jobject ompi_java_status_new(JNIEnv *env, MPI_Status *status)
 163 {
 164     jlongArray jData = (*env)->NewLongArray(env, 6);
 165     ompi_java_status_set(env, jData, status);
 166     jobject jStatus = (*env)->AllocObject(env, ompi_java.StatusClass);
 167     (*env)->SetObjectField(env, jStatus, ompi_java.StatusData, jData);
 168     return jStatus;
 169 }
 170 
 171 jobject ompi_java_status_newIndex(JNIEnv *env, MPI_Status *status, int index)
 172 {
 173     jlongArray jData = (*env)->NewLongArray(env, 6);
 174     ompi_java_status_setIndex(env, jData, status, index);
 175     jobject jStatus = (*env)->AllocObject(env, ompi_java.StatusClass);
 176     (*env)->SetObjectField(env, jStatus, ompi_java.StatusData, jData);
 177     return jStatus;
 178 }
 179 
 180 void ompi_java_status_set(JNIEnv *env, jlongArray jData, MPI_Status *status)
 181 {
 182     /* Copy the whole thing to Java */
 183     int i = 0;
 184     jlong *data = (*env)->GetPrimitiveArrayCritical(env, jData, NULL);
 185     data[i++] = status->MPI_SOURCE;
 186     data[i++] = status->MPI_TAG;
 187     data[i++] = status->MPI_ERROR;
 188     data[i++] = status->_cancelled;
 189     data[i++] = status->_ucount;
 190     (*env)->ReleasePrimitiveArrayCritical(env, jData, data, 0);
 191 }
 192 
 193 void ompi_java_status_setIndex(
 194         JNIEnv *env, jlongArray jData, MPI_Status *status, int index)
 195 {
 196     /* Copy the whole thing to Java */
 197     int i = 0;
 198     jlong *data = (*env)->GetPrimitiveArrayCritical(env, jData, NULL);
 199     data[i++] = status->MPI_SOURCE;
 200     data[i++] = status->MPI_TAG;
 201     data[i++] = status->MPI_ERROR;
 202     data[i++] = status->_cancelled;
 203     data[i++] = status->_ucount;
 204     data[i++] = index;
 205     (*env)->ReleasePrimitiveArrayCritical(env, jData, data, 0);
 206 }

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