root/ompi/mpi/java/c/mpi_GraphComm.c

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

DEFINITIONS

This source file includes following definitions.
  1. Java_mpi_GraphComm_init
  2. Java_mpi_GraphComm_getDims
  3. Java_mpi_GraphComm_getNeighbors
  4. Java_mpi_GraphComm_getDistGraphNeighbors
  5. Java_mpi_GraphComm_map

   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_GraphComm.c
  38  * Headerfile   : mpi_GraphComm.h
  39  * Author       : Xinying Li
  40  * Created      : Thu Apr  9 12:22:15 1998
  41  * Revision     : $Revision: 1.2 $
  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 #ifdef HAVE_TARGETCONDITIONALS_H
  49 #include <TargetConditionals.h>
  50 #endif
  51 
  52 #include "mpi.h"
  53 #include "mpi_GraphComm.h"
  54 #include "mpiJava.h"
  55 
  56 JNIEXPORT void JNICALL Java_mpi_GraphComm_init(JNIEnv *env, jclass clazz)
  57 {
  58     ompi_java.GraphParmsInit = (*env)->GetMethodID(env,
  59             ompi_java.GraphParmsClass, "<init>", "([I[I)V");
  60     ompi_java.DistGraphNeighborsInit = (*env)->GetMethodID(env,
  61             ompi_java.DistGraphNeighborsClass, "<init>", "([I[I[I[IZ)V");
  62 }
  63 
  64 JNIEXPORT jobject JNICALL Java_mpi_GraphComm_getDims(
  65         JNIEnv *env, jobject jthis, jlong comm)
  66 {
  67     int maxInd, maxEdg;
  68     int rc = MPI_Graphdims_get((MPI_Comm)comm, &maxInd, &maxEdg);
  69 
  70     if(ompi_java_exceptionCheck(env, rc))
  71         return NULL;
  72 
  73     jintArray index = (*env)->NewIntArray(env, maxInd),
  74               edges = (*env)->NewIntArray(env, maxEdg);
  75 
  76     jint *jIndex, *jEdges;
  77     int  *cIndex, *cEdges;
  78     ompi_java_getIntArray(env, index, &jIndex, &cIndex);
  79     ompi_java_getIntArray(env, edges, &jEdges, &cEdges);
  80 
  81     rc = MPI_Graph_get((MPI_Comm)comm, maxInd, maxEdg, cIndex, cEdges);
  82     ompi_java_exceptionCheck(env, rc);
  83 
  84     ompi_java_releaseIntArray(env, index, jIndex, cIndex);
  85     ompi_java_releaseIntArray(env, edges, jEdges, cEdges);
  86 
  87     return (*env)->NewObject(env, ompi_java.GraphParmsClass,
  88                              ompi_java.GraphParmsInit, index, edges);
  89 }
  90 
  91 JNIEXPORT jintArray JNICALL Java_mpi_GraphComm_getNeighbors(
  92         JNIEnv *env, jobject jthis, jlong comm, jint rank)
  93 {
  94     int maxNs;
  95     int rc = MPI_Graph_neighbors_count((MPI_Comm)comm, rank, &maxNs);
  96 
  97     if(ompi_java_exceptionCheck(env, rc))
  98         return NULL;
  99 
 100     jintArray neighbors = (*env)->NewIntArray(env, maxNs);
 101     jint *jNeighbors;
 102     int  *cNeighbors;
 103     ompi_java_getIntArray(env, neighbors, &jNeighbors, &cNeighbors);
 104 
 105     rc = MPI_Graph_neighbors((MPI_Comm)comm, rank, maxNs, cNeighbors);
 106     ompi_java_exceptionCheck(env, rc);
 107 
 108     ompi_java_releaseIntArray(env, neighbors, jNeighbors, cNeighbors);
 109     return neighbors;
 110 }
 111 
 112 JNIEXPORT jobject JNICALL Java_mpi_GraphComm_getDistGraphNeighbors(
 113         JNIEnv *env, jobject jthis, jlong comm)
 114 {
 115     int inDegree, outDegree, weighted;
 116 
 117     int rc = MPI_Dist_graph_neighbors_count(
 118              (MPI_Comm)comm, &inDegree, &outDegree, &weighted);
 119 
 120     if(ompi_java_exceptionCheck(env, rc))
 121         return NULL;
 122 
 123     jintArray sources      = (*env)->NewIntArray(env, inDegree),
 124               srcWeights   = (*env)->NewIntArray(env, inDegree),
 125               destinations = (*env)->NewIntArray(env, outDegree),
 126               destWeights  = (*env)->NewIntArray(env, outDegree);
 127 
 128     jint *jSources, *jSrcWeights, *jDestinations, *jDestWeights;
 129     int  *cSources, *cSrcWeights, *cDestinations, *cDestWeights;
 130 
 131     ompi_java_getIntArray(env, sources,      &jSources,      &cSources);
 132     ompi_java_getIntArray(env, srcWeights,   &jSrcWeights,   &cSrcWeights);
 133     ompi_java_getIntArray(env, destinations, &jDestinations, &cDestinations);
 134     ompi_java_getIntArray(env, destWeights,  &jDestWeights,  &cDestWeights);
 135 
 136     rc = MPI_Dist_graph_neighbors((MPI_Comm)comm,
 137             inDegree, cSources, cSrcWeights,
 138             outDegree, cDestinations, cDestWeights);
 139 
 140     ompi_java_exceptionCheck(env, rc);
 141     ompi_java_releaseIntArray(env, sources,      jSources,      cSources);
 142     ompi_java_releaseIntArray(env, srcWeights,   jSrcWeights,   cSrcWeights);
 143     ompi_java_releaseIntArray(env, destinations, jDestinations, cDestinations);
 144     ompi_java_releaseIntArray(env, destWeights,  jDestWeights,  cDestWeights);
 145 
 146     return (*env)->NewObject(env,
 147            ompi_java.DistGraphNeighborsClass, ompi_java.DistGraphNeighborsInit,
 148            sources, srcWeights, destinations, destWeights,
 149            weighted ? JNI_TRUE : JNI_FALSE);
 150 }
 151 
 152 JNIEXPORT jint JNICALL Java_mpi_GraphComm_map(
 153         JNIEnv *env, jobject jthis, jlong comm,
 154         jintArray index, jintArray edges)
 155 {
 156     int nNodes = (*env)->GetArrayLength(env, index);
 157     jint *jIndex, *jEdges;
 158     int  *cIndex, *cEdges;
 159     ompi_java_getIntArray(env, index, &jIndex, &cIndex);
 160     ompi_java_getIntArray(env, edges, &jEdges, &cEdges);
 161 
 162     int newrank;
 163     int rc = MPI_Graph_map((MPI_Comm)comm, nNodes, cIndex, cEdges, &newrank);
 164     ompi_java_exceptionCheck(env, rc);
 165 
 166     ompi_java_releaseIntArray(env, index, jIndex, cIndex);
 167     ompi_java_releaseIntArray(env, edges, jEdges, cEdges);
 168     return newrank;
 169 }

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