File: mpi_Message.c

package info (click to toggle)
openmpi 5.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 202,312 kB
  • sloc: ansic: 612,441; makefile: 42,495; sh: 11,230; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,154; python: 1,856; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (103 lines) | stat: -rw-r--r-- 3,488 bytes parent folder | download | duplicates (5)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2005 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2016      Los Alamos National Security, LLC. All rights
 *                         reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "ompi_config.h"

#ifdef HAVE_TARGETCONDITIONALS_H
#include <TargetConditionals.h>
#endif

#include "mpi.h"
#include "mpi_Message.h"
#include "mpiJava.h"

JNIEXPORT void JNICALL Java_mpi_Message_init(JNIEnv *e, jclass c)
{
    ompi_java_setStaticLongField(e, c, "NULL",    (jlong)MPI_MESSAGE_NULL);
    ompi_java_setStaticLongField(e, c, "NO_PROC", (jlong)MPI_MESSAGE_NO_PROC);
    ompi_java.MessageHandle = (*e)->GetFieldID(e, c, "handle", "J");
}

JNIEXPORT jlong JNICALL Java_mpi_Message_mProbe(
        JNIEnv *env, jobject jthis,
        jint source, jint tag, jlong jComm, jlongArray jStatus)
{
    MPI_Comm comm = (MPI_Comm)jComm;
    MPI_Message message;
    MPI_Status  status;
    int rc = MPI_Mprobe(source, tag, comm, &message, &status);
    
    if(!ompi_java_exceptionCheck(env, rc))
        ompi_java_status_set(env, jStatus, &status);
    
    return (jlong)message;
}

JNIEXPORT jobject JNICALL Java_mpi_Message_imProbe(
        JNIEnv *env, jobject jthis, jint source, jint tag, jlong jComm)
{
    MPI_Comm comm = (MPI_Comm)jComm;
    MPI_Message message;
    MPI_Status  status;
    int rc, flag;
    rc = MPI_Improbe(source, tag, comm, &flag, &message, &status);

    if(ompi_java_exceptionCheck(env, rc) || !flag)
        return NULL;

    (*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)message);
    return ompi_java_status_new(env, &status);
}

JNIEXPORT jlong JNICALL Java_mpi_Message_mRecv(
        JNIEnv *env, jobject jthis, jlong jMessage, jobject buf, jboolean db,
        jint off, jint count, jlong jType, jint bType, jlongArray jStatus)
{
    MPI_Message  message = (MPI_Message)jMessage;
    MPI_Datatype type    = (MPI_Datatype)jType;

    void *ptr;
    ompi_java_buffer_t *item;
    ompi_java_getWritePtr(&ptr, &item, env, buf, db, count, type);

    MPI_Status status;
    int rc = MPI_Mrecv(ptr, count, type, &message, &status);
    
    if(!ompi_java_exceptionCheck(env, rc))
        ompi_java_status_set(env, jStatus, &status);
    
    ompi_java_releaseWritePtr(ptr, item, env, buf, db, off, count, type, bType);
    return (jlong)message;
}

JNIEXPORT jlong JNICALL Java_mpi_Message_imRecv(
        JNIEnv *env, jobject jthis, jlong jMessage,
        jobject buf, jint count, jlong jType)
{
    MPI_Message  message = (MPI_Message)jMessage;
    MPI_Datatype type    = (MPI_Datatype)jType;
    void *ptr = ompi_java_getDirectBufferAddress(env, buf);

    MPI_Request request;
    int rc = MPI_Imrecv(ptr, count, type, &message, &request);
    ompi_java_exceptionCheck(env, rc);
    (*env)->SetLongField(env, jthis, ompi_java.MessageHandle, (jlong)message);
    return (jlong)request;
}