|
26 | 26 | public final class Win implements Freeable |
27 | 27 | { |
28 | 28 | private long handle; |
| 29 | +public static final int WIN_NULL = 0; |
| 30 | +public static final int FLAVOR_PRIVATE = 0; |
| 31 | +public static final int FLAVOR_SHARED = 1; |
29 | 32 |
|
30 | 33 | /** |
31 | 34 | * Java binding of {@code MPI_WIN_CREATE}. |
@@ -65,6 +68,69 @@ private native long createWin( |
65 | 68 | Buffer base, int size, int dispUnit, long info, long comm) |
66 | 69 | throws MPIException; |
67 | 70 |
|
| 71 | +/** |
| 72 | + * Java binding of {@code MPI_WIN_ALLOCATE} and {@code MPI_WIN_ALLOCATE_SHARED}. |
| 73 | + * @param size size of window (buffer elements) |
| 74 | + * @param dispUnit local unit size for displacements (buffer elements) |
| 75 | + * @param info info object |
| 76 | + * @param comm communicator |
| 77 | + * @param base initial address of window |
| 78 | + * @param flavor FLAVOR_PRIVATE or FLAVOR_SHARED |
| 79 | + * @throws MPIException |
| 80 | + */ |
| 81 | +public Win(int size, int dispUnit, Info info, Comm comm, Buffer base, int flavor) |
| 82 | + throws MPIException |
| 83 | +{ |
| 84 | + if(!base.isDirect()) |
| 85 | + throw new IllegalArgumentException("The buffer must be direct."); |
| 86 | + |
| 87 | + int baseSize; |
| 88 | + |
| 89 | + if(base instanceof ByteBuffer) |
| 90 | + baseSize = 1; |
| 91 | + else if(base instanceof CharBuffer || base instanceof ShortBuffer) |
| 92 | + baseSize = 2; |
| 93 | + else if(base instanceof IntBuffer || base instanceof FloatBuffer) |
| 94 | + baseSize = 4; |
| 95 | + else if(base instanceof LongBuffer || base instanceof DoubleBuffer) |
| 96 | + baseSize = 8; |
| 97 | + else |
| 98 | + throw new AssertionError(); |
| 99 | + |
| 100 | + int sizeBytes = size * baseSize, |
| 101 | + dispBytes = dispUnit * baseSize; |
| 102 | + |
| 103 | + if(flavor == 0) { |
| 104 | + handle = allocateWin(sizeBytes, dispBytes, info.handle, comm.handle, base); |
| 105 | + } else if(flavor == 1) { |
| 106 | + handle = allocateSharedWin(sizeBytes, dispBytes, info.handle, comm.handle, base); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +private native long allocateWin( |
| 111 | + int size, int dispUnit, long info, long comm, Buffer base) |
| 112 | + throws MPIException; |
| 113 | + |
| 114 | +private native long allocateSharedWin( |
| 115 | + int size, int dispUnit, long info, long comm, Buffer base) |
| 116 | + throws MPIException; |
| 117 | + |
| 118 | +/** |
| 119 | + * Java binding of {@code MPI_WIN_CREATE_DYNAMIC}. |
| 120 | + * @param info info object |
| 121 | + * @param comm communicator |
| 122 | + * @throws MPIException |
| 123 | + */ |
| 124 | +public Win(Info info, Comm comm) |
| 125 | + throws MPIException |
| 126 | +{ |
| 127 | + handle = createDynamicWin(info.handle, comm.handle); |
| 128 | +} |
| 129 | + |
| 130 | +private native long createDynamicWin( |
| 131 | + long info, long comm) |
| 132 | + throws MPIException; |
| 133 | + |
68 | 134 | private int getBaseType(Datatype orgType, Datatype targetType) |
69 | 135 | { |
70 | 136 | int baseType = orgType.baseType; |
@@ -718,11 +784,38 @@ public void fetchAndOp(Buffer origin, Buffer resultAddr, Datatype dataType, |
718 | 784 | throw new IllegalArgumentException("The origin must be direct buffer."); |
719 | 785 |
|
720 | 786 | fetchAndOp(handle, origin, resultAddr, dataType.handle, targetRank, |
721 | | - targetDisp, op, op.handle, getBaseType(dataType, dataType)); //neccessary? |
| 787 | + targetDisp, op, op.handle, getBaseType(dataType, dataType)); |
722 | 788 | } |
723 | 789 |
|
724 | 790 | private native void fetchAndOp( |
725 | 791 | long win, Buffer origin, Buffer resultAddr, long targetType, int targetRank, |
726 | 792 | int targetDisp, Op jOp, long hOp, int baseType) throws MPIException; |
727 | 793 |
|
| 794 | +/** |
| 795 | + * Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL}. |
| 796 | + * @param targetRank rank of target window |
| 797 | + * @throws MPIException |
| 798 | + */ |
| 799 | + |
| 800 | +public void flushLocal(int targetRank) throws MPIException |
| 801 | +{ |
| 802 | + MPI.check(); |
| 803 | + flushLocal(handle, targetRank); |
| 804 | +} |
| 805 | + |
| 806 | +private native void flushLocal(long win, int targetRank) throws MPIException; |
| 807 | + |
| 808 | +/** |
| 809 | + * Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL_ALL}. |
| 810 | + * @throws MPIException |
| 811 | + */ |
| 812 | + |
| 813 | +public void flushLocalAll() throws MPIException |
| 814 | +{ |
| 815 | + MPI.check(); |
| 816 | + flushLocalAll(handle); |
| 817 | +} |
| 818 | + |
| 819 | +private native void flushLocalAll(long win) throws MPIException; |
| 820 | + |
728 | 821 | } // Win |
0 commit comments