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 (c) 2017-2018 FUJITSU LIMITED. All rights reserved.
15 * $COPYRIGHT$
16 *
17 * Additional copyrights may follow
18 *
19 * $HEADER$
20 *
21 *
22 * IMPLEMENTATION DETAILS
23 *
24 * All methods with buffers that can be direct or non direct have
25 * a companion argument 'db' which is true if the buffer is direct.
26 *
27 * Checking if a buffer is direct is faster in Java than C.
28 */
29
30 package mpi;
31
32 import java.nio.*;
33 import static mpi.MPI.isHeapBuffer;
34 import static mpi.MPI.isDirectBuffer;
35 import static mpi.MPI.assertDirectBuffer;
36
37 /**
38 * This class represents {@code MPI_File}.
39 */
40 public final class File
41 {
42 private long handle;
43 private FileView view = new FileView(0, MPI.BYTE, MPI.BYTE, "native");
44 private Status beginStatus;
45
46 /**
47 * Java binding of {@code MPI_FILE_OPEN} using {@code MPI_INFO_NULL}.
48 * @param comm communicator
49 * @param filename name of the file to open
50 * @param amode file access mode
51 * @throws MPIException Signals that an MPI exception of some sort has occurred.
52 */
53 public File(Comm comm, String filename, int amode) throws MPIException
54 {
55 MPI.check();
56 handle = open(comm.handle, filename, amode, Info.NULL);
57 }
58
59 /**
60 * Java binding of {@code MPI_FILE_OPEN}.
61 * @param comm communicator
62 * @param filename name of the file to open
63 * @param amode file access mode
64 * @param info info object
65 * @throws MPIException Signals that an MPI exception of some sort has occurred.
66 */
67 public File(Comm comm, String filename, int amode, Info info)
68 throws MPIException
69 {
70 MPI.check();
71 handle = open(comm.handle, filename, amode, info.handle);
72 }
73
74 private native long open(long comm, String filename, int amode, long info)
75 throws MPIException;
76
77 /**
78 * Java binding of {@code MPI_FILE_CLOSE}.
79 * @throws MPIException Signals that an MPI exception of some sort has occurred.
80 */
81 public void close() throws MPIException
82 {
83 MPI.check();
84 handle = close(handle);
85 }
86
87 private native long close(long fh) throws MPIException;
88
89 /**
90 * Java binding of {@code MPI_FILE_DELETE} using {@code MPI_INFO_NULL}.
91 * @param filename name of the file to delete
92 * @throws MPIException Signals that an MPI exception of some sort has occurred.
93 */
94 public static void delete(String filename) throws MPIException
95 {
96 MPI.check();
97 delete(filename, Info.NULL);
98 }
99
100 /**
101 * Java binding of {@code MPI_FILE_DELETE}.
102 * @param filename name of the file to delete
103 * @param info info object
104 * @throws MPIException Signals that an MPI exception of some sort has occurred.
105 */
106 public static void delete(String filename, Info info) throws MPIException
107 {
108 MPI.check();
109 delete(filename, info.handle);
110 }
111
112 private static native void delete(String filename, long info)
113 throws MPIException;
114
115 /**
116 * Java binding of {@code MPI_FILE_SET_SIZE}.
117 * @param size size to truncate or expand file
118 * @throws MPIException Signals that an MPI exception of some sort has occurred.
119 */
120 public void setSize(long size) throws MPIException
121 {
122 MPI.check();
123 setSize(handle, size);
124 }
125
126 private native void setSize(long fh, long size) throws MPIException;
127
128 /**
129 * Java binding of {@code MPI_FILE_PREALLOCATE}.
130 * @param size size to preallocate file
131 * @throws MPIException Signals that an MPI exception of some sort has occurred.
132 */
133 public void preallocate(long size) throws MPIException
134 {
135 MPI.check();
136 preallocate(handle, size);
137 }
138
139 private native void preallocate(long fh, long size) throws MPIException;
140
141 /**
142 * Java binding of {@code MPI_FILE_GET_SIZE}.
143 * @return size of file in bytes
144 * @throws MPIException Signals that an MPI exception of some sort has occurred.
145 */
146 public long getSize() throws MPIException
147 {
148 MPI.check();
149 return getSize(handle);
150 }
151
152 private native long getSize(long fh) throws MPIException;
153
154 /**
155 * Java binding of {@code MPI_FILE_GET_GROUP}.
156 * @return group which opened the file
157 * @throws MPIException Signals that an MPI exception of some sort has occurred.
158 */
159 public Group getGroup() throws MPIException
160 {
161 MPI.check();
162 return new Group(getGroup(handle));
163 }
164
165 private native long getGroup(long fh) throws MPIException;
166
167 /**
168 * Java binding of {@code MPI_FILE_GET_AMODE}.
169 * @return file access mode to open the file
170 * @throws MPIException Signals that an MPI exception of some sort has occurred.
171 */
172 public int getAMode() throws MPIException
173 {
174 MPI.check();
175 return getAMode(handle);
176 }
177
178 private native int getAMode(long fh) throws MPIException;
179
180 /**
181 * Java binding of {@code MPI_FILE_SET_INFO}.
182 * @param info info object
183 * @throws MPIException Signals that an MPI exception of some sort has occurred.
184 */
185 public void setInfo(Info info) throws MPIException
186 {
187 MPI.check();
188 setInfo(handle, info.handle);
189 }
190
191 private native void setInfo(long fh, long info) throws MPIException;
192
193 /**
194 * Java binding of {@code MPI_FILE_GET_INFO}.
195 * @return new info object
196 * @throws MPIException Signals that an MPI exception of some sort has occurred.
197 */
198 public Info getInfo() throws MPIException
199 {
200 MPI.check();
201 return new Info(getInfo(handle));
202 }
203
204 private native long getInfo(long fh) throws MPIException;
205
206 /**
207 * Java binding of {@code MPI_FILE_SET_VIEW} using {@code MPI_INFO_NULL}.
208 * @param disp displacement
209 * @param etype elementary datatype
210 * @param filetype filetype
211 * @param datarep data representation
212 * @throws MPIException Signals that an MPI exception of some sort has occurred.
213 */
214 public void setView(long disp, Datatype etype,
215 Datatype filetype, String datarep)
216 throws MPIException
217 {
218 MPI.check();
219 setView(handle, disp, etype.handle, filetype.handle, datarep, Info.NULL);
220 view = new FileView(disp, etype, filetype, datarep);
221 }
222
223 /**
224 * Java binding of {@code MPI_FILE_SET_VIEW}.
225 * @param disp displacement
226 * @param etype elementary datatype
227 * @param filetype filetype
228 * @param datarep data representation
229 * @param info info object
230 * @throws MPIException Signals that an MPI exception of some sort has occurred.
231 */
232 public void setView(long disp, Datatype etype,
233 Datatype filetype, String datarep, Info info)
234 throws MPIException
235 {
236 MPI.check();
237 setView(handle, disp, etype.handle, filetype.handle, datarep, info.handle);
238 view = new FileView(disp, etype, filetype, datarep);
239 }
240
241 private native void setView(
242 long fh, long disp, long etype,
243 long filetype, String datarep, long info) throws MPIException;
244
245 /**
246 * Java binding of {@code MPI_FILE_GET_VIEW}.
247 * @return file view
248 */
249 public FileView getView()
250 {
251 return view;
252 }
253
254 /**
255 * Java binding of {@code MPI_FILE_READ_AT}.
256 * @param offset file offset
257 * @param buf buffer
258 * @param count number of items in buffer
259 * @param type datatype of each buffer element
260 * @return status object
261 * @throws MPIException Signals that an MPI exception of some sort has occurred.
262 */
263 public Status readAt(long offset, Object buf, int count, Datatype type)
264 throws MPIException
265 {
266 MPI.check();
267 int off = 0;
268 boolean db = false;
269 Status status = new Status();
270
271 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
272 {
273 off = type.getOffset(buf);
274 buf = ((Buffer)buf).array();
275 }
276
277 readAt(handle, offset, buf, db, off, count,
278 type.handle, type.baseType, status.data);
279
280 return status;
281 }
282
283 private native void readAt(
284 long fh, long fileOffset, Object buf, boolean db, int offset,
285 int count, long type, int baseType, long[] stat) throws MPIException;
286
287 /**
288 * Java binding of {@code MPI_FILE_READ_AT_ALL}.
289 * @param offset file offset
290 * @param buf buffer
291 * @param count number of items in buffer
292 * @param type datatype of each buffer element
293 * @return status object
294 * @throws MPIException Signals that an MPI exception of some sort has occurred.
295 */
296 public Status readAtAll(long offset, Object buf, int count, Datatype type)
297 throws MPIException
298 {
299 MPI.check();
300 int off = 0;
301 boolean db = false;
302 Status status = new Status();
303
304 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
305 {
306 off = type.getOffset(buf);
307 buf = ((Buffer)buf).array();
308 }
309
310 readAtAll(handle, offset, buf, db, off, count,
311 type.handle, type.baseType, status.data);
312
313 return status;
314 }
315
316 private native void readAtAll(
317 long fh, long fileOffset, Object buf, boolean db, int offset,
318 int count, long type, int baseType, long[] stat) throws MPIException;
319
320 /**
321 * Java binding of {@code MPI_FILE_WRITE_AT}.
322 * @param offset file offset
323 * @param buf buffer
324 * @param count number of items in buffer
325 * @param type datatype of each buffer element
326 * @return status object
327 * @throws MPIException Signals that an MPI exception of some sort has occurred.
328 */
329 public Status writeAt(long offset, Object buf, int count, Datatype type)
330 throws MPIException
331 {
332 MPI.check();
333 int off = 0;
334 boolean db = false;
335 Status status = new Status();
336
337 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
338 {
339 off = type.getOffset(buf);
340 buf = ((Buffer)buf).array();
341 }
342
343 writeAt(handle, offset, buf, db, off, count,
344 type.handle, type.baseType, status.data);
345
346 return status;
347 }
348
349 private native void writeAt(
350 long fh, long fileOffset, Object buf, boolean db, int offset,
351 int count, long type, int baseType, long[] stat) throws MPIException;
352
353 /**
354 * Java binding of {@code MPI_FILE_WRITE_AT_ALL}.
355 * @param offset file offset
356 * @param buf buffer
357 * @param count number of items in buffer
358 * @param type datatype of each buffer element
359 * @return status object
360 * @throws MPIException Signals that an MPI exception of some sort has occurred.
361 */
362 public Status writeAtAll(long offset, Object buf, int count, Datatype type)
363 throws MPIException
364 {
365 MPI.check();
366 int off = 0;
367 boolean db = false;
368 Status status = new Status();
369
370 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
371 {
372 off = type.getOffset(buf);
373 buf = ((Buffer)buf).array();
374 }
375
376 writeAtAll(handle, offset, buf, db, off, count,
377 type.handle, type.baseType, status.data);
378
379 return status;
380 }
381
382 private native void writeAtAll(
383 long fh, long fileOffset, Object buf, boolean db, int offset,
384 int count, long type, int baseType, long[] stat) throws MPIException;
385
386 /**
387 * Java binding of {@code MPI_FILE_IREAD_AT}.
388 * @param offset file offset
389 * @param buf buffer
390 * @param count number of items in buffer
391 * @param type datatype of each buffer element
392 * @return request object
393 * @throws MPIException Signals that an MPI exception of some sort has occurred.
394 */
395 public Request iReadAt(long offset, Buffer buf, int count, Datatype type)
396 throws MPIException
397 {
398 MPI.check();
399 assertDirectBuffer(buf);
400 Request req = new Request(iReadAt(handle, offset, buf, count, type.handle));
401 req.addRecvBufRef(buf);
402 return req;
403 }
404
405 private native long iReadAt(
406 long fh, long offset, Buffer buf, int count, long type)
407 throws MPIException;
408
409 /**
410 * Java binding of {@code MPI_FILE_IREAD_AT_ALL}.
411 * @param offset file offset
412 * @param buf buffer
413 * @param count number of items in buffer
414 * @param type datatype of each buffer element
415 * @return request object
416 * @throws MPIException Signals that an MPI exception of some sort has occurred.
417 */
418 public Request iReadAtAll(long offset, Buffer buf, int count, Datatype type)
419 throws MPIException
420 {
421 MPI.check();
422 assertDirectBuffer(buf);
423 Request req = new Request(iReadAtAll(handle, offset, buf, count, type.handle));
424 req.addRecvBufRef(buf);
425 return req;
426 }
427
428 private native long iReadAtAll(
429 long fh, long offset, Buffer buf, int count, long type)
430 throws MPIException;
431
432 /**
433 * Java binding of {@code MPI_FILE_IWRITE_AT}.
434 * @param offset file offset
435 * @param buf buffer
436 * @param count number of items in buffer
437 * @param type datatype of each buffer element
438 * @return request object
439 * @throws MPIException Signals that an MPI exception of some sort has occurred.
440 */
441 public Request iWriteAt(long offset, Buffer buf, int count, Datatype type)
442 throws MPIException
443 {
444 MPI.check();
445 assertDirectBuffer(buf);
446 Request req = new Request(iWriteAt(handle, offset, buf, count, type.handle));
447 req.addSendBufRef(buf);
448 return req;
449 }
450
451 private native long iWriteAt(
452 long fh, long offset, Buffer buf, int count, long type)
453 throws MPIException;
454
455 /**
456 * Java binding of {@code MPI_FILE_IWRITE_AT_ALL}.
457 * @param offset file offset
458 * @param buf buffer
459 * @param count number of items in buffer
460 * @param type datatype of each buffer element
461 * @return request object
462 * @throws MPIException Signals that an MPI exception of some sort has occurred.
463 */
464 public Request iWriteAtAll(long offset, Buffer buf, int count, Datatype type)
465 throws MPIException
466 {
467 MPI.check();
468 assertDirectBuffer(buf);
469 Request req = new Request(iWriteAtAll(handle, offset, buf, count, type.handle));
470 req.addSendBufRef(buf);
471 return req;
472 }
473
474 private native long iWriteAtAll(
475 long fh, long offset, Buffer buf, int count, long type)
476 throws MPIException;
477
478 /**
479 * Java binding of {@code MPI_FILE_READ}.
480 * @param buf buffer
481 * @param count number of items in buffer
482 * @param type datatype of each buffer element
483 * @return status object
484 * @throws MPIException Signals that an MPI exception of some sort has occurred.
485 */
486 public Status read(Object buf, int count, Datatype type) throws MPIException
487 {
488 MPI.check();
489 int off = 0;
490 boolean db = false;
491 Status status = new Status();
492
493 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
494 {
495 off = type.getOffset(buf);
496 buf = ((Buffer)buf).array();
497 }
498
499 read(handle, buf, db, off, count, type.handle, type.baseType, status.data);
500 return status;
501 }
502
503 private native void read(
504 long fh, Object buf, boolean db, int offset,
505 int count, long type, int baseType, long[] stat) throws MPIException;
506
507 /**
508 * Java binding of {@code MPI_FILE_READ_ALL}.
509 * @param buf buffer
510 * @param count number of items in buffer
511 * @param type datatype of each buffer element
512 * @return status object
513 * @throws MPIException Signals that an MPI exception of some sort has occurred.
514 */
515 public Status readAll(Object buf, int count, Datatype type) throws MPIException
516 {
517 MPI.check();
518 int off = 0;
519 boolean db = false;
520 Status status = new Status();
521
522 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
523 {
524 off = type.getOffset(buf);
525 buf = ((Buffer)buf).array();
526 }
527
528 readAll(handle, buf,db,off, count, type.handle, type.baseType, status.data);
529 return status;
530 }
531
532 private native void readAll(
533 long fh, Object buf, boolean db, int offset,
534 int count, long type, int baseType, long[] stat) throws MPIException;
535
536 /**
537 * Java binding of {@code MPI_FILE_WRITE}.
538 * @param buf buffer
539 * @param count number of items in buffer
540 * @param type datatype of each buffer element
541 * @return status object
542 * @throws MPIException Signals that an MPI exception of some sort has occurred.
543 */
544 public Status write(Object buf, int count, Datatype type) throws MPIException
545 {
546 MPI.check();
547 int off = 0;
548 boolean db = false;
549 Status status = new Status();
550
551 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
552 {
553 off = type.getOffset(buf);
554 buf = ((Buffer)buf).array();
555 }
556
557 write(handle, buf, db, off, count, type.handle, type.baseType, status.data);
558 return status;
559 }
560
561 private native void write(
562 long fh, Object buf, boolean db, int offset,
563 int count, long type, int baseType, long[] stat) throws MPIException;
564
565 /**
566 * Java binding of {@code MPI_FILE_WRITE_ALL}.
567 * @param buf buffer
568 * @param count number of items in buffer
569 * @param type datatype of each buffer element
570 * @return status object
571 * @throws MPIException Signals that an MPI exception of some sort has occurred.
572 */
573 public Status writeAll(Object buf, int count, Datatype type) throws MPIException
574 {
575 MPI.check();
576 int off = 0;
577 boolean db = false;
578 Status status = new Status();
579
580 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
581 {
582 off = type.getOffset(buf);
583 buf = ((Buffer)buf).array();
584 }
585
586 writeAll(handle, buf,db,off, count, type.handle,type.baseType, status.data);
587 return status;
588 }
589
590 private native void writeAll(
591 long fh, Object buf, boolean db, int offset,
592 int count, long type, int baseType, long[] stat) throws MPIException;
593
594 /**
595 * Java binding of {@code MPI_FILE_IREAD}.
596 * @param buf buffer
597 * @param count number of items in buffer
598 * @param type datatype of each buffer element
599 * @return request object
600 * @throws MPIException Signals that an MPI exception of some sort has occurred.
601 */
602 public Request iRead(Buffer buf, int count, Datatype type) throws MPIException
603 {
604 MPI.check();
605 assertDirectBuffer(buf);
606 Request req = new Request(iRead(handle, buf, count, type.handle));
607 req.addRecvBufRef(buf);
608 return req;
609 }
610
611 private native long iRead(long fh, Buffer buf, int count, long type)
612 throws MPIException;
613
614 /**
615 * Java binding of {@code MPI_FILE_IREAD_ALL}.
616 * @param buf buffer
617 * @param count number of items in buffer
618 * @param type datatype of each buffer element
619 * @return request object
620 * @throws MPIException Signals that an MPI exception of some sort has occurred.
621 */
622 public Request iReadAll(Buffer buf, int count, Datatype type) throws MPIException
623 {
624 MPI.check();
625 assertDirectBuffer(buf);
626 Request req = new Request(iReadAll(handle, buf, count, type.handle));
627 req.addRecvBufRef(buf);
628 return req;
629 }
630
631 private native long iReadAll(long fh, Buffer buf, int count, long type)
632 throws MPIException;
633
634 /**
635 * Java binding of {@code MPI_FILE_IWRITE}.
636 * @param buf buffer
637 * @param count number of items in buffer
638 * @param type datatype of each buffer element
639 * @return request object
640 * @throws MPIException Signals that an MPI exception of some sort has occurred.
641 */
642 public Request iWrite(Buffer buf, int count, Datatype type) throws MPIException
643 {
644 MPI.check();
645 assertDirectBuffer(buf);
646 Request req = new Request(iWrite(handle, buf, count, type.handle));
647 req.addRecvBufRef(buf);
648 return req;
649 }
650
651 private native long iWrite(long fh, Buffer buf, int count, long type)
652 throws MPIException;
653
654 /**
655 * Java binding of {@code MPI_FILE_IWRITE_ALL}.
656 * @param buf buffer
657 * @param count number of items in buffer
658 * @param type datatype of each buffer element
659 * @return request object
660 * @throws MPIException Signals that an MPI exception of some sort has occurred.
661 */
662 public Request iWriteAll(Buffer buf, int count, Datatype type) throws MPIException
663 {
664 MPI.check();
665 assertDirectBuffer(buf);
666 Request req = new Request(iWriteAll(handle, buf, count, type.handle));
667 req.addRecvBufRef(buf);
668 return req;
669 }
670
671 private native long iWriteAll(long fh, Buffer buf, int count, long type)
672 throws MPIException;
673
674 /**
675 * Java binding of {@code MPI_FILE_SEEK}.
676 * @param offset file offset
677 * @param whence update mode
678 * @throws MPIException Signals that an MPI exception of some sort has occurred.
679 */
680 public void seek(long offset, int whence) throws MPIException
681 {
682 MPI.check();
683 seek(handle, offset, whence);
684 }
685
686 private native void seek(long fh, long offset, int whence) throws MPIException;
687
688 /**
689 * Java binding of {@code MPI_FILE_GET_POSITION}.
690 * @return offset of individual pointer
691 * @throws MPIException Signals that an MPI exception of some sort has occurred.
692 */
693 public long getPosition() throws MPIException
694 {
695 MPI.check();
696 return getPosition(handle);
697 }
698
699 private native long getPosition(long fh) throws MPIException;
700
701 /**
702 * Java binding of {@code MPI_FILE_GET_BYTE_OFFSET}.
703 * @param offset offset
704 * @return absolute byte position of offset
705 * @throws MPIException Signals that an MPI exception of some sort has occurred.
706 */
707 public long getByteOffset(long offset) throws MPIException
708 {
709 MPI.check();
710 return getByteOffset(handle, offset);
711 }
712
713 private native long getByteOffset(long fh, long offset) throws MPIException;
714
715 /**
716 * Java binding of {@code MPI_FILE_READ_SHARED}.
717 * @param buf buffer
718 * @param count number of items in buffer
719 * @param type datatype of each buffer element
720 * @return status object
721 * @throws MPIException Signals that an MPI exception of some sort has occurred.
722 */
723 public Status readShared(Object buf, int count, Datatype type)
724 throws MPIException
725 {
726 MPI.check();
727 int off = 0;
728 boolean db = false;
729 Status status = new Status();
730
731 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
732 {
733 off = type.getOffset(buf);
734 buf = ((Buffer)buf).array();
735 }
736
737 readShared(handle, buf, db, off, count,
738 type.handle, type.baseType, status.data);
739
740 return status;
741 }
742
743 private native void readShared(
744 long fh, Object buf, boolean db, int offset, int count,
745 long type, int baseType, long[] stat) throws MPIException;
746
747 /**
748 * Java binding of {@code MPI_FILE_WRITE_SHARED}.
749 * @param buf buffer
750 * @param count number of items in buffer
751 * @param type datatype of each buffer element
752 * @return status object
753 * @throws MPIException Signals that an MPI exception of some sort has occurred.
754 */
755 public Status writeShared(Object buf, int count, Datatype type)
756 throws MPIException
757 {
758 MPI.check();
759 int off = 0;
760 boolean db = false;
761 Status status = new Status();
762
763 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
764 {
765 off = type.getOffset(buf);
766 buf = ((Buffer)buf).array();
767 }
768
769 writeShared(handle, buf, db, off, count,
770 type.handle, type.baseType, status.data);
771
772 return status;
773 }
774
775 private native void writeShared(
776 long fh, Object buf, boolean db, int offset, int count,
777 long type, int baseType, long[] stat) throws MPIException;
778
779 /**
780 * Java binding of {@code MPI_FILE_IREAD_SHARED}.
781 * @param buf buffer
782 * @param count number of items in buffer
783 * @param type datatype of each buffer element
784 * @return request object
785 * @throws MPIException Signals that an MPI exception of some sort has occurred.
786 */
787 public Request iReadShared(Buffer buf, int count, Datatype type)
788 throws MPIException
789 {
790 MPI.check();
791 assertDirectBuffer(buf);
792 Request req = new Request(iReadShared(handle, buf, count, type.handle));
793 req.addRecvBufRef(buf);
794 return req;
795 }
796
797 private native long iReadShared(long fh, Buffer buf, int count, long type)
798 throws MPIException;
799
800 /**
801 * Java binding of {@code MPI_FILE_IWRITE_SHARED}.
802 * @param buf buffer
803 * @param count number of items in buffer
804 * @param type datatype of each buffer element
805 * @return request object
806 * @throws MPIException Signals that an MPI exception of some sort has occurred.
807 */
808 public Request iWriteShared(Buffer buf, int count, Datatype type)
809 throws MPIException
810 {
811 MPI.check();
812 assertDirectBuffer(buf);
813 Request req = new Request(iWriteShared(handle, buf, count, type.handle));
814 req.addSendBufRef(buf);
815 return req;
816 }
817
818 private native long iWriteShared(long fh, Buffer buf, int count, long type)
819 throws MPIException;
820
821 /**
822 * Java binding of {@code MPI_FILE_READ_ORDERED}.
823 * @param buf buffer
824 * @param count number of items in buffer
825 * @param type datatype of each buffer element
826 * @return status object
827 * @throws MPIException Signals that an MPI exception of some sort has occurred.
828 */
829 public Status readOrdered(Object buf, int count, Datatype type)
830 throws MPIException
831 {
832 MPI.check();
833 int off = 0;
834 boolean db = false;
835 Status status = new Status();
836
837 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
838 {
839 off = type.getOffset(buf);
840 buf = ((Buffer)buf).array();
841 }
842
843 readOrdered(handle, buf, db, off, count,
844 type.handle, type.baseType, status.data);
845
846 return status;
847 }
848
849 private native void readOrdered(
850 long fh, Object buf, boolean db, int offset, int count,
851 long type, int baseType, long[] stat) throws MPIException;
852
853 /**
854 * Java binding of {@code MPI_FILE_WRITE_ORDERED}.
855 * @param buf buffer
856 * @param count number of items in buffer
857 * @param type datatype of each buffer element
858 * @return status object
859 * @throws MPIException Signals that an MPI exception of some sort has occurred.
860 */
861 public Status writeOrdered(Object buf, int count, Datatype type)
862 throws MPIException
863 {
864 MPI.check();
865 int off = 0;
866 boolean db = false;
867 Status status = new Status();
868
869 if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect()))
870 {
871 off = type.getOffset(buf);
872 buf = ((Buffer)buf).array();
873 }
874
875 writeOrdered(handle, buf, db, off, count,
876 type.handle, type.baseType, status.data);
877
878 return status;
879 }
880
881 private native void writeOrdered(
882 long fh, Object buf, boolean db, int offset, int count,
883 long type, int baseType, long[] stat) throws MPIException;
884
885 /**
886 * Java binding of {@code MPI_FILE_SEEK_SHARED}.
887 * @param offset file offset
888 * @param whence update mode
889 * @throws MPIException Signals that an MPI exception of some sort has occurred.
890 */
891 public void seekShared(long offset, int whence) throws MPIException
892 {
893 MPI.check();
894 seekShared(handle, offset, whence);
895 }
896
897 private native void seekShared(long fh, long offset, int whence)
898 throws MPIException;
899
900 /**
901 * Java binding of {@code MPI_FILE_GET_POSITION_SHARED}.
902 * @return offset of individual pointer
903 * @throws MPIException Signals that an MPI exception of some sort has occurred.
904 */
905 public long getPositionShared() throws MPIException
906 {
907 MPI.check();
908 return getPositionShared(handle);
909 }
910
911 private native long getPositionShared(long fh) throws MPIException;
912
913 /**
914 * Java binding of {@code MPI_FILE_READ_AT_ALL_BEGIN}.
915 * @param offset file offset
916 * @param buf buffer
917 * @param count number of items in buffer
918 * @param type datatype of each buffer element
919 * @throws MPIException Signals that an MPI exception of some sort has occurred.
920 */
921 public void readAtAllBegin(long offset, Object buf, int count, Datatype type)
922 throws MPIException
923 {
924 MPI.check();
925
926 if(isDirectBuffer(buf))
927 {
928 readAtAllBegin(handle, offset, buf, count, type.handle);
929 }
930 else
931 {
932 int off = 0;
933 Status status = new Status();
934
935 if(isHeapBuffer(buf))
936 {
937 off = type.getOffset(buf);
938 buf = ((Buffer)buf).array();
939 }
940
941 readAtAll(handle, offset, buf, false, off, count,
942 type.handle, type.baseType, status.data);
943
944 beginStatus = status;
945 }
946 }
947
948 private native void readAtAllBegin(
949 long fh, long offset, Object buf, int count, long type)
950 throws MPIException;
951
952 /**
953 * Java binding of {@code MPI_FILE_READ_AT_ALL_END}.
954 * @param buf buffer
955 * @return status object
956 * @throws MPIException Signals that an MPI exception of some sort has occurred.
957 */
958 public Status readAtAllEnd(Object buf) throws MPIException
959 {
960 MPI.check();
961
962 if(isDirectBuffer(buf))
963 {
964 Status status = new Status();
965 readAtAllEnd(handle, buf, status.data);
966 return status;
967 }
968 else
969 {
970 return getBeginStatus();
971 }
972 }
973
974 private native void readAtAllEnd(long fh, Object buf, long[] stat)
975 throws MPIException;
976
977 /**
978 * Java binding of {@code MPI_FILE_WRITE_AT_ALL_BEGIN}.
979 * @param offset file offset
980 * @param buf buffer
981 * @param count number of items in buffer
982 * @param type datatype of each buffer element
983 * @throws MPIException Signals that an MPI exception of some sort has occurred.
984 */
985 public void writeAtAllBegin(long offset, Object buf, int count, Datatype type)
986 throws MPIException
987 {
988 MPI.check();
989
990 if(isDirectBuffer(buf))
991 {
992 writeAtAllBegin(handle, offset, buf, count, type.handle);
993 }
994 else
995 {
996 int off = 0;
997 Status status = new Status();
998
999 if(isHeapBuffer(buf))
1000 {
1001 off = type.getOffset(buf);
1002 buf = ((Buffer)buf).array();
1003 }
1004
1005 writeAtAll(handle, offset, buf, false, off, count,
1006 type.handle, type.baseType, status.data);
1007
1008 beginStatus = status;
1009 }
1010 }
1011
1012 private native void writeAtAllBegin(
1013 long fh, long fileOffset, Object buf, int count, long type)
1014 throws MPIException;
1015
1016 /**
1017 * Java binding of {@code MPI_FILE_WRITE_AT_ALL_END}.
1018 * @param buf buffer
1019 * @return status object
1020 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1021 */
1022 public Status writeAtAllEnd(Object buf) throws MPIException
1023 {
1024 MPI.check();
1025
1026 if(isDirectBuffer(buf))
1027 {
1028 Status status = new Status();
1029 writeAtAllEnd(handle, buf, status.data);
1030 return status;
1031 }
1032 else
1033 {
1034 return getBeginStatus();
1035 }
1036 }
1037
1038 private native void writeAtAllEnd(long fh, Object buf, long[] stat)
1039 throws MPIException;
1040
1041 /**
1042 * Java binding of {@code MPI_FILE_READ_ALL_BEGIN}.
1043 * @param buf buffer
1044 * @param count number of items in buffer
1045 * @param type datatype of each buffer element
1046 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1047 */
1048 public void readAllBegin(Object buf, int count, Datatype type)
1049 throws MPIException
1050 {
1051 MPI.check();
1052
1053 if(isDirectBuffer(buf))
1054 {
1055 readAllBegin(handle, buf, count, type.handle);
1056 }
1057 else
1058 {
1059 int off = 0;
1060 Status status = new Status();
1061
1062 if(isHeapBuffer(buf))
1063 {
1064 off = type.getOffset(buf);
1065 buf = ((Buffer)buf).array();
1066 }
1067
1068 readAll(handle, buf, false, off, count,
1069 type.handle, type.baseType, status.data);
1070
1071 beginStatus = status;
1072 }
1073 }
1074
1075 private native void readAllBegin(long fh, Object buf, int count, long type)
1076 throws MPIException;
1077
1078 /**
1079 * Java binding of {@code MPI_FILE_READ_ALL_END}.
1080 * @param buf buffer
1081 * @return status object
1082 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1083 */
1084 public Status readAllEnd(Object buf) throws MPIException
1085 {
1086 MPI.check();
1087
1088 if(isDirectBuffer(buf))
1089 {
1090 Status status = new Status();
1091 readAllEnd(handle, buf, status.data);
1092 return status;
1093 }
1094 else
1095 {
1096 return getBeginStatus();
1097 }
1098 }
1099
1100 private native void readAllEnd(long fh, Object buf, long[] stat)
1101 throws MPIException;
1102
1103 /**
1104 * Java binding of {@code MPI_FILE_WRITE_ALL_BEGIN}.
1105 * @param buf buffer
1106 * @param count number of items in buffer
1107 * @param type datatype of each buffer element
1108 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1109 */
1110 public void writeAllBegin(Object buf, int count, Datatype type)
1111 throws MPIException
1112 {
1113 MPI.check();
1114
1115 if(isDirectBuffer(buf))
1116 {
1117 writeAllBegin(handle, buf, count, type.handle);
1118 }
1119 else
1120 {
1121 int off = 0;
1122 Status status = new Status();
1123
1124 if(isHeapBuffer(buf))
1125 {
1126 off = type.getOffset(buf);
1127 buf = ((Buffer)buf).array();
1128 }
1129
1130 writeAll(handle, buf, false, off, count,
1131 type.handle, type.baseType, status.data);
1132
1133 beginStatus = status;
1134 }
1135 }
1136
1137 private native void writeAllBegin(long fh, Object buf, int count, long type)
1138 throws MPIException;
1139
1140 /**
1141 * Java binding of {@code MPI_FILE_WRITE_ALL_END}.
1142 * @param buf buffer
1143 * @return status object
1144 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1145 */
1146 public Status writeAllEnd(Object buf) throws MPIException
1147 {
1148 MPI.check();
1149
1150 if(isDirectBuffer(buf))
1151 {
1152 Status status = new Status();
1153 writeAllEnd(handle, buf, status.data);
1154 return status;
1155 }
1156 else
1157 {
1158 return getBeginStatus();
1159 }
1160 }
1161
1162 private native void writeAllEnd(long fh, Object buf, long[] stat)
1163 throws MPIException;
1164
1165 /**
1166 * Java binding of {@code MPI_FILE_READ_ORDERED_BEGIN}.
1167 * @param buf buffer
1168 * @param count number of items in buffer
1169 * @param type datatype of each buffer element
1170 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1171 */
1172 public void readOrderedBegin(Object buf, int count, Datatype type)
1173 throws MPIException
1174 {
1175 MPI.check();
1176
1177 if(isDirectBuffer(buf))
1178 {
1179 readOrderedBegin(handle, buf, count, type.handle);
1180 }
1181 else
1182 {
1183 int off = 0;
1184 Status status = new Status();
1185
1186 if(isHeapBuffer(buf))
1187 {
1188 off = type.getOffset(buf);
1189 buf = ((Buffer)buf).array();
1190 }
1191
1192 readOrdered(handle, buf, false, off, count,
1193 type.handle, type.baseType, status.data);
1194
1195 beginStatus = status;
1196 }
1197 }
1198
1199 private native void readOrderedBegin(long fh, Object buf, int count, long type)
1200 throws MPIException;
1201
1202 /**
1203 * Java binding of {@code MPI_FILE_READ_ORDERED_END}.
1204 * @param buf buffer
1205 * @return status object
1206 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1207 */
1208 public Status readOrderedEnd(Object buf) throws MPIException
1209 {
1210 MPI.check();
1211
1212 if(isDirectBuffer(buf))
1213 {
1214 Status status = new Status();
1215 readOrderedEnd(handle, buf, status.data);
1216 return status;
1217 }
1218 else
1219 {
1220 return getBeginStatus();
1221 }
1222 }
1223
1224 private native void readOrderedEnd(long fh, Object buf, long[] stat)
1225 throws MPIException;
1226
1227 /**
1228 * Java binding of {@code MPI_FILE_WRITE_ORDERED_BEGIN}.
1229 * @param buf buffer
1230 * @param count number of items in buffer
1231 * @param type datatype of each buffer element
1232 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1233 */
1234 public void writeOrderedBegin(Object buf, int count, Datatype type)
1235 throws MPIException
1236 {
1237 MPI.check();
1238
1239 if(isDirectBuffer(buf))
1240 {
1241 writeOrderedBegin(handle, buf, count, type.handle);
1242 }
1243 else
1244 {
1245 int off = 0;
1246 Status status = new Status();
1247
1248 if(isHeapBuffer(buf))
1249 {
1250 off = type.getOffset(buf);
1251 buf = ((Buffer)buf).array();
1252 }
1253
1254 writeOrdered(handle, buf, false, off, count,
1255 type.handle, type.baseType, status.data);
1256
1257 beginStatus = status;
1258 }
1259 }
1260
1261 private native void writeOrderedBegin(long fh, Object buf, int count, long type)
1262 throws MPIException;
1263
1264 /**
1265 * Java binding of {@code MPI_FILE_WRITE_ORDERED_END}.
1266 * @param buf buffer
1267 * @return status object
1268 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1269 */
1270 public Status writeOrderedEnd(Object buf) throws MPIException
1271 {
1272 MPI.check();
1273
1274 if(isDirectBuffer(buf))
1275 {
1276 Status status = new Status();
1277 writeOrderedEnd(handle, buf, status.data);
1278 return status;
1279 }
1280 else
1281 {
1282 return getBeginStatus();
1283 }
1284 }
1285
1286 private native void writeOrderedEnd(long fh, Object buf, long[] stat)
1287 throws MPIException;
1288
1289 private Status getBeginStatus()
1290 {
1291 Status s = beginStatus;
1292 beginStatus = null;
1293 return s;
1294 }
1295
1296 /**
1297 * Java binding of {@code MPI_FILE_GET_TYPE_EXTENT}.
1298 * @param type type of data
1299 * @return datatype extent
1300 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1301 */
1302 public int getTypeExtent(Datatype type) throws MPIException
1303 {
1304 MPI.check();
1305 return getTypeExtent(handle, type.handle) / type.baseSize;
1306 }
1307
1308 private native int getTypeExtent(long fh, long type) throws MPIException;
1309
1310 /**
1311 * Java binding of {@code MPI_FILE_SET_ATOMICITY}.
1312 * @param atomicity true to set atomic mode, false to set nonatomic mode
1313 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1314 */
1315 public void setAtomicity(boolean atomicity) throws MPIException
1316 {
1317 MPI.check();
1318 setAtomicity(handle, atomicity);
1319 }
1320
1321 private native void setAtomicity(long fh, boolean atomicity)
1322 throws MPIException;
1323
1324 /**
1325 * Java binding of {@code MPI_FILE_GET_ATOMICITY}.
1326 * @return current consistency of the file
1327 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1328 */
1329 public boolean getAtomicity() throws MPIException
1330 {
1331 MPI.check();
1332 return getAtomicity(handle);
1333 }
1334
1335 private native boolean getAtomicity(long fh) throws MPIException;
1336
1337 /**
1338 * Java binding of {@code MPI_FILE_SYNC}.
1339 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1340 */
1341 public void sync() throws MPIException
1342 {
1343 MPI.check();
1344 sync(handle);
1345 }
1346
1347 private native void sync(long handle) throws MPIException;
1348
1349 /**
1350 * Java binding of the MPI operation {@code MPI_FILE_SET_ERRHANDLER}.
1351 * @param errhandler new MPI error handler for file
1352 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1353 */
1354 public void setErrhandler(Errhandler errhandler) throws MPIException
1355 {
1356 MPI.check();
1357 setErrhandler(handle, errhandler.handle);
1358 }
1359
1360 private native void setErrhandler(long fh, long errhandler)
1361 throws MPIException;
1362
1363 /**
1364 * Java binding of the MPI operation {@code MPI_FILE_GET_ERRHANDLER}.
1365 * @return MPI error handler currently associated with file
1366 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1367 */
1368 public Errhandler getErrhandler() throws MPIException
1369 {
1370 MPI.check();
1371 return new Errhandler(getErrhandler(handle));
1372 }
1373
1374 private native long getErrhandler(long fh);
1375
1376 /**
1377 * Java binding of the MPI operation {@code MPI_FILE_CALL_ERRHANDLER}.
1378 * @param errorCode error code
1379 * @throws MPIException Signals that an MPI exception of some sort has occurred.
1380 */
1381 public void callErrhandler(int errorCode) throws MPIException
1382 {
1383 callErrhandler(handle, errorCode);
1384 }
1385
1386 private native void callErrhandler(long handle, int errorCode)
1387 throws MPIException;
1388
1389 } // File