root/ompi/mpi/java/c/mpi_CartComm.c

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

DEFINITIONS

This source file includes following definitions.
  1. Java_mpi_CartComm_init
  2. Java_mpi_CartComm_getTopo
  3. Java_mpi_CartComm_shift
  4. Java_mpi_CartComm_getCoords
  5. Java_mpi_CartComm_map
  6. Java_mpi_CartComm_getRank
  7. Java_mpi_CartComm_sub
  8. Java_mpi_CartComm_createDims_1jni

   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_CartComm.c
  38  * Headerfile   : mpi_CartComm.h
  39  * Author       : Sung-Hoon Ko, Xinying Li
  40  * Created      : Thu Apr  9 12:22:15 1998
  41  * Revision     : $Revision: 1.6 $
  42  * Updated      : $Date: 2003/01/16 16:39:34 $
  43  * Copyright: Northeast Parallel Architectures Center
  44  *            at Syracuse University 1998
  45  */
  46 #include "ompi_config.h"
  47 
  48 #include <stdlib.h>
  49 #ifdef HAVE_TARGETCONDITIONALS_H
  50 #include <TargetConditionals.h>
  51 #endif
  52 
  53 #include "mpi.h"
  54 #include "mpi_CartComm.h"
  55 #include "mpiJava.h"
  56 
  57 JNIEXPORT void JNICALL Java_mpi_CartComm_init(JNIEnv *env, jclass clazz)
  58 {
  59     ompi_java.CartParmsInit = (*env)->GetMethodID(env,
  60             ompi_java.CartParmsClass, "<init>", "([I[Z[I)V");
  61 
  62     ompi_java.ShiftParmsInit = (*env)->GetMethodID(env,
  63             ompi_java.ShiftParmsClass, "<init>", "(II)V");
  64 }
  65 
  66 JNIEXPORT jobject JNICALL Java_mpi_CartComm_getTopo(
  67         JNIEnv *env, jobject jthis, jlong comm)
  68 {
  69     int maxdims;
  70     int rc = MPI_Cartdim_get((MPI_Comm)comm, &maxdims);
  71 
  72     if(ompi_java_exceptionCheck(env, rc))
  73         return NULL;
  74 
  75     jintArray     dims    = (*env)->NewIntArray(env, maxdims);
  76     jbooleanArray periods = (*env)->NewBooleanArray(env, maxdims);
  77     jintArray     coords  = (*env)->NewIntArray(env, maxdims);
  78 
  79     if(maxdims != 0)
  80     {
  81         jint *jDims, *jCoords;
  82         jboolean *jPeriods;
  83         int  *cDims, *cCoords, *cPeriods;
  84 
  85         ompi_java_getIntArray(env, dims, &jDims, &cDims);
  86         ompi_java_getIntArray(env, coords, &jCoords, &cCoords);
  87         ompi_java_getBooleanArray(env, periods, &jPeriods, &cPeriods);
  88 
  89         rc = MPI_Cart_get((MPI_Comm)comm, maxdims, cDims, cPeriods, cCoords);
  90         ompi_java_exceptionCheck(env, rc);
  91 
  92         ompi_java_releaseIntArray(env, dims, jDims, cDims);
  93         ompi_java_releaseIntArray(env, coords, jCoords, cCoords);
  94         ompi_java_releaseBooleanArray(env, periods, jPeriods, cPeriods);
  95     }
  96 
  97     return (*env)->NewObject(env, ompi_java.CartParmsClass,
  98                              ompi_java.CartParmsInit, dims, periods, coords);
  99 }
 100 
 101 JNIEXPORT jobject JNICALL Java_mpi_CartComm_shift(
 102         JNIEnv *env, jobject jthis, jlong comm, jint direction, jint disp)
 103 {
 104     int sr, dr;
 105     int rc = MPI_Cart_shift((MPI_Comm)comm, direction, disp, &sr, &dr);
 106     ompi_java_exceptionCheck(env, rc);
 107 
 108     return (*env)->NewObject(env, ompi_java.ShiftParmsClass,
 109                              ompi_java.ShiftParmsInit, sr, dr);
 110 }
 111 
 112 JNIEXPORT jintArray JNICALL Java_mpi_CartComm_getCoords(
 113         JNIEnv *env, jobject jthis, jlong comm, jint rank)
 114 {
 115     int maxdims;
 116     int rc = MPI_Cartdim_get((MPI_Comm)comm, &maxdims);
 117 
 118     if(ompi_java_exceptionCheck(env, rc))
 119         return NULL;
 120 
 121     jintArray coords = (*env)->NewIntArray(env, maxdims);
 122     jint *jCoords;
 123     int  *cCoords;
 124     ompi_java_getIntArray(env, coords, &jCoords, &cCoords);
 125 
 126     rc = MPI_Cart_coords((MPI_Comm)comm, rank, maxdims, cCoords);
 127     ompi_java_exceptionCheck(env, rc);
 128 
 129     ompi_java_releaseIntArray(env, coords, jCoords, cCoords);
 130     return coords;
 131 }
 132 
 133 JNIEXPORT jint JNICALL Java_mpi_CartComm_map(
 134         JNIEnv *env, jobject jthis, jlong comm,
 135         jintArray dims, jbooleanArray periods)
 136 {
 137     int nDims = (*env)->GetArrayLength(env, dims);
 138     jint *jDims;
 139     jboolean *jPeriods;
 140     int *cDims, *cPeriods;
 141     ompi_java_getIntArray(env, dims, &jDims, &cDims);
 142     ompi_java_getBooleanArray(env, periods, &jPeriods, &cPeriods);
 143 
 144     int newrank;
 145     int rc = MPI_Cart_map((MPI_Comm)comm, nDims, cDims, cPeriods, &newrank);
 146     ompi_java_exceptionCheck(env, rc);
 147 
 148     ompi_java_forgetIntArray(env, dims, jDims, cDims);
 149     ompi_java_forgetBooleanArray(env, periods, jPeriods, cPeriods);
 150     return newrank;
 151 }
 152 
 153 JNIEXPORT jint JNICALL Java_mpi_CartComm_getRank(
 154         JNIEnv *env, jobject jthis, jlong comm, jintArray coords)
 155 {
 156     jint *jCoords;
 157     int  *cCoords;
 158     ompi_java_getIntArray(env, coords, &jCoords, &cCoords);
 159 
 160     int rank;
 161     int rc = MPI_Cart_rank((MPI_Comm)comm, cCoords, &rank);
 162     ompi_java_exceptionCheck(env, rc);
 163 
 164     ompi_java_forgetIntArray(env, coords, jCoords, cCoords);
 165     return rank;
 166 }
 167 
 168 JNIEXPORT jlong JNICALL Java_mpi_CartComm_sub(
 169         JNIEnv *env, jobject jthis, jlong comm, jbooleanArray remainDims)
 170 {
 171     jboolean *jRemainDims;
 172     int      *cRemainDims;
 173     ompi_java_getBooleanArray(env, remainDims, &jRemainDims, &cRemainDims);
 174 
 175     MPI_Comm newcomm;
 176     int rc = MPI_Cart_sub((MPI_Comm)comm, cRemainDims, &newcomm);
 177     ompi_java_exceptionCheck(env, rc);
 178 
 179     ompi_java_forgetBooleanArray(env, remainDims, jRemainDims, cRemainDims);
 180     return (jlong)newcomm;
 181 }
 182 
 183 JNIEXPORT void JNICALL Java_mpi_CartComm_createDims_1jni(
 184         JNIEnv *env, jclass jthis, jint nNodes, jintArray dims)
 185 {
 186     int   nDims = (*env)->GetArrayLength(env, dims);
 187     jint *jDims;
 188     int  *cDims;
 189     ompi_java_getIntArray(env, dims, &jDims, &cDims);
 190 
 191     int rc = MPI_Dims_create(nNodes, nDims, cDims);
 192     ompi_java_exceptionCheck(env, rc);
 193     ompi_java_releaseIntArray(env, dims, jDims, cDims);
 194 }

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