root/ompi/mpi/java/c/mpi_Request.c

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

DEFINITIONS

This source file includes following definitions.
  1. Java_mpi_Request_init
  2. setIndices
  3. newStatuses
  4. newStatusesIndices
  5. Java_mpi_Request_getNull
  6. Java_mpi_Request_cancel
  7. Java_mpi_Request_free
  8. Java_mpi_Request_waitStatus
  9. Java_mpi_Request_waitFor
  10. Java_mpi_Request_testStatus
  11. Java_mpi_Request_getStatus
  12. Java_mpi_Request_test
  13. Java_mpi_Request_waitAnyStatus
  14. Java_mpi_Request_waitAny
  15. Java_mpi_Request_testAnyStatus
  16. Java_mpi_Request_testAny
  17. Java_mpi_Request_waitAllStatus
  18. Java_mpi_Request_waitAll
  19. Java_mpi_Request_testAllStatus
  20. Java_mpi_Request_testAll
  21. Java_mpi_Request_waitSomeStatus
  22. Java_mpi_Request_waitSome
  23. Java_mpi_Request_testSomeStatus
  24. Java_mpi_Request_testSome

   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) 2016      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_Request.c
  40  * Headerfile   : mpi_Request.h
  41  * Author       : Sung-Hoon Ko, Xinying Li, Bryan Carpenter
  42  * Created      : Thu Apr  9 12:22:15 1998
  43  * Revision     : $Revision: 1.11 $
  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 #include <stdlib.h>
  51 #include <assert.h>
  52 #ifdef HAVE_TARGETCONDITIONALS_H
  53 #include <TargetConditionals.h>
  54 #endif
  55 
  56 #include "mpi.h"
  57 #include "mpi_Request.h"
  58 #include "mpiJava.h"
  59 
  60 JNIEXPORT void JNICALL Java_mpi_Request_init(JNIEnv *env, jclass c)
  61 {
  62     ompi_java.ReqHandle = (*env)->GetFieldID(env, c, "handle", "J");
  63 }
  64 
  65 static void setIndices(JNIEnv *env, jintArray indices, int *cIdx, int count)
  66 {
  67     jint *jIdx;
  68 
  69     if(sizeof(int) == sizeof(jint))
  70     {
  71         jIdx = cIdx;
  72     }
  73     else
  74     {
  75         jIdx = (jint*)calloc(count, sizeof(jint));
  76         int i;
  77 
  78         for(i = 0; i < count; i++)
  79             jIdx[i] = cIdx[i];
  80     }
  81 
  82     (*env)->SetIntArrayRegion(env, indices, 0, count, jIdx);
  83 
  84     if(jIdx != cIdx)
  85         free(jIdx);
  86 }
  87 
  88 static jobjectArray newStatuses(JNIEnv *env, MPI_Status *statuses, int count)
  89 {
  90     jobjectArray array = (*env)->NewObjectArray(env,
  91                          count, ompi_java.StatusClass, NULL);
  92     int i;
  93     for(i = 0; i < count; i++)
  94     {
  95         jobject st = ompi_java_status_new(env, statuses + i);
  96         (*env)->SetObjectArrayElement(env, array, i, st);
  97         (*env)->DeleteLocalRef(env, st);
  98     }
  99 
 100     return array;
 101 }
 102 
 103 static jobjectArray newStatusesIndices(
 104         JNIEnv *env, MPI_Status *statuses, int *indices, int count)
 105 {
 106     if(count < 0)
 107         return NULL;
 108 
 109     jobjectArray array = (*env)->NewObjectArray(env,
 110                          count, ompi_java.StatusClass, NULL);
 111     int i;
 112     for(i = 0; i < count; i++)
 113     {
 114         jobject st = ompi_java_status_newIndex(env, statuses + i, indices[i]);
 115         (*env)->SetObjectArrayElement(env, array, i, st);
 116         (*env)->DeleteLocalRef(env, st);
 117     }
 118 
 119     return array;
 120 }
 121 
 122 JNIEXPORT jlong JNICALL Java_mpi_Request_getNull(JNIEnv *env, jclass clazz)
 123 {
 124     return (jlong)MPI_REQUEST_NULL;
 125 }
 126 
 127 JNIEXPORT void JNICALL Java_mpi_Request_cancel(
 128         JNIEnv *env, jobject jthis, jlong handle)
 129 {
 130     MPI_Request req = (MPI_Request)handle;
 131     int rc = MPI_Cancel(&req);
 132     ompi_java_exceptionCheck(env, rc);
 133 }
 134 
 135 JNIEXPORT jlong JNICALL Java_mpi_Request_free(
 136         JNIEnv *env, jobject jthis, jlong handle)
 137 {
 138     MPI_Request req = (MPI_Request)handle;
 139     int rc = MPI_Request_free(&req);
 140     ompi_java_exceptionCheck(env, rc);
 141     return (jlong)req;
 142 }
 143 
 144 JNIEXPORT jlong JNICALL Java_mpi_Request_waitStatus(
 145         JNIEnv *env, jobject jthis, jlong handle, jlongArray stat)
 146 {
 147     MPI_Request req = (MPI_Request)handle;
 148     MPI_Status status;
 149     int rc = MPI_Wait(&req, &status);
 150     
 151     if(!ompi_java_exceptionCheck(env, rc))
 152         ompi_java_status_set(env, stat, &status);
 153     
 154     return (jlong)req;
 155 }
 156 
 157 JNIEXPORT jlong JNICALL Java_mpi_Request_waitFor(
 158         JNIEnv *env, jobject jthis, jlong handle)
 159 {
 160     MPI_Request req = (MPI_Request)handle;
 161     int rc = MPI_Wait(&req, MPI_STATUS_IGNORE);
 162     ompi_java_exceptionCheck(env, rc);
 163     return (jlong)req;
 164 }
 165 
 166 JNIEXPORT jobject JNICALL Java_mpi_Request_testStatus(
 167         JNIEnv *env, jobject jthis, jlong handle)
 168 {
 169     MPI_Request req = (MPI_Request)handle;
 170     int flag;
 171     MPI_Status status;
 172     int rc = MPI_Test(&req, &flag, &status);
 173     
 174     if(!ompi_java_exceptionCheck(env, rc))
 175         (*env)->SetLongField(env, jthis, ompi_java.ReqHandle, (jlong)req);
 176     
 177     return flag ? ompi_java_status_new(env, &status) : NULL;
 178 }
 179 
 180 JNIEXPORT jobject JNICALL Java_mpi_Request_getStatus(
 181         JNIEnv *env, jobject jthis, jlong handle)
 182 {
 183     MPI_Request req = (MPI_Request)handle;
 184     int flag;
 185     MPI_Status status;
 186     int rc = MPI_Request_get_status(req, &flag, &status);
 187     
 188     if(!ompi_java_exceptionCheck(env, rc))
 189         (*env)->SetLongField(env, jthis, ompi_java.ReqHandle, (jlong)req);
 190     
 191     return flag ? ompi_java_status_new(env, &status) : NULL;
 192 }
 193 
 194 JNIEXPORT jboolean JNICALL Java_mpi_Request_test(
 195         JNIEnv *env, jobject jthis, jlong handle)
 196 {
 197     MPI_Request req = (MPI_Request)handle;
 198     int flag;
 199     int rc = MPI_Test(&req, &flag, MPI_STATUS_IGNORE);
 200     
 201     if(!ompi_java_exceptionCheck(env, rc))
 202         (*env)->SetLongField(env, jthis, ompi_java.ReqHandle, (jlong)req);
 203     
 204     return flag ? JNI_TRUE : JNI_FALSE;
 205 }
 206 
 207 JNIEXPORT void JNICALL Java_mpi_Request_waitAnyStatus(
 208         JNIEnv *env, jclass clazz, jlongArray requests, jobject stat)
 209 {
 210     jboolean exception;
 211     int count = (*env)->GetArrayLength(env, requests);
 212     jlong* jReq;
 213     MPI_Request *cReq;
 214     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 215     int index;
 216     MPI_Status status;
 217     int rc = MPI_Waitany(count, cReq, &index, &status);
 218     exception = ompi_java_exceptionCheck(env, rc);
 219     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 220     
 221     if(!exception)
 222         ompi_java_status_setIndex(env, stat, &status, index);
 223 }
 224 
 225 JNIEXPORT jint JNICALL Java_mpi_Request_waitAny(
 226         JNIEnv *env, jclass clazz, jlongArray requests)
 227 {
 228     int count = (*env)->GetArrayLength(env, requests);
 229     jlong* jReq;
 230     MPI_Request *cReq;
 231     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 232     int index;
 233     int rc = MPI_Waitany(count, cReq, &index, MPI_STATUS_IGNORE);
 234     ompi_java_exceptionCheck(env, rc);
 235     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 236     return index;
 237 }
 238 
 239 JNIEXPORT jobject JNICALL Java_mpi_Request_testAnyStatus(
 240         JNIEnv *env, jclass clazz, jlongArray requests)
 241 {
 242     int count = (*env)->GetArrayLength(env, requests);
 243     jlong* jReq;
 244     MPI_Request *cReq;
 245     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 246     int index, flag;
 247     MPI_Status status;
 248     int rc = MPI_Testany(count, cReq, &index, &flag, &status);
 249     ompi_java_exceptionCheck(env, rc);
 250     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 251     return flag ? ompi_java_status_newIndex(env, &status, index) : NULL;
 252 }
 253 
 254 JNIEXPORT jint JNICALL Java_mpi_Request_testAny(
 255         JNIEnv *env, jclass clazz, jlongArray requests)
 256 {
 257     int count = (*env)->GetArrayLength(env, requests);
 258     jlong* jReq;
 259     MPI_Request *cReq;
 260     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 261     int index, flag;
 262     int rc = MPI_Testany(count, cReq, &index, &flag, MPI_STATUS_IGNORE);
 263     ompi_java_exceptionCheck(env, rc);
 264     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 265     return index;
 266 }
 267 
 268 JNIEXPORT jobjectArray JNICALL Java_mpi_Request_waitAllStatus(
 269         JNIEnv *env, jclass clazz, jlongArray requests)
 270 {
 271     int count = (*env)->GetArrayLength(env, requests);
 272     jlong* jReq;
 273     MPI_Request *cReq;
 274     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 275     MPI_Status *statuses = (MPI_Status*)calloc(count, sizeof(MPI_Status));
 276     int rc = MPI_Waitall(count, cReq, statuses);
 277     ompi_java_exceptionCheck(env, rc);
 278     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 279     jobjectArray jStatuses = newStatuses(env, statuses, count);
 280     free(statuses);
 281     return jStatuses;
 282 }
 283 
 284 JNIEXPORT void JNICALL Java_mpi_Request_waitAll(
 285         JNIEnv *env, jclass jthis, jlongArray requests)
 286 {
 287     int count = (*env)->GetArrayLength(env, requests);
 288     jlong* jReq;
 289     MPI_Request *cReq;
 290     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 291     int rc = MPI_Waitall(count, cReq, MPI_STATUSES_IGNORE);
 292     ompi_java_exceptionCheck(env, rc);
 293     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 294 }
 295 
 296 JNIEXPORT jobjectArray JNICALL Java_mpi_Request_testAllStatus(
 297         JNIEnv *env, jclass clazz, jlongArray requests)
 298 {
 299     int count = (*env)->GetArrayLength(env, requests);
 300     jlong* jReq;
 301     MPI_Request *cReq;
 302     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 303     MPI_Status *statuses = (MPI_Status*)calloc(count, sizeof(MPI_Status));
 304     int flag;
 305     int rc = MPI_Testall(count, cReq, &flag, statuses);
 306     ompi_java_exceptionCheck(env, rc);
 307     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 308     jobjectArray jStatuses = flag ? newStatuses(env, statuses, count) : NULL;
 309     free(statuses);
 310     return jStatuses;
 311 }
 312 
 313 JNIEXPORT jboolean JNICALL Java_mpi_Request_testAll(
 314         JNIEnv *env, jclass jthis, jlongArray requests)
 315 {
 316     int count = (*env)->GetArrayLength(env, requests);
 317     jlong* jReq;
 318     MPI_Request *cReq;
 319     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 320     int flag;
 321     int rc = MPI_Testall(count, cReq, &flag, MPI_STATUSES_IGNORE);
 322     ompi_java_exceptionCheck(env, rc);
 323     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 324     return flag ? JNI_TRUE : JNI_FALSE;
 325 }
 326 
 327 JNIEXPORT jobjectArray JNICALL Java_mpi_Request_waitSomeStatus(
 328         JNIEnv *env, jclass clazz, jlongArray requests)
 329 {
 330     int incount = (*env)->GetArrayLength(env, requests);
 331     jlong* jReq;
 332     MPI_Request *cReq;
 333     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 334     MPI_Status *statuses = (MPI_Status*)calloc(incount, sizeof(MPI_Status));
 335     int *indices = (int*)calloc(incount, sizeof(int));
 336     int outcount;
 337     int rc = MPI_Waitsome(incount, cReq, &outcount, indices, statuses);
 338     ompi_java_exceptionCheck(env, rc);
 339     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 340     jobjectArray jStatuses = newStatusesIndices(env, statuses, indices, outcount);
 341     free(statuses);
 342     free(indices);
 343     return jStatuses;
 344 }
 345 
 346 JNIEXPORT jintArray JNICALL Java_mpi_Request_waitSome(
 347         JNIEnv *env, jclass clazz, jlongArray requests)
 348 {
 349     jboolean exception;
 350     int incount = (*env)->GetArrayLength(env, requests);
 351     jlong* jReq;
 352     MPI_Request *cReq;
 353     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 354     int *indices = (int*)calloc(incount, sizeof(int));
 355     int outcount;
 356     int rc = MPI_Waitsome(incount, cReq, &outcount, indices, MPI_STATUSES_IGNORE);
 357     exception = ompi_java_exceptionCheck(env, rc);
 358     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 359     
 360     if(exception) {
 361         free(indices);
 362         return NULL;
 363     }
 364 
 365     jintArray jindices = NULL;
 366 
 367     if(outcount != MPI_UNDEFINED)
 368     {
 369         jindices = (*env)->NewIntArray(env, outcount);
 370         setIndices(env, jindices, indices, outcount);
 371     }
 372 
 373     free(indices);
 374     return jindices;
 375 }
 376 
 377 JNIEXPORT jobjectArray JNICALL Java_mpi_Request_testSomeStatus(
 378         JNIEnv *env, jclass clazz, jlongArray requests)
 379 {
 380     int incount = (*env)->GetArrayLength(env, requests);
 381     jlong* jReq;
 382     MPI_Request *cReq;
 383     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 384     MPI_Status *statuses = (MPI_Status*)calloc(incount, sizeof(MPI_Status));
 385     int *indices = (int*)calloc(incount, sizeof(int));
 386     int outcount;
 387     int rc = MPI_Testsome(incount, cReq, &outcount, indices, statuses);
 388     ompi_java_exceptionCheck(env, rc);
 389     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 390     jobjectArray jStatuses = newStatusesIndices(env, statuses, indices, outcount);
 391     free(statuses);
 392     free(indices);
 393     return jStatuses;
 394 }
 395 
 396 JNIEXPORT jintArray JNICALL Java_mpi_Request_testSome(
 397         JNIEnv *env, jclass clazz, jlongArray requests)
 398 {
 399     jboolean exception;
 400     int incount = (*env)->GetArrayLength(env, requests);
 401     jlong* jReq;
 402     MPI_Request *cReq;
 403     ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq);
 404     int *indices = (int*)calloc(incount, sizeof(int));
 405     int outcount;
 406     int rc = MPI_Testsome(incount, cReq, &outcount, indices, MPI_STATUSES_IGNORE);
 407     exception = ompi_java_exceptionCheck(env, rc);
 408     ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq);
 409     
 410     if(exception) {
 411         free(indices);
 412         return NULL;
 413     }
 414     
 415     jintArray jindices = NULL;
 416 
 417     if(outcount != MPI_UNDEFINED)
 418     {
 419         jindices = (*env)->NewIntArray(env, outcount);
 420         setIndices(env, jindices, indices, outcount);
 421     }
 422 
 423     free(indices);
 424     return jindices;
 425 }

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