root/ompi/mpi/java/c/mpi_Intracomm.c

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

DEFINITIONS

This source file includes following definitions.
  1. Java_mpi_Intracomm_split
  2. Java_mpi_Intracomm_splitType
  3. Java_mpi_Intracomm_create
  4. Java_mpi_Intracomm_createGroup
  5. Java_mpi_Intracomm_createCart
  6. Java_mpi_Intracomm_createGraph
  7. Java_mpi_Intracomm_createDistGraph
  8. Java_mpi_Intracomm_createDistGraphAdjacent
  9. Java_mpi_Intracomm_scan
  10. Java_mpi_Intracomm_iScan
  11. Java_mpi_Intracomm_exScan
  12. Java_mpi_Intracomm_iExScan
  13. Java_mpi_Intracomm_openPort
  14. Java_mpi_Intracomm_closePort_1jni
  15. Java_mpi_Intracomm_accept
  16. Java_mpi_Intracomm_connect
  17. Java_mpi_Intracomm_publishName
  18. Java_mpi_Intracomm_unpublishName
  19. Java_mpi_Intracomm_lookupName
  20. Java_mpi_Intracomm_spawn
  21. Java_mpi_Intracomm_spawnMultiple

   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  * This file is almost a complete re-write for Open MPI compared to the
  22  * original mpiJava package. Its license and copyright are listed below.
  23  * See <path to ompi/mpi/java/README> for more information.
  24  */
  25 /*
  26     Licensed under the Apache License, Version 2.0 (the "License");
  27     you may not use this file except in compliance with the License.
  28     You may obtain a copy of the License at
  29 
  30        http://www.apache.org/licenses/LICENSE-2.0
  31 
  32     Unless required by applicable law or agreed to in writing, software
  33     distributed under the License is distributed on an "AS IS" BASIS,
  34     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  35     See the License for the specific language governing permissions and
  36     limitations under the License.
  37 */
  38 /*
  39  * File         : mpi_Intracomm.c
  40  * Headerfile   : mpi_Intracomm.h
  41  * Author       : Xinying Li, Bryan Carpenter
  42  * Created      : Thu Apr  9 12:22:15 1998
  43  * Revision     : $Revision: 1.10 $
  44  * Updated      : $Date: 2003/01/16 16:39:34 $
  45  * Copyright: Northeast Parallel Architectures Center
  46  *            at Syracuse University 1998
  47  */
  48 
  49 #include "ompi_config.h"
  50 
  51 #include <stdlib.h>
  52 #include <string.h>
  53 #ifdef HAVE_TARGETCONDITIONALS_H
  54 #include <TargetConditionals.h>
  55 #endif
  56 
  57 #include "mpi.h"
  58 #include "mpi_Comm.h"
  59 #include "mpi_Intracomm.h"
  60 #include "mpiJava.h"
  61 
  62 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_split(
  63         JNIEnv *env, jobject jthis, jlong comm, jint colour, jint key)
  64 {
  65     MPI_Comm newcomm;
  66     int rc = MPI_Comm_split((MPI_Comm)comm, colour, key, &newcomm);
  67     ompi_java_exceptionCheck(env, rc);
  68     return (jlong)newcomm;
  69 }
  70 
  71 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_splitType(
  72         JNIEnv *env, jobject jthis, jlong comm, jint splitType, jint key, jlong info)
  73 {
  74     MPI_Comm newcomm;
  75     int rc = MPI_Comm_split_type((MPI_Comm)comm, splitType, key, (MPI_Info)info, &newcomm);
  76     ompi_java_exceptionCheck(env, rc);
  77     return (jlong)newcomm;
  78 }
  79 
  80 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_create(
  81         JNIEnv *env, jobject jthis, jlong comm, jlong group)
  82 {
  83     MPI_Comm newcomm;
  84     int rc = MPI_Comm_create((MPI_Comm)comm, (MPI_Group)group, &newcomm);
  85     ompi_java_exceptionCheck(env, rc);
  86     return (jlong)newcomm;
  87 }
  88 
  89 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_createGroup(
  90         JNIEnv *env, jobject jthis, jlong comm, jlong group, int tag)
  91 {
  92     MPI_Comm newcomm;
  93     int rc = MPI_Comm_create_group((MPI_Comm)comm, (MPI_Group)group, tag, &newcomm);
  94     ompi_java_exceptionCheck(env, rc);
  95     return (jlong)newcomm;
  96 }
  97 
  98 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_createCart(
  99         JNIEnv *env, jobject jthis, jlong comm,
 100         jintArray dims, jbooleanArray periods, jboolean reorder)
 101 {
 102     jint *jDims;
 103     int  *cDims;
 104     ompi_java_getIntArray(env, dims, &jDims, &cDims);
 105 
 106     jboolean *jPeriods;
 107     int      *cPeriods;
 108     ompi_java_getBooleanArray(env, periods, &jPeriods, &cPeriods);
 109 
 110     int ndims = (*env)->GetArrayLength(env, dims);
 111     MPI_Comm cart;
 112 
 113     int rc = MPI_Cart_create((MPI_Comm)comm, ndims, cDims,
 114                              cPeriods, reorder, &cart);
 115 
 116     ompi_java_exceptionCheck(env, rc);
 117     ompi_java_forgetIntArray(env, dims, jDims, cDims);
 118     ompi_java_forgetBooleanArray(env, periods, jPeriods, cPeriods);
 119     return (jlong)cart;
 120 }
 121 
 122 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_createGraph(
 123         JNIEnv *env, jobject jthis, jlong comm,
 124         jintArray index, jintArray edges, jboolean reorder)
 125 {
 126     MPI_Comm graph;
 127     int nnodes = (*env)->GetArrayLength(env, index);
 128 
 129     jint *jIndex, *jEdges;
 130     int  *cIndex, *cEdges;
 131     ompi_java_getIntArray(env, index, &jIndex, &cIndex);
 132     ompi_java_getIntArray(env, edges, &jEdges, &cEdges);
 133 
 134     int rc = MPI_Graph_create((MPI_Comm)comm,
 135              nnodes, cIndex, cEdges, reorder, &graph);
 136 
 137     ompi_java_exceptionCheck(env, rc);
 138     ompi_java_forgetIntArray(env, index, jIndex, cIndex);
 139     ompi_java_forgetIntArray(env, edges, jEdges, cEdges);
 140     return (jlong)graph;
 141 }
 142 
 143 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_createDistGraph(
 144         JNIEnv *env, jobject jthis, jlong comm, jintArray sources,
 145         jintArray degrees, jintArray destins, jintArray weights,
 146         jlong info, jboolean reorder, jboolean weighted)
 147 {
 148     MPI_Comm graph;
 149     int nnodes = (*env)->GetArrayLength(env, sources);
 150 
 151     jint *jSources, *jDegrees, *jDestins, *jWeights = NULL;
 152     int  *cSources, *cDegrees, *cDestins, *cWeights = MPI_UNWEIGHTED;
 153     ompi_java_getIntArray(env, sources, &jSources, &cSources);
 154     ompi_java_getIntArray(env, degrees, &jDegrees, &cDegrees);
 155     ompi_java_getIntArray(env, destins, &jDestins, &cDestins);
 156 
 157     if(weighted)
 158         ompi_java_getIntArray(env, weights, &jWeights, &cWeights);
 159 
 160     int rc = MPI_Dist_graph_create((MPI_Comm)comm,
 161              nnodes, cSources, cDegrees, cDestins, cWeights,
 162              (MPI_Info)info, reorder, &graph);
 163 
 164     ompi_java_exceptionCheck(env, rc);
 165     ompi_java_forgetIntArray(env, sources, jSources, cSources);
 166     ompi_java_forgetIntArray(env, degrees, jDegrees, cDegrees);
 167     ompi_java_forgetIntArray(env, destins, jDestins, cDestins);
 168 
 169     if(weighted)
 170         ompi_java_forgetIntArray(env, weights, jWeights, cWeights);
 171 
 172     return (jlong)graph;
 173 }
 174 
 175 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_createDistGraphAdjacent(
 176         JNIEnv *env, jobject jthis, jlong comm, jintArray sources,
 177         jintArray srcWeights, jintArray destins, jintArray desWeights,
 178         jlong info, jboolean reorder, jboolean weighted)
 179 {
 180     MPI_Comm graph;
 181 
 182     int inDegree  = (*env)->GetArrayLength(env, sources),
 183         outDegree = (*env)->GetArrayLength(env, destins);
 184 
 185     jint *jSources, *jDestins, *jSrcWeights, *jDesWeights;
 186     int  *cSources, *cDestins, *cSrcWeights, *cDesWeights;
 187     ompi_java_getIntArray(env, sources, &jSources, &cSources);
 188     ompi_java_getIntArray(env, destins, &jDestins, &cDestins);
 189 
 190     if(weighted)
 191     {
 192         ompi_java_getIntArray(env, srcWeights, &jSrcWeights, &cSrcWeights);
 193         ompi_java_getIntArray(env, desWeights, &jDesWeights, &cDesWeights);
 194     }
 195     else
 196     {
 197         jSrcWeights = jDesWeights = NULL;
 198         cSrcWeights = cDesWeights = MPI_UNWEIGHTED;
 199     }
 200 
 201     int rc = MPI_Dist_graph_create_adjacent((MPI_Comm)comm,
 202              inDegree, cSources, cSrcWeights, outDegree, cDestins,
 203              cDesWeights, (MPI_Info)info, reorder, &graph);
 204 
 205     ompi_java_exceptionCheck(env, rc);
 206     ompi_java_forgetIntArray(env, sources, jSources, cSources);
 207     ompi_java_forgetIntArray(env, destins, jDestins, cDestins);
 208 
 209     if(weighted)
 210     {
 211         ompi_java_forgetIntArray(env, srcWeights, jSrcWeights, cSrcWeights);
 212         ompi_java_forgetIntArray(env, desWeights, jDesWeights, cDesWeights);
 213     }
 214 
 215     return (jlong)graph;
 216 }
 217 
 218 JNIEXPORT void JNICALL Java_mpi_Intracomm_scan(
 219         JNIEnv *env, jobject jthis, jlong jComm,
 220         jobject sBuf, jboolean sdb, jint sOff,
 221         jobject rBuf, jboolean rdb, jint rOff, jint count,
 222         jlong jType, jint bType, jobject jOp, jlong hOp)
 223 {
 224     MPI_Comm     comm = (MPI_Comm)jComm;
 225     MPI_Datatype type = (MPI_Datatype)jType;
 226 
 227     void *sPtr, *rPtr;
 228     ompi_java_buffer_t *sItem, *rItem;
 229 
 230     if(sBuf == NULL)
 231     {
 232         sPtr = MPI_IN_PLACE;
 233         ompi_java_getReadPtr(&rPtr,&rItem,env,rBuf,rdb,rOff,count,type,bType);
 234     }
 235     else
 236     {
 237         ompi_java_getReadPtr(&sPtr,&sItem,env,sBuf,sdb,sOff,count,type,bType);
 238         ompi_java_getWritePtr(&rPtr, &rItem, env, rBuf, rdb, count, type);
 239     }
 240 
 241     MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, bType);
 242     int rc = MPI_Scan(sPtr, rPtr, count, type, op, comm);
 243     ompi_java_exceptionCheck(env, rc);
 244 
 245     if(sBuf != NULL)
 246         ompi_java_releaseReadPtr(sPtr, sItem, sBuf, sdb);
 247 
 248     ompi_java_releaseWritePtr(rPtr,rItem,env,rBuf,rdb,rOff,count,type,bType);
 249 }
 250 
 251 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_iScan(
 252         JNIEnv *env, jobject jthis, jlong comm,
 253         jobject sendBuf, jobject recvBuf, jint count,
 254         jlong type, int baseType, jobject jOp, jlong hOp)
 255 {
 256     void *sPtr, *rPtr;
 257     MPI_Request request;
 258 
 259     if(sendBuf == NULL)
 260         sPtr = MPI_IN_PLACE;
 261     else
 262         sPtr = (*env)->GetDirectBufferAddress(env, sendBuf);
 263 
 264     rPtr = (*env)->GetDirectBufferAddress(env, recvBuf);
 265 
 266     int rc = MPI_Iscan(sPtr, rPtr, count, (MPI_Datatype)type,
 267                        ompi_java_op_getHandle(env, jOp, hOp, baseType),
 268                        (MPI_Comm)comm, &request);
 269 
 270     ompi_java_exceptionCheck(env, rc);
 271     return (jlong)request;
 272 }
 273 
 274 JNIEXPORT void JNICALL Java_mpi_Intracomm_exScan(
 275         JNIEnv *env, jobject jthis, jlong jComm,
 276         jobject sBuf, jboolean sdb, jint sOff,
 277         jobject rBuf, jboolean rdb, jint rOff, jint count,
 278         jlong jType, int bType, jobject jOp, jlong hOp)
 279 {
 280     MPI_Comm     comm = (MPI_Comm)jComm;
 281     MPI_Datatype type = (MPI_Datatype)jType;
 282 
 283     void *sPtr, *rPtr;
 284     ompi_java_buffer_t *sItem, *rItem;
 285 
 286     if(sBuf == NULL)
 287     {
 288         sPtr = MPI_IN_PLACE;
 289         ompi_java_getReadPtr(&rPtr,&rItem,env,rBuf,rdb,rOff,count,type,bType);
 290     }
 291     else
 292     {
 293         ompi_java_getReadPtr(&sPtr,&sItem,env,sBuf,sdb,sOff,count,type,bType);
 294         ompi_java_getWritePtr(&rPtr, &rItem, env, rBuf, rdb, count, type);
 295     }
 296 
 297     MPI_Op op = ompi_java_op_getHandle(env, jOp, hOp, bType);
 298     int rc = MPI_Exscan(sPtr, rPtr, count, type, op, comm);
 299     ompi_java_exceptionCheck(env, rc);
 300 
 301     if(sBuf != NULL)
 302         ompi_java_releaseReadPtr(sPtr, sItem, sBuf, sdb);
 303 
 304     ompi_java_releaseWritePtr(rPtr,rItem,env,rBuf,rdb,rOff,count,type,bType);
 305 }
 306 
 307 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_iExScan(
 308         JNIEnv *env, jobject jthis, jlong comm,
 309         jobject sendBuf, jobject recvBuf, jint count,
 310         jlong type, int bType, jobject jOp, jlong hOp)
 311 {
 312     void *sPtr, *rPtr;
 313 
 314     if(sendBuf == NULL)
 315         sPtr = MPI_IN_PLACE;
 316     else
 317         sPtr = (*env)->GetDirectBufferAddress(env, sendBuf);
 318 
 319     rPtr = (*env)->GetDirectBufferAddress(env, recvBuf);
 320     MPI_Request request;
 321 
 322     int rc = MPI_Iexscan(sPtr, rPtr, count, (MPI_Datatype)type,
 323                          ompi_java_op_getHandle(env, jOp, hOp, bType),
 324                          (MPI_Comm)comm, &request);
 325 
 326     ompi_java_exceptionCheck(env, rc);
 327     return (jlong)request;
 328 }
 329 
 330 JNIEXPORT jstring JNICALL Java_mpi_Intracomm_openPort(
 331                           JNIEnv *env, jclass clazz, jlong info)
 332 {
 333     char port[MPI_MAX_PORT_NAME + 1];
 334     int rc = MPI_Open_port((MPI_Info)info, port);
 335 
 336     return ompi_java_exceptionCheck(env, rc)
 337            ? NULL : (*env)->NewStringUTF(env, port);
 338 }
 339 
 340 JNIEXPORT void JNICALL Java_mpi_Intracomm_closePort_1jni(
 341                        JNIEnv *env, jclass clazz, jstring jport)
 342 {
 343     const char *port = (*env)->GetStringUTFChars(env, jport, NULL);
 344     int rc = MPI_Close_port((char*)port);
 345     ompi_java_exceptionCheck(env, rc);
 346     (*env)->ReleaseStringUTFChars(env, jport, port);
 347 }
 348 
 349 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_accept(
 350         JNIEnv *env, jobject jthis, jlong comm,
 351         jstring jport, jlong info, jint root)
 352 {
 353     const char *port = jport == NULL ? NULL :
 354                        (*env)->GetStringUTFChars(env, jport, NULL);
 355     MPI_Comm newComm;
 356 
 357     int rc = MPI_Comm_accept((char*)port, (MPI_Info)info,
 358                              root, (MPI_Comm)comm, &newComm);
 359 
 360     ompi_java_exceptionCheck(env, rc);
 361 
 362     if(jport != NULL)
 363         (*env)->ReleaseStringUTFChars(env, jport, port);
 364 
 365     return (jlong)newComm;
 366 }
 367 
 368 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_connect(
 369         JNIEnv *env, jobject jthis, jlong comm,
 370         jstring jport, jlong info, jint root)
 371 {
 372     const char *port = jport == NULL ? NULL :
 373                        (*env)->GetStringUTFChars(env, jport, NULL);
 374     MPI_Comm newComm;
 375 
 376     int rc = MPI_Comm_connect((char*)port, (MPI_Info)info,
 377                               root, (MPI_Comm)comm, &newComm);
 378 
 379     ompi_java_exceptionCheck(env, rc);
 380 
 381     if(jport != NULL)
 382         (*env)->ReleaseStringUTFChars(env, jport, port);
 383 
 384     return (jlong)newComm;
 385 }
 386 
 387 JNIEXPORT void JNICALL Java_mpi_Intracomm_publishName(
 388         JNIEnv *env, jclass clazz, jstring jservice, jlong info, jstring jport)
 389 {
 390     const char *service = (*env)->GetStringUTFChars(env, jservice, NULL),
 391                *port    = (*env)->GetStringUTFChars(env, jport,    NULL);
 392 
 393     int rc = MPI_Publish_name((char*)service, (MPI_Info)info, (char*)port);
 394     ompi_java_exceptionCheck(env, rc);
 395 
 396     (*env)->ReleaseStringUTFChars(env, jservice, service);
 397     (*env)->ReleaseStringUTFChars(env, jport,    port);
 398 }
 399 
 400 JNIEXPORT void JNICALL Java_mpi_Intracomm_unpublishName(
 401         JNIEnv *env, jclass clazz, jstring jservice, jlong info, jstring jport)
 402 {
 403     const char *service = (*env)->GetStringUTFChars(env, jservice, NULL),
 404                *port    = (*env)->GetStringUTFChars(env, jport,    NULL);
 405 
 406     int rc = MPI_Unpublish_name((char*)service, (MPI_Info)info, (char*)port);
 407     ompi_java_exceptionCheck(env, rc);
 408 
 409     (*env)->ReleaseStringUTFChars(env, jservice, service);
 410     (*env)->ReleaseStringUTFChars(env, jport,    port);
 411 }
 412 
 413 JNIEXPORT jstring JNICALL Java_mpi_Intracomm_lookupName(
 414         JNIEnv *env, jclass clazz, jstring jservice, jlong info)
 415 {
 416     char port[MPI_MAX_PORT_NAME + 1];
 417     const char *service = (*env)->GetStringUTFChars(env, jservice, NULL);
 418 
 419     int rc = MPI_Lookup_name((char*)service, (MPI_Info)info, port);
 420     (*env)->ReleaseStringUTFChars(env, jservice, service);
 421 
 422     return ompi_java_exceptionCheck(env, rc)
 423            ? NULL : (*env)->NewStringUTF(env, port);
 424 }
 425 
 426 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_spawn(
 427         JNIEnv *env, jobject jthis, jlong comm, jstring jCommand,
 428         jobjectArray jArgv, jint maxprocs, jlong info, jint root,
 429         jintArray errCodes)
 430 {
 431     int i, rc;
 432     MPI_Comm intercomm;
 433     const char* command = (*env)->GetStringUTFChars(env, jCommand, NULL);
 434 
 435     jint *jErrCodes;
 436     int  *cErrCodes = MPI_ERRCODES_IGNORE;
 437 
 438     if(errCodes != NULL)
 439         ompi_java_getIntArray(env, errCodes, &jErrCodes, &cErrCodes);
 440 
 441     char **argv = MPI_ARGV_NULL;
 442 
 443     if(jArgv != NULL)
 444     {
 445         jsize argvLength = (*env)->GetArrayLength(env, jArgv);
 446         argv = (char**)calloc(argvLength + 1, sizeof(char*));
 447 
 448         for(i = 0; i < argvLength; i++)
 449         {
 450             jstring a = (*env)->GetObjectArrayElement(env, jArgv, i);
 451             argv[i] = strdup((*env)->GetStringUTFChars(env, a, NULL));
 452             (*env)->DeleteLocalRef(env, a);
 453         }
 454 
 455         argv[argvLength] = NULL;
 456     }
 457 
 458     rc = MPI_Comm_spawn((char*)command, argv, maxprocs, (MPI_Info)info,
 459                         root, (MPI_Comm)comm, &intercomm, cErrCodes);
 460 
 461     ompi_java_exceptionCheck(env, rc);
 462 
 463     if(jArgv != NULL)
 464     {
 465         jsize argvLength = (*env)->GetArrayLength(env, jArgv);
 466 
 467         for(i = 0; i < argvLength; i++)
 468         {
 469             jstring a = (*env)->GetObjectArrayElement(env, jArgv, i);
 470             (*env)->ReleaseStringUTFChars(env, a, argv[i]);
 471             (*env)->DeleteLocalRef(env, a);
 472         }
 473 
 474         free(argv);
 475     }
 476 
 477     if(errCodes != NULL)
 478         ompi_java_releaseIntArray(env, errCodes, jErrCodes, cErrCodes);
 479 
 480     (*env)->ReleaseStringUTFChars(env, jCommand, command);
 481     return (jlong)intercomm;
 482 }
 483 
 484 JNIEXPORT jlong JNICALL Java_mpi_Intracomm_spawnMultiple(
 485         JNIEnv *env, jobject jthis, jlong comm, jobjectArray jCommands,
 486         jobjectArray jArgv, jintArray maxProcs, jlongArray info,
 487         jint root, jintArray errCodes)
 488 {
 489     int i, rc;
 490     MPI_Comm intercomm;
 491     jlong *jInfo = (*env)->GetLongArrayElements(env, info, NULL);
 492 
 493     jint *jMaxProcs, *jErrCodes;
 494     int  *cMaxProcs, *cErrCodes = MPI_ERRCODES_IGNORE;
 495     ompi_java_getIntArray(env, maxProcs, &jMaxProcs, &cMaxProcs);
 496 
 497     if(errCodes != NULL)
 498         ompi_java_getIntArray(env, errCodes, &jErrCodes, &cErrCodes);
 499 
 500     int commandsLength = (*env)->GetArrayLength(env, jCommands),
 501         infoLength     = (*env)->GetArrayLength(env, info);
 502 
 503     char **commands = calloc(commandsLength, sizeof(char*)),
 504          ***argv    = MPI_ARGVS_NULL;
 505     MPI_Info *cInfo = calloc(infoLength, sizeof(MPI_Info));
 506 
 507     for(i = 0; i < infoLength; i++)
 508         cInfo[i] = (MPI_Info)jInfo[i];
 509 
 510     for(i = 0; i < commandsLength; i++)
 511     {
 512         jstring a = (*env)->GetObjectArrayElement(env, jCommands, i);
 513         commands[i] = (char*)(*env)->GetStringUTFChars(env, a, NULL);
 514         (*env)->DeleteLocalRef(env, a);
 515     }
 516 
 517     if(jArgv != NULL)
 518     {
 519         int argvLength = (*env)->GetArrayLength(env, jArgv);
 520         argv = calloc(argvLength, sizeof(char**));
 521 
 522         for(i = 0; i < argvLength; i++)
 523         {
 524             jobjectArray arr = (*env)->GetObjectArrayElement(env, jArgv, i);
 525             int j, length = (*env)->GetArrayLength(env, arr);
 526             argv[i] = calloc(length + 1, sizeof(char*));
 527 
 528             for(j = 0; j < length; j++)
 529             {
 530                 jstring a = (*env)->GetObjectArrayElement(env, arr, j);
 531                 argv[i][j] = (char*)(*env)->GetStringUTFChars(env, a, NULL);
 532                 (*env)->DeleteLocalRef(env, a);
 533             }
 534 
 535             argv[i][length] = NULL;
 536             (*env)->DeleteLocalRef(env, arr);
 537         }
 538     }
 539 
 540     rc = MPI_Comm_spawn_multiple(
 541             commandsLength, commands, argv, cMaxProcs, cInfo,
 542             root, (MPI_Comm)comm, &intercomm, cErrCodes);
 543 
 544     ompi_java_exceptionCheck(env, rc);
 545 
 546     if(jArgv != NULL)
 547     {
 548         int argvLength = (*env)->GetArrayLength(env, jArgv);
 549 
 550         for(i = 0; i < argvLength; i++)
 551         {
 552             jobjectArray arr = (*env)->GetObjectArrayElement(env, jArgv, i);
 553             int j, length = (*env)->GetArrayLength(env, arr);
 554 
 555             for(j = 0; j < length; j++)
 556             {
 557                 jstring a = (*env)->GetObjectArrayElement(env, arr, j);
 558                 (*env)->ReleaseStringUTFChars(env, a, argv[i][j]);
 559                 (*env)->DeleteLocalRef(env, a);
 560             }
 561 
 562             (*env)->DeleteLocalRef(env, arr);
 563             free(argv[i]);
 564         }
 565 
 566         free(argv);
 567     }
 568 
 569     for(i = 0; i < commandsLength; i++)
 570     {
 571         jstring a = (*env)->GetObjectArrayElement(env, jCommands, i);
 572         (*env)->ReleaseStringUTFChars(env, a, commands[i]);
 573         (*env)->DeleteLocalRef(env, a);
 574     }
 575 
 576     if(errCodes != NULL)
 577         ompi_java_releaseIntArray(env, errCodes, jErrCodes, cErrCodes);
 578 
 579     free(cInfo);
 580     free(commands);
 581     (*env)->ReleaseLongArrayElements(env, info, jInfo, JNI_ABORT);
 582     ompi_java_forgetIntArray(env, maxProcs, jMaxProcs, cMaxProcs);
 583     return (jlong)intercomm;
 584 }

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