File: gov_ornl_ccs_Adios.cxx

package info (click to toggle)
adios 1.13.1-28.2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 23,688 kB
  • sloc: ansic: 133,236; f90: 8,791; sh: 7,783; python: 7,648; xml: 3,793; makefile: 2,994; cpp: 2,340; java: 626; sed: 16; perl: 8
file content (576 lines) | stat: -rw-r--r-- 17,652 bytes parent folder | download | duplicates (6)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
#include "gov_ornl_ccs_Adios.h"

#include <adios.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>

#define STR(A) #A
#define CONCAT2(A, B) A ## B
#define CONCAT3(A, B, C) CONCAT2(CONCAT2(A, B), C)
#define GET_ARRAY_ELEMENT(TYPE) CONCAT3(Get, TYPE, ArrayElements)
#define WRITE_ONE(JTYPE)                                        \
    /* std::cout << __FUNCTION__ << "..." << std::endl; */      \
    int result;                                                 \
    const char *str_var_name;                                   \
    str_var_name = env->GetStringUTFChars(var_name, NULL);      \
    if (str_var_name == NULL) return -1;                        \
    result = adios_write ((int64_t) fh, str_var_name, &val);    \
    env->ReleaseStringUTFChars(var_name, str_var_name);         \
    return result;

#define WRITE_ARRAY(JTYPE, CTYPE)                                       \
    /* std::cout << __FUNCTION__ << " ..." << std::endl;*/              \
    int result;                                                         \
    const char *str_var_name;                                           \
    JTYPE *valarr = env->Get ##CTYPE ##ArrayElements(val, NULL);        \
    str_var_name = env->GetStringUTFChars(var_name, NULL);              \
    if (str_var_name == NULL) return -1;                                \
    result = adios_write ((int64_t) fh, str_var_name, (void *) valarr); \
    env->ReleaseStringUTFChars(var_name, str_var_name);                 \
    env->Release ##CTYPE ##ArrayElements(val, valarr, 0);               \
    return result;

#define FUNC_WRITE_ONE(FNAME, JTYPE)                                    \
    JNIEXPORT jint JNICALL FNAME                                        \
    (JNIEnv * env, jclass cls, jlong fh, jstring var_name, JTYPE val)   \
    {                                                                   \
        WRITE_ONE(JTYPE);                                               \
    }

