This source file includes following definitions.
- Java_mpi_GraphComm_init
- Java_mpi_GraphComm_getDims
- Java_mpi_GraphComm_getNeighbors
- Java_mpi_GraphComm_getDistGraphNeighbors
- Java_mpi_GraphComm_map
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  23 
  24 
  25 
  26 
  27 
  28 
  29 
  30 
  31 
  32 
  33 
  34 
  35 
  36 
  37 
  38 
  39 
  40 
  41 
  42 
  43 
  44 
  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 }