#define FUNC_WRITE_ARRAY(FNAME, JTYPE, CTYPE)                           \
    JNIEXPORT jint JNICALL FNAME                                        \
    (JNIEnv * env, jclass cls, jlong fh, jstring var_name, JTYPE ##Array val) \
    {                                                                   \
        WRITE_ARRAY(JTYPE, CTYPE);                                      \
    }

#define STR_ALLOC(var) \
    const char *str_##var = env->GetStringUTFChars(var, NULL); \
    if (str_##var == NULL) return -1;

#define STR_ALLOC2(var) \
    const char *str_##var = env->GetStringUTFChars(var, NULL); \
    if (str_##var == NULL) goto end;

#define STR_FREE(var) \
    env->ReleaseStringUTFChars(var, str_##var);


/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_init
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL
Java_gov_ornl_ccs_Adios_adios_1init
(JNIEnv *env, jclass cls, jstring xml_fname, jlong comm)
{
    //std::cout << __FUNCTION__ << "..." << std::endl;
    int result;
    jboolean isCopy;

    STR_ALLOC(xml_fname);

    result = adios_init(str_xml_fname, (MPI_Comm) comm);
    //std::cout << "result = " << result << std::endl;

    STR_FREE(xml_fname);

    return result;
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_open
 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;J)J
 */
JNIEXPORT jlong JNICALL Java_gov_ornl_ccs_Adios_adios_1open
(JNIEnv * env, jclass cls, jstring group_name, jstring file_name, jstring mode, jlong comm)
{
    //std::cout << __FUNCTION__ << "..." << std::endl;

    int result;
    int64_t fd_p = 0;

    STR_ALLOC(group_name);
    STR_ALLOC(file_name);
    STR_ALLOC(mode);

    //std::cout << "[IN] fd_p = " << (int64_t) fd_p << std::endl;
    //std::cout << "[IN] str_group_name = " << str_group_name << std::endl;
    //std::cout << "[IN] str_file_name = " << str_file_name << std::endl;
    //std::cout << "[IN] str_mode = " << str_mode << std::endl;
    //std::cout << "[IN] comm = " << (long) comm << std::endl;
    result = adios_open(&fd_p, str_group_name, str_file_name, str_mode, (MPI_Comm) comm);
    //std::cout << "[OUT] fd_p = " << fd_p << std::endl;
    //std::cout << "[OUT] result = " << result << std::endl;

    STR_FREE(group_name);
    STR_FREE(file_name);
    STR_FREE(mode);

    return (jlong) fd_p;
}

JNIEXPORT jlong JNICALL Java_gov_ornl_ccs_Adios_adios_1group_1size
(JNIEnv * env, jclass cls, jlong fh, jlong group_size)
{
    //std::cout << __FUNCTION__ << "..." << std::endl;

    uint64_t total_size = 0;
    int result;

    //std::cout << "[IN] fh = " << (int64_t) fh << std::endl;
    //std::cout << "[IN] group_size = " << (uint64_t) group_size << std::endl;
    result = adios_group_size ((int64_t) fh, (uint64_t) group_size, (uint64_t *) &total_size);
    //std::cout << "[OUT] fh = " << (int64_t) fh << std::endl;
    //std::cout << "[OUT] total size = " << total_size << std::endl;
    //std::cout << "[OUT] result = " << result << std::endl;

    return total_size;
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_write
 * Signature: (JLjava/lang/String;B)I
 * Signature: (JLjava/lang/String;I)I
 * Signature: (JLjava/lang/String;J)I
 * Signature: (JLjava/lang/String;F)I
 * Signature: (JLjava/lang/String;D)I
 */
FUNC_WRITE_ONE (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2B,
    jbyte)

FUNC_WRITE_ONE (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2I,
    jint)

FUNC_WRITE_ONE (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2J,
    jlong)

FUNC_WRITE_ONE (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2F,
    jfloat)

FUNC_WRITE_ONE (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2D,
    jdouble)

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_write
 * Signature: (JLjava/lang/String;[B)I
 * Signature: (JLjava/lang/String;[I)I
 * Signature: (JLjava/lang/String;[J)I
 * Signature: (JLjava/lang/String;[F)I
 * Signature: (JLjava/lang/String;[D)I
 */
FUNC_WRITE_ARRAY (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2_3B,
    jbyte,
    Byte)

FUNC_WRITE_ARRAY (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2_3I,
    jint,
    Int)

FUNC_WRITE_ARRAY (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2_3J,
    jlong,
    Long)

FUNC_WRITE_ARRAY (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2_3F,
    jfloat,
    Float)

FUNC_WRITE_ARRAY (
    Java_gov_ornl_ccs_Adios_adios_1write__JLjava_lang_String_2_3D,
    jdouble,
    Double)

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_close
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1close
(JNIEnv * env, jclass cls, jlong fh)
{
    //std::cout << __FUNCTION__ << "..." << std::endl;

    //std::cout << "[IN] fh = " << fh << std::endl;
    return adios_close ((int64_t) fh);
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_finalize
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1finalize
(JNIEnv * env, jclass cls, jint id)
{
    //std::cout << __FUNCTION__ << "..." << std::endl;
    return adios_finalize (id);
}

#ifdef ADIOS_USE_MPI
/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_mpi_init
 * Signature: ([Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1mpi_1init
(JNIEnv * env, jclass cls, jobjectArray args)
{
    int argc = env->GetArrayLength(args);
    char **argv;
    int result;

    for (int i = 0; i < argc; i  )
    {
        jstring jstr = (jstring) env->GetObjectArrayElement(args, i);
        const char *chr = env->GetStringUTFChars(jstr, 0);

        //argv[i] = (char *) malloc(env->GetStringLength(jstr)   1);
        argv[i] = new char[env->GetStringLength(jstr)   1];
        strcpy(argv[i], chr);

        env->ReleaseStringUTFChars(jstr, chr);
    }

    result = MPI_Init(&argc, &argv);

    for (int i = 0; i < argc; i  )
    {
        //free(argv[i]);
        delete[] argv[i];
    }

    return result;
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_mpi_comm_rank
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1mpi_1comm_1rank
(JNIEnv * env, jclass cls, jlong comm)
{
    int rank;
    MPI_Comm_rank((MPI_Comm) comm, &rank);

    return rank;
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_mpi_comm_size
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1mpi_1comm_1size
(JNIEnv * env, jclass cls, jlong comm)
{
    int size;
    MPI_Comm_size((MPI_Comm) comm, &size);

    return size;
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_mpi_finalize
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1mpi_1finalize
(JNIEnv * env, jclass cls)
{
    return MPI_Finalize();
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_mpi_comm_world
 * Signature: ()I
 */
JNIEXPORT jlong JNICALL Java_gov_ornl_ccs_Adios_adios_1mpi_1comm_1world
(JNIEnv * env, jclass cls)
{
    return (jlong) MPI_COMM_WORLD;
}
#endif

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_open_and_set_group_size
 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JJ)J
 */
JNIEXPORT jlong JNICALL Java_gov_ornl_ccs_Adios_adios_1open_1and_1set_1group_1size
(JNIEnv * env, jclass cls, jstring group_name, jstring file_name, jstring mode, jlong group_size, jlong comm)
{
    // Doesn't work, either
    //jlong fh = Java_gov_ornl_ccs_Adios_adios_1open(env, cls, group_name, file_name, mode, comm);
    //Java_gov_ornl_ccs_Adios_adios_1group_1size(env, cls, fh, group_size);

    //std::cout << __FUNCTION__ << "..." << std::endl;

    int result;
    int64_t fd_p = 0;

    STR_ALLOC(group_name);
    STR_ALLOC(file_name);
    STR_ALLOC(mode);

    //std::cout << "[IN] fd_p = " << (int64_t) fd_p << std::endl;
    //std::cout << "[IN] str_group_name = " << str_group_name << std::endl;
    //std::cout << "[IN] str_file_name = " << str_file_name << std::endl;
    //std::cout << "[IN] str_mode = " << str_mode << std::endl;
    //std::cout << "[IN] comm = " << (long) comm << std::endl;
    result = adios_open(&fd_p, str_group_name, str_file_name, str_mode, (MPI_Comm) comm);
    //std::cout << "[OUT] fd_p = " << fd_p << std::endl;
    //std::cout << "[OUT] result = " << result << std::endl;

    STR_FREE(group_name);
    STR_FREE(file_name);
    STR_FREE(mode);

    uint64_t total_size;
    //std::cout << "[IN] fd_p = " << (int64_t) fd_p << std::endl;
    adios_group_size (fd_p, group_size, (uint64_t *) &total_size);
    //std::cout << "[OUT] total size = " << total_size << std::endl;

    return (jlong) fd_p;
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_init_noxml
 * Signature: ()I
 */
JNIEXPORT jint JNICALL
Java_gov_ornl_ccs_Adios_adios_1init_1noxml
(JNIEnv *env, jclass cls, jlong comm)
{
    return adios_init_noxml((MPI_Comm) comm);
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_allocate_buffer
 * Signature: (IJ)I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1allocate_1buffer
(JNIEnv * env, jclass cls, jint when, jlong size)
{
    return adios_allocate_buffer((ADIOS_BUFFER_ALLOC_WHEN) when, size);
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_declare_group
 * Signature: (Ljava/lang/String;Ljava/lang/String;I)J
 */
JNIEXPORT jlong JNICALL Java_gov_ornl_ccs_Adios_adios_1declare_1group
(JNIEnv * env, jclass cls, jstring name, jstring time_index, jint stats)
{
    int64_t id_p;
    int result;

    STR_ALLOC(name);
    STR_ALLOC(time_index);

    result = adios_declare_group(&id_p, str_name, str_time_index, (ADIOS_STATISTICS_FLAG) stats);

    STR_FREE(name);
    STR_FREE(time_index);

    return (jlong) id_p;
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_define_var
 * Signature: (JLjava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1define_1var
(JNIEnv * env, jclass cls, jlong group_id, jstring name, jstring path, jint type, jstring dimensions, jstring global_dimensions, jstring local_offsets)
{
    int result;

    STR_ALLOC(name);
    STR_ALLOC(path);
    STR_ALLOC(dimensions);
    STR_ALLOC(global_dimensions);
    STR_ALLOC(local_offsets);

    result = adios_define_var((int64_t) group_id, str_name, str_path, (ADIOS_DATATYPES) type, str_dimensions, str_global_dimensions, str_local_offsets);

    STR_FREE(name);
    STR_FREE(path);
    STR_FREE(dimensions);
    STR_FREE(global_dimensions);
    STR_FREE(local_offsets);

    return result;
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_define_attribute
 * Signature: (JLjava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1define_1attribute
(JNIEnv * env, jclass cls, jlong group_id, jstring name, jstring path, jint type, jstring value, jstring var)
{
    int result;

    STR_ALLOC(name);
    STR_ALLOC(path);
    STR_ALLOC(value);
    STR_ALLOC(var);

    result = adios_define_attribute((int64_t) group_id, str_name, str_path, (ADIOS_DATATYPES) type, str_value, str_var);

    STR_FREE(name);
    STR_FREE(path);
    STR_FREE(value);
    STR_FREE(var);

    return result;
}

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_select_method
 * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_gov_ornl_ccs_Adios_adios_1select_1method
(JNIEnv * env, jclass cls, jlong group_id, jstring method, jstring parameters, jstring base_path)
{
    int result;

    STR_ALLOC(method);
    STR_ALLOC(parameters);
    STR_ALLOC(base_path);

    result = adios_select_method((int64_t) group_id, str_method, str_parameters, str_base_path);

    STR_FREE(method);
    STR_FREE(parameters);
    STR_FREE(base_path);

    return result;
}

#define READ_ONE(JTYPE)                                                 \
    /* std::cout << __FUNCTION__ << " ..." << std::endl; */             \
    int result;                                                         \
    JTYPE val;                                                          \
    const char *str_var_name;                                           \
    uint64_t read_size = sizeof(JTYPE);                                 \
    str_var_name = env->GetStringUTFChars(var_name, NULL);              \
    if (str_var_name == NULL) return -1;                                \
    result = adios_read ((int64_t) fh, str_var_name, &val, sizeof(JTYPE)); \
    env->ReleaseStringUTFChars(var_name, str_var_name);                 \
    return val;

#define FUNC_READ_ONE(FNAME, JTYPE)                                     \
    JNIEXPORT JTYPE JNICALL FNAME                                       \
    (JNIEnv * env, jclass cls, jlong fh, jstring var_name)              \
    {                                                                   \
        READ_ONE(JTYPE);                                                \
    }

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_read_byte_value
 * Signature: (JLjava/lang/String;)B
 * Signature: (JLjava/lang/String;)I
 * Signature: (JLjava/lang/String;)J
 * Signature: (JLjava/lang/String;)F
 * Signature: (JLjava/lang/String;)D
 */

FUNC_READ_ONE(
    Java_gov_ornl_ccs_Adios_adios_1read_1byte_1value,
    jbyte);

FUNC_READ_ONE(
    Java_gov_ornl_ccs_Adios_adios_1read_1int_1value,
    jint);

FUNC_READ_ONE(
    Java_gov_ornl_ccs_Adios_adios_1read_1long_1value,
    jlong);

FUNC_READ_ONE(
    Java_gov_ornl_ccs_Adios_adios_1read_1float_1value,
    jfloat);

FUNC_READ_ONE(
    Java_gov_ornl_ccs_Adios_adios_1read_1double_1value,
    jdouble);



#define READ_ARRAY(JTYPE, CTYPE)                                        \
    /* std::cout << __FUNCTION__ << " ..." << std::endl; */             \
    int result;                                                         \
    const char *str_var_name;                                           \
    JTYPE *valarr = env->Get ##CTYPE ##ArrayElements(val, NULL);        \
    uint64_t read_size = env->GetArrayLength(val) * sizeof(JTYPE);      \
    str_var_name = env->GetStringUTFChars(var_name, NULL);              \
    if (str_var_name == NULL) return -1;                                \
    result = adios_read ((int64_t) fh, str_var_name, (void *) valarr, read_size); \
    env->ReleaseStringUTFChars(var_name, str_var_name);                 \
    env->Release ##CTYPE ##ArrayElements(val, valarr, 0);               \
    return result;

#define FUNC_READ_ARRAY(FNAME, JTYPE, CTYPE)                            \
    JNIEXPORT jint JNICALL FNAME                                        \
    (JNIEnv * env, jclass cls, jlong fh, jstring var_name, JTYPE ##Array val) \
    {                                                                   \
        READ_ARRAY(JTYPE, CTYPE);                                      \
    }

/*
 * Class:     gov_ornl_ccs_Adios
 * Method:    adios_read
 * Signature: (JLjava/lang/String;[B)I
 * Signature: (JLjava/lang/String;[I)I
 * Signature: (JLjava/lang/String;[J)I
 * Signature: (JLjava/lang/String;[F)I
 * Signature: (JLjava/lang/String;[D)I
 */

FUNC_READ_ARRAY(
    Java_gov_ornl_ccs_Adios_adios_1read__JLjava_lang_String_2_3B,
    jbyte,
    Byte);

FUNC_READ_ARRAY(
    Java_gov_ornl_ccs_Adios_adios_1read__JLjava_lang_String_2_3I,
    jint,
    Int);

FUNC_READ_ARRAY(
    Java_gov_ornl_ccs_Adios_adios_1read__JLjava_lang_String_2_3J,
    jlong,
    Long);

FUNC_READ_ARRAY(
    Java_gov_ornl_ccs_Adios_adios_1read__JLjava_lang_String_2_3F,
    jfloat,
    Float);

FUNC_READ_ARRAY(
    Java_gov_ornl_ccs_Adios_adios_1read__JLjava_lang_String_2_3D,
    jdouble,
    Double);