From 0d7a38552eba1da910c6db7debd3ed891f0275ab Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Fri, 24 Jul 2015 11:02:13 -0600 Subject: [PATCH 1/2] Formatting fixes for Java files. Fixed tab indenting as well as some of the block comments at the top of a few of the files. Signed-off-by: Nathaniel Graham --- ompi/mpi/java/java/CartComm.java | 346 +- ompi/mpi/java/java/CartParms.java | 142 +- ompi/mpi/java/java/Comm.java | 6546 ++++++++++---------- ompi/mpi/java/java/Constant.java | 173 +- ompi/mpi/java/java/Datatype.java | 954 +-- ompi/mpi/java/java/DistGraphNeighbors.java | 146 +- ompi/mpi/java/java/DoubleComplex.java | 216 +- ompi/mpi/java/java/DoubleInt.java | 154 +- ompi/mpi/java/java/Errhandler.java | 50 +- ompi/mpi/java/java/File.java | 2394 +++---- ompi/mpi/java/java/FileView.java | 100 +- ompi/mpi/java/java/FloatComplex.java | 216 +- ompi/mpi/java/java/FloatInt.java | 154 +- ompi/mpi/java/java/Freeable.java | 44 +- ompi/mpi/java/java/GraphComm.java | 260 +- ompi/mpi/java/java/GraphParms.java | 146 +- ompi/mpi/java/java/Group.java | 412 +- ompi/mpi/java/java/Info.java | 256 +- ompi/mpi/java/java/Int2.java | 178 +- ompi/mpi/java/java/Intercomm.java | 232 +- ompi/mpi/java/java/Intracomm.java | 1602 ++--- ompi/mpi/java/java/LongInt.java | 190 +- ompi/mpi/java/java/MPI.java | 2836 ++++++--- ompi/mpi/java/java/MPIException.java | 116 +- ompi/mpi/java/java/Message.java | 214 +- ompi/mpi/java/java/Op.java | 164 +- ompi/mpi/java/java/Prequest.java | 106 +- ompi/mpi/java/java/Request.java | 750 +-- ompi/mpi/java/java/ShiftParms.java | 82 +- ompi/mpi/java/java/ShortInt.java | 196 +- ompi/mpi/java/java/Status.java | 252 +- ompi/mpi/java/java/Struct.java | 1540 ++--- ompi/mpi/java/java/UserFunction.java | 278 +- ompi/mpi/java/java/Win.java | 1740 +++--- 34 files changed, 12060 insertions(+), 11125 deletions(-) diff --git a/ompi/mpi/java/java/CartComm.java b/ompi/mpi/java/java/CartComm.java index 7e9a1e17c1..383b78de60 100644 --- a/ompi/mpi/java/java/CartComm.java +++ b/ompi/mpi/java/java/CartComm.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Cartcomm.java * Author : Xinying Li * Created : Thu Apr 9 12:22:15 1998 @@ -52,181 +52,181 @@ package mpi; */ public final class CartComm extends Intracomm { -static -{ - init(); -} + static + { + init(); + } -private static native void init(); + private static native void init(); -protected CartComm(long handle) throws MPIException -{ - super(handle); -} + protected CartComm(long handle) throws MPIException + { + super(handle); + } -protected CartComm(long[] commRequest) -{ - super(commRequest); -} + protected CartComm(long[] commRequest) + { + super(commRequest); + } -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - *

It is recommended to use {@link #dup} instead of {@link #clone} - * because the last can't throw an {@link mpi.MPIException}. - * @return copy of this communicator - */ -@Override public CartComm clone() -{ - try - { - return dup(); - } - catch(MPIException e) - { - throw new RuntimeException(e.getMessage()); - } -} + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + *

It is recommended to use {@link #dup} instead of {@link #clone} + * because the last can't throw an {@link mpi.MPIException}. + * @return copy of this communicator + */ + @Override public CartComm clone() + { + try + { + return dup(); + } + catch(MPIException e) + { + throw new RuntimeException(e.getMessage()); + } + } -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public CartComm dup() throws MPIException -{ - MPI.check(); - return new CartComm(dup(handle)); -} + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public CartComm dup() throws MPIException + { + MPI.check(); + return new CartComm(dup(handle)); + } -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_IDUP}. - *

The new communicator can't be used before the operation completes. - * The request object must be obtained calling {@link #getRequest}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. Signals that an MPI exception of some sort has occurred. - */ -@Override public CartComm iDup() throws MPIException -{ - MPI.check(); - return new CartComm(iDup(handle)); -} + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_IDUP}. + *

The new communicator can't be used before the operation completes. + * The request object must be obtained calling {@link #getRequest}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. Signals that an MPI exception of some sort has occurred. + */ + @Override public CartComm iDup() throws MPIException + { + MPI.check(); + return new CartComm(iDup(handle)); + } -/** - * Returns cartesian topology information. - *

Java binding of the MPI operations {@code MPI_CARTDIM_GET} and - * {@code MPI_CART_GET}. - *

The number of dimensions can be obtained from the size of (eg) - * {@code dims} field of the returned object. - * @return object containing dimensions, periods and local coordinates - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public CartParms getTopo() throws MPIException -{ - MPI.check(); - return getTopo(handle); -} + /** + * Returns cartesian topology information. + *

Java binding of the MPI operations {@code MPI_CARTDIM_GET} and + * {@code MPI_CART_GET}. + *

The number of dimensions can be obtained from the size of (eg) + * {@code dims} field of the returned object. + * @return object containing dimensions, periods and local coordinates + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public CartParms getTopo() throws MPIException + { + MPI.check(); + return getTopo(handle); + } -private native CartParms getTopo(long comm) throws MPIException; + private native CartParms getTopo(long comm) throws MPIException; -/** - * Translate logical process coordinates to process rank. - *

Java binding of the MPI operation {@code MPI_CART_RANK}. - * @param coords Cartesian coordinates of a process - * @return rank of the specified process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getRank(int[] coords) throws MPIException -{ - MPI.check(); - return getRank(handle, coords); -} + /** + * Translate logical process coordinates to process rank. + *

Java binding of the MPI operation {@code MPI_CART_RANK}. + * @param coords Cartesian coordinates of a process + * @return rank of the specified process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getRank(int[] coords) throws MPIException + { + MPI.check(); + return getRank(handle, coords); + } -private native int getRank(long comm, int[] coords) throws MPIException; + private native int getRank(long comm, int[] coords) throws MPIException; -/** - * Translate process rank to logical process coordinates. - *

Java binding of the MPI operation {@code MPI_CART_COORDS}. - * @param rank rank of a process - * @return Cartesian coordinates of the specified process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int[] getCoords(int rank) throws MPIException -{ - MPI.check(); - return getCoords(handle, rank); -} + /** + * Translate process rank to logical process coordinates. + *

Java binding of the MPI operation {@code MPI_CART_COORDS}. + * @param rank rank of a process + * @return Cartesian coordinates of the specified process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int[] getCoords(int rank) throws MPIException + { + MPI.check(); + return getCoords(handle, rank); + } -private native int[] getCoords(long comm, int rank) throws MPIException; + private native int[] getCoords(long comm, int rank) throws MPIException; -/** - * Compute source and destination ranks for "shift" communication. - *

Java binding of the MPI operation {@code MPI_CART_SHIFT}. - * @param direction coordinate dimension of shift - * @param disp displacement - * @return object containing ranks of source and destination processes - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public ShiftParms shift(int direction, int disp) throws MPIException -{ - MPI.check(); - return shift(handle, direction, disp); -} + /** + * Compute source and destination ranks for "shift" communication. + *

Java binding of the MPI operation {@code MPI_CART_SHIFT}. + * @param direction coordinate dimension of shift + * @param disp displacement + * @return object containing ranks of source and destination processes + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public ShiftParms shift(int direction, int disp) throws MPIException + { + MPI.check(); + return shift(handle, direction, disp); + } -private native ShiftParms shift(long comm, int direction, int disp) - throws MPIException; + private native ShiftParms shift(long comm, int direction, int disp) + throws MPIException; -/** - * Partition cartesian communicator into subgroups of lower dimension. - *

Java binding of the MPI operation {@code MPI_CART_SUB}. - * @param remainDims by dimension, {@code true} if dimension is to be kept, - * {@code false} otherwise - * @return communicator containing subgrid including this process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public CartComm sub(boolean[] remainDims) throws MPIException -{ - MPI.check(); - return new CartComm(sub(handle, remainDims)); -} + /** + * Partition cartesian communicator into subgroups of lower dimension. + *

Java binding of the MPI operation {@code MPI_CART_SUB}. + * @param remainDims by dimension, {@code true} if dimension is to be kept, + * {@code false} otherwise + * @return communicator containing subgrid including this process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public CartComm sub(boolean[] remainDims) throws MPIException + { + MPI.check(); + return new CartComm(sub(handle, remainDims)); + } -private native long sub(long comm, boolean[] remainDims) throws MPIException; + private native long sub(long comm, boolean[] remainDims) throws MPIException; -/** - * Compute an optimal placement. - *

Java binding of the MPI operation {@code MPI_CART_MAP}. - *

The number of dimensions is taken to be size of the {@code dims} argument. - * @param dims the number of processes in each dimension - * @param periods {@code true} if grid is periodic, - * {@code false} if not, in each dimension - * @return reordered rank of calling process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int map(int[] dims, boolean[] periods) throws MPIException -{ - MPI.check(); - return map(handle, dims, periods); -} + /** + * Compute an optimal placement. + *

Java binding of the MPI operation {@code MPI_CART_MAP}. + *

The number of dimensions is taken to be size of the {@code dims} argument. + * @param dims the number of processes in each dimension + * @param periods {@code true} if grid is periodic, + * {@code false} if not, in each dimension + * @return reordered rank of calling process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int map(int[] dims, boolean[] periods) throws MPIException + { + MPI.check(); + return map(handle, dims, periods); + } -private native int map(long comm, int[] dims, boolean[] periods) - throws MPIException; + private native int map(long comm, int[] dims, boolean[] periods) + throws MPIException; -/** - * Select a balanced distribution of processes per coordinate direction. - *

Java binding of the MPI operation {@code MPI_DIMS_CREATE}. - * @param nnodes number of nodes in a grid - * @param dims array specifying the number of nodes in each dimension - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void createDims(int nnodes, int[] dims) throws MPIException -{ - MPI.check(); - createDims_jni(nnodes, dims); -} + /** + * Select a balanced distribution of processes per coordinate direction. + *

Java binding of the MPI operation {@code MPI_DIMS_CREATE}. + * @param nnodes number of nodes in a grid + * @param dims array specifying the number of nodes in each dimension + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void createDims(int nnodes, int[] dims) throws MPIException + { + MPI.check(); + createDims_jni(nnodes, dims); + } -private static native void createDims_jni(int nnodes, int[] dims) - throws MPIException; + private static native void createDims_jni(int nnodes, int[] dims) + throws MPIException; } // Cartcomm diff --git a/ompi/mpi/java/java/CartParms.java b/ompi/mpi/java/java/CartParms.java index bbcd867a8f..756082951c 100644 --- a/ompi/mpi/java/java/CartParms.java +++ b/ompi/mpi/java/java/CartParms.java @@ -9,31 +9,33 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : CartParms.java * Author : Xinying Li * Created : Thu Apr 9 12:22:15 1998 @@ -50,65 +52,65 @@ package mpi; */ public final class CartParms { -/** Number of processes for each cartesian dimension. */ -private final int[] dims; + /** Number of processes for each cartesian dimension. */ + private final int[] dims; -/** Periodicity (true/false) for each cartesian dimension. */ -private final boolean[] periods; + /** Periodicity (true/false) for each cartesian dimension. */ + private final boolean[] periods; -/** Coordinates of calling process in cartesian structure. */ -private final int[] coords; + /** Coordinates of calling process in cartesian structure. */ + private final int[] coords; -/** - * Constructs a cartesian topology information object. - * @param dims number of processes for each cartesian dimension. - * @param periods periodicity (true/false) for each cartesian dimension. - * @param coords coordinates of calling process in cartesian structure. - */ -protected CartParms(int[] dims, boolean[] periods, int[] coords) -{ - this.dims = dims; - this.periods = periods; - this.coords = coords; -} + /** + * Constructs a cartesian topology information object. + * @param dims number of processes for each cartesian dimension. + * @param periods periodicity (true/false) for each cartesian dimension. + * @param coords coordinates of calling process in cartesian structure. + */ + protected CartParms(int[] dims, boolean[] periods, int[] coords) + { + this.dims = dims; + this.periods = periods; + this.coords = coords; + } -/** - * Returns the number of dimensions. - * @return number of dimensions. - */ -public int getDimCount() -{ - return dims.length; -} + /** + * Returns the number of dimensions. + * @return number of dimensions. + */ + public int getDimCount() + { + return dims.length; + } -/** - * Returns the number of processes for a cartesian dimension. - * @param i cartesian dimension. - * @return number of processes for a cartesian dimension. - */ -public int getDim(int i) -{ - return dims[i]; -} + /** + * Returns the number of processes for a cartesian dimension. + * @param i cartesian dimension. + * @return number of processes for a cartesian dimension. + */ + public int getDim(int i) + { + return dims[i]; + } -/** - * Returns the periodicity (true/false) for a cartesian dimension. - * @param i cartesian dimension. - * @return periodicity for a cartesian dimension. - */ -public boolean getPeriod(int i) -{ - return periods[i]; -} + /** + * Returns the periodicity (true/false) for a cartesian dimension. + * @param i cartesian dimension. + * @return periodicity for a cartesian dimension. + */ + public boolean getPeriod(int i) + { + return periods[i]; + } -/** - * Returns the coordinate of calling process for a cartesian dimension. - * @param i cartesian dimension. - * @return coordinate of calling process for a cartesian dimension. - */ -public int getCoord(int i) -{ - return coords[i]; -} + /** + * Returns the coordinate of calling process for a cartesian dimension. + * @param i cartesian dimension. + * @return coordinate of calling process for a cartesian dimension. + */ + public int getCoord(int i) + { + return coords[i]; + } } // CartParms diff --git a/ompi/mpi/java/java/Comm.java b/ompi/mpi/java/java/Comm.java index 97b681cb81..a20f22dc50 100644 --- a/ompi/mpi/java/java/Comm.java +++ b/ompi/mpi/java/java/Comm.java @@ -18,26 +18,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Comm.java * Author : Sang Lim, Sung-Hoon Ko, Xinying Li, Bryan Carpenter * Created : Thu Apr 9 12:22:15 1998 @@ -45,9 +45,9 @@ * Updated : $Date: 2001/08/07 16:36:25 $ * Copyright: Northeast Parallel Architectures Center * at Syracuse University 1998 - */ - -/* + * + * + * * IMPLEMENTATION DETAILS * * All methods with buffers that can be direct or non direct have @@ -67,3260 +67,3260 @@ import static mpi.MPI.assertDirectBuffer; */ public class Comm implements Freeable { -public final static int TYPE_SHARED = 0; -protected final static int SELF = 1; -protected final static int WORLD = 2; -protected long handle; -private Request request; - -private static long nullHandle; - -static -{ - init(); -} - -private static native void init(); - -protected Comm() -{ -} - -protected Comm(long handle) -{ - this.handle = handle; -} - -protected Comm(long[] commRequest) -{ - handle = commRequest[0]; - request = new Request(commRequest[1]); -} - -protected final void setType(int type) -{ - getComm(type); -} - -private native void getComm(int type); - -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - *

It is recommended to use {@link #dup} instead of {@link #clone} - * because the last can't throw an {@link mpi.MPIException}. - * @return copy of this communicator - */ -@Override public Comm clone() -{ - try - { - return dup(); - } - catch(MPIException e) - { - throw new RuntimeException(e.getMessage()); - } -} - -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Comm dup() throws MPIException -{ - MPI.check(); - return new Comm(dup(handle)); -} - -protected final native long dup(long comm) throws MPIException; - -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_IDUP}. - *

The new communicator can't be used before the operation completes. - * The request object must be obtained calling {@link #getRequest}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Comm iDup() throws MPIException -{ - MPI.check(); - return new Comm(iDup(handle)); -} - -protected final native long[] iDup(long comm) throws MPIException; - -/** - * Returns the associated request to this communicator if it was - * created using {@link #iDup}. - * @return associated request if this communicator was created - * using {@link #iDup}, or null otherwise. - */ -public final Request getRequest() -{ - return request; -} - -/** - * Size of group of this communicator. - *

Java binding of the MPI operation {@code MPI_COMM_SIZE}. - * @return number of processors in the group of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int getSize() throws MPIException -{ - MPI.check(); - return getSize(handle); -} - -private native int getSize(long comm) throws MPIException; - -/** - * Rank of this process in group of this communicator. - *

Java binding of the MPI operation {@code MPI_COMM_RANK}. - * @return rank of the calling process in the group of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int getRank() throws MPIException -{ - MPI.check(); - return getRank(handle); -} - -private native int getRank(long comm) throws MPIException; - -/** - * Compare two communicators. - *

Java binding of the MPI operation {@code MPI_COMM_COMPARE}. - * @param comm1 first communicator - * @param comm2 second communicator - * @return - * {@code MPI.IDENT} results if the {@code comm1} and {@code comm2} - * are references to the same object (ie, if {@code comm1 == comm2}).
- * {@code MPI.CONGRUENT} results if the underlying groups are identical - * but the communicators differ by context.
- * {@code MPI.SIMILAR} results if the underlying groups are similar - * but the communicators differ by context.
- * {@code MPI.UNEQUAL} results otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int compare(Comm comm1, Comm comm2) throws MPIException -{ - MPI.check(); - return compare(comm1.handle, comm2.handle); -} - -private static native int compare(long comm1, long comm2) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_COMM_FREE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override final public void free() throws MPIException -{ - MPI.check(); - handle = free(handle); -} - -private native long free(long comm) throws MPIException; - -/** - * Test if communicator object is null (has been freed). - * Java binding of {@code MPI_COMM_NULL}. - * @return true if the comm object is null, false otherwise - */ -public final boolean isNull() -{ - return handle == nullHandle; -} - -/** - * Java binding of {@code MPI_COMM_SET_INFO}. - * @param info info object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void setInfo(Info info) throws MPIException -{ - MPI.check(); - setInfo(handle, info.handle); -} - -private native void setInfo(long comm, long info) throws MPIException; - -/** - * Java binding of {@code MPI_COMM_GET_INFO}. - * @return new info object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Info getInfo() throws MPIException -{ - MPI.check(); - return new Info(getInfo(handle)); -} - -private native long getInfo(long comm) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_COMM_DISCONNECT}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void disconnect() throws MPIException -{ - MPI.check(); - handle = disconnect(handle); -} - -private native long disconnect(long comm) throws MPIException; - -/** - * Return group associated with a communicator. - *

Java binding of the MPI operation {@code MPI_COMM_GROUP}. - * @return group corresponding to this communicator group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Group getGroup() throws MPIException -{ - MPI.check(); - return new Group(getGroup(handle)); -} - -private native long getGroup(long comm); - -// Inter-communication - -/** - * Test if this communicator is an inter-communicator. - *

Java binding of the MPI operation {@code MPI_COMM_TEST_INTER}. - * @return {@code true} if this is an inter-communicator, - * {@code false} otherwise - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final boolean isInter() throws MPIException -{ - MPI.check(); - return isInter(handle); -} - -private native boolean isInter(long comm) throws MPIException; - -/** - * Create an inter-communicator. - *

- * Java binding of the MPI operation {@code MPI_INTERCOMM_CREATE}. - *

- * This operation is defined as a method on the "peer communicator", - * making it analogous to a {@code send} or {@code recv} communication - * with the remote group leader. - * @param localComm local intra-communicator - * @param localLeader rank of local group leader in {@code localComm} - * @param remoteLeader rank of remote group leader in this communicator - * @param tag "safe" tag - * @return new inter-communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intercomm createIntercomm(Comm localComm, int localLeader, - int remoteLeader, int tag) - throws MPIException -{ - MPI.check(); - - return new Intercomm(createIntercomm(handle, localComm.handle, - localLeader, remoteLeader, tag)); -} - -private native long createIntercomm( - long comm, long localComm, int localLeader, - int remoteLeader, int tag) throws MPIException; - -// Blocking Send and Recv - -/** - * Blocking send operation. - *

Java binding of the MPI operation {@code MPI_SEND}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void send(Object buf, int count, Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - send(handle, buf, db, off, count, type.handle, type.baseType, dest, tag); -} - -private native void send( - long comm, Object buf, boolean db, int offset, int count, - long type, int baseType, int dest, int tag) throws MPIException; - -/** - * Blocking receive operation. - *

Java binding of the MPI operation {@code MPI_RECV}. - * @param buf receive buffer - * @param count number of items in receive buffer - * @param type datatype of each item in receive buffer - * @param source rank of source - * @param tag message tag - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Status recv(Object buf, int count, - Datatype type, int source, int tag) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - Status status = new Status(); - - recv(handle, buf, db, off, count, - type.handle, type.baseType, source, tag, status.data); - - return status; -} - -private native void recv( - long comm, Object buf, boolean db, int offset, int count, - long type, int basetype, int source, int tag, long[] stat) - throws MPIException; - -// Send-Recv - -/** - * Execute a blocking send and receive operation. - *

Java binding of the MPI operation {@code MPI_SENDRECV}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param dest rank of destination - * @param sendtag send tag - * @param recvbuf receive buffer - * @param recvcount number of items in receive buffer - * @param recvtype datatype of each item in receive buffer - * @param source rank of source - * @param recvtag receive tag - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - * @see mpi.Comm#recv(Object, int, Datatype, int, int) - */ -public final Status sendRecv( - Object sendbuf, int sendcount, Datatype sendtype, int dest, int sendtag, - Object recvbuf, int recvcount, Datatype recvtype, int source, int recvtag) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - Status status = new Status(); - - sendRecv(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, dest, sendtag, - recvbuf, rdb, recvoff, recvcount, - recvtype.handle, recvtype.baseType, source, recvtag, status.data); - - return status; -} - -private native void sendRecv( - long comm, Object sbuf, boolean sdb, int soffset, int scount, - long sType, int sBaseType, int dest, int stag, - Object rbuf, boolean rdb, int roffset, int rcount, - long rType, int rBaseType, int source, int rtag, - long[] stat) throws MPIException; - -/** - * Execute a blocking send and receive operation, - * receiving message into send buffer. - *

Java binding of the MPI operation {@code MPI_SENDRECV_REPLACE}. - * @param buf buffer - * @param count number of items to send - * @param type datatype of each item in buffer - * @param dest rank of destination - * @param sendtag send tag - * @param source rank of source - * @param recvtag receive tag - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - * @see mpi.Comm#recv(Object, int, Datatype, int, int) - */ -public final Status sendRecvReplace( - Object buf, int count, Datatype type, - int dest, int sendtag, int source, int recvtag) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - Status status = new Status(); - - sendRecvReplace(handle, buf, db, off, count, type.handle, type.baseType, - dest, sendtag, source, recvtag, status.data); - - return status; -} - -private native void sendRecvReplace( - long comm, Object buf, boolean db, int offset, int count, - long type, int baseType, int dest, int stag, - int source, int rtag, long[] stat) throws MPIException; - -// Communication Modes - -/** - * Send in buffered mode. - *

Java binding of the MPI operation {@code MPI_BSEND}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final void bSend(Object buf, int count, Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - bSend(handle, buf, db, off, count, type.handle, type.baseType, dest, tag); -} - -private native void bSend( - long comm, Object buf, boolean db, int offset, int count, - long type, int baseType, int dest, int tag) throws MPIException; - -/** - * Send in synchronous mode. - *

Java binding of the MPI operation {@code MPI_SSEND}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final void sSend(Object buf, int count, Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - sSend(handle, buf, db, off, count, type.handle, type.baseType, dest, tag); -} - -private native void sSend( - long comm, Object buf, boolean db, int offset, int count, - long type, int baseType, int dest, int tag) throws MPIException; - -/** - * Send in ready mode. - *

Java binding of the MPI operation {@code MPI_RSEND}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final void rSend(Object buf, int count, Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - rSend(handle, buf, db, off, count, type.handle, type.baseType, dest, tag); -} - -private native void rSend( - long comm, Object buf, boolean db, int offset, int count, - long type, int baseType, int dest, int tag) throws MPIException; - -// Nonblocking communication - -/** - * Start a standard mode, nonblocking send. - *

Java binding of the MPI operation {@code MPI_ISEND}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final Request iSend(Buffer buf, int count, - Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iSend(handle, buf, count, type.handle, dest, tag)); -} - -private native long iSend( - long comm, Buffer buf, int count, long type, int dest, int tag) - throws MPIException; - -/** - * Start a buffered mode, nonblocking send. - *

Java binding of the MPI operation MPI_IBSEND. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final Request ibSend(Buffer buf, int count, - Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(ibSend(handle, buf, count, type.handle, dest, tag)); -} - -private native long ibSend( - long comm, Buffer buf, int count, long type, int dest, int tag) - throws MPIException; - -/** - * Start a synchronous mode, nonblocking send. - *

Java binding of the MPI operation {@code MPI_ISSEND}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final Request isSend(Buffer buf, int count, - Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(isSend(handle, buf, count, type.handle, dest, tag)); -} - -private native long isSend( - long comm, Buffer buf, int count, long type, int dest, int tag) - throws MPIException; - -/** - * Start a ready mode, nonblocking send. - *

Java binding of the MPI operation {@code MPI_IRSEND}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final Request irSend(Buffer buf, int count, - Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(irSend(handle, buf, count, type.handle, dest, tag)); -} - -private native long irSend( - long comm, Buffer buf, int count, long type, int dest, int tag) - throws MPIException; - -/** - * Start a nonblocking receive. - *

Java binding of the MPI operation {@code MPI_IRECV}. - * @param buf receive buffer - * @param count number of items in receive buffer - * @param type datatype of each item in receive buffer - * @param source rank of source - * @param tag message tag - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#recv(Object, int, Datatype, int, int) - */ -public final Request iRecv(Buffer buf, int count, - Datatype type, int source, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iRecv(handle, buf, count, type.handle, source, tag)); -} - -private native long iRecv( - long comm, Buffer buf, int count, long type, int source, int tag) - throws MPIException; - - -// Persistent communication requests - -/** - * Creates a persistent communication request for a standard mode send. - *

Java binding of the MPI operation {@code MPI_SEND_INIT}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @return persistent communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final Prequest sendInit(Buffer buf, int count, - Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Prequest(sendInit(handle, buf, count, type.handle, dest, tag)); -} - -private native long sendInit( - long comm, Buffer buf, int count, long type, int dest, int tag) - throws MPIException; - -/** - * Creates a persistent communication request for a buffered mode send. - *

Java binding of the MPI operation {@code MPI_BSEND_INIT}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @return persistent communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final Prequest bSendInit(Buffer buf, int count, - Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Prequest(bSendInit(handle, buf, count, type.handle, dest, tag)); -} - -private native long bSendInit( - long comm, Buffer buf, int count, long type, int dest, int tag) - throws MPIException; - -/** - * Creates a persistent communication request for a synchronous mode send. - *

Java binding of the MPI operation {@code MPI_SSEND_INIT}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @return persistent communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final Prequest sSendInit(Buffer buf, int count, - Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Prequest(sSendInit(handle, buf, count, type.handle, dest, tag)); -} - -private native long sSendInit( - long comm, Buffer buf, int count, long type, int dest, int tag) - throws MPIException; - -/** - * Creates a persistent communication request for a ready mode send. - *

Java binding of the MPI operation {@code MPI_RSEND_INIT}. - * @param buf send buffer - * @param count number of items to send - * @param type datatype of each item in send buffer - * @param dest rank of destination - * @param tag message tag - * @return persistent communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#send(Object, int, Datatype, int, int) - */ -public final Prequest rSendInit(Buffer buf, int count, - Datatype type, int dest, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Prequest(rSendInit(handle, buf, count, type.handle, dest, tag)); -} - -private native long rSendInit( - long comm, Buffer buf, int count, long type, int dest, int tag) - throws MPIException; - -/** - * Creates a persistent communication request for a receive operation. - *

Java binding of the MPI operation {@code MPI_RECV_INIT}. - * @param buf receive buffer - * @param count number of items in receive buffer - * @param type datatype of each item in receive buffer - * @param source rank of source - * @param tag message tag - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - * @see mpi.Comm#recv(Object, int, Datatype, int, int) - */ -public final Prequest recvInit(Buffer buf, int count, - Datatype type, int source, int tag) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Prequest(recvInit(handle, buf, count, type.handle, source, tag)); -} - -private native long recvInit( - long comm, Buffer buf, int count, long type, int source, int tag) - throws MPIException; - -// Pack and Unpack - -/** - * Packs message in send buffer {@code inbuf} into space specified in - * {@code outbuf}. - *

- * Java binding of the MPI operation {@code MPI_PACK}. - *

- * The return value is the output value of {@code position} - the - * inital value incremented by the number of bytes written. - * @param inbuf input buffer - * @param incount number of items in input buffer - * @param type datatype of each item in input buffer - * @param outbuf output buffer - * @param position initial position in output buffer - * @return final position in output buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int pack(Object inbuf, int incount, Datatype type, - byte[] outbuf, int position) - throws MPIException -{ - MPI.check(); - int offset = 0; - boolean indb = false; - - if(inbuf instanceof Buffer && !(indb = ((Buffer)inbuf).isDirect())) - { - offset = type.getOffset(inbuf); - inbuf = ((Buffer)inbuf).array(); - } - - return pack(handle, inbuf, indb, offset, incount, - type.handle, outbuf, position); -} - -private native int pack( - long comm, Object inbuf, boolean indb, int offset, int incount, - long type, byte[] outbuf, int position) throws MPIException; - -/** - * Unpacks message in receive buffer {@code outbuf} into space specified in - * {@code inbuf}. - *

- * Java binding of the MPI operation {@code MPI_UNPACK}. - *

- * The return value is the output value of {@code position} - the - * inital value incremented by the number of bytes read. - * @param inbuf input buffer - * @param position initial position in input buffer - * @param outbuf output buffer - * @param outcount number of items in output buffer - * @param type datatype of each item in output buffer - * @return final position in input buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int unpack(byte[] inbuf, int position, - Object outbuf, int outcount, Datatype type) - throws MPIException -{ - MPI.check(); - int offset = 0; - boolean outdb = false; - - if(outbuf instanceof Buffer && !(outdb = ((Buffer)outbuf).isDirect())) - { - offset = type.getOffset(outbuf); - outbuf = ((Buffer)outbuf).array(); - } - - return unpack(handle, inbuf, position, outbuf, outdb, - offset, outcount, type.handle); -} - -private native int unpack( - long comm, byte[] inbuf, int position, Object outbuf, boolean outdb, - int offset, int outcount, long type) throws MPIException; - -/** - * Returns an upper bound on the increment of {@code position} effected - * by {@code pack}. - *

Java binding of the MPI operation {@code MPI_PACK_SIZE}. - * @param incount number of items in input buffer - * @param type datatype of each item in input buffer - * @return upper bound on size of packed message - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int packSize(int incount, Datatype type) throws MPIException -{ - MPI.check(); - return packSize(handle, incount, type.handle); -} - -private native int packSize(long comm, int incount, long type) - throws MPIException; - -// Probe and Cancel - -/** - * Check if there is an incoming message matching the pattern specified. - *

Java binding of the MPI operation {@code MPI_IPROBE}. - *

If such a message is currently available, a status object similar - * to the return value of a matching {@code recv} operation is returned. - * @param source rank of source - * @param tag message tag - * @return status object if such a message is currently available, - * {@code null} otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Status iProbe(int source, int tag) throws MPIException -{ - MPI.check(); - return iProbe(handle, source, tag); -} - -private native Status iProbe(long comm, int source, int tag) - throws MPIException; - -/** - * Wait until there is an incoming message matching the pattern specified. - *

Java binding of the MPI operation {@code MPI_PROBE}. - *

Returns a status object similar to the return value of a matching - * {@code recv} operation. - * @param source rank of source - * @param tag message tag - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Status probe(int source, int tag) throws MPIException -{ - MPI.check(); - Status status = new Status(); - probe(handle, source, tag, status.data); - return status; -} - -private native void probe(long comm, int source, int tag, long[] stat) - throws MPIException; - -// Caching - -/** - * Create a new attribute key. - *

Java binding of the MPI operation {@code MPI_COMM_CREATE_KEYVAL}. - * @return attribute key for future access - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int createKeyval() throws MPIException -{ - MPI.check(); - return createKeyval_jni(); -} - -private static native int createKeyval_jni() throws MPIException; - -/** - * Frees an attribute key for communicators. - *

Java binding of the MPI operation {@code MPI_COMM_FREE_KEYVAL}. - * @param keyval attribute key - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void freeKeyval(int keyval) throws MPIException -{ - MPI.check(); - freeKeyval_jni(keyval); -} - -private static native void freeKeyval_jni(int keyval) throws MPIException; - -/** - * Stores attribute value associated with a key. - *

Java binding of the MPI operation {@code MPI_COMM_SET_ATTR}. - * @param keyval attribute key - * @param value attribute value - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void setAttr(int keyval, Object value) throws MPIException -{ - MPI.check(); - setAttr(handle, keyval, MPI.attrSet(value)); -} - -private native void setAttr(long comm, int keyval, byte[] value) - throws MPIException; - -/** - * Retrieves attribute value by key. - *

Java binding of the MPI operation {@code MPI_COMM_GET_ATTR}. - * @param keyval attribute key - * @return attribute value or null if no attribute is associated with the key. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Object getAttr(int keyval) throws MPIException -{ - MPI.check(); - - if( keyval == MPI.TAG_UB || - keyval == MPI.HOST || - keyval == MPI.IO || - keyval == MPI.APPNUM || - keyval == MPI.LASTUSEDCODE || - keyval == MPI.UNIVERSE_SIZE) - { - return getAttr_predefined(handle, keyval); - } - else if(keyval == MPI.WTIME_IS_GLOBAL) - { - Integer value = (Integer)getAttr_predefined(handle, keyval); - return value==null ? null : value.intValue() != 0; - } - else - { - return MPI.attrGet(getAttr(handle, keyval)); - } -} - -private native Object getAttr_predefined(long comm, int keyval) - throws MPIException; - -private native byte[] getAttr(long comm, int keyval) throws MPIException; - -/** - * Deletes an attribute value associated with a key on a communicator. - *

Java binding of the MPI operation {@code MPI_COMM_DELETE_ATTR}. - * @param keyval attribute key - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void deleteAttr(int keyval) throws MPIException -{ - MPI.check(); - deleteAttr(handle, keyval); -} - -private native void deleteAttr(long comm, int keyval) throws MPIException; - -// Process Topologies - -/** - * Returns the type of topology associated with the communicator. - *

Java binding of the MPI operation {@code MPI_TOPO_TEST}. - *

The return value will be one of {@code MPI.GRAPH}, {@code MPI.CART} - * or {@code MPI.UNDEFINED}. - * @return topology type of communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int getTopology() throws MPIException -{ - MPI.check(); - return getTopology(handle); -} - -private native int getTopology(long comm) throws MPIException; - -// Enviromental Management - -/** - * Abort MPI. - *

Java binding of the MPI operation {@code MPI_ABORT}. - * @param errorcode error code for Unix or POSIX environments - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void abort(int errorcode) throws MPIException -{ - MPI.check(); - abort(handle, errorcode); -} - -private native void abort(long comm, int errorcode) throws MPIException; - -// Error handler - -/** - * Associates a new error handler with communicator at the calling process. - *

Java binding of the MPI operation {@code MPI_ERRHANDLER_SET}. - * @param errhandler new MPI error handler for communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void setErrhandler(Errhandler errhandler) throws MPIException -{ - MPI.check(); - setErrhandler(handle, errhandler.handle); -} - -private native void setErrhandler(long comm, long errhandler) - throws MPIException; - -/** - * Returns the error handler currently associated with the communicator. - *

Java binding of the MPI operation {@code MPI_ERRHANDLER_GET}. - * @return MPI error handler currently associated with communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Errhandler getErrhandler() throws MPIException -{ - MPI.check(); - return new Errhandler(getErrhandler(handle)); -} - -private native long getErrhandler(long comm); - -// Collective Communication - -/** - * A call to {@code barrier} blocks the caller until all process - * in the group have called it. - *

Java binding of the MPI operation {@code MPI_BARRIER}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void barrier() throws MPIException -{ - MPI.check(); - barrier(handle); -} - -private native void barrier(long comm) throws MPIException; - -/** - * Nonblocking barrier sinchronization. - *

Java binding of the MPI operation {@code MPI_IBARRIER}. - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iBarrier() throws MPIException -{ - MPI.check(); - return new Request(iBarrier(handle)); -} - -private native long iBarrier(long comm) throws MPIException; - -/** - * Broadcast a message from the process with rank {@code root} - * to all processes of the group. - *

Java binding of the MPI operation {@code MPI_BCAST}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each item in buffer - * @param root rank of broadcast root - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void bcast(Object buf, int count, Datatype type, int root) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - bcast(handle, buf, db, off, count, type.handle, type.baseType, root); -} - -private native void bcast( - long comm, Object buf, boolean db, int offset, int count, - long type, int basetype, int root) throws MPIException; - -/** - * Broadcast a message from the process with rank {@code root} - * to all processes of the group. - *

Java binding of the MPI operation {@code MPI_IBCAST}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each item in buffer - * @param root rank of broadcast root - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iBcast(Buffer buf, int count, Datatype type, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iBcast(handle, buf, count, type.handle, root)); -} - -private native long iBcast( - long comm, Buffer buf, int count, long type, int root) - throws MPIException; - -/** - * Each process sends the contents of its send buffer to the root process. - *

Java binding of the MPI operation {@code MPI_GATHER}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @param root rank of receiving process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void gather( - Object sendbuf, int sendcount, Datatype sendtype, - Object recvbuf, int recvcount, Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - gather(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, - recvtype.handle, recvtype.baseType, root); -} - -/** - * Each process sends the contents of its send buffer to the root process. - *

Java binding of the MPI operation {@code MPI_GATHER} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * The buffer is used by the root process to receive data, - * and it is used by the non-root processes to send data. - * @param buf buffer - * @param count number of items to send/receive - * @param type datatype of each item in buffer - * @param root rank of receiving process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void gather(Object buf, int count, Datatype type, int root) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - gather(handle, null, false, 0, 0, 0, 0, - buf, db, off, count, type.handle, type.baseType, root); -} - -private native void gather( - long comm, Object sendBuf, boolean sdb, int sendOff, int sendCount, - long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOff, int recvCount, - long recvType, int recvBaseType, int root) - throws MPIException; - -/** - * Each process sends the contents of its send buffer to the root process. - *

Java binding of the MPI operation {@code MPI_IGATHER}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @param root rank of receiving process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iGather( - Buffer sendbuf, int sendcount, Datatype sendtype, - Buffer recvbuf, int recvcount, Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iGather(handle, sendbuf, sendcount, sendtype.handle, - recvbuf, recvcount, recvtype.handle, root)); -} - -/** - * Each process sends the contents of its send buffer to the root process. - *

Java binding of the MPI operation {@code MPI_IGATHER} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * The buffer is used by the root process to receive data, - * and it is used by the non-root processes to send data. - * @param buf buffer - * @param count number of items to send/receive - * @param type datatype of each item in buffer - * @param root rank of receiving process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iGather(Buffer buf, int count, Datatype type, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - - return new Request(iGather(handle, null, 0, 0, - buf, count, type.handle, root)); -} - -private native long iGather( - long comm, Buffer sendbuf, int sendcount, long sendtype, - Buffer recvbuf, int recvcount, long recvtype, - int root) throws MPIException; - -/** - * Extends functionality of {@code gather} by allowing varying - * counts of data from each process. - *

Java binding of the MPI operation {@code MPI_GATHERV}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param displs displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @param root rank of receiving process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void gatherv(Object sendbuf, int sendcount, Datatype sendtype, - Object recvbuf, int[] recvcount, int[] displs, - Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - gatherv(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, displs, - recvtype.handle, recvtype.baseType, root); -} - -/** - * Extends functionality of {@code gather} by allowing varying - * counts of data from each process. - *

Java binding of the MPI operation {@code MPI_GATHERV} using - * {@code MPI_IN_PLACE} instead of the send buffer in the root process. - * This method must be used in the root process. - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param displs displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @param root rank of receiving process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void gatherv(Object recvbuf, int[] recvcount, int[] displs, - Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - int recvoff = 0; - boolean rdb = false; - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - gatherv(handle, null, false, 0, 0, 0, 0, recvbuf, rdb, recvoff, recvcount, - displs, recvtype.handle, recvtype.baseType, root); -} - -/** - * Extends functionality of {@code gather} by allowing varying - * counts of data from each process. - *

Java binding of the MPI operation {@code MPI_GATHERV} using - * {@code MPI_IN_PLACE} instead of the send buffer in the root process. - * This method must be used in the non-root processes. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param root rank of receiving process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void gatherv(Object sendbuf, int sendcount, - Datatype sendtype, int root) - throws MPIException -{ - MPI.check(); - int sendoff = 0; - boolean sdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - gatherv(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - null, false, 0, null, null, 0, 0, root); -} - -private native void gatherv( - long comm, Object sendBuf, boolean sdb, int sendOffset, - int sendCount, long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOffset, - int[] recvCount, int[] displs, long recvType, int recvBaseType, - int root) throws MPIException; - -/** - * Extends functionality of {@code gather} by allowing varying - * counts of data from each process. - *

Java binding of the MPI operation {@code MPI_IGATHERV}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param displs displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @param root rank of receiving process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iGatherv( - Buffer sendbuf, int sendcount, Datatype sendtype, Buffer recvbuf, - int[] recvcount, int[] displs, Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iGatherv( - handle, sendbuf, sendcount, sendtype.handle, - recvbuf, recvcount, displs, recvtype.handle, root)); -} - -/** - * Extends functionality of {@code gather} by allowing varying - * counts of data from each process. - *

Java binding of the MPI operation {@code MPI_IGATHERV} using - * {@code MPI_IN_PLACE} instead of the send buffer in the root process. - * This method must be used in the root process. - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param displs displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @param root rank of receiving process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iGatherv(Buffer recvbuf, int[] recvcount, int[] displs, - Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(recvbuf); - - return new Request(iGatherv(handle, null, 0, 0, - recvbuf, recvcount, displs, recvtype.handle, root)); -} - -/** - * Extends functionality of {@code gather} by allowing varying - * counts of data from each process. - *

Java binding of the MPI operation {@code MPI_IGATHERV} using - * {@code MPI_IN_PLACE} instead of the send buffer in the root process. - * This method must be used in the non-root processes. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param root rank of receiving process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iGatherv(Buffer sendbuf, int sendcount, - Datatype sendtype, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf); - - return new Request(iGatherv(handle, sendbuf, sendcount, sendtype.handle, - null, null, null, 0, root)); -} - -private native long iGatherv( - long handle, Buffer sendbuf, int sendcount, long sendtype, - Buffer recvbuf, int[] recvcount, int[] displs, - long recvtype, int root) - throws MPIException; - -/** - * Inverse of the operation {@code gather}. - *

Java binding of the MPI operation {@code MPI_SCATTER}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @param root rank of sending process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void scatter( - Object sendbuf, int sendcount, Datatype sendtype, - Object recvbuf, int recvcount, Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - scatter(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, - recvtype.handle, recvtype.baseType, root); -} - -/** - * Inverse of the operation {@code gather}. - *

Java binding of the MPI operation {@code MPI_SCATTER} - * using {@code MPI_IN_PLACE} instead of the receive buffer. - * The buffer is used by the root process to send data, - * and it is used by the non-root processes to receive data. - * @param buf send/receive buffer - * @param count number of items to send/receive - * @param type datatype of each item in buffer - * @param root rank of sending process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void scatter(Object buf, int count, Datatype type, int root) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - scatter(handle, buf, db, off, count, type.handle, type.baseType, - null, false, 0, 0, 0, 0, root); -} - -private native void scatter( - long comm, Object sendBuf, boolean sdb, int sendOffset, int sendCount, - long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOffset, int recvCount, - long recvType, int recvBaseType, int root) throws MPIException; - -/** - * Inverse of the operation {@code gather}. - *

Java binding of the MPI operation {@code MPI_ISCATTER}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @param root rank of sending process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iScatter( - Buffer sendbuf, int sendcount, Datatype sendtype, - Buffer recvbuf, int recvcount, Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iScatter(handle, sendbuf, sendcount, sendtype.handle, - recvbuf, recvcount, recvtype.handle, root)); -} - -/** - * Inverse of the operation {@code gather}. - *

Java binding of the MPI operation {@code MPI_ISCATTER} - * using {@code MPI_IN_PLACE} instead of the receive buffer. - * The buffer is used by the root process to send data, - * and it is used by the non-root processes to receive data. - * @param buf send/receive buffer - * @param count number of items to send/receive - * @param type datatype of each item in buffer - * @param root rank of sending process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iScatter(Buffer buf, int count, Datatype type, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - - return new Request(iScatter(handle, buf, count, type.handle, - null, 0, 0, root)); -} - -private native long iScatter( - long comm, Buffer sendbuf, int sendcount, long sendtype, - Buffer recvbuf, int recvcount, long recvtype, int root) - throws MPIException; - -/** - * Inverse of the operation {@code gatherv}. - *

Java binding of the MPI operation {@code MPI_SCATTERV}. - * @param sendbuf send buffer - * @param sendcount number of items sent to each process - * @param displs displacements from which to take outgoing data - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @param root rank of sending process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void scatterv( - Object sendbuf, int[] sendcount, int[] displs, Datatype sendtype, - Object recvbuf, int recvcount, Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - scatterv(handle, sendbuf, sdb, sendoff, sendcount, displs, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, - recvtype.handle, recvtype.baseType, root); -} - -/** - * Inverse of the operation {@code gatherv}. - *

Java binding of the MPI operation {@code MPI_SCATTERV} using - * {@code MPI_IN_PLACE} instead of the receive buffer in the root process. - * This method must be used in the root process. - * @param sendbuf send buffer - * @param sendcount number of items sent to each process - * @param displs displacements from which to take outgoing data - * @param sendtype datatype of each item in send buffer - * @param root rank of sending process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void scatterv(Object sendbuf, int[] sendcount, int[] displs, - Datatype sendtype, int root) - throws MPIException -{ - MPI.check(); - int sendoff = 0; - boolean sdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - scatterv(handle, sendbuf, sdb, sendoff, sendcount, displs, - sendtype.handle, sendtype.baseType, - null, false, 0, 0, 0, 0, root); -} - -/** - * Inverse of the operation {@code gatherv}. - *

Java binding of the MPI operation {@code MPI_SCATTERV} using - * {@code MPI_IN_PLACE} instead of the receive buffer in the root process. - * This method must be used in the non-root processes. - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @param root rank of sending process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void scatterv(Object recvbuf, int recvcount, - Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - int recvoff = 0; - boolean rdb = false; - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - scatterv(handle, null, false, 0, null, null, 0, 0, - recvbuf, rdb, recvoff, recvcount, - recvtype.handle, recvtype.baseType, root); -} - -private native void scatterv( - long comm, Object sendBuf, boolean sdb, int sendOffset, - int[] sendCount, int[] displs, long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOffset, int recvCount, - long recvType, int recvBaseType, int root) - throws MPIException; - -/** - * Inverse of the operation {@code gatherv}. - *

Java binding of the MPI operation {@code MPI_ISCATTERV}. - * @param sendbuf send buffer - * @param sendcount number of items sent to each process - * @param displs displacements from which to take outgoing data - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @param root rank of sending process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iScatterv( - Buffer sendbuf, int[] sendcount, int[] displs, Datatype sendtype, - Buffer recvbuf, int recvcount, Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iScatterv( - handle, sendbuf, sendcount, displs, sendtype.handle, - recvbuf, recvcount, recvtype.handle, root)); -} - -/** - * Inverse of the operation {@code gatherv}. - *

Java binding of the MPI operation {@code MPI_ISCATTERV} using - * {@code MPI_IN_PLACE} instead of the receive buffer in the root process. - * This method must be used in the root process. - * @param sendbuf send buffer - * @param sendcount number of items sent to each process - * @param displs displacements from which to take outgoing data - * @param sendtype datatype of each item in send buffer - * @param root rank of sending process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iScatterv(Buffer sendbuf, int[] sendcount, int[] displs, - Datatype sendtype, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf); - - return new Request(iScatterv(handle, sendbuf, sendcount, displs, - sendtype.handle, null, 0, 0, root)); -} - -/** - * Inverse of the operation {@code gatherv}. - *

Java binding of the MPI operation {@code MPI_ISCATTERV} using - * {@code MPI_IN_PLACE} instead of the receive buffer in the root process. - * This method must be used in the non-root processes. - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @param root rank of sending process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iScatterv(Buffer recvbuf, int recvcount, - Datatype recvtype, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(recvbuf); - - return new Request(iScatterv(handle, null, null, null, 0, - recvbuf, recvcount, recvtype.handle, root)); -} - -private native long iScatterv( - long comm, Buffer sendbuf, int[] sendcount, int[] displs, long sendtype, - Buffer recvbuf, int recvcount, long recvtype, int root) - throws MPIException; - -/** - * Similar to {@code gather}, but all processes receive the result. - *

Java binding of the MPI operation {@code MPI_ALLGATHER}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void allGather(Object sendbuf, int sendcount, Datatype sendtype, - Object recvbuf, int recvcount, Datatype recvtype) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - allGather(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, - recvtype.handle, recvtype.baseType); -} - -/** - * Similar to {@code gather}, but all processes receive the result. - *

Java binding of the MPI operation {@code MPI_ALLGATHER} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer - * @param count number of items to receive - * @param type datatype of each item in receive buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void allGather(Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - allGather(handle, null, false, 0, 0, 0, 0, - buf, db, off, count, type.handle, type.baseType); -} - -private native void allGather( - long comm, Object sendBuf, boolean sdb, int sendOffset, int sendCount, - long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOffset, int recvCount, - long recvType, int recvBaseType) throws MPIException; - -/** - * Similar to {@code gather}, but all processes receive the result. - *

Java binding of the MPI operation {@code MPI_IALLGATHER}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iAllGather( - Buffer sendbuf, int sendcount, Datatype sendtype, - Buffer recvbuf, int recvcount, Datatype recvtype) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iAllGather(handle, sendbuf, sendcount, sendtype.handle, - recvbuf, recvcount, recvtype.handle)); -} - -/** - * Similar to {@code gather}, but all processes receive the result. - *

Java binding of the MPI operation {@code MPI_IALLGATHER} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer - * @param count number of items to receive - * @param type datatype of each item in receive buffer - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iAllGather(Buffer buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iAllGather(handle, null, 0, 0, buf, count, type.handle)); -} - -private native long iAllGather( - long comm, Buffer sendbuf, int sendcount, long sendtype, - Buffer recvbuf, int recvcount, long recvtype) throws MPIException; - -/** - * Similar to {@code gatherv}, but all processes receive the result. - *

Java binding of the MPI operation {@code MPI_ALLGATHERV}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param displs displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void allGatherv( - Object sendbuf, int sendcount, Datatype sendtype, - Object recvbuf, int[] recvcount, int[] displs, Datatype recvtype) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - allGatherv(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, displs, - recvtype.handle, recvtype.baseType); -} - -/** - * Similar to {@code gatherv}, but all processes receive the result. - *

Java binding of the MPI operation {@code MPI_ALLGATHERV} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param displs displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void allGatherv(Object recvbuf, int[] recvcount, - int[] displs, Datatype recvtype) - throws MPIException -{ - MPI.check(); - int recvoff = 0; - boolean rdb = false; - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - allGatherv(handle, null, false, 0, 0, 0, 0, - recvbuf, rdb, recvoff, recvcount, - displs, recvtype.handle, recvtype.baseType); -} - -private native void allGatherv( - long comm, Object sendBuf, boolean sdb, int sendOffset, int sendCount, - long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOffset, int[] recvCount, - int[] displs, long recvType, int recvBasetype) throws MPIException; - -/** - * Similar to {@code gatherv}, but all processes receive the result. - *

Java binding of the MPI operation {@code MPI_IALLGATHERV}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param displs displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iAllGatherv( - Buffer sendbuf, int sendcount, Datatype sendtype, - Buffer recvbuf, int[] recvcount, int[] displs, Datatype recvtype) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iAllGatherv( - handle, sendbuf, sendcount, sendtype.handle, - recvbuf, recvcount, displs, recvtype.handle)); -} - -/** - * Similar to {@code gatherv}, but all processes receive the result. - *

Java binding of the MPI operation {@code MPI_IALLGATHERV} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer - * @param count number of elements received from each process - * @param displs displacements at which to place incoming data - * @param type datatype of each item in receive buffer - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iAllGatherv( - Buffer buf, int[] count, int[] displs, Datatype type) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - - return new Request(iAllGatherv( - handle, null, 0, 0, buf, count, displs, type.handle)); -} - -private native long iAllGatherv( - long handle, Buffer sendbuf, int sendcount, long sendtype, - Buffer recvbuf, int[] recvcount, int[] displs, long recvtype) - throws MPIException; - -/** - * Extension of {@code allGather} to the case where each process sends - * distinct data to each of the receivers. - *

Java binding of the MPI operation {@code MPI_ALLTOALL}. - * @param sendbuf send buffer - * @param sendcount number of items sent to each process - * @param sendtype datatype send buffer items - * @param recvbuf receive buffer - * @param recvcount number of items received from any process - * @param recvtype datatype of receive buffer items - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void allToAll(Object sendbuf, int sendcount, Datatype sendtype, - Object recvbuf, int recvcount, Datatype recvtype) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - allToAll(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, - recvtype.handle, recvtype.baseType); -} - -private native void allToAll( - long comm, Object sendBuf, boolean sdb, int sendOffset, int sendCount, - long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOffset, int recvCount, - long recvType, int recvBaseType) throws MPIException; - -/** - * Extension of {@code allGather} to the case where each process sends - * distinct data to each of the receivers. - *

Java binding of the MPI operation {@code MPI_IALLTOALL}. - * @param sendbuf send buffer - * @param sendcount number of items sent to each process - * @param sendtype datatype send buffer items - * @param recvbuf receive buffer - * @param recvcount number of items received from any process - * @param recvtype datatype of receive buffer items - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iAllToAll(Buffer sendbuf, int sendcount, Datatype sendtype, - Buffer recvbuf, int recvcount, Datatype recvtype) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iAllToAll(handle, sendbuf, sendcount, sendtype.handle, - recvbuf, recvcount, recvtype.handle)); -} - -private native long iAllToAll( - long comm, Buffer sendbuf, int sendcount, long sendtype, - Buffer recvbuf, int recvcount, long recvtype) throws MPIException; - -/** - * Adds flexibility to {@code allToAll}: location of data for send is - * specified by {@code sdispls} and location to place data on receive - * side is specified by {@code rdispls}. - *

Java binding of the MPI operation {@code MPI_ALLTOALLV}. - * @param sendbuf send buffer - * @param sendcount number of items sent to each buffer - * @param sdispls displacements from which to take outgoing data - * @param sendtype datatype send buffer items - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param rdispls displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void allToAllv( - Object sendbuf, int[] sendcount, int[] sdispls, Datatype sendtype, - Object recvbuf, int[] recvcount, int[] rdispls, Datatype recvtype) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - allToAllv(handle, sendbuf, sdb, sendoff, sendcount, sdispls, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, rdispls, - recvtype.handle, recvtype.baseType); -} - -private native void allToAllv( - long comm, Object sendBuf, boolean sdb, int sendOffset, - int[] sendCount, int[] sdispls, long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOffset, - int[] recvCount, int[] rdispls, long recvType, int recvBaseType) - throws MPIException; - -/** - * Adds flexibility to {@code allToAll}: location of data for send is - * specified by {@code sdispls} and location to place data on receive - * side is specified by {@code rdispls}. - *

Java binding of the MPI operation {@code MPI_IALLTOALLV}. - * @param sendbuf send buffer - * @param sendcount number of items sent to each buffer - * @param sdispls displacements from which to take outgoing data - * @param sendtype datatype send buffer items - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param rdispls displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iAllToAllv( - Buffer sendbuf, int[] sendcount, int[] sdispls, Datatype sendtype, - Buffer recvbuf, int[] recvcount, int[] rdispls, Datatype recvtype) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iAllToAllv( - handle, sendbuf, sendcount, sdispls, sendtype.handle, - recvbuf, recvcount, rdispls, recvtype.handle)); -} - -private native long iAllToAllv(long comm, - Buffer sendbuf, int[] sendcount, int[] sdispls, long sendtype, - Buffer recvbuf, int[] recvcount, int[] rdispls, long recvtype) - throws MPIException; - -/** - * Adds flexibility to {@code allToAll}: location of data for send is //here - * specified by {@code sDispls} and location to place data on receive - * side is specified by {@code rDispls}. - *

Java binding of the MPI operation {@code MPI_ALLTOALLW}. - * @param sendBuf send buffer - * @param sendCount number of items sent to each buffer - * @param sDispls displacements from which to take outgoing data - * @param sendTypes datatypes of send buffer items - * @param recvBuf receive buffer - * @param recvCount number of elements received from each process - * @param rDispls displacements at which to place incoming data - * @param recvTypes datatype of each item in receive buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void allToAllw( - Buffer sendBuf, int[] sendCount, int[] sDispls, Datatype[] sendTypes, - Buffer recvBuf, int[] recvCount, int[] rDispls, Datatype[] recvTypes) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendBuf, recvBuf); - - long[] sendHandles = convertTypeArray(sendTypes); - long[] recvHandles = convertTypeArray(recvTypes); - - allToAllw(handle, sendBuf, sendCount, sDispls, - sendHandles, recvBuf, recvCount, rDispls, - recvHandles); -} - -private native void allToAllw(long comm, - Buffer sendBuf, int[] sendCount, int[] sDispls, long[] sendTypes, - Buffer recvBuf, int[] recvCount, int[] rDispls, long[] recvTypes) - throws MPIException; - -/** - * Adds flexibility to {@code iAllToAll}: location of data for send is - * specified by {@code sDispls} and location to place data on receive - * side is specified by {@code rDispls}. - *

Java binding of the MPI operation {@code MPI_IALLTOALLW}. - * @param sendBuf send buffer - * @param sendCount number of items sent to each buffer - * @param sDispls displacements from which to take outgoing data - * @param sendTypes datatype send buffer items - * @param recvBuf receive buffer - * @param recvCount number of elements received from each process - * @param rDispls displacements at which to place incoming data - * @param recvTypes datatype of each item in receive buffer - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iAllToAllw( - Buffer sendBuf, int[] sendCount, int[] sDispls, Datatype[] sendTypes, - Buffer recvBuf, int[] recvCount, int[] rDispls, Datatype[] recvTypes) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendBuf, recvBuf); - - long[] sendHandles = convertTypeArray(sendTypes); - long[] recvHandles = convertTypeArray(recvTypes); - - return new Request(iAllToAllw( - handle, sendBuf, sendCount, sDispls, sendHandles, - recvBuf, recvCount, rDispls, recvHandles)); -} - -private native long iAllToAllw(long comm, - Buffer sendBuf, int[] sendCount, int[] sDispls, long[] sendTypes, - Buffer recvBuf, int[] recvCount, int[] rDispls, long[] recvTypes) - throws MPIException; - -/** - * Java binding of {@code MPI_NEIGHBOR_ALLGATHER}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void neighborAllGather( - Object sendbuf, int sendcount, Datatype sendtype, - Object recvbuf, int recvcount, Datatype recvtype) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - neighborAllGather(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, - recvtype.handle, recvtype.baseType); -} - -private native void neighborAllGather( - long comm, Object sendBuf, boolean sdb, int sendOffset, - int sendCount, long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOffset, - int recvCount, long recvType, int recvBaseType) - throws MPIException; - -/** - * Java binding of {@code MPI_INEIGHBOR_ALLGATHER}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iNeighborAllGather( - Buffer sendbuf, int sendcount, Datatype sendtype, - Buffer recvbuf, int recvcount, Datatype recvtype) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iNeighborAllGather( - handle, sendbuf, sendcount, sendtype.handle, - recvbuf, recvcount, recvtype.handle)); -} - -private native long iNeighborAllGather( - long comm, Buffer sendBuf, int sendCount, long sendType, - Buffer recvBuf, int recvCount, long recvType) - throws MPIException; - -/** - * Java binding of {@code MPI_NEIGHBOR_ALLGATHERV}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of elements that are received from each neighbor - * @param displs displacements at which to place incoming data - * @param recvtype datatype of receive buffer elements - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void neighborAllGatherv( - Object sendbuf, int sendcount, Datatype sendtype, - Object recvbuf, int[] recvcount, int[] displs, Datatype recvtype) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - neighborAllGatherv(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, displs, - recvtype.handle, recvtype.baseType); -} - -private native void neighborAllGatherv( - long comm, Object sendBuf, boolean sdb, int sendOff, - int sendCount, long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOff, - int[] recvCount, int[] displs, long recvType, int recvBaseType); - -/** - * Java binding of {@code MPI_INEIGHBOR_ALLGATHERV}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of elements that are received from each neighbor - * @param displs displacements at which to place incoming data - * @param recvtype datatype of receive buffer elements - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iNeighborAllGatherv( - Buffer sendbuf, int sendcount, Datatype sendtype, - Buffer recvbuf, int[] recvcount, int[] displs, Datatype recvtype) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iNeighborAllGatherv( - handle, sendbuf, sendcount, sendtype.handle, - recvbuf, recvcount, displs, recvtype.handle)); -} - -private native long iNeighborAllGatherv( - long comm, Buffer sendBuf, int sendCount, long sendType, - Buffer recvBuf, int[] recvCount, int[] displs, long recvType) - throws MPIException; - -/** - * Java binding of {@code MPI_NEIGHBOR_ALLTOALL}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void neighborAllToAll( - Object sendbuf, int sendcount, Datatype sendtype, - Object recvbuf, int recvcount, Datatype recvtype) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - neighborAllToAll(handle, sendbuf, sdb, sendoff, sendcount, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, - recvtype.handle, recvtype.baseType); -} - -private native void neighborAllToAll( - long comm, Object sendBuf, boolean sdb, int sendOff, - int sendCount, long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOff, - int recvCount, long recvType, int recvBaseType) - throws MPIException; - -/** - * Java binding of {@code MPI_INEIGHBOR_ALLTOALL}. - * @param sendbuf send buffer - * @param sendcount number of items to send - * @param sendtype datatype of each item in send buffer - * @param recvbuf receive buffer - * @param recvcount number of items to receive - * @param recvtype datatype of each item in receive buffer - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iNeighborAllToAll( - Buffer sendbuf, int sendcount, Datatype sendtype, - Buffer recvbuf, int recvcount, Datatype recvtype) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iNeighborAllToAll( - handle, sendbuf, sendcount, sendtype.handle, - recvbuf, recvcount, recvtype.handle)); -} - -private native long iNeighborAllToAll( - long comm, Buffer sendBuf, int sendCount, long sendType, - Buffer recvBuf, int recvCount, long recvType); - -/** - * Java binding of {@code MPI_NEIGHBOR_ALLTOALLV}. - * @param sendbuf send buffer - * @param sendcount number of items sent to each buffer - * @param sdispls displacements from which to take outgoing data - * @param sendtype datatype send buffer items - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param rdispls displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void neighborAllToAllv( - Object sendbuf, int[] sendcount, int[] sdispls, Datatype sendtype, - Object recvbuf, int[] recvcount, int[] rdispls, Datatype recvtype) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = sendtype.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = recvtype.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - neighborAllToAllv(handle, - sendbuf, sdb, sendoff, sendcount, sdispls, - sendtype.handle, sendtype.baseType, - recvbuf, rdb, recvoff, recvcount, rdispls, - recvtype.handle, recvtype.baseType); -} - -private native void neighborAllToAllv( - long comm, Object sendBuf, boolean sdb, int sendOff, - int[] sendCount, int[] sdispls, long sendType, int sendBaseType, - Object recvBuf, boolean rdb, int recvOff, - int[] recvCount, int[] rdispls, long recvType, int recvBaseType) - throws MPIException; - -/** - * Java binding of {@code MPI_INEIGHBOR_ALLTOALLV}. - * @param sendbuf send buffer - * @param sendcount number of items sent to each buffer - * @param sdispls displacements from which to take outgoing data - * @param sendtype datatype send buffer items - * @param recvbuf receive buffer - * @param recvcount number of elements received from each process - * @param rdispls displacements at which to place incoming data - * @param recvtype datatype of each item in receive buffer - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iNeighborAllToAllv( - Buffer sendbuf, int[] sendcount, int[] sdispls, Datatype sendtype, - Buffer recvbuf, int[] recvcount, int[] rdispls, Datatype recvtype) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iNeighborAllToAllv( - handle, sendbuf, sendcount, sdispls, sendtype.handle, - recvbuf, recvcount, rdispls, recvtype.handle)); -} - -private native long iNeighborAllToAllv( - long comm, Buffer sendBuf, int[] sendCount, int[] sdispls, long sType, - Buffer recvBuf, int[] recvCount, int[] rdispls, long rType) - throws MPIException; - -/** - * Combine elements in input buffer of each process using the reduce - * operation, and return the combined value in the output buffer of the - * root process. - *

- * Java binding of the MPI operation {@code MPI_REDUCE}. - *

- * The predefined operations are available in Java as {@code MPI.MAX}, - * {@code MPI.MIN}, {@code MPI.SUM}, {@code MPI.PROD}, {@code MPI.LAND}, - * {@code MPI.BAND}, {@code MPI.LOR}, {@code MPI.BOR}, {@code MPI.LXOR}, - * {@code MPI.BXOR}, {@code MPI.MINLOC} and {@code MPI.MAXLOC}. - * @param sendbuf send buffer - * @param recvbuf receive buffer - * @param count number of items in send buffer - * @param type data type of each item in send buffer - * @param op reduce operation - * @param root rank of root process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void reduce(Object sendbuf, Object recvbuf, int count, - Datatype type, Op op, int root) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = type.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = type.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - reduce(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, - count, type.handle, type.baseType, op, op.handle, root); -} - -/** - * Combine elements in input buffer of each process using the reduce - * operation, and return the combined value in the output buffer of the - * root process. - *

Java binding of the MPI operation {@code MPI_REDUCE} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf send/receive buffer - * @param count number of items in buffer - * @param type data type of each item in buffer - * @param op reduce operation - * @param root rank of root process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void reduce(Object buf, int count, Datatype type, Op op, int root) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - reduce(handle, null, false, 0, buf, db, off, count, - type.handle, type.baseType, op, op.handle, root); -} - -private native void reduce( - long comm, Object sendbuf, boolean sdb, int sendoff, - Object recvbuf, boolean rdb, int recvoff, int count, - long type, int baseType, Op jOp, long hOp, int root) - throws MPIException; - -/** - * Combine elements in input buffer of each process using the reduce - * operation, and return the combined value in the output buffer of the - * root process. - *

Java binding of the MPI operation {@code MPI_IREDUCE}. - * @param sendbuf send buffer - * @param recvbuf receive buffer - * @param count number of items in send buffer - * @param type data type of each item in send buffer - * @param op reduce operation - * @param root rank of root process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iReduce(Buffer sendbuf, Buffer recvbuf, - int count, Datatype type, Op op, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - op.setDatatype(type); - - return new Request(iReduce( - handle, sendbuf, recvbuf, count, - type.handle, type.baseType, op, op.handle, root)); -} - -/** - * Combine elements in input buffer of each process using the reduce - * operation, and return the combined value in the output buffer of the - * root process. - *

Java binding of the MPI operation {@code MPI_IREDUCE} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf send/receive buffer - * @param count number of items in buffer - * @param type data type of each item in buffer - * @param op reduce operation - * @param root rank of root process - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iReduce(Buffer buf, int count, - Datatype type, Op op, int root) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - op.setDatatype(type); - - return new Request(iReduce( - handle, null, buf, count, - type.handle, type.baseType, op, op.handle, root)); -} - -private native long iReduce( - long comm, Buffer sendbuf, Buffer recvbuf, int count, - long type, int baseType, Op jOp, long hOp, int root) - throws MPIException; - -/** - * Same as {@code reduce} except that the result appears in receive - * buffer of all process in the group. - *

Java binding of the MPI operation {@code MPI_ALLREDUCE}. - * @param sendbuf send buffer - * @param recvbuf receive buffer - * @param count number of items in send buffer - * @param type data type of each item in send buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void allReduce(Object sendbuf, Object recvbuf, - int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = type.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = type.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - allReduce(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, - count, type.handle, type.baseType, op, op.handle); -} - -/** - * Same as {@code reduce} except that the result appears in receive - * buffer of all process in the group. - *

Java binding of the MPI operation {@code MPI_ALLREDUCE} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer - * @param count number of items in send buffer - * @param type data type of each item in send buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void allReduce(Object buf, int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - allReduce(handle, null, false, 0, buf, db, off, count, - type.handle, type.baseType, op, op.handle); -} - -private native void allReduce( - long comm, Object sendbuf, boolean sdb, int sendoff, - Object recvbuf, boolean rdb, int recvoff, int count, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Same as {@code reduce} except that the result appears in receive - * buffer of all process in the group. - *

Java binding of the MPI operation {@code MPI_IALLREDUCE}. - * @param sendbuf send buffer - * @param recvbuf receive buffer - * @param count number of items in send buffer - * @param type data type of each item in send buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iAllReduce(Buffer sendbuf, Buffer recvbuf, - int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(sendbuf, recvbuf); - op.setDatatype(type); - - return new Request(iAllReduce(handle, sendbuf, recvbuf, count, - type.handle, type.baseType, op, op.handle)); -} - -/** - * Same as {@code reduce} except that the result appears in receive - * buffer of all process in the group. - *

Java binding of the MPI operation {@code MPI_IALLREDUCE} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer - * @param count number of items in send buffer - * @param type data type of each item in send buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iAllReduce(Buffer buf, int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - assertDirectBuffer(buf); - - return new Request(iAllReduce( - handle, null, buf, count, - type.handle, type.baseType, op, op.handle)); -} - -private native long iAllReduce( - long comm, Buffer sendbuf, Buffer recvbuf, int count, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Combine elements in input buffer of each process using the reduce - * operation, and scatter the combined values over the output buffers - * of the processes. - *

Java binding of the MPI operation {@code MPI_REDUCE_SCATTER}. - * @param sendbuf send buffer - * @param recvbuf receive buffer - * @param recvcounts numbers of result elements distributed to each process - * @param type data type of each item in send buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void reduceScatter(Object sendbuf, Object recvbuf, - int[] recvcounts, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = type.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = type.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - reduceScatter(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, - recvcounts, type.handle, type.baseType, op, op.handle); -} - -/** - * Combine elements in input buffer of each process using the reduce - * operation, and scatter the combined values over the output buffers - * of the processes. - *

Java binding of the MPI operation {@code MPI_REDUCE_SCATTER} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer - * @param counts numbers of result elements distributed to each process - * @param type data type of each item in send buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void reduceScatter(Object buf, int[] counts, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - reduceScatter(handle, null, false, 0, buf, db, off, counts, - type.handle, type.baseType, op, op.handle); -} - -private native void reduceScatter( - long comm, Object sendbuf, boolean sdb, int sendoff, - Object recvbuf, boolean rdb, int recvoff, int[] recvcounts, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Combine elements in input buffer of each process using the reduce - * operation, and scatter the combined values over the output buffers - * of the processes. - *

Java binding of the MPI operation {@code MPI_IREDUCE_SCATTER}. - * @param sendbuf send buffer - * @param recvbuf receive buffer - * @param recvcounts numbers of result elements distributed to each process - * @param type data type of each item in send buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iReduceScatter(Buffer sendbuf, Buffer recvbuf, - int[] recvcounts, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iReduceScatter( - handle, sendbuf, recvbuf, recvcounts, - type.handle, type.baseType, op, op.handle)); -} - -/** - * Combine elements in input buffer of each process using the reduce - * operation, and scatter the combined values over the output buffers - * of the processes. - *

Java binding of the MPI operation {@code MPI_IREDUCE_SCATTER} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer - * @param counts numbers of result elements distributed to each process - * @param type data type of each item in send buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iReduceScatter( - Buffer buf, int[] counts, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - assertDirectBuffer(buf); - - return new Request(iReduceScatter( - handle, null, buf, counts, - type.handle, type.baseType, op, op.handle)); -} - -private native long iReduceScatter( - long handle, Buffer sendbuf, Object recvbuf, int[] recvcounts, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Combine values and scatter the results. - *

Java binding of the MPI operation {@code MPI_REDUCE_SCATTER_BLOCK}. - * @param sendbuf send buffer - * @param recvbuf receive buffer - * @param recvcount element count per block - * @param type data type of each item in send buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void reduceScatterBlock(Object sendbuf, Object recvbuf, - int recvcount, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = type.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = type.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - reduceScatterBlock(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, - recvcount, type.handle, type.baseType, op, op.handle); -} - -/** - * Combine values and scatter the results. - *

Java binding of the MPI operation {@code MPI_REDUCE_SCATTER_BLOCK} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer - * @param count element count per block - * @param type data type of each item in send buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void reduceScatterBlock( - Object buf, int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - reduceScatterBlock(handle, null, false, 0, buf, db, off, count, - type.handle, type.baseType, op, op.handle); -} - -private native void reduceScatterBlock( - long comm, Object sendBuf, boolean sdb, int sOffset, - Object recvBuf, boolean rdb, int rOffset, int rCount, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Combine values and scatter the results. - *

Java binding of the MPI operation {@code MPI_IREDUCE_SCATTER_BLOCK}. - * @param sendbuf send buffer - * @param recvbuf receive buffer - * @param recvcount element count per block - * @param type data type of each item in send buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iReduceScatterBlock( - Buffer sendbuf, Buffer recvbuf, int recvcount, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iReduceScatterBlock( - handle, sendbuf, recvbuf, recvcount, - type.handle, type.baseType, op, op.handle)); -} - -/** - * Combine values and scatter the results. - *

Java binding of the MPI operation {@code MPI_IREDUCE_SCATTER_BLOCK} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer - * @param count element count per block - * @param type data type of each item in send buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iReduceScatterBlock( - Buffer buf, int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - assertDirectBuffer(buf); - - return new Request(iReduceScatterBlock( - handle, null, buf, count, type.handle, - type.baseType, op, op.handle)); -} - -private native long iReduceScatterBlock( - long handle, Buffer sendbuf, Buffer recvbuf, int recvcount, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Apply the operation given by {@code op} element-wise to the - * elements of {@code inBuf} and {@code inOutBuf} with the result - * stored element-wise in {@code inOutBuf}. - *

Java binding of the MPI operation {@code MPI_REDUCE_LOCAL}. - * @param inBuf input buffer - * @param inOutBuf input buffer, will contain combined output - * @param count number of elements - * @param type data type of each item - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void reduceLocal( - Object inBuf, Object inOutBuf, int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - - int inOff = 0, - inOutOff = 0; - - boolean idb = false, - iodb = false; - - if(inBuf instanceof Buffer && !(idb = ((Buffer)inBuf).isDirect())) - { - inOff = type.getOffset(inBuf); - inBuf = ((Buffer)inBuf).array(); - } - - if(inOutBuf instanceof Buffer && !(iodb = ((Buffer)inOutBuf).isDirect())) - { - inOutOff = type.getOffset(inOutBuf); - inOutBuf = ((Buffer)inOutBuf).array(); - } - - if(op.uf == null) - { - reduceLocal(inBuf, idb, inOff, inOutBuf, iodb, inOutOff, - count, type.handle, op.handle); - } - else - { - reduceLocalUf(inBuf, idb, inOff, inOutBuf, iodb, inOutOff, - count, type.handle, type.baseType, op, op.handle); - } -} - -private static native void reduceLocal( - Object inBuf, boolean idb, int inOff, - Object inOutBuf, boolean iodb, int inOutOff, int count, - long type, long op) throws MPIException; - -private static native void reduceLocalUf( - Object inBuf, boolean idb, int inOff, - Object inOutBuf, boolean iodb, int inOutOff, int count, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Sets the print name for the communicator. - * @param name name for the communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void setName(String name) throws MPIException -{ - MPI.check(); - setName(handle, name); -} - -private native void setName(long handle, String name) throws MPIException; - -/** - * Return the print name from the communicator. - * @return name of the communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final String getName() throws MPIException -{ - MPI.check(); - return getName(handle); -} - -private native String getName(long handle) throws MPIException; - -/** - * A helper method to convert an array of Datatypes to - * an array of longs (handles). - * @param dArray Array of Datatypes - * @return converted Datatypes - */ -private long[] convertTypeArray(Datatype[] dArray) { - long[] lArray = new long[dArray.length]; - - for(int i = 0; i < lArray.length; i++) { - if(dArray[i] != null) { - lArray[i] = dArray[i].handle; + public final static int TYPE_SHARED = 0; + protected final static int SELF = 1; + protected final static int WORLD = 2; + protected long handle; + private Request request; + + private static long nullHandle; + + static + { + init(); + } + + private static native void init(); + + protected Comm() + { + } + + protected Comm(long handle) + { + this.handle = handle; + } + + protected Comm(long[] commRequest) + { + handle = commRequest[0]; + request = new Request(commRequest[1]); + } + + protected final void setType(int type) + { + getComm(type); + } + + private native void getComm(int type); + + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + *

It is recommended to use {@link #dup} instead of {@link #clone} + * because the last can't throw an {@link mpi.MPIException}. + * @return copy of this communicator + */ + @Override public Comm clone() + { + try + { + return dup(); + } + catch(MPIException e) + { + throw new RuntimeException(e.getMessage()); } } - return lArray; -} + + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Comm dup() throws MPIException + { + MPI.check(); + return new Comm(dup(handle)); + } + + protected final native long dup(long comm) throws MPIException; + + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_IDUP}. + *

The new communicator can't be used before the operation completes. + * The request object must be obtained calling {@link #getRequest}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Comm iDup() throws MPIException + { + MPI.check(); + return new Comm(iDup(handle)); + } + + protected final native long[] iDup(long comm) throws MPIException; + + /** + * Returns the associated request to this communicator if it was + * created using {@link #iDup}. + * @return associated request if this communicator was created + * using {@link #iDup}, or null otherwise. + */ + public final Request getRequest() + { + return request; + } + + /** + * Size of group of this communicator. + *

Java binding of the MPI operation {@code MPI_COMM_SIZE}. + * @return number of processors in the group of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int getSize() throws MPIException + { + MPI.check(); + return getSize(handle); + } + + private native int getSize(long comm) throws MPIException; + + /** + * Rank of this process in group of this communicator. + *

Java binding of the MPI operation {@code MPI_COMM_RANK}. + * @return rank of the calling process in the group of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int getRank() throws MPIException + { + MPI.check(); + return getRank(handle); + } + + private native int getRank(long comm) throws MPIException; + + /** + * Compare two communicators. + *

Java binding of the MPI operation {@code MPI_COMM_COMPARE}. + * @param comm1 first communicator + * @param comm2 second communicator + * @return + * {@code MPI.IDENT} results if the {@code comm1} and {@code comm2} + * are references to the same object (ie, if {@code comm1 == comm2}).
+ * {@code MPI.CONGRUENT} results if the underlying groups are identical + * but the communicators differ by context.
+ * {@code MPI.SIMILAR} results if the underlying groups are similar + * but the communicators differ by context.
+ * {@code MPI.UNEQUAL} results otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int compare(Comm comm1, Comm comm2) throws MPIException + { + MPI.check(); + return compare(comm1.handle, comm2.handle); + } + + private static native int compare(long comm1, long comm2) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_COMM_FREE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override final public void free() throws MPIException + { + MPI.check(); + handle = free(handle); + } + + private native long free(long comm) throws MPIException; + + /** + * Test if communicator object is null (has been freed). + * Java binding of {@code MPI_COMM_NULL}. + * @return true if the comm object is null, false otherwise + */ + public final boolean isNull() + { + return handle == nullHandle; + } + + /** + * Java binding of {@code MPI_COMM_SET_INFO}. + * @param info info object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void setInfo(Info info) throws MPIException + { + MPI.check(); + setInfo(handle, info.handle); + } + + private native void setInfo(long comm, long info) throws MPIException; + + /** + * Java binding of {@code MPI_COMM_GET_INFO}. + * @return new info object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Info getInfo() throws MPIException + { + MPI.check(); + return new Info(getInfo(handle)); + } + + private native long getInfo(long comm) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_COMM_DISCONNECT}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void disconnect() throws MPIException + { + MPI.check(); + handle = disconnect(handle); + } + + private native long disconnect(long comm) throws MPIException; + + /** + * Return group associated with a communicator. + *

Java binding of the MPI operation {@code MPI_COMM_GROUP}. + * @return group corresponding to this communicator group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Group getGroup() throws MPIException + { + MPI.check(); + return new Group(getGroup(handle)); + } + + private native long getGroup(long comm); + + // Inter-communication + + /** + * Test if this communicator is an inter-communicator. + *

Java binding of the MPI operation {@code MPI_COMM_TEST_INTER}. + * @return {@code true} if this is an inter-communicator, + * {@code false} otherwise + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final boolean isInter() throws MPIException + { + MPI.check(); + return isInter(handle); + } + + private native boolean isInter(long comm) throws MPIException; + + /** + * Create an inter-communicator. + *

+ * Java binding of the MPI operation {@code MPI_INTERCOMM_CREATE}. + *

+ * This operation is defined as a method on the "peer communicator", + * making it analogous to a {@code send} or {@code recv} communication + * with the remote group leader. + * @param localComm local intra-communicator + * @param localLeader rank of local group leader in {@code localComm} + * @param remoteLeader rank of remote group leader in this communicator + * @param tag "safe" tag + * @return new inter-communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intercomm createIntercomm(Comm localComm, int localLeader, + int remoteLeader, int tag) + throws MPIException + { + MPI.check(); + + return new Intercomm(createIntercomm(handle, localComm.handle, + localLeader, remoteLeader, tag)); + } + + private native long createIntercomm( + long comm, long localComm, int localLeader, + int remoteLeader, int tag) throws MPIException; + + // Blocking Send and Recv + + /** + * Blocking send operation. + *

Java binding of the MPI operation {@code MPI_SEND}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void send(Object buf, int count, Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + send(handle, buf, db, off, count, type.handle, type.baseType, dest, tag); + } + + private native void send( + long comm, Object buf, boolean db, int offset, int count, + long type, int baseType, int dest, int tag) throws MPIException; + + /** + * Blocking receive operation. + *

Java binding of the MPI operation {@code MPI_RECV}. + * @param buf receive buffer + * @param count number of items in receive buffer + * @param type datatype of each item in receive buffer + * @param source rank of source + * @param tag message tag + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Status recv(Object buf, int count, + Datatype type, int source, int tag) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + Status status = new Status(); + + recv(handle, buf, db, off, count, + type.handle, type.baseType, source, tag, status.data); + + return status; + } + + private native void recv( + long comm, Object buf, boolean db, int offset, int count, + long type, int basetype, int source, int tag, long[] stat) + throws MPIException; + + // Send-Recv + + /** + * Execute a blocking send and receive operation. + *

Java binding of the MPI operation {@code MPI_SENDRECV}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param dest rank of destination + * @param sendtag send tag + * @param recvbuf receive buffer + * @param recvcount number of items in receive buffer + * @param recvtype datatype of each item in receive buffer + * @param source rank of source + * @param recvtag receive tag + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + * @see mpi.Comm#recv(Object, int, Datatype, int, int) + */ + public final Status sendRecv( + Object sendbuf, int sendcount, Datatype sendtype, int dest, int sendtag, + Object recvbuf, int recvcount, Datatype recvtype, int source, int recvtag) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + Status status = new Status(); + + sendRecv(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, dest, sendtag, + recvbuf, rdb, recvoff, recvcount, + recvtype.handle, recvtype.baseType, source, recvtag, status.data); + + return status; + } + + private native void sendRecv( + long comm, Object sbuf, boolean sdb, int soffset, int scount, + long sType, int sBaseType, int dest, int stag, + Object rbuf, boolean rdb, int roffset, int rcount, + long rType, int rBaseType, int source, int rtag, + long[] stat) throws MPIException; + + /** + * Execute a blocking send and receive operation, + * receiving message into send buffer. + *

Java binding of the MPI operation {@code MPI_SENDRECV_REPLACE}. + * @param buf buffer + * @param count number of items to send + * @param type datatype of each item in buffer + * @param dest rank of destination + * @param sendtag send tag + * @param source rank of source + * @param recvtag receive tag + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + * @see mpi.Comm#recv(Object, int, Datatype, int, int) + */ + public final Status sendRecvReplace( + Object buf, int count, Datatype type, + int dest, int sendtag, int source, int recvtag) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + Status status = new Status(); + + sendRecvReplace(handle, buf, db, off, count, type.handle, type.baseType, + dest, sendtag, source, recvtag, status.data); + + return status; + } + + private native void sendRecvReplace( + long comm, Object buf, boolean db, int offset, int count, + long type, int baseType, int dest, int stag, + int source, int rtag, long[] stat) throws MPIException; + + // Communication Modes + + /** + * Send in buffered mode. + *

Java binding of the MPI operation {@code MPI_BSEND}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final void bSend(Object buf, int count, Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + bSend(handle, buf, db, off, count, type.handle, type.baseType, dest, tag); + } + + private native void bSend( + long comm, Object buf, boolean db, int offset, int count, + long type, int baseType, int dest, int tag) throws MPIException; + + /** + * Send in synchronous mode. + *

Java binding of the MPI operation {@code MPI_SSEND}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final void sSend(Object buf, int count, Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + sSend(handle, buf, db, off, count, type.handle, type.baseType, dest, tag); + } + + private native void sSend( + long comm, Object buf, boolean db, int offset, int count, + long type, int baseType, int dest, int tag) throws MPIException; + + /** + * Send in ready mode. + *

Java binding of the MPI operation {@code MPI_RSEND}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final void rSend(Object buf, int count, Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + rSend(handle, buf, db, off, count, type.handle, type.baseType, dest, tag); + } + + private native void rSend( + long comm, Object buf, boolean db, int offset, int count, + long type, int baseType, int dest, int tag) throws MPIException; + + // Nonblocking communication + + /** + * Start a standard mode, nonblocking send. + *

Java binding of the MPI operation {@code MPI_ISEND}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final Request iSend(Buffer buf, int count, + Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iSend(handle, buf, count, type.handle, dest, tag)); + } + + private native long iSend( + long comm, Buffer buf, int count, long type, int dest, int tag) + throws MPIException; + + /** + * Start a buffered mode, nonblocking send. + *

Java binding of the MPI operation MPI_IBSEND. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final Request ibSend(Buffer buf, int count, + Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(ibSend(handle, buf, count, type.handle, dest, tag)); + } + + private native long ibSend( + long comm, Buffer buf, int count, long type, int dest, int tag) + throws MPIException; + + /** + * Start a synchronous mode, nonblocking send. + *

Java binding of the MPI operation {@code MPI_ISSEND}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final Request isSend(Buffer buf, int count, + Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(isSend(handle, buf, count, type.handle, dest, tag)); + } + + private native long isSend( + long comm, Buffer buf, int count, long type, int dest, int tag) + throws MPIException; + + /** + * Start a ready mode, nonblocking send. + *

Java binding of the MPI operation {@code MPI_IRSEND}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final Request irSend(Buffer buf, int count, + Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(irSend(handle, buf, count, type.handle, dest, tag)); + } + + private native long irSend( + long comm, Buffer buf, int count, long type, int dest, int tag) + throws MPIException; + + /** + * Start a nonblocking receive. + *

Java binding of the MPI operation {@code MPI_IRECV}. + * @param buf receive buffer + * @param count number of items in receive buffer + * @param type datatype of each item in receive buffer + * @param source rank of source + * @param tag message tag + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#recv(Object, int, Datatype, int, int) + */ + public final Request iRecv(Buffer buf, int count, + Datatype type, int source, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iRecv(handle, buf, count, type.handle, source, tag)); + } + + private native long iRecv( + long comm, Buffer buf, int count, long type, int source, int tag) + throws MPIException; + + + // Persistent communication requests + + /** + * Creates a persistent communication request for a standard mode send. + *

Java binding of the MPI operation {@code MPI_SEND_INIT}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @return persistent communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final Prequest sendInit(Buffer buf, int count, + Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Prequest(sendInit(handle, buf, count, type.handle, dest, tag)); + } + + private native long sendInit( + long comm, Buffer buf, int count, long type, int dest, int tag) + throws MPIException; + + /** + * Creates a persistent communication request for a buffered mode send. + *

Java binding of the MPI operation {@code MPI_BSEND_INIT}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @return persistent communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final Prequest bSendInit(Buffer buf, int count, + Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Prequest(bSendInit(handle, buf, count, type.handle, dest, tag)); + } + + private native long bSendInit( + long comm, Buffer buf, int count, long type, int dest, int tag) + throws MPIException; + + /** + * Creates a persistent communication request for a synchronous mode send. + *

Java binding of the MPI operation {@code MPI_SSEND_INIT}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @return persistent communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final Prequest sSendInit(Buffer buf, int count, + Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Prequest(sSendInit(handle, buf, count, type.handle, dest, tag)); + } + + private native long sSendInit( + long comm, Buffer buf, int count, long type, int dest, int tag) + throws MPIException; + + /** + * Creates a persistent communication request for a ready mode send. + *

Java binding of the MPI operation {@code MPI_RSEND_INIT}. + * @param buf send buffer + * @param count number of items to send + * @param type datatype of each item in send buffer + * @param dest rank of destination + * @param tag message tag + * @return persistent communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#send(Object, int, Datatype, int, int) + */ + public final Prequest rSendInit(Buffer buf, int count, + Datatype type, int dest, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Prequest(rSendInit(handle, buf, count, type.handle, dest, tag)); + } + + private native long rSendInit( + long comm, Buffer buf, int count, long type, int dest, int tag) + throws MPIException; + + /** + * Creates a persistent communication request for a receive operation. + *

Java binding of the MPI operation {@code MPI_RECV_INIT}. + * @param buf receive buffer + * @param count number of items in receive buffer + * @param type datatype of each item in receive buffer + * @param source rank of source + * @param tag message tag + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + * @see mpi.Comm#recv(Object, int, Datatype, int, int) + */ + public final Prequest recvInit(Buffer buf, int count, + Datatype type, int source, int tag) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Prequest(recvInit(handle, buf, count, type.handle, source, tag)); + } + + private native long recvInit( + long comm, Buffer buf, int count, long type, int source, int tag) + throws MPIException; + + // Pack and Unpack + + /** + * Packs message in send buffer {@code inbuf} into space specified in + * {@code outbuf}. + *

+ * Java binding of the MPI operation {@code MPI_PACK}. + *

+ * The return value is the output value of {@code position} - the + * inital value incremented by the number of bytes written. + * @param inbuf input buffer + * @param incount number of items in input buffer + * @param type datatype of each item in input buffer + * @param outbuf output buffer + * @param position initial position in output buffer + * @return final position in output buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int pack(Object inbuf, int incount, Datatype type, + byte[] outbuf, int position) + throws MPIException + { + MPI.check(); + int offset = 0; + boolean indb = false; + + if(inbuf instanceof Buffer && !(indb = ((Buffer)inbuf).isDirect())) + { + offset = type.getOffset(inbuf); + inbuf = ((Buffer)inbuf).array(); + } + + return pack(handle, inbuf, indb, offset, incount, + type.handle, outbuf, position); + } + + private native int pack( + long comm, Object inbuf, boolean indb, int offset, int incount, + long type, byte[] outbuf, int position) throws MPIException; + + /** + * Unpacks message in receive buffer {@code outbuf} into space specified in + * {@code inbuf}. + *

+ * Java binding of the MPI operation {@code MPI_UNPACK}. + *

+ * The return value is the output value of {@code position} - the + * inital value incremented by the number of bytes read. + * @param inbuf input buffer + * @param position initial position in input buffer + * @param outbuf output buffer + * @param outcount number of items in output buffer + * @param type datatype of each item in output buffer + * @return final position in input buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int unpack(byte[] inbuf, int position, + Object outbuf, int outcount, Datatype type) + throws MPIException + { + MPI.check(); + int offset = 0; + boolean outdb = false; + + if(outbuf instanceof Buffer && !(outdb = ((Buffer)outbuf).isDirect())) + { + offset = type.getOffset(outbuf); + outbuf = ((Buffer)outbuf).array(); + } + + return unpack(handle, inbuf, position, outbuf, outdb, + offset, outcount, type.handle); + } + + private native int unpack( + long comm, byte[] inbuf, int position, Object outbuf, boolean outdb, + int offset, int outcount, long type) throws MPIException; + + /** + * Returns an upper bound on the increment of {@code position} effected + * by {@code pack}. + *

Java binding of the MPI operation {@code MPI_PACK_SIZE}. + * @param incount number of items in input buffer + * @param type datatype of each item in input buffer + * @return upper bound on size of packed message + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int packSize(int incount, Datatype type) throws MPIException + { + MPI.check(); + return packSize(handle, incount, type.handle); + } + + private native int packSize(long comm, int incount, long type) + throws MPIException; + + // Probe and Cancel + + /** + * Check if there is an incoming message matching the pattern specified. + *

Java binding of the MPI operation {@code MPI_IPROBE}. + *

If such a message is currently available, a status object similar + * to the return value of a matching {@code recv} operation is returned. + * @param source rank of source + * @param tag message tag + * @return status object if such a message is currently available, + * {@code null} otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Status iProbe(int source, int tag) throws MPIException + { + MPI.check(); + return iProbe(handle, source, tag); + } + + private native Status iProbe(long comm, int source, int tag) + throws MPIException; + + /** + * Wait until there is an incoming message matching the pattern specified. + *

Java binding of the MPI operation {@code MPI_PROBE}. + *

Returns a status object similar to the return value of a matching + * {@code recv} operation. + * @param source rank of source + * @param tag message tag + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Status probe(int source, int tag) throws MPIException + { + MPI.check(); + Status status = new Status(); + probe(handle, source, tag, status.data); + return status; + } + + private native void probe(long comm, int source, int tag, long[] stat) + throws MPIException; + + // Caching + + /** + * Create a new attribute key. + *

Java binding of the MPI operation {@code MPI_COMM_CREATE_KEYVAL}. + * @return attribute key for future access + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int createKeyval() throws MPIException + { + MPI.check(); + return createKeyval_jni(); + } + + private static native int createKeyval_jni() throws MPIException; + + /** + * Frees an attribute key for communicators. + *

Java binding of the MPI operation {@code MPI_COMM_FREE_KEYVAL}. + * @param keyval attribute key + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void freeKeyval(int keyval) throws MPIException + { + MPI.check(); + freeKeyval_jni(keyval); + } + + private static native void freeKeyval_jni(int keyval) throws MPIException; + + /** + * Stores attribute value associated with a key. + *

Java binding of the MPI operation {@code MPI_COMM_SET_ATTR}. + * @param keyval attribute key + * @param value attribute value + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void setAttr(int keyval, Object value) throws MPIException + { + MPI.check(); + setAttr(handle, keyval, MPI.attrSet(value)); + } + + private native void setAttr(long comm, int keyval, byte[] value) + throws MPIException; + + /** + * Retrieves attribute value by key. + *

Java binding of the MPI operation {@code MPI_COMM_GET_ATTR}. + * @param keyval attribute key + * @return attribute value or null if no attribute is associated with the key. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Object getAttr(int keyval) throws MPIException + { + MPI.check(); + + if( keyval == MPI.TAG_UB || + keyval == MPI.HOST || + keyval == MPI.IO || + keyval == MPI.APPNUM || + keyval == MPI.LASTUSEDCODE || + keyval == MPI.UNIVERSE_SIZE) + { + return getAttr_predefined(handle, keyval); + } + else if(keyval == MPI.WTIME_IS_GLOBAL) + { + Integer value = (Integer)getAttr_predefined(handle, keyval); + return value==null ? null : value.intValue() != 0; + } + else + { + return MPI.attrGet(getAttr(handle, keyval)); + } + } + + private native Object getAttr_predefined(long comm, int keyval) + throws MPIException; + + private native byte[] getAttr(long comm, int keyval) throws MPIException; + + /** + * Deletes an attribute value associated with a key on a communicator. + *

Java binding of the MPI operation {@code MPI_COMM_DELETE_ATTR}. + * @param keyval attribute key + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void deleteAttr(int keyval) throws MPIException + { + MPI.check(); + deleteAttr(handle, keyval); + } + + private native void deleteAttr(long comm, int keyval) throws MPIException; + + // Process Topologies + + /** + * Returns the type of topology associated with the communicator. + *

Java binding of the MPI operation {@code MPI_TOPO_TEST}. + *

The return value will be one of {@code MPI.GRAPH}, {@code MPI.CART} + * or {@code MPI.UNDEFINED}. + * @return topology type of communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int getTopology() throws MPIException + { + MPI.check(); + return getTopology(handle); + } + + private native int getTopology(long comm) throws MPIException; + + // Enviromental Management + + /** + * Abort MPI. + *

Java binding of the MPI operation {@code MPI_ABORT}. + * @param errorcode error code for Unix or POSIX environments + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void abort(int errorcode) throws MPIException + { + MPI.check(); + abort(handle, errorcode); + } + + private native void abort(long comm, int errorcode) throws MPIException; + + // Error handler + + /** + * Associates a new error handler with communicator at the calling process. + *

Java binding of the MPI operation {@code MPI_ERRHANDLER_SET}. + * @param errhandler new MPI error handler for communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void setErrhandler(Errhandler errhandler) throws MPIException + { + MPI.check(); + setErrhandler(handle, errhandler.handle); + } + + private native void setErrhandler(long comm, long errhandler) + throws MPIException; + + /** + * Returns the error handler currently associated with the communicator. + *

Java binding of the MPI operation {@code MPI_ERRHANDLER_GET}. + * @return MPI error handler currently associated with communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Errhandler getErrhandler() throws MPIException + { + MPI.check(); + return new Errhandler(getErrhandler(handle)); + } + + private native long getErrhandler(long comm); + + // Collective Communication + + /** + * A call to {@code barrier} blocks the caller until all process + * in the group have called it. + *

Java binding of the MPI operation {@code MPI_BARRIER}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void barrier() throws MPIException + { + MPI.check(); + barrier(handle); + } + + private native void barrier(long comm) throws MPIException; + + /** + * Nonblocking barrier sinchronization. + *

Java binding of the MPI operation {@code MPI_IBARRIER}. + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iBarrier() throws MPIException + { + MPI.check(); + return new Request(iBarrier(handle)); + } + + private native long iBarrier(long comm) throws MPIException; + + /** + * Broadcast a message from the process with rank {@code root} + * to all processes of the group. + *

Java binding of the MPI operation {@code MPI_BCAST}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each item in buffer + * @param root rank of broadcast root + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void bcast(Object buf, int count, Datatype type, int root) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + bcast(handle, buf, db, off, count, type.handle, type.baseType, root); + } + + private native void bcast( + long comm, Object buf, boolean db, int offset, int count, + long type, int basetype, int root) throws MPIException; + + /** + * Broadcast a message from the process with rank {@code root} + * to all processes of the group. + *

Java binding of the MPI operation {@code MPI_IBCAST}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each item in buffer + * @param root rank of broadcast root + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iBcast(Buffer buf, int count, Datatype type, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iBcast(handle, buf, count, type.handle, root)); + } + + private native long iBcast( + long comm, Buffer buf, int count, long type, int root) + throws MPIException; + + /** + * Each process sends the contents of its send buffer to the root process. + *

Java binding of the MPI operation {@code MPI_GATHER}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @param root rank of receiving process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void gather( + Object sendbuf, int sendcount, Datatype sendtype, + Object recvbuf, int recvcount, Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + gather(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, + recvtype.handle, recvtype.baseType, root); + } + + /** + * Each process sends the contents of its send buffer to the root process. + *

Java binding of the MPI operation {@code MPI_GATHER} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * The buffer is used by the root process to receive data, + * and it is used by the non-root processes to send data. + * @param buf buffer + * @param count number of items to send/receive + * @param type datatype of each item in buffer + * @param root rank of receiving process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void gather(Object buf, int count, Datatype type, int root) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + gather(handle, null, false, 0, 0, 0, 0, + buf, db, off, count, type.handle, type.baseType, root); + } + + private native void gather( + long comm, Object sendBuf, boolean sdb, int sendOff, int sendCount, + long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOff, int recvCount, + long recvType, int recvBaseType, int root) + throws MPIException; + + /** + * Each process sends the contents of its send buffer to the root process. + *

Java binding of the MPI operation {@code MPI_IGATHER}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @param root rank of receiving process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iGather( + Buffer sendbuf, int sendcount, Datatype sendtype, + Buffer recvbuf, int recvcount, Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iGather(handle, sendbuf, sendcount, sendtype.handle, + recvbuf, recvcount, recvtype.handle, root)); + } + + /** + * Each process sends the contents of its send buffer to the root process. + *

Java binding of the MPI operation {@code MPI_IGATHER} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * The buffer is used by the root process to receive data, + * and it is used by the non-root processes to send data. + * @param buf buffer + * @param count number of items to send/receive + * @param type datatype of each item in buffer + * @param root rank of receiving process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iGather(Buffer buf, int count, Datatype type, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + + return new Request(iGather(handle, null, 0, 0, + buf, count, type.handle, root)); + } + + private native long iGather( + long comm, Buffer sendbuf, int sendcount, long sendtype, + Buffer recvbuf, int recvcount, long recvtype, + int root) throws MPIException; + + /** + * Extends functionality of {@code gather} by allowing varying + * counts of data from each process. + *

Java binding of the MPI operation {@code MPI_GATHERV}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param displs displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @param root rank of receiving process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void gatherv(Object sendbuf, int sendcount, Datatype sendtype, + Object recvbuf, int[] recvcount, int[] displs, + Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + gatherv(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, displs, + recvtype.handle, recvtype.baseType, root); + } + + /** + * Extends functionality of {@code gather} by allowing varying + * counts of data from each process. + *

Java binding of the MPI operation {@code MPI_GATHERV} using + * {@code MPI_IN_PLACE} instead of the send buffer in the root process. + * This method must be used in the root process. + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param displs displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @param root rank of receiving process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void gatherv(Object recvbuf, int[] recvcount, int[] displs, + Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + int recvoff = 0; + boolean rdb = false; + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + gatherv(handle, null, false, 0, 0, 0, 0, recvbuf, rdb, recvoff, recvcount, + displs, recvtype.handle, recvtype.baseType, root); + } + + /** + * Extends functionality of {@code gather} by allowing varying + * counts of data from each process. + *

Java binding of the MPI operation {@code MPI_GATHERV} using + * {@code MPI_IN_PLACE} instead of the send buffer in the root process. + * This method must be used in the non-root processes. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param root rank of receiving process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void gatherv(Object sendbuf, int sendcount, + Datatype sendtype, int root) + throws MPIException + { + MPI.check(); + int sendoff = 0; + boolean sdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + gatherv(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + null, false, 0, null, null, 0, 0, root); + } + + private native void gatherv( + long comm, Object sendBuf, boolean sdb, int sendOffset, + int sendCount, long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOffset, + int[] recvCount, int[] displs, long recvType, int recvBaseType, + int root) throws MPIException; + + /** + * Extends functionality of {@code gather} by allowing varying + * counts of data from each process. + *

Java binding of the MPI operation {@code MPI_IGATHERV}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param displs displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @param root rank of receiving process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iGatherv( + Buffer sendbuf, int sendcount, Datatype sendtype, Buffer recvbuf, + int[] recvcount, int[] displs, Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iGatherv( + handle, sendbuf, sendcount, sendtype.handle, + recvbuf, recvcount, displs, recvtype.handle, root)); + } + + /** + * Extends functionality of {@code gather} by allowing varying + * counts of data from each process. + *

Java binding of the MPI operation {@code MPI_IGATHERV} using + * {@code MPI_IN_PLACE} instead of the send buffer in the root process. + * This method must be used in the root process. + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param displs displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @param root rank of receiving process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iGatherv(Buffer recvbuf, int[] recvcount, int[] displs, + Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(recvbuf); + + return new Request(iGatherv(handle, null, 0, 0, + recvbuf, recvcount, displs, recvtype.handle, root)); + } + + /** + * Extends functionality of {@code gather} by allowing varying + * counts of data from each process. + *

Java binding of the MPI operation {@code MPI_IGATHERV} using + * {@code MPI_IN_PLACE} instead of the send buffer in the root process. + * This method must be used in the non-root processes. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param root rank of receiving process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iGatherv(Buffer sendbuf, int sendcount, + Datatype sendtype, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf); + + return new Request(iGatherv(handle, sendbuf, sendcount, sendtype.handle, + null, null, null, 0, root)); + } + + private native long iGatherv( + long handle, Buffer sendbuf, int sendcount, long sendtype, + Buffer recvbuf, int[] recvcount, int[] displs, + long recvtype, int root) + throws MPIException; + + /** + * Inverse of the operation {@code gather}. + *

Java binding of the MPI operation {@code MPI_SCATTER}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @param root rank of sending process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void scatter( + Object sendbuf, int sendcount, Datatype sendtype, + Object recvbuf, int recvcount, Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + scatter(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, + recvtype.handle, recvtype.baseType, root); + } + + /** + * Inverse of the operation {@code gather}. + *

Java binding of the MPI operation {@code MPI_SCATTER} + * using {@code MPI_IN_PLACE} instead of the receive buffer. + * The buffer is used by the root process to send data, + * and it is used by the non-root processes to receive data. + * @param buf send/receive buffer + * @param count number of items to send/receive + * @param type datatype of each item in buffer + * @param root rank of sending process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void scatter(Object buf, int count, Datatype type, int root) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + scatter(handle, buf, db, off, count, type.handle, type.baseType, + null, false, 0, 0, 0, 0, root); + } + + private native void scatter( + long comm, Object sendBuf, boolean sdb, int sendOffset, int sendCount, + long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOffset, int recvCount, + long recvType, int recvBaseType, int root) throws MPIException; + + /** + * Inverse of the operation {@code gather}. + *

Java binding of the MPI operation {@code MPI_ISCATTER}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @param root rank of sending process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iScatter( + Buffer sendbuf, int sendcount, Datatype sendtype, + Buffer recvbuf, int recvcount, Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iScatter(handle, sendbuf, sendcount, sendtype.handle, + recvbuf, recvcount, recvtype.handle, root)); + } + + /** + * Inverse of the operation {@code gather}. + *

Java binding of the MPI operation {@code MPI_ISCATTER} + * using {@code MPI_IN_PLACE} instead of the receive buffer. + * The buffer is used by the root process to send data, + * and it is used by the non-root processes to receive data. + * @param buf send/receive buffer + * @param count number of items to send/receive + * @param type datatype of each item in buffer + * @param root rank of sending process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iScatter(Buffer buf, int count, Datatype type, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + + return new Request(iScatter(handle, buf, count, type.handle, + null, 0, 0, root)); + } + + private native long iScatter( + long comm, Buffer sendbuf, int sendcount, long sendtype, + Buffer recvbuf, int recvcount, long recvtype, int root) + throws MPIException; + + /** + * Inverse of the operation {@code gatherv}. + *

Java binding of the MPI operation {@code MPI_SCATTERV}. + * @param sendbuf send buffer + * @param sendcount number of items sent to each process + * @param displs displacements from which to take outgoing data + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @param root rank of sending process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void scatterv( + Object sendbuf, int[] sendcount, int[] displs, Datatype sendtype, + Object recvbuf, int recvcount, Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + scatterv(handle, sendbuf, sdb, sendoff, sendcount, displs, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, + recvtype.handle, recvtype.baseType, root); + } + + /** + * Inverse of the operation {@code gatherv}. + *

Java binding of the MPI operation {@code MPI_SCATTERV} using + * {@code MPI_IN_PLACE} instead of the receive buffer in the root process. + * This method must be used in the root process. + * @param sendbuf send buffer + * @param sendcount number of items sent to each process + * @param displs displacements from which to take outgoing data + * @param sendtype datatype of each item in send buffer + * @param root rank of sending process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void scatterv(Object sendbuf, int[] sendcount, int[] displs, + Datatype sendtype, int root) + throws MPIException + { + MPI.check(); + int sendoff = 0; + boolean sdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + scatterv(handle, sendbuf, sdb, sendoff, sendcount, displs, + sendtype.handle, sendtype.baseType, + null, false, 0, 0, 0, 0, root); + } + + /** + * Inverse of the operation {@code gatherv}. + *

Java binding of the MPI operation {@code MPI_SCATTERV} using + * {@code MPI_IN_PLACE} instead of the receive buffer in the root process. + * This method must be used in the non-root processes. + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @param root rank of sending process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void scatterv(Object recvbuf, int recvcount, + Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + int recvoff = 0; + boolean rdb = false; + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + scatterv(handle, null, false, 0, null, null, 0, 0, + recvbuf, rdb, recvoff, recvcount, + recvtype.handle, recvtype.baseType, root); + } + + private native void scatterv( + long comm, Object sendBuf, boolean sdb, int sendOffset, + int[] sendCount, int[] displs, long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOffset, int recvCount, + long recvType, int recvBaseType, int root) + throws MPIException; + + /** + * Inverse of the operation {@code gatherv}. + *

Java binding of the MPI operation {@code MPI_ISCATTERV}. + * @param sendbuf send buffer + * @param sendcount number of items sent to each process + * @param displs displacements from which to take outgoing data + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @param root rank of sending process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iScatterv( + Buffer sendbuf, int[] sendcount, int[] displs, Datatype sendtype, + Buffer recvbuf, int recvcount, Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iScatterv( + handle, sendbuf, sendcount, displs, sendtype.handle, + recvbuf, recvcount, recvtype.handle, root)); + } + + /** + * Inverse of the operation {@code gatherv}. + *

Java binding of the MPI operation {@code MPI_ISCATTERV} using + * {@code MPI_IN_PLACE} instead of the receive buffer in the root process. + * This method must be used in the root process. + * @param sendbuf send buffer + * @param sendcount number of items sent to each process + * @param displs displacements from which to take outgoing data + * @param sendtype datatype of each item in send buffer + * @param root rank of sending process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iScatterv(Buffer sendbuf, int[] sendcount, int[] displs, + Datatype sendtype, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf); + + return new Request(iScatterv(handle, sendbuf, sendcount, displs, + sendtype.handle, null, 0, 0, root)); + } + + /** + * Inverse of the operation {@code gatherv}. + *

Java binding of the MPI operation {@code MPI_ISCATTERV} using + * {@code MPI_IN_PLACE} instead of the receive buffer in the root process. + * This method must be used in the non-root processes. + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @param root rank of sending process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iScatterv(Buffer recvbuf, int recvcount, + Datatype recvtype, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(recvbuf); + + return new Request(iScatterv(handle, null, null, null, 0, + recvbuf, recvcount, recvtype.handle, root)); + } + + private native long iScatterv( + long comm, Buffer sendbuf, int[] sendcount, int[] displs, long sendtype, + Buffer recvbuf, int recvcount, long recvtype, int root) + throws MPIException; + + /** + * Similar to {@code gather}, but all processes receive the result. + *

Java binding of the MPI operation {@code MPI_ALLGATHER}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void allGather(Object sendbuf, int sendcount, Datatype sendtype, + Object recvbuf, int recvcount, Datatype recvtype) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + allGather(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, + recvtype.handle, recvtype.baseType); + } + + /** + * Similar to {@code gather}, but all processes receive the result. + *

Java binding of the MPI operation {@code MPI_ALLGATHER} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer + * @param count number of items to receive + * @param type datatype of each item in receive buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void allGather(Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + allGather(handle, null, false, 0, 0, 0, 0, + buf, db, off, count, type.handle, type.baseType); + } + + private native void allGather( + long comm, Object sendBuf, boolean sdb, int sendOffset, int sendCount, + long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOffset, int recvCount, + long recvType, int recvBaseType) throws MPIException; + + /** + * Similar to {@code gather}, but all processes receive the result. + *

Java binding of the MPI operation {@code MPI_IALLGATHER}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iAllGather( + Buffer sendbuf, int sendcount, Datatype sendtype, + Buffer recvbuf, int recvcount, Datatype recvtype) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iAllGather(handle, sendbuf, sendcount, sendtype.handle, + recvbuf, recvcount, recvtype.handle)); + } + + /** + * Similar to {@code gather}, but all processes receive the result. + *

Java binding of the MPI operation {@code MPI_IALLGATHER} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer + * @param count number of items to receive + * @param type datatype of each item in receive buffer + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iAllGather(Buffer buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iAllGather(handle, null, 0, 0, buf, count, type.handle)); + } + + private native long iAllGather( + long comm, Buffer sendbuf, int sendcount, long sendtype, + Buffer recvbuf, int recvcount, long recvtype) throws MPIException; + + /** + * Similar to {@code gatherv}, but all processes receive the result. + *

Java binding of the MPI operation {@code MPI_ALLGATHERV}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param displs displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void allGatherv( + Object sendbuf, int sendcount, Datatype sendtype, + Object recvbuf, int[] recvcount, int[] displs, Datatype recvtype) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + allGatherv(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, displs, + recvtype.handle, recvtype.baseType); + } + + /** + * Similar to {@code gatherv}, but all processes receive the result. + *

Java binding of the MPI operation {@code MPI_ALLGATHERV} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param displs displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void allGatherv(Object recvbuf, int[] recvcount, + int[] displs, Datatype recvtype) + throws MPIException + { + MPI.check(); + int recvoff = 0; + boolean rdb = false; + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + allGatherv(handle, null, false, 0, 0, 0, 0, + recvbuf, rdb, recvoff, recvcount, + displs, recvtype.handle, recvtype.baseType); + } + + private native void allGatherv( + long comm, Object sendBuf, boolean sdb, int sendOffset, int sendCount, + long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOffset, int[] recvCount, + int[] displs, long recvType, int recvBasetype) throws MPIException; + + /** + * Similar to {@code gatherv}, but all processes receive the result. + *

Java binding of the MPI operation {@code MPI_IALLGATHERV}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param displs displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iAllGatherv( + Buffer sendbuf, int sendcount, Datatype sendtype, + Buffer recvbuf, int[] recvcount, int[] displs, Datatype recvtype) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iAllGatherv( + handle, sendbuf, sendcount, sendtype.handle, + recvbuf, recvcount, displs, recvtype.handle)); + } + + /** + * Similar to {@code gatherv}, but all processes receive the result. + *

Java binding of the MPI operation {@code MPI_IALLGATHERV} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer + * @param count number of elements received from each process + * @param displs displacements at which to place incoming data + * @param type datatype of each item in receive buffer + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iAllGatherv( + Buffer buf, int[] count, int[] displs, Datatype type) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + + return new Request(iAllGatherv( + handle, null, 0, 0, buf, count, displs, type.handle)); + } + + private native long iAllGatherv( + long handle, Buffer sendbuf, int sendcount, long sendtype, + Buffer recvbuf, int[] recvcount, int[] displs, long recvtype) + throws MPIException; + + /** + * Extension of {@code allGather} to the case where each process sends + * distinct data to each of the receivers. + *

Java binding of the MPI operation {@code MPI_ALLTOALL}. + * @param sendbuf send buffer + * @param sendcount number of items sent to each process + * @param sendtype datatype send buffer items + * @param recvbuf receive buffer + * @param recvcount number of items received from any process + * @param recvtype datatype of receive buffer items + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void allToAll(Object sendbuf, int sendcount, Datatype sendtype, + Object recvbuf, int recvcount, Datatype recvtype) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + allToAll(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, + recvtype.handle, recvtype.baseType); + } + + private native void allToAll( + long comm, Object sendBuf, boolean sdb, int sendOffset, int sendCount, + long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOffset, int recvCount, + long recvType, int recvBaseType) throws MPIException; + + /** + * Extension of {@code allGather} to the case where each process sends + * distinct data to each of the receivers. + *

Java binding of the MPI operation {@code MPI_IALLTOALL}. + * @param sendbuf send buffer + * @param sendcount number of items sent to each process + * @param sendtype datatype send buffer items + * @param recvbuf receive buffer + * @param recvcount number of items received from any process + * @param recvtype datatype of receive buffer items + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iAllToAll(Buffer sendbuf, int sendcount, Datatype sendtype, + Buffer recvbuf, int recvcount, Datatype recvtype) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iAllToAll(handle, sendbuf, sendcount, sendtype.handle, + recvbuf, recvcount, recvtype.handle)); + } + + private native long iAllToAll( + long comm, Buffer sendbuf, int sendcount, long sendtype, + Buffer recvbuf, int recvcount, long recvtype) throws MPIException; + + /** + * Adds flexibility to {@code allToAll}: location of data for send is + * specified by {@code sdispls} and location to place data on receive + * side is specified by {@code rdispls}. + *

Java binding of the MPI operation {@code MPI_ALLTOALLV}. + * @param sendbuf send buffer + * @param sendcount number of items sent to each buffer + * @param sdispls displacements from which to take outgoing data + * @param sendtype datatype send buffer items + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param rdispls displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void allToAllv( + Object sendbuf, int[] sendcount, int[] sdispls, Datatype sendtype, + Object recvbuf, int[] recvcount, int[] rdispls, Datatype recvtype) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + allToAllv(handle, sendbuf, sdb, sendoff, sendcount, sdispls, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, rdispls, + recvtype.handle, recvtype.baseType); + } + + private native void allToAllv( + long comm, Object sendBuf, boolean sdb, int sendOffset, + int[] sendCount, int[] sdispls, long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOffset, + int[] recvCount, int[] rdispls, long recvType, int recvBaseType) + throws MPIException; + + /** + * Adds flexibility to {@code allToAll}: location of data for send is + * specified by {@code sdispls} and location to place data on receive + * side is specified by {@code rdispls}. + *

Java binding of the MPI operation {@code MPI_IALLTOALLV}. + * @param sendbuf send buffer + * @param sendcount number of items sent to each buffer + * @param sdispls displacements from which to take outgoing data + * @param sendtype datatype send buffer items + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param rdispls displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iAllToAllv( + Buffer sendbuf, int[] sendcount, int[] sdispls, Datatype sendtype, + Buffer recvbuf, int[] recvcount, int[] rdispls, Datatype recvtype) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iAllToAllv( + handle, sendbuf, sendcount, sdispls, sendtype.handle, + recvbuf, recvcount, rdispls, recvtype.handle)); + } + + private native long iAllToAllv(long comm, + Buffer sendbuf, int[] sendcount, int[] sdispls, long sendtype, + Buffer recvbuf, int[] recvcount, int[] rdispls, long recvtype) + throws MPIException; + + /** + * Adds flexibility to {@code allToAll}: location of data for send is //here + * specified by {@code sDispls} and location to place data on receive + * side is specified by {@code rDispls}. + *

Java binding of the MPI operation {@code MPI_ALLTOALLW}. + * @param sendBuf send buffer + * @param sendCount number of items sent to each buffer + * @param sDispls displacements from which to take outgoing data + * @param sendTypes datatypes of send buffer items + * @param recvBuf receive buffer + * @param recvCount number of elements received from each process + * @param rDispls displacements at which to place incoming data + * @param recvTypes datatype of each item in receive buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void allToAllw( + Buffer sendBuf, int[] sendCount, int[] sDispls, Datatype[] sendTypes, + Buffer recvBuf, int[] recvCount, int[] rDispls, Datatype[] recvTypes) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendBuf, recvBuf); + + long[] sendHandles = convertTypeArray(sendTypes); + long[] recvHandles = convertTypeArray(recvTypes); + + allToAllw(handle, sendBuf, sendCount, sDispls, + sendHandles, recvBuf, recvCount, rDispls, + recvHandles); + } + + private native void allToAllw(long comm, + Buffer sendBuf, int[] sendCount, int[] sDispls, long[] sendTypes, + Buffer recvBuf, int[] recvCount, int[] rDispls, long[] recvTypes) + throws MPIException; + + /** + * Adds flexibility to {@code iAllToAll}: location of data for send is + * specified by {@code sDispls} and location to place data on receive + * side is specified by {@code rDispls}. + *

Java binding of the MPI operation {@code MPI_IALLTOALLW}. + * @param sendBuf send buffer + * @param sendCount number of items sent to each buffer + * @param sDispls displacements from which to take outgoing data + * @param sendTypes datatype send buffer items + * @param recvBuf receive buffer + * @param recvCount number of elements received from each process + * @param rDispls displacements at which to place incoming data + * @param recvTypes datatype of each item in receive buffer + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iAllToAllw( + Buffer sendBuf, int[] sendCount, int[] sDispls, Datatype[] sendTypes, + Buffer recvBuf, int[] recvCount, int[] rDispls, Datatype[] recvTypes) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendBuf, recvBuf); + + long[] sendHandles = convertTypeArray(sendTypes); + long[] recvHandles = convertTypeArray(recvTypes); + + return new Request(iAllToAllw( + handle, sendBuf, sendCount, sDispls, sendHandles, + recvBuf, recvCount, rDispls, recvHandles)); + } + + private native long iAllToAllw(long comm, + Buffer sendBuf, int[] sendCount, int[] sDispls, long[] sendTypes, + Buffer recvBuf, int[] recvCount, int[] rDispls, long[] recvTypes) + throws MPIException; + + /** + * Java binding of {@code MPI_NEIGHBOR_ALLGATHER}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void neighborAllGather( + Object sendbuf, int sendcount, Datatype sendtype, + Object recvbuf, int recvcount, Datatype recvtype) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + neighborAllGather(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, + recvtype.handle, recvtype.baseType); + } + + private native void neighborAllGather( + long comm, Object sendBuf, boolean sdb, int sendOffset, + int sendCount, long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOffset, + int recvCount, long recvType, int recvBaseType) + throws MPIException; + + /** + * Java binding of {@code MPI_INEIGHBOR_ALLGATHER}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iNeighborAllGather( + Buffer sendbuf, int sendcount, Datatype sendtype, + Buffer recvbuf, int recvcount, Datatype recvtype) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iNeighborAllGather( + handle, sendbuf, sendcount, sendtype.handle, + recvbuf, recvcount, recvtype.handle)); + } + + private native long iNeighborAllGather( + long comm, Buffer sendBuf, int sendCount, long sendType, + Buffer recvBuf, int recvCount, long recvType) + throws MPIException; + + /** + * Java binding of {@code MPI_NEIGHBOR_ALLGATHERV}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of elements that are received from each neighbor + * @param displs displacements at which to place incoming data + * @param recvtype datatype of receive buffer elements + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void neighborAllGatherv( + Object sendbuf, int sendcount, Datatype sendtype, + Object recvbuf, int[] recvcount, int[] displs, Datatype recvtype) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + neighborAllGatherv(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, displs, + recvtype.handle, recvtype.baseType); + } + + private native void neighborAllGatherv( + long comm, Object sendBuf, boolean sdb, int sendOff, + int sendCount, long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOff, + int[] recvCount, int[] displs, long recvType, int recvBaseType); + + /** + * Java binding of {@code MPI_INEIGHBOR_ALLGATHERV}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of elements that are received from each neighbor + * @param displs displacements at which to place incoming data + * @param recvtype datatype of receive buffer elements + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iNeighborAllGatherv( + Buffer sendbuf, int sendcount, Datatype sendtype, + Buffer recvbuf, int[] recvcount, int[] displs, Datatype recvtype) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iNeighborAllGatherv( + handle, sendbuf, sendcount, sendtype.handle, + recvbuf, recvcount, displs, recvtype.handle)); + } + + private native long iNeighborAllGatherv( + long comm, Buffer sendBuf, int sendCount, long sendType, + Buffer recvBuf, int[] recvCount, int[] displs, long recvType) + throws MPIException; + + /** + * Java binding of {@code MPI_NEIGHBOR_ALLTOALL}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void neighborAllToAll( + Object sendbuf, int sendcount, Datatype sendtype, + Object recvbuf, int recvcount, Datatype recvtype) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + neighborAllToAll(handle, sendbuf, sdb, sendoff, sendcount, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, + recvtype.handle, recvtype.baseType); + } + + private native void neighborAllToAll( + long comm, Object sendBuf, boolean sdb, int sendOff, + int sendCount, long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOff, + int recvCount, long recvType, int recvBaseType) + throws MPIException; + + /** + * Java binding of {@code MPI_INEIGHBOR_ALLTOALL}. + * @param sendbuf send buffer + * @param sendcount number of items to send + * @param sendtype datatype of each item in send buffer + * @param recvbuf receive buffer + * @param recvcount number of items to receive + * @param recvtype datatype of each item in receive buffer + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iNeighborAllToAll( + Buffer sendbuf, int sendcount, Datatype sendtype, + Buffer recvbuf, int recvcount, Datatype recvtype) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iNeighborAllToAll( + handle, sendbuf, sendcount, sendtype.handle, + recvbuf, recvcount, recvtype.handle)); + } + + private native long iNeighborAllToAll( + long comm, Buffer sendBuf, int sendCount, long sendType, + Buffer recvBuf, int recvCount, long recvType); + + /** + * Java binding of {@code MPI_NEIGHBOR_ALLTOALLV}. + * @param sendbuf send buffer + * @param sendcount number of items sent to each buffer + * @param sdispls displacements from which to take outgoing data + * @param sendtype datatype send buffer items + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param rdispls displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void neighborAllToAllv( + Object sendbuf, int[] sendcount, int[] sdispls, Datatype sendtype, + Object recvbuf, int[] recvcount, int[] rdispls, Datatype recvtype) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = sendtype.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = recvtype.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + neighborAllToAllv(handle, + sendbuf, sdb, sendoff, sendcount, sdispls, + sendtype.handle, sendtype.baseType, + recvbuf, rdb, recvoff, recvcount, rdispls, + recvtype.handle, recvtype.baseType); + } + + private native void neighborAllToAllv( + long comm, Object sendBuf, boolean sdb, int sendOff, + int[] sendCount, int[] sdispls, long sendType, int sendBaseType, + Object recvBuf, boolean rdb, int recvOff, + int[] recvCount, int[] rdispls, long recvType, int recvBaseType) + throws MPIException; + + /** + * Java binding of {@code MPI_INEIGHBOR_ALLTOALLV}. + * @param sendbuf send buffer + * @param sendcount number of items sent to each buffer + * @param sdispls displacements from which to take outgoing data + * @param sendtype datatype send buffer items + * @param recvbuf receive buffer + * @param recvcount number of elements received from each process + * @param rdispls displacements at which to place incoming data + * @param recvtype datatype of each item in receive buffer + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iNeighborAllToAllv( + Buffer sendbuf, int[] sendcount, int[] sdispls, Datatype sendtype, + Buffer recvbuf, int[] recvcount, int[] rdispls, Datatype recvtype) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iNeighborAllToAllv( + handle, sendbuf, sendcount, sdispls, sendtype.handle, + recvbuf, recvcount, rdispls, recvtype.handle)); + } + + private native long iNeighborAllToAllv( + long comm, Buffer sendBuf, int[] sendCount, int[] sdispls, long sType, + Buffer recvBuf, int[] recvCount, int[] rdispls, long rType) + throws MPIException; + + /** + * Combine elements in input buffer of each process using the reduce + * operation, and return the combined value in the output buffer of the + * root process. + *

+ * Java binding of the MPI operation {@code MPI_REDUCE}. + *

+ * The predefined operations are available in Java as {@code MPI.MAX}, + * {@code MPI.MIN}, {@code MPI.SUM}, {@code MPI.PROD}, {@code MPI.LAND}, + * {@code MPI.BAND}, {@code MPI.LOR}, {@code MPI.BOR}, {@code MPI.LXOR}, + * {@code MPI.BXOR}, {@code MPI.MINLOC} and {@code MPI.MAXLOC}. + * @param sendbuf send buffer + * @param recvbuf receive buffer + * @param count number of items in send buffer + * @param type data type of each item in send buffer + * @param op reduce operation + * @param root rank of root process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void reduce(Object sendbuf, Object recvbuf, int count, + Datatype type, Op op, int root) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = type.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = type.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + reduce(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, + count, type.handle, type.baseType, op, op.handle, root); + } + + /** + * Combine elements in input buffer of each process using the reduce + * operation, and return the combined value in the output buffer of the + * root process. + *

Java binding of the MPI operation {@code MPI_REDUCE} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf send/receive buffer + * @param count number of items in buffer + * @param type data type of each item in buffer + * @param op reduce operation + * @param root rank of root process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void reduce(Object buf, int count, Datatype type, Op op, int root) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + reduce(handle, null, false, 0, buf, db, off, count, + type.handle, type.baseType, op, op.handle, root); + } + + private native void reduce( + long comm, Object sendbuf, boolean sdb, int sendoff, + Object recvbuf, boolean rdb, int recvoff, int count, + long type, int baseType, Op jOp, long hOp, int root) + throws MPIException; + + /** + * Combine elements in input buffer of each process using the reduce + * operation, and return the combined value in the output buffer of the + * root process. + *

Java binding of the MPI operation {@code MPI_IREDUCE}. + * @param sendbuf send buffer + * @param recvbuf receive buffer + * @param count number of items in send buffer + * @param type data type of each item in send buffer + * @param op reduce operation + * @param root rank of root process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iReduce(Buffer sendbuf, Buffer recvbuf, + int count, Datatype type, Op op, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + op.setDatatype(type); + + return new Request(iReduce( + handle, sendbuf, recvbuf, count, + type.handle, type.baseType, op, op.handle, root)); + } + + /** + * Combine elements in input buffer of each process using the reduce + * operation, and return the combined value in the output buffer of the + * root process. + *

Java binding of the MPI operation {@code MPI_IREDUCE} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf send/receive buffer + * @param count number of items in buffer + * @param type data type of each item in buffer + * @param op reduce operation + * @param root rank of root process + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iReduce(Buffer buf, int count, + Datatype type, Op op, int root) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + op.setDatatype(type); + + return new Request(iReduce( + handle, null, buf, count, + type.handle, type.baseType, op, op.handle, root)); + } + + private native long iReduce( + long comm, Buffer sendbuf, Buffer recvbuf, int count, + long type, int baseType, Op jOp, long hOp, int root) + throws MPIException; + + /** + * Same as {@code reduce} except that the result appears in receive + * buffer of all process in the group. + *

Java binding of the MPI operation {@code MPI_ALLREDUCE}. + * @param sendbuf send buffer + * @param recvbuf receive buffer + * @param count number of items in send buffer + * @param type data type of each item in send buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void allReduce(Object sendbuf, Object recvbuf, + int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = type.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = type.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + allReduce(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, + count, type.handle, type.baseType, op, op.handle); + } + + /** + * Same as {@code reduce} except that the result appears in receive + * buffer of all process in the group. + *

Java binding of the MPI operation {@code MPI_ALLREDUCE} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer + * @param count number of items in send buffer + * @param type data type of each item in send buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void allReduce(Object buf, int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + allReduce(handle, null, false, 0, buf, db, off, count, + type.handle, type.baseType, op, op.handle); + } + + private native void allReduce( + long comm, Object sendbuf, boolean sdb, int sendoff, + Object recvbuf, boolean rdb, int recvoff, int count, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Same as {@code reduce} except that the result appears in receive + * buffer of all process in the group. + *

Java binding of the MPI operation {@code MPI_IALLREDUCE}. + * @param sendbuf send buffer + * @param recvbuf receive buffer + * @param count number of items in send buffer + * @param type data type of each item in send buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iAllReduce(Buffer sendbuf, Buffer recvbuf, + int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + assertDirectBuffer(sendbuf, recvbuf); + op.setDatatype(type); + + return new Request(iAllReduce(handle, sendbuf, recvbuf, count, + type.handle, type.baseType, op, op.handle)); + } + + /** + * Same as {@code reduce} except that the result appears in receive + * buffer of all process in the group. + *

Java binding of the MPI operation {@code MPI_IALLREDUCE} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer + * @param count number of items in send buffer + * @param type data type of each item in send buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iAllReduce(Buffer buf, int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + assertDirectBuffer(buf); + + return new Request(iAllReduce( + handle, null, buf, count, + type.handle, type.baseType, op, op.handle)); + } + + private native long iAllReduce( + long comm, Buffer sendbuf, Buffer recvbuf, int count, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Combine elements in input buffer of each process using the reduce + * operation, and scatter the combined values over the output buffers + * of the processes. + *

Java binding of the MPI operation {@code MPI_REDUCE_SCATTER}. + * @param sendbuf send buffer + * @param recvbuf receive buffer + * @param recvcounts numbers of result elements distributed to each process + * @param type data type of each item in send buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void reduceScatter(Object sendbuf, Object recvbuf, + int[] recvcounts, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = type.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = type.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + reduceScatter(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, + recvcounts, type.handle, type.baseType, op, op.handle); + } + + /** + * Combine elements in input buffer of each process using the reduce + * operation, and scatter the combined values over the output buffers + * of the processes. + *

Java binding of the MPI operation {@code MPI_REDUCE_SCATTER} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer + * @param counts numbers of result elements distributed to each process + * @param type data type of each item in send buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void reduceScatter(Object buf, int[] counts, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + reduceScatter(handle, null, false, 0, buf, db, off, counts, + type.handle, type.baseType, op, op.handle); + } + + private native void reduceScatter( + long comm, Object sendbuf, boolean sdb, int sendoff, + Object recvbuf, boolean rdb, int recvoff, int[] recvcounts, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Combine elements in input buffer of each process using the reduce + * operation, and scatter the combined values over the output buffers + * of the processes. + *

Java binding of the MPI operation {@code MPI_IREDUCE_SCATTER}. + * @param sendbuf send buffer + * @param recvbuf receive buffer + * @param recvcounts numbers of result elements distributed to each process + * @param type data type of each item in send buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iReduceScatter(Buffer sendbuf, Buffer recvbuf, + int[] recvcounts, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iReduceScatter( + handle, sendbuf, recvbuf, recvcounts, + type.handle, type.baseType, op, op.handle)); + } + + /** + * Combine elements in input buffer of each process using the reduce + * operation, and scatter the combined values over the output buffers + * of the processes. + *

Java binding of the MPI operation {@code MPI_IREDUCE_SCATTER} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer + * @param counts numbers of result elements distributed to each process + * @param type data type of each item in send buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iReduceScatter( + Buffer buf, int[] counts, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + assertDirectBuffer(buf); + + return new Request(iReduceScatter( + handle, null, buf, counts, + type.handle, type.baseType, op, op.handle)); + } + + private native long iReduceScatter( + long handle, Buffer sendbuf, Object recvbuf, int[] recvcounts, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Combine values and scatter the results. + *

Java binding of the MPI operation {@code MPI_REDUCE_SCATTER_BLOCK}. + * @param sendbuf send buffer + * @param recvbuf receive buffer + * @param recvcount element count per block + * @param type data type of each item in send buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void reduceScatterBlock(Object sendbuf, Object recvbuf, + int recvcount, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = type.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = type.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + reduceScatterBlock(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, + recvcount, type.handle, type.baseType, op, op.handle); + } + + /** + * Combine values and scatter the results. + *

Java binding of the MPI operation {@code MPI_REDUCE_SCATTER_BLOCK} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer + * @param count element count per block + * @param type data type of each item in send buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void reduceScatterBlock( + Object buf, int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + reduceScatterBlock(handle, null, false, 0, buf, db, off, count, + type.handle, type.baseType, op, op.handle); + } + + private native void reduceScatterBlock( + long comm, Object sendBuf, boolean sdb, int sOffset, + Object recvBuf, boolean rdb, int rOffset, int rCount, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Combine values and scatter the results. + *

Java binding of the MPI operation {@code MPI_IREDUCE_SCATTER_BLOCK}. + * @param sendbuf send buffer + * @param recvbuf receive buffer + * @param recvcount element count per block + * @param type data type of each item in send buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iReduceScatterBlock( + Buffer sendbuf, Buffer recvbuf, int recvcount, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iReduceScatterBlock( + handle, sendbuf, recvbuf, recvcount, + type.handle, type.baseType, op, op.handle)); + } + + /** + * Combine values and scatter the results. + *

Java binding of the MPI operation {@code MPI_IREDUCE_SCATTER_BLOCK} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer + * @param count element count per block + * @param type data type of each item in send buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iReduceScatterBlock( + Buffer buf, int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + assertDirectBuffer(buf); + + return new Request(iReduceScatterBlock( + handle, null, buf, count, type.handle, + type.baseType, op, op.handle)); + } + + private native long iReduceScatterBlock( + long handle, Buffer sendbuf, Buffer recvbuf, int recvcount, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Apply the operation given by {@code op} element-wise to the + * elements of {@code inBuf} and {@code inOutBuf} with the result + * stored element-wise in {@code inOutBuf}. + *

Java binding of the MPI operation {@code MPI_REDUCE_LOCAL}. + * @param inBuf input buffer + * @param inOutBuf input buffer, will contain combined output + * @param count number of elements + * @param type data type of each item + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void reduceLocal( + Object inBuf, Object inOutBuf, int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + + int inOff = 0, + inOutOff = 0; + + boolean idb = false, + iodb = false; + + if(inBuf instanceof Buffer && !(idb = ((Buffer)inBuf).isDirect())) + { + inOff = type.getOffset(inBuf); + inBuf = ((Buffer)inBuf).array(); + } + + if(inOutBuf instanceof Buffer && !(iodb = ((Buffer)inOutBuf).isDirect())) + { + inOutOff = type.getOffset(inOutBuf); + inOutBuf = ((Buffer)inOutBuf).array(); + } + + if(op.uf == null) + { + reduceLocal(inBuf, idb, inOff, inOutBuf, iodb, inOutOff, + count, type.handle, op.handle); + } + else + { + reduceLocalUf(inBuf, idb, inOff, inOutBuf, iodb, inOutOff, + count, type.handle, type.baseType, op, op.handle); + } + } + + private static native void reduceLocal( + Object inBuf, boolean idb, int inOff, + Object inOutBuf, boolean iodb, int inOutOff, int count, + long type, long op) throws MPIException; + + private static native void reduceLocalUf( + Object inBuf, boolean idb, int inOff, + Object inOutBuf, boolean iodb, int inOutOff, int count, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Sets the print name for the communicator. + * @param name name for the communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void setName(String name) throws MPIException + { + MPI.check(); + setName(handle, name); + } + + private native void setName(long handle, String name) throws MPIException; + + /** + * Return the print name from the communicator. + * @return name of the communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final String getName() throws MPIException + { + MPI.check(); + return getName(handle); + } + + private native String getName(long handle) throws MPIException; + + /** + * A helper method to convert an array of Datatypes to + * an array of longs (handles). + * @param dArray Array of Datatypes + * @return converted Datatypes + */ + private long[] convertTypeArray(Datatype[] dArray) { + long[] lArray = new long[dArray.length]; + + for(int i = 0; i < lArray.length; i++) { + if(dArray[i] != null) { + lArray[i] = dArray[i].handle; + } + } + return lArray; + } } // Comm diff --git a/ompi/mpi/java/java/Constant.java b/ompi/mpi/java/java/Constant.java index f0e70db54b..e3e47fb90a 100644 --- a/ompi/mpi/java/java/Constant.java +++ b/ompi/mpi/java/java/Constant.java @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -20,103 +22,100 @@ package mpi; class Constant { - protected int THREAD_SINGLE, THREAD_FUNNELED, THREAD_SERIALIZED, - THREAD_MULTIPLE; + protected int THREAD_SINGLE, THREAD_FUNNELED, THREAD_SERIALIZED, THREAD_MULTIPLE; - protected int GRAPH, DIST_GRAPH, CART; - protected int ANY_SOURCE, ANY_TAG; - protected int PROC_NULL; - protected int UNDEFINED; - protected int IDENT, CONGRUENT, SIMILAR, UNEQUAL; - protected int TAG_UB, HOST, IO, WTIME_IS_GLOBAL; + protected int GRAPH, DIST_GRAPH, CART; + protected int ANY_SOURCE, ANY_TAG; + protected int PROC_NULL; + protected int UNDEFINED; + protected int IDENT, CONGRUENT, SIMILAR, UNEQUAL; + protected int TAG_UB, HOST, IO, WTIME_IS_GLOBAL; - protected int APPNUM, LASTUSEDCODE, UNIVERSE_SIZE, WIN_BASE, WIN_SIZE, - WIN_DISP_UNIT; + protected int APPNUM, LASTUSEDCODE, UNIVERSE_SIZE, WIN_BASE, WIN_SIZE, WIN_DISP_UNIT; - protected int VERSION, SUBVERSION; - protected int ROOT, KEYVAL_INVALID, BSEND_OVERHEAD; - protected int MAX_OBJECT_NAME, MAX_PORT_NAME, MAX_DATAREP_STRING; - protected int MAX_INFO_KEY, MAX_INFO_VAL; - protected int ORDER_C, ORDER_FORTRAN; + protected int VERSION, SUBVERSION; + protected int ROOT, KEYVAL_INVALID, BSEND_OVERHEAD; + protected int MAX_OBJECT_NAME, MAX_PORT_NAME, MAX_DATAREP_STRING; + protected int MAX_INFO_KEY, MAX_INFO_VAL; + protected int ORDER_C, ORDER_FORTRAN; - protected int DISTRIBUTE_BLOCK, DISTRIBUTE_CYCLIC, DISTRIBUTE_NONE, - DISTRIBUTE_DFLT_DARG; + protected int DISTRIBUTE_BLOCK, DISTRIBUTE_CYCLIC, DISTRIBUTE_NONE, DISTRIBUTE_DFLT_DARG; - protected int MODE_CREATE, MODE_RDONLY, MODE_WRONLY, MODE_RDWR, - MODE_DELETE_ON_CLOSE, MODE_UNIQUE_OPEN, MODE_EXCL, - MODE_APPEND, MODE_SEQUENTIAL; + protected int MODE_CREATE, MODE_RDONLY, MODE_WRONLY, MODE_RDWR, + MODE_DELETE_ON_CLOSE, MODE_UNIQUE_OPEN, MODE_EXCL, + MODE_APPEND, MODE_SEQUENTIAL; - protected int DISPLACEMENT_CURRENT; - protected int SEEK_SET, SEEK_CUR, SEEK_END; + protected int DISPLACEMENT_CURRENT; + protected int SEEK_SET, SEEK_CUR, SEEK_END; - protected int MODE_NOCHECK, MODE_NOPRECEDE, MODE_NOPUT, MODE_NOSTORE, - MODE_NOSUCCEED; + protected int MODE_NOCHECK, MODE_NOPRECEDE, MODE_NOPUT, MODE_NOSTORE, + MODE_NOSUCCEED; - protected int LOCK_EXCLUSIVE, LOCK_SHARED; + protected int LOCK_EXCLUSIVE, LOCK_SHARED; - // Error classes and codes - protected int SUCCESS; - protected int ERR_BUFFER; - protected int ERR_COUNT; - protected int ERR_TYPE; - protected int ERR_TAG; - protected int ERR_COMM; - protected int ERR_RANK; - protected int ERR_REQUEST; - protected int ERR_ROOT; - protected int ERR_GROUP; - protected int ERR_OP; - protected int ERR_TOPOLOGY; - protected int ERR_DIMS; - protected int ERR_ARG; - protected int ERR_UNKNOWN; - protected int ERR_TRUNCATE; - protected int ERR_OTHER; - protected int ERR_INTERN; - protected int ERR_IN_STATUS; - protected int ERR_PENDING; - protected int ERR_ACCESS; - protected int ERR_AMODE; - protected int ERR_ASSERT; - protected int ERR_BAD_FILE; - protected int ERR_BASE; - protected int ERR_CONVERSION; - protected int ERR_DISP; - protected int ERR_DUP_DATAREP; - protected int ERR_FILE_EXISTS; - protected int ERR_FILE_IN_USE; - protected int ERR_FILE; - protected int ERR_INFO_KEY; - protected int ERR_INFO_NOKEY; - protected int ERR_INFO_VALUE; - protected int ERR_INFO; - protected int ERR_IO; - protected int ERR_KEYVAL; - protected int ERR_LOCKTYPE; - protected int ERR_NAME; - protected int ERR_NO_MEM; - protected int ERR_NOT_SAME; - protected int ERR_NO_SPACE; - protected int ERR_NO_SUCH_FILE; - protected int ERR_PORT; - protected int ERR_QUOTA; - protected int ERR_READ_ONLY; - protected int ERR_RMA_CONFLICT; - protected int ERR_RMA_SYNC; - protected int ERR_SERVICE; - protected int ERR_SIZE; - protected int ERR_SPAWN; - protected int ERR_UNSUPPORTED_DATAREP; - protected int ERR_UNSUPPORTED_OPERATION; - protected int ERR_WIN; - protected int ERR_LASTCODE; - protected int ERR_SYSRESOURCE; + // Error classes and codes + protected int SUCCESS; + protected int ERR_BUFFER; + protected int ERR_COUNT; + protected int ERR_TYPE; + protected int ERR_TAG; + protected int ERR_COMM; + protected int ERR_RANK; + protected int ERR_REQUEST; + protected int ERR_ROOT; + protected int ERR_GROUP; + protected int ERR_OP; + protected int ERR_TOPOLOGY; + protected int ERR_DIMS; + protected int ERR_ARG; + protected int ERR_UNKNOWN; + protected int ERR_TRUNCATE; + protected int ERR_OTHER; + protected int ERR_INTERN; + protected int ERR_IN_STATUS; + protected int ERR_PENDING; + protected int ERR_ACCESS; + protected int ERR_AMODE; + protected int ERR_ASSERT; + protected int ERR_BAD_FILE; + protected int ERR_BASE; + protected int ERR_CONVERSION; + protected int ERR_DISP; + protected int ERR_DUP_DATAREP; + protected int ERR_FILE_EXISTS; + protected int ERR_FILE_IN_USE; + protected int ERR_FILE; + protected int ERR_INFO_KEY; + protected int ERR_INFO_NOKEY; + protected int ERR_INFO_VALUE; + protected int ERR_INFO; + protected int ERR_IO; + protected int ERR_KEYVAL; + protected int ERR_LOCKTYPE; + protected int ERR_NAME; + protected int ERR_NO_MEM; + protected int ERR_NOT_SAME; + protected int ERR_NO_SPACE; + protected int ERR_NO_SUCH_FILE; + protected int ERR_PORT; + protected int ERR_QUOTA; + protected int ERR_READ_ONLY; + protected int ERR_RMA_CONFLICT; + protected int ERR_RMA_SYNC; + protected int ERR_SERVICE; + protected int ERR_SIZE; + protected int ERR_SPAWN; + protected int ERR_UNSUPPORTED_DATAREP; + protected int ERR_UNSUPPORTED_OPERATION; + protected int ERR_WIN; + protected int ERR_LASTCODE; + protected int ERR_SYSRESOURCE; - protected Constant() - { - setConstant(); - } + protected Constant() + { + setConstant(); + } - private native void setConstant(); + private native void setConstant(); } // Constant diff --git a/ompi/mpi/java/java/Datatype.java b/ompi/mpi/java/java/Datatype.java index 4cc7bca1b3..bf16fe2d8e 100644 --- a/ompi/mpi/java/java/Datatype.java +++ b/ompi/mpi/java/java/Datatype.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Datatype.java * Author : Sang Lim, Sung-Hoon Ko, Xinying Li, Bryan Carpenter * Created : Thu Apr 9 12:22:15 1998 @@ -54,526 +54,526 @@ import java.nio.*; */ public final class Datatype implements Freeable { -protected long handle; -protected int baseType; -protected int baseSize; + protected long handle; + protected int baseType; + protected int baseSize; -// Cache to avoid unnecessary jni calls. -private int lb, extent, trueLb, trueExtent; + // Cache to avoid unnecessary jni calls. + private int lb, extent, trueLb, trueExtent; -protected static final int NULL = 0; -protected static final int BYTE = 1; -protected static final int CHAR = 2; -protected static final int SHORT = 3; -protected static final int BOOLEAN = 4; -protected static final int INT = 5; -protected static final int LONG = 6; -protected static final int FLOAT = 7; -protected static final int DOUBLE = 8; -protected static final int PACKED = 9; -protected static final int INT2 = 10; -protected static final int SHORT_INT = 11; -protected static final int LONG_INT = 12; -protected static final int FLOAT_INT = 13; -protected static final int DOUBLE_INT = 14; -protected static final int FLOAT_COMPLEX = 15; -protected static final int DOUBLE_COMPLEX = 16; + protected static final int NULL = 0; + protected static final int BYTE = 1; + protected static final int CHAR = 2; + protected static final int SHORT = 3; + protected static final int BOOLEAN = 4; + protected static final int INT = 5; + protected static final int LONG = 6; + protected static final int FLOAT = 7; + protected static final int DOUBLE = 8; + protected static final int PACKED = 9; + protected static final int INT2 = 10; + protected static final int SHORT_INT = 11; + protected static final int LONG_INT = 12; + protected static final int FLOAT_INT = 13; + protected static final int DOUBLE_INT = 14; + protected static final int FLOAT_COMPLEX = 15; + protected static final int DOUBLE_COMPLEX = 16; -static -{ - init(); -} + static + { + init(); + } -private static native void init(); + private static native void init(); -/* - * Constructor used in static initializer of 'MPI'. - * - * (Called before MPI.Init(), so cannot make any native MPI calls.) - * - * (Initialization done in separate 'setBasic', so can create - * datatype objects for 'BYTE', etc in static initializers invoked before - * MPI.Init(), then initialize objects after MPI initialized.) - */ -protected Datatype() -{ -} + /* + * Constructor used in static initializer of 'MPI'. + * + * (Called before MPI.Init(), so cannot make any native MPI calls.) + * + * (Initialization done in separate 'setBasic', so can create + * datatype objects for 'BYTE', etc in static initializers invoked before + * MPI.Init(), then initialize objects after MPI initialized.) + */ + protected Datatype() + { + } -protected void setBasic(int type) -{ - baseType = type; - handle = getDatatype(type); - baseSize = type == NULL ? 0 : getSize(handle); -} + protected void setBasic(int type) + { + baseType = type; + handle = getDatatype(type); + baseSize = type == NULL ? 0 : getSize(handle); + } -protected void setBasic(int type, Datatype oldType) -{ - baseType = oldType.baseType; - handle = getDatatype(type); - baseSize = oldType.baseSize; -} + protected void setBasic(int type, Datatype oldType) + { + baseType = oldType.baseType; + handle = getDatatype(type); + baseSize = oldType.baseSize; + } -private static native long getDatatype(int type); + private static native long getDatatype(int type); -/* - * Constructor used in 'create*' methods. - */ -private Datatype(Datatype oldType, long handle) -{ - baseType = oldType.baseType; - baseSize = oldType.baseSize; - this.handle = handle; -} + /* + * Constructor used in 'create*' methods. + */ + private Datatype(Datatype oldType, long handle) + { + baseType = oldType.baseType; + baseSize = oldType.baseSize; + this.handle = handle; + } -/* - * Constructor used in 'create*' methods. - */ -private Datatype(int baseType, int baseSize, long handle) -{ - this.baseType = baseType; - this.baseSize = baseSize; - this.handle = handle; -} + /* + * Constructor used in 'create*' methods. + */ + private Datatype(int baseType, int baseSize, long handle) + { + this.baseType = baseType; + this.baseSize = baseSize; + this.handle = handle; + } -/** - * Returns the lower bound of a datatype. - *

Java binding of the MPI operation {@code MPI_TYPE_GET_EXTENT}. - * @return lower bound of datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getLb() throws MPIException -{ - if(extent == 0) - getLbExtent(); + /** + * Returns the lower bound of a datatype. + *

Java binding of the MPI operation {@code MPI_TYPE_GET_EXTENT}. + * @return lower bound of datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getLb() throws MPIException + { + if(extent == 0) + getLbExtent(); - return lb; -} + return lb; + } -/** - * Returns the extent of a datatype. - *

Java binding of the MPI operation {@code MPI_TYPE_GET_EXTENT}. - * @return datatype extent - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getExtent() throws MPIException -{ - if(extent == 0) - getLbExtent(); + /** + * Returns the extent of a datatype. + *

Java binding of the MPI operation {@code MPI_TYPE_GET_EXTENT}. + * @return datatype extent + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getExtent() throws MPIException + { + if(extent == 0) + getLbExtent(); - return extent; -} + return extent; + } -private void getLbExtent() throws MPIException -{ - MPI.check(); - int lbExt[] = new int[2]; - getLbExtent(handle, lbExt); - lb = lbExt[0] / baseSize; - extent = lbExt[1] / baseSize; -} + private void getLbExtent() throws MPIException + { + MPI.check(); + int lbExt[] = new int[2]; + getLbExtent(handle, lbExt); + lb = lbExt[0] / baseSize; + extent = lbExt[1] / baseSize; + } -private native void getLbExtent(long handle, int[] lbExt); + private native void getLbExtent(long handle, int[] lbExt); -/** - * Returns the true lower bound of a datatype. - *

Java binding of the MPI operation {@code MPI_TYPE_GET_TRUE_EXTENT}. - * @return lower bound of datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getTrueLb() throws MPIException -{ - if(trueExtent == 0) - getTrueLbExtent(); + /** + * Returns the true lower bound of a datatype. + *

Java binding of the MPI operation {@code MPI_TYPE_GET_TRUE_EXTENT}. + * @return lower bound of datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getTrueLb() throws MPIException + { + if(trueExtent == 0) + getTrueLbExtent(); - return trueLb; -} + return trueLb; + } -/** - * Returns the true extent of a datatype. - *

Java binding of the MPI operation {@code MPI_TYPE_GET_TRUE_EXTENT}. - * @return datatype true extent - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getTrueExtent() throws MPIException -{ - if(trueExtent == 0) - getTrueLbExtent(); + /** + * Returns the true extent of a datatype. + *

Java binding of the MPI operation {@code MPI_TYPE_GET_TRUE_EXTENT}. + * @return datatype true extent + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getTrueExtent() throws MPIException + { + if(trueExtent == 0) + getTrueLbExtent(); - return trueExtent; -} + return trueExtent; + } -private void getTrueLbExtent() throws MPIException -{ - MPI.check(); - int lbExt[] = new int[2]; - getTrueLbExtent(handle, lbExt); - trueLb = lbExt[0] / baseSize; - trueExtent = lbExt[1] / baseSize; -} + private void getTrueLbExtent() throws MPIException + { + MPI.check(); + int lbExt[] = new int[2]; + getTrueLbExtent(handle, lbExt); + trueLb = lbExt[0] / baseSize; + trueExtent = lbExt[1] / baseSize; + } -private native void getTrueLbExtent(long handle, int[] lbExt); + private native void getTrueLbExtent(long handle, int[] lbExt); -/** - * Returns the total size of a datatype - the number of buffer - * elements it represents. - *

Java binding of the MPI operation {@code MPI_TYPE_SIZE}. - * @return datatype size - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getSize() throws MPIException -{ - MPI.check(); - return getSize(handle) / baseSize; -} + /** + * Returns the total size of a datatype - the number of buffer + * elements it represents. + *

Java binding of the MPI operation {@code MPI_TYPE_SIZE}. + * @return datatype size + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getSize() throws MPIException + { + MPI.check(); + return getSize(handle) / baseSize; + } -private native int getSize(long type); + private native int getSize(long type); -/** - * Commits a derived datatype. - * Java binding of the MPI operation {@code MPI_TYPE_COMMIT}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void commit() throws MPIException -{ - MPI.check(); - commit(handle); -} + /** + * Commits a derived datatype. + * Java binding of the MPI operation {@code MPI_TYPE_COMMIT}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void commit() throws MPIException + { + MPI.check(); + commit(handle); + } -private native void commit(long type); + private native void commit(long type); -/** - * Frees the datatype. - *

Java binding of the MPI operation {@code MPI_TYPE_FREE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public void free() throws MPIException -{ - MPI.check(); - handle = free(handle); -} + /** + * Frees the datatype. + *

Java binding of the MPI operation {@code MPI_TYPE_FREE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public void free() throws MPIException + { + MPI.check(); + handle = free(handle); + } -private native long free(long type) throws MPIException; + private native long free(long type) throws MPIException; -/** - * Returns {@code true} if this datatype is MPI_DATATYPE_NULL. - * @return {@code true} if this datatype is MPI_DATATYPE_NULL - */ -public boolean isNull() -{ - return handle == MPI.DATATYPE_NULL.handle; -} + /** + * Returns {@code true} if this datatype is MPI_DATATYPE_NULL. + * @return {@code true} if this datatype is MPI_DATATYPE_NULL + */ + public boolean isNull() + { + return handle == MPI.DATATYPE_NULL.handle; + } -/** - * Java binding of {@code MPI_TYPE_DUP}. - *

It is recommended to use {@link #dup} instead of {@link #clone} - * because the last can't throw an {@link mpi.MPIException}. - * @return new datatype - */ -@Override public Datatype clone() -{ - try - { - return dup(); - } - catch(MPIException e) - { - throw new RuntimeException(e.getMessage()); - } -} + /** + * Java binding of {@code MPI_TYPE_DUP}. + *

It is recommended to use {@link #dup} instead of {@link #clone} + * because the last can't throw an {@link mpi.MPIException}. + * @return new datatype + */ + @Override public Datatype clone() + { + try + { + return dup(); + } + catch(MPIException e) + { + throw new RuntimeException(e.getMessage()); + } + } -/** - * Java binding of {@code MPI_TYPE_DUP}. - * @return new datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Datatype dup() throws MPIException -{ - MPI.check(); - return new Datatype(this, dup(handle)); -} + /** + * Java binding of {@code MPI_TYPE_DUP}. + * @return new datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Datatype dup() throws MPIException + { + MPI.check(); + return new Datatype(this, dup(handle)); + } -private native long dup(long type) throws MPIException; + private native long dup(long type) throws MPIException; -/** - * Construct new datatype representing replication of old datatype into - * contiguous locations. - *

Java binding of the MPI operation {@code MPI_TYPE_CONTIGUOUS}. - *

The base type of the new datatype is the same as the base type of - * {@code oldType}. - * @param count replication count - * @param oldType old datatype - * @return new datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Datatype createContiguous(int count, Datatype oldType) - throws MPIException -{ - MPI.check(); - return new Datatype(oldType, getContiguous(count, oldType.handle)); -} + /** + * Construct new datatype representing replication of old datatype into + * contiguous locations. + *

Java binding of the MPI operation {@code MPI_TYPE_CONTIGUOUS}. + *

The base type of the new datatype is the same as the base type of + * {@code oldType}. + * @param count replication count + * @param oldType old datatype + * @return new datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Datatype createContiguous(int count, Datatype oldType) + throws MPIException + { + MPI.check(); + return new Datatype(oldType, getContiguous(count, oldType.handle)); + } -private static native long getContiguous(int count, long oldType); + private static native long getContiguous(int count, long oldType); -/** - * Construct new datatype representing replication of old datatype into - * locations that consist of equally spaced blocks. - *

Java binding of the MPI operation {@code MPI_TYPE_VECTOR}. - *

The base type of the new datatype is the same as the base type of - * {@code oldType}. - * @param count number of blocks - * @param blockLength number of elements in each block - * @param stride number of elements between start of each block - * @param oldType old datatype - * @return new datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Datatype createVector(int count, int blockLength, - int stride, Datatype oldType) - throws MPIException -{ - MPI.check(); - long handle = getVector(count, blockLength, stride, oldType.handle); - return new Datatype(oldType, handle); -} + /** + * Construct new datatype representing replication of old datatype into + * locations that consist of equally spaced blocks. + *

Java binding of the MPI operation {@code MPI_TYPE_VECTOR}. + *

The base type of the new datatype is the same as the base type of + * {@code oldType}. + * @param count number of blocks + * @param blockLength number of elements in each block + * @param stride number of elements between start of each block + * @param oldType old datatype + * @return new datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Datatype createVector(int count, int blockLength, + int stride, Datatype oldType) + throws MPIException + { + MPI.check(); + long handle = getVector(count, blockLength, stride, oldType.handle); + return new Datatype(oldType, handle); + } -private static native long getVector( - int count, int blockLength, int stride, long oldType) - throws MPIException; + private static native long getVector( + int count, int blockLength, int stride, long oldType) + throws MPIException; -/** - * Identical to {@code createVector} except that the stride is expressed - * directly in terms of the buffer index, rather than the units of - * the old type. - *

Java binding of the MPI operation {@code MPI_TYPE_HVECTOR}. - * @param count number of blocks - * @param blockLength number of elements in each - * @param stride number of bytes between start of each block - * @param oldType old datatype - * @return new datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Datatype createHVector(int count, int blockLength, - int stride, Datatype oldType) - throws MPIException -{ - MPI.check(); - long handle = getHVector(count, blockLength, stride, oldType.handle); - return new Datatype(oldType, handle); -} + /** + * Identical to {@code createVector} except that the stride is expressed + * directly in terms of the buffer index, rather than the units of + * the old type. + *

Java binding of the MPI operation {@code MPI_TYPE_HVECTOR}. + * @param count number of blocks + * @param blockLength number of elements in each + * @param stride number of bytes between start of each block + * @param oldType old datatype + * @return new datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Datatype createHVector(int count, int blockLength, + int stride, Datatype oldType) + throws MPIException + { + MPI.check(); + long handle = getHVector(count, blockLength, stride, oldType.handle); + return new Datatype(oldType, handle); + } -private static native long getHVector( - int count, int blockLength, int stride, long oldType) - throws MPIException; + private static native long getHVector( + int count, int blockLength, int stride, long oldType) + throws MPIException; -/** - * Construct new datatype representing replication of old datatype into - * a sequence of blocks where each block can contain a different number - * of copies and have a different displacement. - *

Java binding of the MPI operation {@code MPI_TYPE_INDEXED}. - *

The number of blocks is taken to be size of the {@code blockLengths} - * argument. The second argument, {@code displacements}, should be the - * same size. The base type of the new datatype is the same as the base - * type of {@code oldType}. - * @param blockLengths number of elements per block - * @param displacements displacement of each block in units of old type - * @param oldType old datatype - * @return new datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Datatype createIndexed(int[] blockLengths, - int[] displacements, Datatype oldType) - throws MPIException -{ - MPI.check(); - long handle = getIndexed(blockLengths, displacements, oldType.handle); - return new Datatype(oldType, handle); -} + /** + * Construct new datatype representing replication of old datatype into + * a sequence of blocks where each block can contain a different number + * of copies and have a different displacement. + *

Java binding of the MPI operation {@code MPI_TYPE_INDEXED}. + *

The number of blocks is taken to be size of the {@code blockLengths} + * argument. The second argument, {@code displacements}, should be the + * same size. The base type of the new datatype is the same as the base + * type of {@code oldType}. + * @param blockLengths number of elements per block + * @param displacements displacement of each block in units of old type + * @param oldType old datatype + * @return new datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Datatype createIndexed(int[] blockLengths, + int[] displacements, Datatype oldType) + throws MPIException + { + MPI.check(); + long handle = getIndexed(blockLengths, displacements, oldType.handle); + return new Datatype(oldType, handle); + } -private static native long getIndexed( - int[] blockLengths, int[] displacements, long oldType) - throws MPIException; + private static native long getIndexed( + int[] blockLengths, int[] displacements, long oldType) + throws MPIException; -/** - * Identical to {@code createIndexed} except that the displacements are - * expressed directly in terms of the buffer index, rather than the - * units of the old type. - *

Java binding of the MPI operation {@code MPI_TYPE_HINDEXED}. - * @param blockLengths number of elements per block - * @param displacements byte displacement in buffer for each block - * @param oldType old datatype - * @return new datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Datatype createHIndexed(int[] blockLengths, - int[] displacements, Datatype oldType) - throws MPIException -{ - MPI.check(); - long handle = getHIndexed(blockLengths, displacements, oldType.handle); - return new Datatype(oldType, handle); -} + /** + * Identical to {@code createIndexed} except that the displacements are + * expressed directly in terms of the buffer index, rather than the + * units of the old type. + *

Java binding of the MPI operation {@code MPI_TYPE_HINDEXED}. + * @param blockLengths number of elements per block + * @param displacements byte displacement in buffer for each block + * @param oldType old datatype + * @return new datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Datatype createHIndexed(int[] blockLengths, + int[] displacements, Datatype oldType) + throws MPIException + { + MPI.check(); + long handle = getHIndexed(blockLengths, displacements, oldType.handle); + return new Datatype(oldType, handle); + } -private static native long getHIndexed( - int[] blockLengths, int[] displacements, long oldType) - throws MPIException; + private static native long getHIndexed( + int[] blockLengths, int[] displacements, long oldType) + throws MPIException; -/** - * The most general type constructor. - *

Java binding of the MPI operation {@code MPI_TYPE_STRUCT}. - *

The number of blocks is taken to be size of the {@code blockLengths} - * argument. The second and third arguments, {@code displacements}, - * and {@code types}, should be the same size. - * @param blockLengths number of elements in each block - * @param displacements byte displacement of each block - * @param types type of elements in each block - * @return new datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Datatype createStruct(int[] blockLengths, - int[] displacements, Datatype[] types) - throws MPIException -{ - MPI.check(); - long handle = getStruct(blockLengths, displacements, types); - return new Datatype(MPI.BYTE, handle); -} + /** + * The most general type constructor. + *

Java binding of the MPI operation {@code MPI_TYPE_STRUCT}. + *

The number of blocks is taken to be size of the {@code blockLengths} + * argument. The second and third arguments, {@code displacements}, + * and {@code types}, should be the same size. + * @param blockLengths number of elements in each block + * @param displacements byte displacement of each block + * @param types type of elements in each block + * @return new datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Datatype createStruct(int[] blockLengths, + int[] displacements, Datatype[] types) + throws MPIException + { + MPI.check(); + long handle = getStruct(blockLengths, displacements, types); + return new Datatype(MPI.BYTE, handle); + } -private static native long getStruct( - int[] blockLengths, int[] displacements, Datatype[] types) - throws MPIException; + private static native long getStruct( + int[] blockLengths, int[] displacements, Datatype[] types) + throws MPIException; -/* - * JMS add proper documentation here - * JMS int != Aint! This needs to be fixed throughout. - */ -/** - * Create a datatype with a new lower bound and extent from an existing - * datatype. - *

Java binding of the MPI operation {@code MPI_TYPE_CREATE_RESIZED}. - * @param oldType input datatype - * @param lb new lower bound of datatype (address integer) - * @param extent new extent of datatype (address integer) - * @return new datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Datatype createResized(Datatype oldType, int lb, int extent) - throws MPIException -{ - MPI.check(); - long handle = getResized(oldType.handle, lb, extent); - return new Datatype(oldType, handle); -} + /* + * JMS add proper documentation here + * JMS int != Aint! This needs to be fixed throughout. + */ + /** + * Create a datatype with a new lower bound and extent from an existing + * datatype. + *

Java binding of the MPI operation {@code MPI_TYPE_CREATE_RESIZED}. + * @param oldType input datatype + * @param lb new lower bound of datatype (address integer) + * @param extent new extent of datatype (address integer) + * @return new datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Datatype createResized(Datatype oldType, int lb, int extent) + throws MPIException + { + MPI.check(); + long handle = getResized(oldType.handle, lb, extent); + return new Datatype(oldType, handle); + } -private static native long getResized(long oldType, int lb, int extent); + private static native long getResized(long oldType, int lb, int extent); -/** - * Sets the print name for the datatype. - * @param name name for the datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setName(String name) throws MPIException -{ - MPI.check(); - setName(handle, name); -} + /** + * Sets the print name for the datatype. + * @param name name for the datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setName(String name) throws MPIException + { + MPI.check(); + setName(handle, name); + } -private native void setName(long handle, String name) throws MPIException; + private native void setName(long handle, String name) throws MPIException; -/** - * Return the print name from the datatype. - * @return name of the datatype - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public String getName() throws MPIException -{ - MPI.check(); - return getName(handle); -} + /** + * Return the print name from the datatype. + * @return name of the datatype + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public String getName() throws MPIException + { + MPI.check(); + return getName(handle); + } -private native String getName(long handle) throws MPIException; + private native String getName(long handle) throws MPIException; -/** - * Create a new attribute key. - *

Java binding of the MPI operation {@code MPI_TYPE_CREATE_KEYVAL}. - * @return attribute key for future access - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int createKeyval() throws MPIException -{ - MPI.check(); - return createKeyval_jni(); -} + /** + * Create a new attribute key. + *

Java binding of the MPI operation {@code MPI_TYPE_CREATE_KEYVAL}. + * @return attribute key for future access + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int createKeyval() throws MPIException + { + MPI.check(); + return createKeyval_jni(); + } -private static native int createKeyval_jni() throws MPIException; + private static native int createKeyval_jni() throws MPIException; -/** - * Frees an attribute key. - *

Java binding of the MPI operation {@code MPI_TYPE_FREE_KEYVAL}. - * @param keyval attribute key - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void freeKeyval(int keyval) throws MPIException -{ - MPI.check(); - freeKeyval_jni(keyval); -} + /** + * Frees an attribute key. + *

Java binding of the MPI operation {@code MPI_TYPE_FREE_KEYVAL}. + * @param keyval attribute key + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void freeKeyval(int keyval) throws MPIException + { + MPI.check(); + freeKeyval_jni(keyval); + } -private static native void freeKeyval_jni(int keyval) throws MPIException; + private static native void freeKeyval_jni(int keyval) throws MPIException; -/** - * Stores attribute value associated with a key. - *

Java binding of the MPI operation {@code MPI_TYPE_SET_ATTR}. - * @param keyval attribute key - * @param value attribute value - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setAttr(int keyval, Object value) throws MPIException -{ - MPI.check(); - setAttr(handle, keyval, MPI.attrSet(value)); -} + /** + * Stores attribute value associated with a key. + *

Java binding of the MPI operation {@code MPI_TYPE_SET_ATTR}. + * @param keyval attribute key + * @param value attribute value + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setAttr(int keyval, Object value) throws MPIException + { + MPI.check(); + setAttr(handle, keyval, MPI.attrSet(value)); + } -private native void setAttr(long type, int keyval, byte[] value) - throws MPIException; + private native void setAttr(long type, int keyval, byte[] value) + throws MPIException; -/** - * Retrieves attribute value by key. - *

Java binding of the MPI operation {@code MPI_TYPE_GET_ATTR}. - * @param keyval attribute key - * @return attribute value or null if no attribute is associated with the key. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Object getAttr(int keyval) throws MPIException -{ - MPI.check(); - Object obj = getAttr(handle, keyval); - return obj instanceof byte[] ? MPI.attrGet((byte[])obj) : obj; -} + /** + * Retrieves attribute value by key. + *

Java binding of the MPI operation {@code MPI_TYPE_GET_ATTR}. + * @param keyval attribute key + * @return attribute value or null if no attribute is associated with the key. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Object getAttr(int keyval) throws MPIException + { + MPI.check(); + Object obj = getAttr(handle, keyval); + return obj instanceof byte[] ? MPI.attrGet((byte[])obj) : obj; + } -private native Object getAttr(long type, int keyval) throws MPIException; + private native Object getAttr(long type, int keyval) throws MPIException; -/** - * Deletes an attribute value associated with a key. - *

Java binding of the MPI operation {@code MPI_TYPE_DELETE_ATTR}. - * @param keyval attribute key - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void deleteAttr(int keyval) throws MPIException -{ - MPI.check(); - deleteAttr(handle, keyval); -} + /** + * Deletes an attribute value associated with a key. + *

Java binding of the MPI operation {@code MPI_TYPE_DELETE_ATTR}. + * @param keyval attribute key + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void deleteAttr(int keyval) throws MPIException + { + MPI.check(); + deleteAttr(handle, keyval); + } -private native void deleteAttr(long type, int keyval) throws MPIException; + private native void deleteAttr(long type, int keyval) throws MPIException; -/** - * Gets the offset of a buffer in bytes. - * @param buffer buffer - * @return offset in bytes - */ -protected int getOffset(Object buffer) -{ - return baseSize * ((Buffer)buffer).arrayOffset(); -} + /** + * Gets the offset of a buffer in bytes. + * @param buffer buffer + * @return offset in bytes + */ + protected int getOffset(Object buffer) + { + return baseSize * ((Buffer)buffer).arrayOffset(); + } } // Datatype diff --git a/ompi/mpi/java/java/DistGraphNeighbors.java b/ompi/mpi/java/java/DistGraphNeighbors.java index 123c1bf54b..e545b6f3a1 100644 --- a/ompi/mpi/java/java/DistGraphNeighbors.java +++ b/ompi/mpi/java/java/DistGraphNeighbors.java @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -23,85 +25,85 @@ package mpi; */ public final class DistGraphNeighbors { -private final int[] sources, sourceWeights, destinations, destWeights; -private final boolean weighted; + private final int[] sources, sourceWeights, destinations, destWeights; + private final boolean weighted; -protected DistGraphNeighbors( - int[] sources, int[] sourceWeights, - int[] destinations, int[] destWeights, boolean weighted) -{ - this.sources = sources; - this.sourceWeights = sourceWeights; - this.destinations = destinations; - this.destWeights = destWeights; - this.weighted = weighted; -} + protected DistGraphNeighbors( + int[] sources, int[] sourceWeights, + int[] destinations, int[] destWeights, boolean weighted) + { + this.sources = sources; + this.sourceWeights = sourceWeights; + this.destinations = destinations; + this.destWeights = destWeights; + this.weighted = weighted; + } -/** - * Gets the number of edges into this process. - * @return number of edges into this process - */ -public int getInDegree() -{ - return sources.length; -} + /** + * Gets the number of edges into this process. + * @return number of edges into this process + */ + public int getInDegree() + { + return sources.length; + } -/** - * Gets the number of edges out of this process. - * @return number of edges out of this process - */ -public int getOutDegree() -{ - return destinations.length; -} + /** + * Gets the number of edges out of this process. + * @return number of edges out of this process + */ + public int getOutDegree() + { + return destinations.length; + } -/** - * Returns false if {@code MPI_UNWEIGHTED} was supplied during creation. - * @return false if {@code MPI_UNWEIGHTED} was supplied, true otherwise - */ -public boolean isWeighted() -{ - return weighted; -} + /** + * Returns false if {@code MPI_UNWEIGHTED} was supplied during creation. + * @return false if {@code MPI_UNWEIGHTED} was supplied, true otherwise + */ + public boolean isWeighted() + { + return weighted; + } -/** - * Gets a process for which the calling processs is a destination. - * @param i source index - * @return process for which the calling processs is a destination - */ -public int getSource(int i) -{ - return sources[i]; -} + /** + * Gets a process for which the calling processs is a destination. + * @param i source index + * @return process for which the calling processs is a destination + */ + public int getSource(int i) + { + return sources[i]; + } -/** - * Gets the weight of an edge into the calling process. - * @param i source index - * @return weight of the edge into the calling process - */ -public int getSourceWeight(int i) -{ - return sourceWeights[i]; -} + /** + * Gets the weight of an edge into the calling process. + * @param i source index + * @return weight of the edge into the calling process + */ + public int getSourceWeight(int i) + { + return sourceWeights[i]; + } -/** - * Gets a process for which the calling process is a source - * @param i destination index - * @return process for which the calling process is a source - */ -public int getDestination(int i) -{ - return destinations[i]; -} + /** + * Gets a process for which the calling process is a source + * @param i destination index + * @return process for which the calling process is a source + */ + public int getDestination(int i) + { + return destinations[i]; + } -/** - * Gets the weight of an edge out of the calling process. - * @param i destination index - * @return weight of an edge out of the calling process - */ -public int getDestinationWeight(int i) -{ - return destWeights[i]; -} + /** + * Gets the weight of an edge out of the calling process. + * @param i destination index + * @return weight of an edge out of the calling process + */ + public int getDestinationWeight(int i) + { + return destWeights[i]; + } } // DistGraphNeighbors diff --git a/ompi/mpi/java/java/DoubleComplex.java b/ompi/mpi/java/java/DoubleComplex.java index ecaafbb8e4..3a75e3e686 100644 --- a/ompi/mpi/java/java/DoubleComplex.java +++ b/ompi/mpi/java/java/DoubleComplex.java @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -25,124 +27,124 @@ import java.nio.*; */ public final class DoubleComplex { -private final int offset; -private final DoubleBuffer buffer; + private final int offset; + private final DoubleBuffer buffer; -private DoubleComplex(DoubleBuffer buffer, int index) -{ - this.buffer = buffer; - this.offset = index * 2; -} + private DoubleComplex(DoubleBuffer buffer, int index) + { + this.buffer = buffer; + this.offset = index * 2; + } -/** - * Wraps a complex number stored in a buffer - * @param buffer buffer - * @return complex number - */ -public static DoubleComplex get(DoubleBuffer buffer) -{ - return new DoubleComplex(buffer, 0); -} + /** + * Wraps a complex number stored in a buffer + * @param buffer buffer + * @return complex number + */ + public static DoubleComplex get(DoubleBuffer buffer) + { + return new DoubleComplex(buffer, 0); + } -/** - * Wraps the complex number at the specified position - * of an array of complex numbers stored in a buffer. - * @param buffer buffer - * @param index index - * @return complex number - */ -public static DoubleComplex get(DoubleBuffer buffer, int index) -{ - return new DoubleComplex(buffer, index); -} + /** + * Wraps the complex number at the specified position + * of an array of complex numbers stored in a buffer. + * @param buffer buffer + * @param index index + * @return complex number + */ + public static DoubleComplex get(DoubleBuffer buffer, int index) + { + return new DoubleComplex(buffer, index); + } -/** - * Wraps a complex number stored in the first two values of an array. - * @param array array - * @return complex number - */ -public static DoubleComplex get(double[] array) -{ - return new DoubleComplex(DoubleBuffer.wrap(array), 0); -} + /** + * Wraps a complex number stored in the first two values of an array. + * @param array array + * @return complex number + */ + public static DoubleComplex get(double[] array) + { + return new DoubleComplex(DoubleBuffer.wrap(array), 0); + } -/** - * Wraps the complex number at the specified position of - * an array of complex numbers stored in an array of doubles. - * @param array array - * @param index index - * @return complex number - */ -public static DoubleComplex get(double[] array, int index) -{ - return new DoubleComplex(DoubleBuffer.wrap(array), index); -} + /** + * Wraps the complex number at the specified position of + * an array of complex numbers stored in an array of doubles. + * @param array array + * @param index index + * @return complex number + */ + public static DoubleComplex get(double[] array, int index) + { + return new DoubleComplex(DoubleBuffer.wrap(array), index); + } -/** - * Wraps a complex number stored in a buffer - * @param buffer buffer - * @return complex number - */ -public static DoubleComplex get(ByteBuffer buffer) -{ - return new DoubleComplex(buffer.asDoubleBuffer(), 0); -} + /** + * Wraps a complex number stored in a buffer + * @param buffer buffer + * @return complex number + */ + public static DoubleComplex get(ByteBuffer buffer) + { + return new DoubleComplex(buffer.asDoubleBuffer(), 0); + } -/** - * Wraps the complex number at the specified position - * of an array of complex numbers stored in a buffer. - * @param buffer buffer - * @param index index - * @return complex number - */ -public static DoubleComplex get(ByteBuffer buffer, int index) -{ - return new DoubleComplex(buffer.asDoubleBuffer(), index); -} + /** + * Wraps the complex number at the specified position + * of an array of complex numbers stored in a buffer. + * @param buffer buffer + * @param index index + * @return complex number + */ + public static DoubleComplex get(ByteBuffer buffer, int index) + { + return new DoubleComplex(buffer.asDoubleBuffer(), index); + } -/** - * Gets the real value. - * @return real value - */ -public double getReal() -{ - return buffer.get(offset); -} + /** + * Gets the real value. + * @return real value + */ + public double getReal() + { + return buffer.get(offset); + } -/** - * Gets the imaginary value. - * @return imaginary value. - */ -public double getImag() -{ - return buffer.get(offset + 1); -} + /** + * Gets the imaginary value. + * @return imaginary value. + */ + public double getImag() + { + return buffer.get(offset + 1); + } -/** - * Puts the real value. - * @param real real value - */ -public void putReal(double real) -{ - buffer.put(offset, real); -} + /** + * Puts the real value. + * @param real real value + */ + public void putReal(double real) + { + buffer.put(offset, real); + } -/** - * Puts the imaginary value. - * @param imag imaginary value - */ -public void putImag(double imag) -{ - buffer.put(offset + 1, imag); -} + /** + * Puts the imaginary value. + * @param imag imaginary value + */ + public void putImag(double imag) + { + buffer.put(offset + 1, imag); + } -/** - * Gets the buffer where the complex number is stored. - * @return buffer where the complex number is stored - */ -public DoubleBuffer getBuffer() -{ - return offset == 0 ? buffer : MPI.slice(buffer, offset); -} + /** + * Gets the buffer where the complex number is stored. + * @return buffer where the complex number is stored + */ + public DoubleBuffer getBuffer() + { + return offset == 0 ? buffer : MPI.slice(buffer, offset); + } } // DoubleComplex diff --git a/ompi/mpi/java/java/DoubleInt.java b/ompi/mpi/java/java/DoubleInt.java index 554494d342..ac75ffb5e7 100644 --- a/ompi/mpi/java/java/DoubleInt.java +++ b/ompi/mpi/java/java/DoubleInt.java @@ -25,91 +25,91 @@ package mpi; */ public final class DoubleInt extends Struct { -private final int iOff, iSize; + private final int iOff, iSize; -/** - * The struct object will be created only in MPI class. - * @param intOff int offset - * @param intSize int size - * @see MPI#doubleInt - */ -protected DoubleInt(int intOff, int intSize) -{ - int dOff = addDouble(); - assert dOff == 0; + /** + * The struct object will be created only in MPI class. + * @param intOff int offset + * @param intSize int size + * @see MPI#doubleInt + */ + protected DoubleInt(int intOff, int intSize) + { + int dOff = addDouble(); + assert dOff == 0; - iSize = intSize; - setOffset(intOff); + iSize = intSize; + setOffset(intOff); - switch(iSize) - { - case 4: iOff = addInt(); break; - case 8: iOff = addLong(); break; - default: throw new AssertionError("Unsupported int size: "+ iSize); - } + switch(iSize) + { + case 4: iOff = addInt(); break; + case 8: iOff = addLong(); break; + default: throw new AssertionError("Unsupported int size: "+ iSize); + } - assert(intOff == iOff); -} + assert(intOff == iOff); + } -/** - * Creates a Data object. - * @return new Data object. - */ -@Override protected DoubleInt.Data newData() -{ - return new DoubleInt.Data(); -} + /** + * Creates a Data object. + * @return new Data object. + */ + @Override protected DoubleInt.Data newData() + { + return new DoubleInt.Data(); + } -/** - * Class for reading/writing data in a struct stored in a byte buffer. - */ -public final class Data extends Struct.Data -{ - /** - * Gets the double value. - * @return double value - */ - public double getValue() - { - return getDouble(0); - } + /** + * Class for reading/writing data in a struct stored in a byte buffer. + */ + public final class Data extends Struct.Data + { + /** + * Gets the double value. + * @return double value + */ + public double getValue() + { + return getDouble(0); + } - /** - * Gets the int value. - * @return int value - */ - public int getIndex() - { - switch(iSize) - { - case 4: return getInt(iOff); - case 8: return (int)getLong(iOff); - default: throw new AssertionError(); - } - } + /** + * Gets the int value. + * @return int value + */ + public int getIndex() + { + switch(iSize) + { + case 4: return getInt(iOff); + case 8: return (int)getLong(iOff); + default: throw new AssertionError(); + } + } - /** - * Puts the double value. - * @param v double value - */ - public void putValue(double v) - { - putDouble(0, v); - } + /** + * Puts the double value. + * @param v double value + */ + public void putValue(double v) + { + putDouble(0, v); + } - /** - * Puts the int value. - * @param v int value - */ - public void putIndex(int v) - { - switch(iSize) - { - case 4: putInt(iOff, v); break; - case 8: putLong(iOff, v); break; - default: throw new AssertionError(); - } - } -} // Data + /** + * Puts the int value. + * @param v int value + */ + public void putIndex(int v) + { + switch(iSize) + { + case 4: putInt(iOff, v); break; + case 8: putLong(iOff, v); break; + default: throw new AssertionError(); + } + } + } // Data } // DoubleInt diff --git a/ompi/mpi/java/java/Errhandler.java b/ompi/mpi/java/java/Errhandler.java index bbef58e4a1..75917b408e 100644 --- a/ompi/mpi/java/java/Errhandler.java +++ b/ompi/mpi/java/java/Errhandler.java @@ -9,31 +9,33 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Errhandler.java * Author : Xinying Li * Created : Thu Apr 9 12:22:15 1998 @@ -50,14 +52,14 @@ package mpi; */ public final class Errhandler { -protected long handle; + protected long handle; -protected static native long getFatal(); -protected static native long getReturn(); + protected static native long getFatal(); + protected static native long getReturn(); -protected Errhandler(long handle) -{ - this.handle = handle; -} + protected Errhandler(long handle) + { + this.handle = handle; + } } // Errhandler diff --git a/ompi/mpi/java/java/File.java b/ompi/mpi/java/java/File.java index 50e3557e8f..1ac9564b09 100644 --- a/ompi/mpi/java/java/File.java +++ b/ompi/mpi/java/java/File.java @@ -16,8 +16,8 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * IMPLEMENTATION DETAILS * * All methods with buffers that can be direct or non direct have @@ -38,1200 +38,1200 @@ import static mpi.MPI.assertDirectBuffer; */ public final class File { -private long handle; -private FileView view = new FileView(0, MPI.BYTE, MPI.BYTE, "native"); -private Status beginStatus; - -/** - * Java binding of {@code MPI_FILE_OPEN} using {@code MPI_INFO_NULL}. - * @param comm communicator - * @param filename name of the file to open - * @param amode file access mode - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public File(Comm comm, String filename, int amode) throws MPIException -{ - MPI.check(); - handle = open(comm.handle, filename, amode, Info.NULL); -} - -/** - * Java binding of {@code MPI_FILE_OPEN}. - * @param comm communicator - * @param filename name of the file to open - * @param amode file access mode - * @param info info object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public File(Comm comm, String filename, int amode, Info info) - throws MPIException -{ - MPI.check(); - handle = open(comm.handle, filename, amode, info.handle); -} - -private native long open(long comm, String filename, int amode, long info) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_CLOSE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void close() throws MPIException -{ - MPI.check(); - handle = close(handle); -} - -private native long close(long fh) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_DELETE} using {@code MPI_INFO_NULL}. - * @param filename name of the file to delete - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void delete(String filename) throws MPIException -{ - MPI.check(); - delete(filename, Info.NULL); -} - -/** - * Java binding of {@code MPI_FILE_DELETE}. - * @param filename name of the file to delete - * @param info info object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void delete(String filename, Info info) throws MPIException -{ - MPI.check(); - delete(filename, info.handle); -} - -private static native void delete(String filename, long info) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_SET_SIZE}. - * @param size size to truncate or expand file - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setSize(long size) throws MPIException -{ - MPI.check(); - setSize(handle, size); -} - -private native void setSize(long fh, long size) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_PREALLOCATE}. - * @param size size to preallocate file - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void preallocate(long size) throws MPIException -{ - MPI.check(); - preallocate(handle, size); -} - -private native void preallocate(long fh, long size) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_GET_SIZE}. - * @return size of file in bytes - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public long getSize() throws MPIException -{ - MPI.check(); - return getSize(handle); -} - -private native long getSize(long fh) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_GET_GROUP}. - * @return group wich opened the file - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Group getGroup() throws MPIException -{ - MPI.check(); - return new Group(getGroup(handle)); -} - -private native long getGroup(long fh) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_GET_AMODE}. - * @return file access mode to open the file - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getAMode() throws MPIException -{ - MPI.check(); - return getAMode(handle); -} - -private native int getAMode(long fh) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_SET_INFO}. - * @param info info object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setInfo(Info info) throws MPIException -{ - MPI.check(); - setInfo(handle, info.handle); -} - -private native void setInfo(long fh, long info) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_GET_INFO}. - * @return new info object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Info getInfo() throws MPIException -{ - MPI.check(); - return new Info(getInfo(handle)); -} - -private native long getInfo(long fh) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_SET_VIEW} using {@code MPI_INFO_NULL}. - * @param disp displacement - * @param etype elementary datatype - * @param filetype filetype - * @param datarep data representation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setView(long disp, Datatype etype, - Datatype filetype, String datarep) - throws MPIException -{ - MPI.check(); - setView(handle, disp, etype.handle, filetype.handle, datarep, Info.NULL); - view = new FileView(disp, etype, filetype, datarep); -} - -/** - * Java binding of {@code MPI_FILE_SET_VIEW}. - * @param disp displacement - * @param etype elementary datatype - * @param filetype filetype - * @param datarep data representation - * @param info info object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setView(long disp, Datatype etype, - Datatype filetype, String datarep, Info info) - throws MPIException -{ - MPI.check(); - setView(handle, disp, etype.handle, filetype.handle, datarep, info.handle); - view = new FileView(disp, etype, filetype, datarep); -} - -private native void setView( - long fh, long disp, long etype, - long filetype, String datarep, long info) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_GET_VIEW}. - * @return file view - */ -public FileView getView() -{ - return view; -} - -/** - * Java binding of {@code MPI_FILE_READ_AT}. - * @param offset file offset - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status readAt(long offset, Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - readAt(handle, offset, buf, db, off, count, - type.handle, type.baseType, status.data); - - return status; -} - -private native void readAt( - long fh, long fileOffset, Object buf, boolean db, int offset, - int count, long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_AT_ALL}. - * @param offset file offset - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status readAtAll(long offset, Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - readAtAll(handle, offset, buf, db, off, count, - type.handle, type.baseType, status.data); - - return status; -} - -private native void readAtAll( - long fh, long fileOffset, Object buf, boolean db, int offset, - int count, long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_AT}. - * @param offset file offset - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status writeAt(long offset, Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - writeAt(handle, offset, buf, db, off, count, - type.handle, type.baseType, status.data); - - return status; -} - -private native void writeAt( - long fh, long fileOffset, Object buf, boolean db, int offset, - int count, long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_AT_ALL}. - * @param offset file offset - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status writeAtAll(long offset, Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - writeAtAll(handle, offset, buf, db, off, count, - type.handle, type.baseType, status.data); - - return status; -} - -private native void writeAtAll( - long fh, long fileOffset, Object buf, boolean db, int offset, - int count, long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_IREAD_AT}. - * @param offset file offset - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return request object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Request iReadAt(long offset, Buffer buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iReadAt(handle, offset, buf, count, type.handle)); -} - -private native long iReadAt( - long fh, long offset, Buffer buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_IWRITE_AT}. - * @param offset file offset - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return request object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Request iWriteAt(long offset, Buffer buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iWriteAt(handle, offset, buf, count, type.handle)); -} - -private native long iWriteAt( - long fh, long offset, Buffer buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status read(Object buf, int count, Datatype type) throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - read(handle, buf, db, off, count, type.handle, type.baseType, status.data); - return status; -} - -private native void read( - long fh, Object buf, boolean db, int offset, - int count, long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_ALL}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status readAll(Object buf, int count, Datatype type) throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - readAll(handle, buf,db,off, count, type.handle, type.baseType, status.data); - return status; -} - -private native void readAll( - long fh, Object buf, boolean db, int offset, - int count, long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status write(Object buf, int count, Datatype type) throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - write(handle, buf, db, off, count, type.handle, type.baseType, status.data); - return status; -} - -private native void write( - long fh, Object buf, boolean db, int offset, - int count, long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_ALL}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status writeAll(Object buf, int count, Datatype type) throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - writeAll(handle, buf,db,off, count, type.handle,type.baseType, status.data); - return status; -} - -private native void writeAll( - long fh, Object buf, boolean db, int offset, - int count, long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_IREAD}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return request object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Request iRead(Buffer buf, int count, Datatype type) throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iRead(handle, buf, count, type.handle)); -} - -private native long iRead(long fh, Buffer buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_IWRITE}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return request object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Request iWrite(Buffer buf, int count, Datatype type) throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iWrite(handle, buf, count, type.handle)); -} - -private native long iWrite(long fh, Buffer buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_SEEK}. - * @param offset file offset - * @param whence update mode - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void seek(long offset, int whence) throws MPIException -{ - MPI.check(); - seek(handle, offset, whence); -} - -private native void seek(long fh, long offset, int whence) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_GET_POSITION}. - * @return offset of individual pointer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public long getPosition() throws MPIException -{ - MPI.check(); - return getPosition(handle); -} - -private native long getPosition(long fh) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_GET_BYTE_OFFSET}. - * @param offset offset - * @return absolute byte position of offset - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public long getByteOffset(long offset) throws MPIException -{ - MPI.check(); - return getByteOffset(handle, offset); -} - -private native long getByteOffset(long fh, long offset) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_SHARED}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status readShared(Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - readShared(handle, buf, db, off, count, - type.handle, type.baseType, status.data); - - return status; -} - -private native void readShared( - long fh, Object buf, boolean db, int offset, int count, - long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_SHARED}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status writeShared(Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - writeShared(handle, buf, db, off, count, - type.handle, type.baseType, status.data); - - return status; -} - -private native void writeShared( - long fh, Object buf, boolean db, int offset, int count, - long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_IREAD_SHARED}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return request object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Request iReadShared(Buffer buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iReadShared(handle, buf, count, type.handle)); -} - -private native long iReadShared(long fh, Buffer buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_IWRITE_SHARED}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return request object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Request iWriteShared(Buffer buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(iWriteShared(handle, buf, count, type.handle)); -} - -private native long iWriteShared(long fh, Buffer buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_ORDERED}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status readOrdered(Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - readOrdered(handle, buf, db, off, count, - type.handle, type.baseType, status.data); - - return status; -} - -private native void readOrdered( - long fh, Object buf, boolean db, int offset, int count, - long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_ORDERED}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status writeOrdered(Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - writeOrdered(handle, buf, db, off, count, - type.handle, type.baseType, status.data); - - return status; -} - -private native void writeOrdered( - long fh, Object buf, boolean db, int offset, int count, - long type, int baseType, long[] stat) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_SEEK_SHARED}. - * @param offset file offset - * @param whence update mode - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void seekShared(long offset, int whence) throws MPIException -{ - MPI.check(); - seekShared(handle, offset, whence); -} - -private native void seekShared(long fh, long offset, int whence) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_GET_POSITION_SHARED}. - * @return offset of individual pointer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public long getPositionShared() throws MPIException -{ - MPI.check(); - return getPositionShared(handle); -} - -private native long getPositionShared(long fh) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_AT_ALL_BEGIN}. - * @param offset file offset - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void readAtAllBegin(long offset, Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - readAtAllBegin(handle, offset, buf, count, type.handle); - } - else - { - int off = 0; - Status status = new Status(); - - if(isHeapBuffer(buf)) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - readAtAll(handle, offset, buf, false, off, count, - type.handle, type.baseType, status.data); - - beginStatus = status; - } -} - -private native void readAtAllBegin( - long fh, long offset, Object buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_AT_ALL_END}. - * @param buf buffer - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status readAtAllEnd(Object buf) throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - Status status = new Status(); - readAtAllEnd(handle, buf, status.data); - return status; - } - else - { - return getBeginStatus(); - } -} - -private native void readAtAllEnd(long fh, Object buf, long[] stat) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_AT_ALL_BEGIN}. - * @param offset file offset - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void writeAtAllBegin(long offset, Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - writeAtAllBegin(handle, offset, buf, count, type.handle); - } - else - { - int off = 0; - Status status = new Status(); - - if(isHeapBuffer(buf)) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - writeAtAll(handle, offset, buf, false, off, count, - type.handle, type.baseType, status.data); - - beginStatus = status; - } -} - -private native void writeAtAllBegin( - long fh, long fileOffset, Object buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_AT_ALL_END}. - * @param buf buffer - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status writeAtAllEnd(Object buf) throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - Status status = new Status(); - writeAtAllEnd(handle, buf, status.data); - return status; - } - else - { - return getBeginStatus(); - } -} - -private native void writeAtAllEnd(long fh, Object buf, long[] stat) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_ALL_BEGIN}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void readAllBegin(Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - readAllBegin(handle, buf, count, type.handle); - } - else - { - int off = 0; - Status status = new Status(); - - if(isHeapBuffer(buf)) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - readAll(handle, buf, false, off, count, - type.handle, type.baseType, status.data); - - beginStatus = status; - } -} - -private native void readAllBegin(long fh, Object buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_ALL_END}. - * @param buf buffer - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status readAllEnd(Object buf) throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - Status status = new Status(); - readAllEnd(handle, buf, status.data); - return status; - } - else - { - return getBeginStatus(); - } -} - -private native void readAllEnd(long fh, Object buf, long[] stat) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_ALL_BEGIN}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void writeAllBegin(Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - writeAllBegin(handle, buf, count, type.handle); - } - else - { - int off = 0; - Status status = new Status(); - - if(isHeapBuffer(buf)) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - writeAll(handle, buf, false, off, count, - type.handle, type.baseType, status.data); - - beginStatus = status; - } -} - -private native void writeAllBegin(long fh, Object buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_ALL_END}. - * @param buf buffer - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status writeAllEnd(Object buf) throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - Status status = new Status(); - writeAllEnd(handle, buf, status.data); - return status; - } - else - { - return getBeginStatus(); - } -} - -private native void writeAllEnd(long fh, Object buf, long[] stat) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_ORDERED_BEGIN}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void readOrderedBegin(Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - readOrderedBegin(handle, buf, count, type.handle); - } - else - { - int off = 0; - Status status = new Status(); - - if(isHeapBuffer(buf)) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - readOrdered(handle, buf, false, off, count, - type.handle, type.baseType, status.data); - - beginStatus = status; - } -} - -private native void readOrderedBegin(long fh, Object buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_READ_ORDERED_END}. - * @param buf buffer - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status readOrderedEnd(Object buf) throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - Status status = new Status(); - readOrderedEnd(handle, buf, status.data); - return status; - } - else - { - return getBeginStatus(); - } -} - -private native void readOrderedEnd(long fh, Object buf, long[] stat) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_ORDERED_BEGIN}. - * @param buf buffer - * @param count number of items in buffer - * @param type datatype of each buffer element - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void writeOrderedBegin(Object buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - writeOrderedBegin(handle, buf, count, type.handle); - } - else - { - int off = 0; - Status status = new Status(); - - if(isHeapBuffer(buf)) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - writeOrdered(handle, buf, false, off, count, - type.handle, type.baseType, status.data); - - beginStatus = status; - } -} - -private native void writeOrderedBegin(long fh, Object buf, int count, long type) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_WRITE_ORDERED_END}. - * @param buf buffer - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status writeOrderedEnd(Object buf) throws MPIException -{ - MPI.check(); - - if(isDirectBuffer(buf)) - { - Status status = new Status(); - writeOrderedEnd(handle, buf, status.data); - return status; - } - else - { - return getBeginStatus(); - } -} - -private native void writeOrderedEnd(long fh, Object buf, long[] stat) - throws MPIException; - -private Status getBeginStatus() -{ - Status s = beginStatus; - beginStatus = null; - return s; -} - -/** - * Java binding of {@code MPI_FILE_GET_TYPE_EXTENT}. - * @param type type of data - * @return datatype extent - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getTypeExtent(Datatype type) throws MPIException -{ - MPI.check(); - return getTypeExtent(handle, type.handle) / type.baseSize; -} - -private native int getTypeExtent(long fh, long type) throws MPIException; - -/** - * Java binding of {@code MPI_FILE_SET_ATOMICITY}. - * @param atomicity true to set atomic mode, false to set nonatomic mode - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setAtomicity(boolean atomicity) throws MPIException -{ - MPI.check(); - setAtomicity(handle, atomicity); -} - -private native void setAtomicity(long fh, boolean atomicity) - throws MPIException; - -/** - * Java binding of {@code MPI_FILE_SYNC}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void sync() throws MPIException -{ - MPI.check(); - sync(handle); -} - -private native void sync(long handle) throws MPIException; + private long handle; + private FileView view = new FileView(0, MPI.BYTE, MPI.BYTE, "native"); + private Status beginStatus; + + /** + * Java binding of {@code MPI_FILE_OPEN} using {@code MPI_INFO_NULL}. + * @param comm communicator + * @param filename name of the file to open + * @param amode file access mode + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public File(Comm comm, String filename, int amode) throws MPIException + { + MPI.check(); + handle = open(comm.handle, filename, amode, Info.NULL); + } + + /** + * Java binding of {@code MPI_FILE_OPEN}. + * @param comm communicator + * @param filename name of the file to open + * @param amode file access mode + * @param info info object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public File(Comm comm, String filename, int amode, Info info) + throws MPIException + { + MPI.check(); + handle = open(comm.handle, filename, amode, info.handle); + } + + private native long open(long comm, String filename, int amode, long info) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_CLOSE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void close() throws MPIException + { + MPI.check(); + handle = close(handle); + } + + private native long close(long fh) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_DELETE} using {@code MPI_INFO_NULL}. + * @param filename name of the file to delete + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void delete(String filename) throws MPIException + { + MPI.check(); + delete(filename, Info.NULL); + } + + /** + * Java binding of {@code MPI_FILE_DELETE}. + * @param filename name of the file to delete + * @param info info object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void delete(String filename, Info info) throws MPIException + { + MPI.check(); + delete(filename, info.handle); + } + + private static native void delete(String filename, long info) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_SET_SIZE}. + * @param size size to truncate or expand file + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setSize(long size) throws MPIException + { + MPI.check(); + setSize(handle, size); + } + + private native void setSize(long fh, long size) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_PREALLOCATE}. + * @param size size to preallocate file + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void preallocate(long size) throws MPIException + { + MPI.check(); + preallocate(handle, size); + } + + private native void preallocate(long fh, long size) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_GET_SIZE}. + * @return size of file in bytes + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public long getSize() throws MPIException + { + MPI.check(); + return getSize(handle); + } + + private native long getSize(long fh) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_GET_GROUP}. + * @return group wich opened the file + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Group getGroup() throws MPIException + { + MPI.check(); + return new Group(getGroup(handle)); + } + + private native long getGroup(long fh) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_GET_AMODE}. + * @return file access mode to open the file + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getAMode() throws MPIException + { + MPI.check(); + return getAMode(handle); + } + + private native int getAMode(long fh) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_SET_INFO}. + * @param info info object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setInfo(Info info) throws MPIException + { + MPI.check(); + setInfo(handle, info.handle); + } + + private native void setInfo(long fh, long info) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_GET_INFO}. + * @return new info object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Info getInfo() throws MPIException + { + MPI.check(); + return new Info(getInfo(handle)); + } + + private native long getInfo(long fh) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_SET_VIEW} using {@code MPI_INFO_NULL}. + * @param disp displacement + * @param etype elementary datatype + * @param filetype filetype + * @param datarep data representation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setView(long disp, Datatype etype, + Datatype filetype, String datarep) + throws MPIException + { + MPI.check(); + setView(handle, disp, etype.handle, filetype.handle, datarep, Info.NULL); + view = new FileView(disp, etype, filetype, datarep); + } + + /** + * Java binding of {@code MPI_FILE_SET_VIEW}. + * @param disp displacement + * @param etype elementary datatype + * @param filetype filetype + * @param datarep data representation + * @param info info object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setView(long disp, Datatype etype, + Datatype filetype, String datarep, Info info) + throws MPIException + { + MPI.check(); + setView(handle, disp, etype.handle, filetype.handle, datarep, info.handle); + view = new FileView(disp, etype, filetype, datarep); + } + + private native void setView( + long fh, long disp, long etype, + long filetype, String datarep, long info) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_GET_VIEW}. + * @return file view + */ + public FileView getView() + { + return view; + } + + /** + * Java binding of {@code MPI_FILE_READ_AT}. + * @param offset file offset + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status readAt(long offset, Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + readAt(handle, offset, buf, db, off, count, + type.handle, type.baseType, status.data); + + return status; + } + + private native void readAt( + long fh, long fileOffset, Object buf, boolean db, int offset, + int count, long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_AT_ALL}. + * @param offset file offset + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status readAtAll(long offset, Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + readAtAll(handle, offset, buf, db, off, count, + type.handle, type.baseType, status.data); + + return status; + } + + private native void readAtAll( + long fh, long fileOffset, Object buf, boolean db, int offset, + int count, long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_AT}. + * @param offset file offset + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status writeAt(long offset, Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + writeAt(handle, offset, buf, db, off, count, + type.handle, type.baseType, status.data); + + return status; + } + + private native void writeAt( + long fh, long fileOffset, Object buf, boolean db, int offset, + int count, long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_AT_ALL}. + * @param offset file offset + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status writeAtAll(long offset, Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + writeAtAll(handle, offset, buf, db, off, count, + type.handle, type.baseType, status.data); + + return status; + } + + private native void writeAtAll( + long fh, long fileOffset, Object buf, boolean db, int offset, + int count, long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_IREAD_AT}. + * @param offset file offset + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return request object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Request iReadAt(long offset, Buffer buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iReadAt(handle, offset, buf, count, type.handle)); + } + + private native long iReadAt( + long fh, long offset, Buffer buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_IWRITE_AT}. + * @param offset file offset + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return request object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Request iWriteAt(long offset, Buffer buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iWriteAt(handle, offset, buf, count, type.handle)); + } + + private native long iWriteAt( + long fh, long offset, Buffer buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status read(Object buf, int count, Datatype type) throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + read(handle, buf, db, off, count, type.handle, type.baseType, status.data); + return status; + } + + private native void read( + long fh, Object buf, boolean db, int offset, + int count, long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_ALL}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status readAll(Object buf, int count, Datatype type) throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + readAll(handle, buf,db,off, count, type.handle, type.baseType, status.data); + return status; + } + + private native void readAll( + long fh, Object buf, boolean db, int offset, + int count, long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status write(Object buf, int count, Datatype type) throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + write(handle, buf, db, off, count, type.handle, type.baseType, status.data); + return status; + } + + private native void write( + long fh, Object buf, boolean db, int offset, + int count, long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_ALL}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status writeAll(Object buf, int count, Datatype type) throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + writeAll(handle, buf,db,off, count, type.handle,type.baseType, status.data); + return status; + } + + private native void writeAll( + long fh, Object buf, boolean db, int offset, + int count, long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_IREAD}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return request object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Request iRead(Buffer buf, int count, Datatype type) throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iRead(handle, buf, count, type.handle)); + } + + private native long iRead(long fh, Buffer buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_IWRITE}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return request object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Request iWrite(Buffer buf, int count, Datatype type) throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iWrite(handle, buf, count, type.handle)); + } + + private native long iWrite(long fh, Buffer buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_SEEK}. + * @param offset file offset + * @param whence update mode + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void seek(long offset, int whence) throws MPIException + { + MPI.check(); + seek(handle, offset, whence); + } + + private native void seek(long fh, long offset, int whence) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_GET_POSITION}. + * @return offset of individual pointer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public long getPosition() throws MPIException + { + MPI.check(); + return getPosition(handle); + } + + private native long getPosition(long fh) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_GET_BYTE_OFFSET}. + * @param offset offset + * @return absolute byte position of offset + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public long getByteOffset(long offset) throws MPIException + { + MPI.check(); + return getByteOffset(handle, offset); + } + + private native long getByteOffset(long fh, long offset) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_SHARED}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status readShared(Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + readShared(handle, buf, db, off, count, + type.handle, type.baseType, status.data); + + return status; + } + + private native void readShared( + long fh, Object buf, boolean db, int offset, int count, + long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_SHARED}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status writeShared(Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + writeShared(handle, buf, db, off, count, + type.handle, type.baseType, status.data); + + return status; + } + + private native void writeShared( + long fh, Object buf, boolean db, int offset, int count, + long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_IREAD_SHARED}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return request object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Request iReadShared(Buffer buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iReadShared(handle, buf, count, type.handle)); + } + + private native long iReadShared(long fh, Buffer buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_IWRITE_SHARED}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return request object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Request iWriteShared(Buffer buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(iWriteShared(handle, buf, count, type.handle)); + } + + private native long iWriteShared(long fh, Buffer buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_ORDERED}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status readOrdered(Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + readOrdered(handle, buf, db, off, count, + type.handle, type.baseType, status.data); + + return status; + } + + private native void readOrdered( + long fh, Object buf, boolean db, int offset, int count, + long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_ORDERED}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status writeOrdered(Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + writeOrdered(handle, buf, db, off, count, + type.handle, type.baseType, status.data); + + return status; + } + + private native void writeOrdered( + long fh, Object buf, boolean db, int offset, int count, + long type, int baseType, long[] stat) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_SEEK_SHARED}. + * @param offset file offset + * @param whence update mode + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void seekShared(long offset, int whence) throws MPIException + { + MPI.check(); + seekShared(handle, offset, whence); + } + + private native void seekShared(long fh, long offset, int whence) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_GET_POSITION_SHARED}. + * @return offset of individual pointer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public long getPositionShared() throws MPIException + { + MPI.check(); + return getPositionShared(handle); + } + + private native long getPositionShared(long fh) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_AT_ALL_BEGIN}. + * @param offset file offset + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void readAtAllBegin(long offset, Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + readAtAllBegin(handle, offset, buf, count, type.handle); + } + else + { + int off = 0; + Status status = new Status(); + + if(isHeapBuffer(buf)) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + readAtAll(handle, offset, buf, false, off, count, + type.handle, type.baseType, status.data); + + beginStatus = status; + } + } + + private native void readAtAllBegin( + long fh, long offset, Object buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_AT_ALL_END}. + * @param buf buffer + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status readAtAllEnd(Object buf) throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + Status status = new Status(); + readAtAllEnd(handle, buf, status.data); + return status; + } + else + { + return getBeginStatus(); + } + } + + private native void readAtAllEnd(long fh, Object buf, long[] stat) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_AT_ALL_BEGIN}. + * @param offset file offset + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void writeAtAllBegin(long offset, Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + writeAtAllBegin(handle, offset, buf, count, type.handle); + } + else + { + int off = 0; + Status status = new Status(); + + if(isHeapBuffer(buf)) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + writeAtAll(handle, offset, buf, false, off, count, + type.handle, type.baseType, status.data); + + beginStatus = status; + } + } + + private native void writeAtAllBegin( + long fh, long fileOffset, Object buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_AT_ALL_END}. + * @param buf buffer + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status writeAtAllEnd(Object buf) throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + Status status = new Status(); + writeAtAllEnd(handle, buf, status.data); + return status; + } + else + { + return getBeginStatus(); + } + } + + private native void writeAtAllEnd(long fh, Object buf, long[] stat) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_ALL_BEGIN}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void readAllBegin(Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + readAllBegin(handle, buf, count, type.handle); + } + else + { + int off = 0; + Status status = new Status(); + + if(isHeapBuffer(buf)) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + readAll(handle, buf, false, off, count, + type.handle, type.baseType, status.data); + + beginStatus = status; + } + } + + private native void readAllBegin(long fh, Object buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_ALL_END}. + * @param buf buffer + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status readAllEnd(Object buf) throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + Status status = new Status(); + readAllEnd(handle, buf, status.data); + return status; + } + else + { + return getBeginStatus(); + } + } + + private native void readAllEnd(long fh, Object buf, long[] stat) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_ALL_BEGIN}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void writeAllBegin(Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + writeAllBegin(handle, buf, count, type.handle); + } + else + { + int off = 0; + Status status = new Status(); + + if(isHeapBuffer(buf)) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + writeAll(handle, buf, false, off, count, + type.handle, type.baseType, status.data); + + beginStatus = status; + } + } + + private native void writeAllBegin(long fh, Object buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_ALL_END}. + * @param buf buffer + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status writeAllEnd(Object buf) throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + Status status = new Status(); + writeAllEnd(handle, buf, status.data); + return status; + } + else + { + return getBeginStatus(); + } + } + + private native void writeAllEnd(long fh, Object buf, long[] stat) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_ORDERED_BEGIN}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void readOrderedBegin(Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + readOrderedBegin(handle, buf, count, type.handle); + } + else + { + int off = 0; + Status status = new Status(); + + if(isHeapBuffer(buf)) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + readOrdered(handle, buf, false, off, count, + type.handle, type.baseType, status.data); + + beginStatus = status; + } + } + + private native void readOrderedBegin(long fh, Object buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_READ_ORDERED_END}. + * @param buf buffer + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status readOrderedEnd(Object buf) throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + Status status = new Status(); + readOrderedEnd(handle, buf, status.data); + return status; + } + else + { + return getBeginStatus(); + } + } + + private native void readOrderedEnd(long fh, Object buf, long[] stat) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_ORDERED_BEGIN}. + * @param buf buffer + * @param count number of items in buffer + * @param type datatype of each buffer element + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void writeOrderedBegin(Object buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + writeOrderedBegin(handle, buf, count, type.handle); + } + else + { + int off = 0; + Status status = new Status(); + + if(isHeapBuffer(buf)) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + writeOrdered(handle, buf, false, off, count, + type.handle, type.baseType, status.data); + + beginStatus = status; + } + } + + private native void writeOrderedBegin(long fh, Object buf, int count, long type) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_WRITE_ORDERED_END}. + * @param buf buffer + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status writeOrderedEnd(Object buf) throws MPIException + { + MPI.check(); + + if(isDirectBuffer(buf)) + { + Status status = new Status(); + writeOrderedEnd(handle, buf, status.data); + return status; + } + else + { + return getBeginStatus(); + } + } + + private native void writeOrderedEnd(long fh, Object buf, long[] stat) + throws MPIException; + + private Status getBeginStatus() + { + Status s = beginStatus; + beginStatus = null; + return s; + } + + /** + * Java binding of {@code MPI_FILE_GET_TYPE_EXTENT}. + * @param type type of data + * @return datatype extent + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getTypeExtent(Datatype type) throws MPIException + { + MPI.check(); + return getTypeExtent(handle, type.handle) / type.baseSize; + } + + private native int getTypeExtent(long fh, long type) throws MPIException; + + /** + * Java binding of {@code MPI_FILE_SET_ATOMICITY}. + * @param atomicity true to set atomic mode, false to set nonatomic mode + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setAtomicity(boolean atomicity) throws MPIException + { + MPI.check(); + setAtomicity(handle, atomicity); + } + + private native void setAtomicity(long fh, boolean atomicity) + throws MPIException; + + /** + * Java binding of {@code MPI_FILE_SYNC}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void sync() throws MPIException + { + MPI.check(); + sync(handle); + } + + private native void sync(long handle) throws MPIException; } // File diff --git a/ompi/mpi/java/java/FileView.java b/ompi/mpi/java/java/FileView.java index 7695770726..cb791056c4 100644 --- a/ompi/mpi/java/java/FileView.java +++ b/ompi/mpi/java/java/FileView.java @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -23,59 +25,59 @@ package mpi; */ public final class FileView { -private final long disp; -private final Datatype etype, filetype; -private final String datarep; + private final long disp; + private final Datatype etype, filetype; + private final String datarep; -/** - * Constructs a file view. - * @param disp displacement - * @param etype elementary datatype - * @param filetype file type - * @param datarep data representation - */ -public FileView(long disp, Datatype etype, Datatype filetype, String datarep) -{ - this.disp = disp; - this.etype = etype; - this.filetype = filetype; - this.datarep = datarep; -} + /** + * Constructs a file view. + * @param disp displacement + * @param etype elementary datatype + * @param filetype file type + * @param datarep data representation + */ + public FileView(long disp, Datatype etype, Datatype filetype, String datarep) + { + this.disp = disp; + this.etype = etype; + this.filetype = filetype; + this.datarep = datarep; + } -/** - * Gets the displacement. - * @return displacement - */ -public long getDisp() -{ - return disp; -} + /** + * Gets the displacement. + * @return displacement + */ + public long getDisp() + { + return disp; + } -/** - * Gets the elementary datatype. - * @return elementary datatype - */ -public Datatype getEType() -{ - return etype; -} + /** + * Gets the elementary datatype. + * @return elementary datatype + */ + public Datatype getEType() + { + return etype; + } -/** - * Gets the file type. - * @return file type - */ -public Datatype getFileType() -{ - return filetype; -} + /** + * Gets the file type. + * @return file type + */ + public Datatype getFileType() + { + return filetype; + } -/** - * Gets the data representation. - * @return data representation - */ -public String getDataRep() -{ - return datarep; -} + /** + * Gets the data representation. + * @return data representation + */ + public String getDataRep() + { + return datarep; + } } // FileView diff --git a/ompi/mpi/java/java/FloatComplex.java b/ompi/mpi/java/java/FloatComplex.java index dd7f652dcc..572f1d6fb3 100644 --- a/ompi/mpi/java/java/FloatComplex.java +++ b/ompi/mpi/java/java/FloatComplex.java @@ -9,6 +9,8 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -25,124 +27,124 @@ import java.nio.*; */ public final class FloatComplex { -private final int offset; -private final FloatBuffer buffer; + private final int offset; + private final FloatBuffer buffer; -private FloatComplex(FloatBuffer buffer, int index) -{ - this.buffer = buffer; - this.offset = index * 2; -} + private FloatComplex(FloatBuffer buffer, int index) + { + this.buffer = buffer; + this.offset = index * 2; + } -/** - * Wraps a complex number stored in a buffer - * @param buffer buffer - * @return complex number - */ -public static FloatComplex get(FloatBuffer buffer) -{ - return new FloatComplex(buffer, 0); -} + /** + * Wraps a complex number stored in a buffer + * @param buffer buffer + * @return complex number + */ + public static FloatComplex get(FloatBuffer buffer) + { + return new FloatComplex(buffer, 0); + } -/** - * Wraps the complex number at the specified position - * of an array of complex numbers stored in a buffer. - * @param buffer buffer - * @param index index - * @return complex number - */ -public static FloatComplex get(FloatBuffer buffer, int index) -{ - return new FloatComplex(buffer, index); -} + /** + * Wraps the complex number at the specified position + * of an array of complex numbers stored in a buffer. + * @param buffer buffer + * @param index index + * @return complex number + */ + public static FloatComplex get(FloatBuffer buffer, int index) + { + return new FloatComplex(buffer, index); + } -/** - * Wraps a complex number stored in the first two values of an array. - * @param array array - * @return complex number - */ -public static FloatComplex get(float[] array) -{ - return new FloatComplex(FloatBuffer.wrap(array), 0); -} + /** + * Wraps a complex number stored in the first two values of an array. + * @param array array + * @return complex number + */ + public static FloatComplex get(float[] array) + { + return new FloatComplex(FloatBuffer.wrap(array), 0); + } -/** - * Wraps the complex number at the specified position of - * an array of complex numbers stored in an array of floats. - * @param array array - * @param index index - * @return complex number - */ -public static FloatComplex get(float[] array, int index) -{ - return new FloatComplex(FloatBuffer.wrap(array), index); -} + /** + * Wraps the complex number at the specified position of + * an array of complex numbers stored in an array of floats. + * @param array array + * @param index index + * @return complex number + */ + public static FloatComplex get(float[] array, int index) + { + return new FloatComplex(FloatBuffer.wrap(array), index); + } -/** - * Wraps a complex number stored in a buffer - * @param buffer buffer - * @return complex number - */ -public static FloatComplex get(ByteBuffer buffer) -{ - return new FloatComplex(buffer.asFloatBuffer(), 0); -} + /** + * Wraps a complex number stored in a buffer + * @param buffer buffer + * @return complex number + */ + public static FloatComplex get(ByteBuffer buffer) + { + return new FloatComplex(buffer.asFloatBuffer(), 0); + } -/** - * Wraps the complex number at the specified position - * of an array of complex numbers stored in a buffer. - * @param buffer buffer - * @param index index - * @return complex number - */ -public static FloatComplex get(ByteBuffer buffer, int index) -{ - return new FloatComplex(buffer.asFloatBuffer(), index); -} + /** + * Wraps the complex number at the specified position + * of an array of complex numbers stored in a buffer. + * @param buffer buffer + * @param index index + * @return complex number + */ + public static FloatComplex get(ByteBuffer buffer, int index) + { + return new FloatComplex(buffer.asFloatBuffer(), index); + } -/** - * Gets the real value. - * @return real value - */ -public float getReal() -{ - return buffer.get(offset); -} + /** + * Gets the real value. + * @return real value + */ + public float getReal() + { + return buffer.get(offset); + } -/** - * Gets the imaginary value. - * @return imaginary value. - */ -public float getImag() -{ - return buffer.get(offset + 1); -} + /** + * Gets the imaginary value. + * @return imaginary value. + */ + public float getImag() + { + return buffer.get(offset + 1); + } -/** - * Puts the real value. - * @param real real value - */ -public void putReal(float real) -{ - buffer.put(offset, real); -} + /** + * Puts the real value. + * @param real real value + */ + public void putReal(float real) + { + buffer.put(offset, real); + } -/** - * Puts the imaginary value. - * @param imag imaginary value - */ -public void putImag(float imag) -{ - buffer.put(offset + 1, imag); -} + /** + * Puts the imaginary value. + * @param imag imaginary value + */ + public void putImag(float imag) + { + buffer.put(offset + 1, imag); + } -/** - * Gets the buffer where the complex number is stored. - * @return buffer where the complex number is stored - */ -public FloatBuffer getBuffer() -{ - return offset == 0 ? buffer : MPI.slice(buffer, offset); -} + /** + * Gets the buffer where the complex number is stored. + * @return buffer where the complex number is stored + */ + public FloatBuffer getBuffer() + { + return offset == 0 ? buffer : MPI.slice(buffer, offset); + } } // FloatComplex diff --git a/ompi/mpi/java/java/FloatInt.java b/ompi/mpi/java/java/FloatInt.java index 0be322a643..1eb55bde76 100644 --- a/ompi/mpi/java/java/FloatInt.java +++ b/ompi/mpi/java/java/FloatInt.java @@ -25,91 +25,91 @@ package mpi; */ public final class FloatInt extends Struct { -private final int iOff, iSize; + private final int iOff, iSize; -/** - * The struct object will be created only in MPI class. - * @param intOff int offset - * @param intSize int size - * @see MPI#floatInt - */ -protected FloatInt(int intOff, int intSize) -{ - int fOff = addFloat(); - assert fOff == 0; + /** + * The struct object will be created only in MPI class. + * @param intOff int offset + * @param intSize int size + * @see MPI#floatInt + */ + protected FloatInt(int intOff, int intSize) + { + int fOff = addFloat(); + assert fOff == 0; - iSize = intSize; - setOffset(intOff); + iSize = intSize; + setOffset(intOff); - switch(iSize) - { - case 4: iOff = addInt(); break; - case 8: iOff = addLong(); break; - default: throw new AssertionError("Unsupported int size: "+ iSize); - } + switch(iSize) + { + case 4: iOff = addInt(); break; + case 8: iOff = addLong(); break; + default: throw new AssertionError("Unsupported int size: "+ iSize); + } - assert(intOff == iOff); -} + assert(intOff == iOff); + } -/** - * Creates a Data object. - * @return new Data object. - */ -@Override protected Data newData() -{ - return new Data(); -} + /** + * Creates a Data object. + * @return new Data object. + */ + @Override protected Data newData() + { + return new Data(); + } -/** - * Class for reading/writing data in a struct stored in a byte buffer. - */ -public final class Data extends Struct.Data -{ - /** - * Gets the float value. - * @return float value - */ - public float getValue() - { - return getFloat(0); - } + /** + * Class for reading/writing data in a struct stored in a byte buffer. + */ + public final class Data extends Struct.Data + { + /** + * Gets the float value. + * @return float value + */ + public float getValue() + { + return getFloat(0); + } - /** - * Gets the int value. - * @return int value - */ - public int getIndex() - { - switch(iSize) - { - case 4: return getInt(iOff); - case 8: return (int)getLong(iOff); - default: throw new AssertionError(); - } - } + /** + * Gets the int value. + * @return int value + */ + public int getIndex() + { + switch(iSize) + { + case 4: return getInt(iOff); + case 8: return (int)getLong(iOff); + default: throw new AssertionError(); + } + } - /** - * Puts the float value. - * @param v float value - */ - public void putValue(float v) - { - putFloat(0, v); - } + /** + * Puts the float value. + * @param v float value + */ + public void putValue(float v) + { + putFloat(0, v); + } - /** - * Puts the int value. - * @param v int value - */ - public void putIndex(int v) - { - switch(iSize) - { - case 4: putInt(iOff, v); break; - case 8: putLong(iOff, v); break; - default: throw new AssertionError(); - } - } -} // Data + /** + * Puts the int value. + * @param v int value + */ + public void putIndex(int v) + { + switch(iSize) + { + case 4: putInt(iOff, v); break; + case 8: putLong(iOff, v); break; + default: throw new AssertionError(); + } + } + } // Data } // FloatInt diff --git a/ompi/mpi/java/java/Freeable.java b/ompi/mpi/java/java/Freeable.java index d77709e6d3..9ec8a4571d 100644 --- a/ompi/mpi/java/java/Freeable.java +++ b/ompi/mpi/java/java/Freeable.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Freeable.java * Author : Bryan Carpenter * Created : Wed Jan 15 23:14:43 EST 2003 @@ -50,10 +50,10 @@ package mpi; */ public interface Freeable { - /** - * Frees a freeable object. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - void free() throws MPIException; + /** + * Frees a freeable object. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + void free() throws MPIException; } diff --git a/ompi/mpi/java/java/GraphComm.java b/ompi/mpi/java/java/GraphComm.java index f539ec3fc9..302a90478f 100644 --- a/ompi/mpi/java/java/GraphComm.java +++ b/ompi/mpi/java/java/GraphComm.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Graphcomm.java * Author : Xinying Li * Created : Thu Apr 9 12:22:15 1998 @@ -52,132 +52,132 @@ package mpi; */ public final class GraphComm extends Intracomm { -static -{ - init(); -} + static + { + init(); + } -private static native void init(); + private static native void init(); -protected GraphComm(long handle) throws MPIException -{ - super(handle); -} + protected GraphComm(long handle) throws MPIException + { + super(handle); + } -protected GraphComm(long[] commRequest) -{ - super(commRequest); -} + protected GraphComm(long[] commRequest) + { + super(commRequest); + } -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - *

It is recommended to use {@link #dup} instead of {@link #clone} - * because the last can't throw an {@link mpi.MPIException}. - * @return copy of this communicator - */ -@Override public GraphComm clone() -{ - try - { - return dup(); - } - catch(MPIException e) - { - throw new RuntimeException(e.getMessage()); - } -} + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + *

It is recommended to use {@link #dup} instead of {@link #clone} + * because the last can't throw an {@link mpi.MPIException}. + * @return copy of this communicator + */ + @Override public GraphComm clone() + { + try + { + return dup(); + } + catch(MPIException e) + { + throw new RuntimeException(e.getMessage()); + } + } -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public GraphComm dup() throws MPIException -{ - MPI.check(); - return new GraphComm(dup(handle)); -} + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public GraphComm dup() throws MPIException + { + MPI.check(); + return new GraphComm(dup(handle)); + } -/** - * Duplicates this communicator. - *

The new communicator can't be used before the operation completes. - * The request object must be obtained calling {@link #getRequest}. - *

Java binding of {@code MPI_COMM_IDUP}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public GraphComm iDup() throws MPIException -{ - MPI.check(); - return new GraphComm(iDup(handle)); -} + /** + * Duplicates this communicator. + *

The new communicator can't be used before the operation completes. + * The request object must be obtained calling {@link #getRequest}. + *

Java binding of {@code MPI_COMM_IDUP}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public GraphComm iDup() throws MPIException + { + MPI.check(); + return new GraphComm(iDup(handle)); + } -/** - * Returns graph topology information. - *

Java binding of the MPI operations {@code MPI_GRAPHDIMS_GET} - * and {@code MPI_GRAPH_GET}. - *

The number of nodes and number of edges can be extracted - * from the sizes of the {@code index} and {@code edges} fields - * of the returned object. - * @return object defining node degress and edges of graph - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public GraphParms getDims() throws MPIException -{ - MPI.check(); - return getDims(handle); -} + /** + * Returns graph topology information. + *

Java binding of the MPI operations {@code MPI_GRAPHDIMS_GET} + * and {@code MPI_GRAPH_GET}. + *

The number of nodes and number of edges can be extracted + * from the sizes of the {@code index} and {@code edges} fields + * of the returned object. + * @return object defining node degress and edges of graph + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public GraphParms getDims() throws MPIException + { + MPI.check(); + return getDims(handle); + } -private native GraphParms getDims(long comm) throws MPIException; + private native GraphParms getDims(long comm) throws MPIException; -/** - * Provides adjacency information for general graph topology. - *

Java binding of the MPI operations {@code MPI_GRAPH_NEIGHBORS_COUNT} - * and {@code MPI_GRAPH_NEIGHBORS}. - *

The number of neighbors can be extracted from the size of the result. - * @param rank rank of a process in the group of this communicator - * @return array of ranks of neighbouring processes to one specified - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int[] getNeighbors(int rank) throws MPIException -{ - MPI.check(); - return getNeighbors(handle, rank); -} + /** + * Provides adjacency information for general graph topology. + *

Java binding of the MPI operations {@code MPI_GRAPH_NEIGHBORS_COUNT} + * and {@code MPI_GRAPH_NEIGHBORS}. + *

The number of neighbors can be extracted from the size of the result. + * @param rank rank of a process in the group of this communicator + * @return array of ranks of neighbouring processes to one specified + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int[] getNeighbors(int rank) throws MPIException + { + MPI.check(); + return getNeighbors(handle, rank); + } -private native int[] getNeighbors(long comm, int rank) throws MPIException; + private native int[] getNeighbors(long comm, int rank) throws MPIException; -/** - * Gets the adjacency information for a distributed graph topology. - * @return adjacency information for a distributed graph topology - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public DistGraphNeighbors getDistGraphNeighbors() throws MPIException -{ - MPI.check(); - return getDistGraphNeighbors(handle); -} + /** + * Gets the adjacency information for a distributed graph topology. + * @return adjacency information for a distributed graph topology + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public DistGraphNeighbors getDistGraphNeighbors() throws MPIException + { + MPI.check(); + return getDistGraphNeighbors(handle); + } -private native DistGraphNeighbors getDistGraphNeighbors(long comm) - throws MPIException; + private native DistGraphNeighbors getDistGraphNeighbors(long comm) + throws MPIException; -/** - * Compute an optimal placement. - *

Java binding of the MPI operation {@code MPI_GRAPH_MAP}. - *

The number of nodes is taken to be size of the {@code index} argument. - * @param index node degrees - * @param edges graph edges - * @return reordered rank of calling process - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int map(int[] index, int[] edges) throws MPIException -{ - MPI.check(); - return map(handle, index, edges); -} + /** + * Compute an optimal placement. + *

Java binding of the MPI operation {@code MPI_GRAPH_MAP}. + *

The number of nodes is taken to be size of the {@code index} argument. + * @param index node degrees + * @param edges graph edges + * @return reordered rank of calling process + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int map(int[] index, int[] edges) throws MPIException + { + MPI.check(); + return map(handle, index, edges); + } -private native int map(long comm, int[] index, int[] edges) throws MPIException; + private native int map(long comm, int[] index, int[] edges) throws MPIException; } // Graphcomm diff --git a/ompi/mpi/java/java/GraphParms.java b/ompi/mpi/java/java/GraphParms.java index 959b8a5e20..357c94f2c0 100644 --- a/ompi/mpi/java/java/GraphParms.java +++ b/ompi/mpi/java/java/GraphParms.java @@ -9,31 +9,33 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : GraphParms.java * Author : Xinying Li * Created : Thu Apr 9 12:22:15 1998 @@ -50,66 +52,66 @@ package mpi; */ public final class GraphParms { -/** Node degrees. */ -private final int[] index; + /** Node degrees. */ + private final int[] index; -/** Graph edges. */ -private final int[] edges; + /** Graph edges. */ + private final int[] edges; -/** - * Constructs a graph topology information object. - * @param index node degrees. - * @param edges graph edges. - */ -protected GraphParms(int[] index, int[] edges) -{ - this.index = index; - this.edges = edges; -} + /** + * Constructs a graph topology information object. + * @param index node degrees. + * @param edges graph edges. + */ + protected GraphParms(int[] index, int[] edges) + { + this.index = index; + this.edges = edges; + } -/** - * Returns the number of nodes. - * @return number of nodes. - */ -public int getIndexCount() -{ - return index.length; -} + /** + * Returns the number of nodes. + * @return number of nodes. + */ + public int getIndexCount() + { + return index.length; + } -/** - * Returns the index of the node {@code i}. - *

{@code getIndex(0)} returns the degree of the node {@code 0}, and - * {@code getIndex(i)-getIndex(i-1)} is the degree of the node {@code i}. - * @param i position of the node. - * @return the index. - */ -public int getIndex(int i) -{ - return index[i]; -} + /** + * Returns the index of the node {@code i}. + *

{@code getIndex(0)} returns the degree of the node {@code 0}, and + * {@code getIndex(i)-getIndex(i-1)} is the degree of the node {@code i}. + * @param i position of the node. + * @return the index. + */ + public int getIndex(int i) + { + return index[i]; + } -/** - * Returns the number of edges. - * @return number of edges. - */ -public int getEdgeCount() -{ - return edges.length; -} + /** + * Returns the number of edges. + * @return number of edges. + */ + public int getEdgeCount() + { + return edges.length; + } -/** - * Returns the edge {@code i}. - *

The list of neighbors of node zero is stored in {@code getEdge(j)}, - * for {@code 0} ≤ {@code j} ≤ {@code getIndex(0)-1} and the list - * of neighbors of node {@code i}, {@code i} > {@code 0}, is stored - * in {@code getEdge(j)}, {@code getIndex(i-1)} ≤ {@code j} ≤ - * {@code getIndex(i)-1}. - * @param i index of the edge. - * @return the edge. - */ -public int getEdge(int i) -{ - return edges[i]; -} + /** + * Returns the edge {@code i}. + *

The list of neighbors of node zero is stored in {@code getEdge(j)}, + * for {@code 0} ≤ {@code j} ≤ {@code getIndex(0)-1} and the list + * of neighbors of node {@code i}, {@code i} > {@code 0}, is stored + * in {@code getEdge(j)}, {@code getIndex(i-1)} ≤ {@code j} ≤ + * {@code getIndex(i)-1}. + * @param i index of the edge. + * @return the edge. + */ + public int getEdge(int i) + { + return edges[i]; + } } // GraphParms diff --git a/ompi/mpi/java/java/Group.java b/ompi/mpi/java/java/Group.java index a3a9ed500c..d5d6eee7b7 100644 --- a/ompi/mpi/java/java/Group.java +++ b/ompi/mpi/java/java/Group.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Group.java * Author : Xinying Li, Bryan Carpenter * Created : Thu Apr 9 12:22:15 1998 @@ -52,223 +52,223 @@ package mpi; */ public final class Group implements Freeable { -protected long handle; -private static long nullHandle; + protected long handle; + private static long nullHandle; -static -{ - init(); -} + static + { + init(); + } -private static native void init(); + private static native void init(); -protected static native long getEmpty(); + protected static native long getEmpty(); -protected Group(long handle) -{ - this.handle = handle; -} + protected Group(long handle) + { + this.handle = handle; + } -/** - * Java binding of the MPI operation {@code MPI_GROUP_SIZE}. - * @return number of processes in the group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getSize() throws MPIException -{ - MPI.check(); - return getSize(handle); -} + /** + * Java binding of the MPI operation {@code MPI_GROUP_SIZE}. + * @return number of processes in the group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getSize() throws MPIException + { + MPI.check(); + return getSize(handle); + } -private native int getSize(long group) throws MPIException; + private native int getSize(long group) throws MPIException; -/** - * Rank of this process in the group. - *

Java binding of the MPI operation {@code MPI_GROUP_RANK}. - * @return rank of this process in the group, or {@code MPI.UNDEFINED} - * if this process is not a member of the group. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getRank() throws MPIException -{ - MPI.check(); - return getRank(handle); -} + /** + * Rank of this process in the group. + *

Java binding of the MPI operation {@code MPI_GROUP_RANK}. + * @return rank of this process in the group, or {@code MPI.UNDEFINED} + * if this process is not a member of the group. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getRank() throws MPIException + { + MPI.check(); + return getRank(handle); + } -private native int getRank(long group) throws MPIException; + private native int getRank(long group) throws MPIException; -/** - * Java binding of the MPI operation {@code MPI_GROUP_FREE}. - */ -@Override public void free() throws MPIException -{ - MPI.check(); - handle = free(handle); -} + /** + * Java binding of the MPI operation {@code MPI_GROUP_FREE}. + */ + @Override public void free() throws MPIException + { + MPI.check(); + handle = free(handle); + } -private native long free(long group); + private native long free(long group); -/** - * Test if group object is null. - * @return true if the group object is null. - */ -public boolean isNull() -{ - return handle == nullHandle; -} + /** + * Test if group object is null. + * @return true if the group object is null. + */ + public boolean isNull() + { + return handle == nullHandle; + } -/** - * Translate ranks within one group to ranks within another. - *

Java binding of the MPI operation {@code MPI_GROUP_TRANSLATE_RANKS}. - *

Result elements are {@code MPI.UNDEFINED} where no correspondence exists. - * @param group1 a group - * @param ranks1 array of valid ranks in group1 - * @param group2 another group - * @return array of corresponding ranks in group2 - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int[] translateRanks(Group group1, int[] ranks1, Group group2) - throws MPIException -{ - MPI.check(); - return translateRanks(group1.handle, ranks1, group2.handle); -} + /** + * Translate ranks within one group to ranks within another. + *

Java binding of the MPI operation {@code MPI_GROUP_TRANSLATE_RANKS}. + *

Result elements are {@code MPI.UNDEFINED} where no correspondence exists. + * @param group1 a group + * @param ranks1 array of valid ranks in group1 + * @param group2 another group + * @return array of corresponding ranks in group2 + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int[] translateRanks(Group group1, int[] ranks1, Group group2) + throws MPIException + { + MPI.check(); + return translateRanks(group1.handle, ranks1, group2.handle); + } -private static native int[] translateRanks( - long group1, int[] ranks1, long group2) throws MPIException; + private static native int[] translateRanks( + long group1, int[] ranks1, long group2) throws MPIException; -/** - * Compare two groups. - *

Java binding of the MPI operation {@code MPI_GROUP_COMPARE}. - * @param group1 first group - * @param group2 second group - * @return {@code MPI.IDENT} if the group members and group order are exactly - * the same in both groups, {@code MPI.SIMILAR} if the group members are - * the same but the order is different, {@code MPI.UNEQUAL} otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int compare(Group group1, Group group2) throws MPIException -{ - MPI.check(); - return compare(group1.handle, group2.handle); -} + /** + * Compare two groups. + *

Java binding of the MPI operation {@code MPI_GROUP_COMPARE}. + * @param group1 first group + * @param group2 second group + * @return {@code MPI.IDENT} if the group members and group order are exactly + * the same in both groups, {@code MPI.SIMILAR} if the group members are + * the same but the order is different, {@code MPI.UNEQUAL} otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int compare(Group group1, Group group2) throws MPIException + { + MPI.check(); + return compare(group1.handle, group2.handle); + } -private static native int compare(long group1, long group2) throws MPIException; + private static native int compare(long group1, long group2) throws MPIException; -/** - * Set union of two groups. - *

Java binding of the MPI operation {@code MPI_GROUP_UNION}. - * @param group1 first group - * @param group2 second group - * @return union group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Group union(Group group1, Group group2) throws MPIException -{ - MPI.check(); - return new Group(union(group1.handle, group2.handle)); -} + /** + * Set union of two groups. + *

Java binding of the MPI operation {@code MPI_GROUP_UNION}. + * @param group1 first group + * @param group2 second group + * @return union group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Group union(Group group1, Group group2) throws MPIException + { + MPI.check(); + return new Group(union(group1.handle, group2.handle)); + } -private static native long union(long group1, long group2); + private static native long union(long group1, long group2); -/** - * Set intersection of two groups. - * Java binding of the MPI operation {@code MPI_GROUP_INTERSECTION}. - * @param group1 first group - * @param group2 second group - * @return intersection group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Group intersection(Group group1, Group group2) throws MPIException -{ - MPI.check(); - return new Group(intersection(group1.handle, group2.handle)); -} + /** + * Set intersection of two groups. + * Java binding of the MPI operation {@code MPI_GROUP_INTERSECTION}. + * @param group1 first group + * @param group2 second group + * @return intersection group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Group intersection(Group group1, Group group2) throws MPIException + { + MPI.check(); + return new Group(intersection(group1.handle, group2.handle)); + } -private static native long intersection(long group1, long group2); + private static native long intersection(long group1, long group2); -/** - * Set difference of two groups. - * Java binding of the MPI operation {@code MPI_GROUP_DIFFERENCE}. - * @param group1 first group - * @param group2 second group - * @return difference group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Group difference(Group group1, Group group2) throws MPIException -{ - MPI.check(); - return new Group(difference(group1.handle, group2.handle)); -} + /** + * Set difference of two groups. + * Java binding of the MPI operation {@code MPI_GROUP_DIFFERENCE}. + * @param group1 first group + * @param group2 second group + * @return difference group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Group difference(Group group1, Group group2) throws MPIException + { + MPI.check(); + return new Group(difference(group1.handle, group2.handle)); + } -private static native long difference(long group1, long group2); + private static native long difference(long group1, long group2); -/** - * Create a subset group including specified processes. - *

Java binding of the MPI operation {@code MPI_GROUP_INCL}. - * @param ranks ranks from this group to appear in new group - * @return new group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Group incl(int[] ranks) throws MPIException -{ - MPI.check(); - return new Group(incl(handle, ranks)); -} + /** + * Create a subset group including specified processes. + *

Java binding of the MPI operation {@code MPI_GROUP_INCL}. + * @param ranks ranks from this group to appear in new group + * @return new group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Group incl(int[] ranks) throws MPIException + { + MPI.check(); + return new Group(incl(handle, ranks)); + } -private native long incl(long group, int[] ranks); + private native long incl(long group, int[] ranks); -/** - * Create a subset group excluding specified processes. - *

Java binding of the MPI operation {@code MPI_GROUP_EXCL}. - * @param ranks ranks from this group not to appear in new group - * @return new group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Group excl(int[] ranks) throws MPIException -{ - MPI.check(); - return new Group(excl(handle, ranks)); -} + /** + * Create a subset group excluding specified processes. + *

Java binding of the MPI operation {@code MPI_GROUP_EXCL}. + * @param ranks ranks from this group not to appear in new group + * @return new group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Group excl(int[] ranks) throws MPIException + { + MPI.check(); + return new Group(excl(handle, ranks)); + } -private native long excl(long group, int[] ranks); + private native long excl(long group, int[] ranks); -/** - * Create a subset group including processes specified - * by strided intervals of ranks. - *

Java binding of the MPI operation {@code MPI_GROUP_RANGE_INCL}. - *

The triplets are of the form (first rank, last rank, stride) - * indicating ranks in this group to be included in the new group. - * The size of the first dimension of {@code ranges} is the number - * of triplets. The size of the second dimension is 3. - * @param ranges array of integer triplets - * @return new group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Group rangeIncl(int[][] ranges) throws MPIException -{ - MPI.check(); - return new Group(rangeIncl(handle, ranges)); -} + /** + * Create a subset group including processes specified + * by strided intervals of ranks. + *

Java binding of the MPI operation {@code MPI_GROUP_RANGE_INCL}. + *

The triplets are of the form (first rank, last rank, stride) + * indicating ranks in this group to be included in the new group. + * The size of the first dimension of {@code ranges} is the number + * of triplets. The size of the second dimension is 3. + * @param ranges array of integer triplets + * @return new group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Group rangeIncl(int[][] ranges) throws MPIException + { + MPI.check(); + return new Group(rangeIncl(handle, ranges)); + } -private native long rangeIncl(long group, int[][] ranges); + private native long rangeIncl(long group, int[][] ranges); -/** - * Create a subset group excluding processes specified - * by strided intervals of ranks. - *

Java binding of the MPI operation {@code MPI_GROUP_RANGE_EXCL}. - *

Triplet array is defined as for {@code rangeIncl}, the ranges - * indicating ranks in this group to be excluded from the new group. - * @param ranges array of integer triplets - * @return new group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Group rangeExcl(int[][] ranges) throws MPIException -{ - MPI.check(); - return new Group(rangeExcl(handle, ranges)); -} + /** + * Create a subset group excluding processes specified + * by strided intervals of ranks. + *

Java binding of the MPI operation {@code MPI_GROUP_RANGE_EXCL}. + *

Triplet array is defined as for {@code rangeIncl}, the ranges + * indicating ranks in this group to be excluded from the new group. + * @param ranges array of integer triplets + * @return new group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Group rangeExcl(int[][] ranges) throws MPIException + { + MPI.check(); + return new Group(rangeExcl(handle, ranges)); + } -private native long rangeExcl(long group, int[][] ranges); + private native long rangeExcl(long group, int[][] ranges); } // Group diff --git a/ompi/mpi/java/java/Info.java b/ompi/mpi/java/java/Info.java index d9608ebe31..428ef0ba50 100644 --- a/ompi/mpi/java/java/Info.java +++ b/ompi/mpi/java/java/Info.java @@ -25,155 +25,155 @@ package mpi; */ public final class Info implements Freeable { -protected long handle; -protected static final long NULL = getNull(); + protected long handle; + protected static final long NULL = getNull(); -/** - * Java binding of the MPI operation {@code MPI_INFO_CREATE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Info() throws MPIException -{ - MPI.check(); - handle = create(); -} + /** + * Java binding of the MPI operation {@code MPI_INFO_CREATE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Info() throws MPIException + { + MPI.check(); + handle = create(); + } -protected Info(long handle) -{ - this.handle = handle; -} + protected Info(long handle) + { + this.handle = handle; + } -private native long create(); + private native long create(); -protected static Info newEnv() -{ - return new Info(getEnv()); -} + protected static Info newEnv() + { + return new Info(getEnv()); + } -private native static long getEnv(); -private native static long getNull(); + private native static long getEnv(); + private native static long getNull(); -/** - * Java binding of the MPI operation {@code MPI_INFO_SET}. - * @param key key - * @param value value - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void set(String key, String value) throws MPIException -{ - MPI.check(); - set(handle, key, value); -} + /** + * Java binding of the MPI operation {@code MPI_INFO_SET}. + * @param key key + * @param value value + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void set(String key, String value) throws MPIException + { + MPI.check(); + set(handle, key, value); + } -private native void set(long handle, String key, String value) - throws MPIException; + private native void set(long handle, String key, String value) + throws MPIException; -/** - * Java binding of the MPI operation {@code MPI_INFO_SET}. - * @param key key - * @return value or {@code null} if key is not defined - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public String get(String key) throws MPIException -{ - MPI.check(); - return get(handle, key); -} + /** + * Java binding of the MPI operation {@code MPI_INFO_SET}. + * @param key key + * @return value or {@code null} if key is not defined + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public String get(String key) throws MPIException + { + MPI.check(); + return get(handle, key); + } -private native String get(long handle, String key) throws MPIException; + private native String get(long handle, String key) throws MPIException; -/** - * Java binding of the MPI operation {@code MPI_INFO_SET}. - * @param key key - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void delete(String key) throws MPIException -{ - MPI.check(); - delete(handle, key); -} + /** + * Java binding of the MPI operation {@code MPI_INFO_SET}. + * @param key key + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void delete(String key) throws MPIException + { + MPI.check(); + delete(handle, key); + } -private native void delete(long handle, String key) throws MPIException; + private native void delete(long handle, String key) throws MPIException; -/** - * Java binding of the MPI operation {@code MPI_INFO_GET_NKEYS}. - * @return number of defined keys - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int size() throws MPIException -{ - MPI.check(); - return size(handle); -} + /** + * Java binding of the MPI operation {@code MPI_INFO_GET_NKEYS}. + * @return number of defined keys + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int size() throws MPIException + { + MPI.check(); + return size(handle); + } -private native int size(long handle) throws MPIException; + private native int size(long handle) throws MPIException; -/** - * Java binding of the MPI operation {@code MPI_INFO_GET_NTHKEY}. - * @param i key number - * @return key - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public String getKey(int i) throws MPIException -{ - MPI.check(); - return getKey(handle, i); -} + /** + * Java binding of the MPI operation {@code MPI_INFO_GET_NTHKEY}. + * @param i key number + * @return key + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public String getKey(int i) throws MPIException + { + MPI.check(); + return getKey(handle, i); + } -private native String getKey(long handle, int i) throws MPIException; + private native String getKey(long handle, int i) throws MPIException; -/** - * Java binding of the MPI operation {@code MPI_INFO_DUP}. - *

It is recommended to use {@link #dup} instead of {@link #clone} - * because the last can't throw an {@link mpi.MPIException}. - * @return info object - */ -@Override public Info clone() -{ - try - { - return dup(); - } - catch(MPIException e) - { - throw new RuntimeException(e.getMessage()); - } -} + /** + * Java binding of the MPI operation {@code MPI_INFO_DUP}. + *

It is recommended to use {@link #dup} instead of {@link #clone} + * because the last can't throw an {@link mpi.MPIException}. + * @return info object + */ + @Override public Info clone() + { + try + { + return dup(); + } + catch(MPIException e) + { + throw new RuntimeException(e.getMessage()); + } + } -/** - * Java binding of the MPI operation {@code MPI_INFO_DUP}. - * @return info object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Info dup() throws MPIException -{ - MPI.check(); - return new Info(dup(handle)); -} + /** + * Java binding of the MPI operation {@code MPI_INFO_DUP}. + * @return info object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Info dup() throws MPIException + { + MPI.check(); + return new Info(dup(handle)); + } -private native long dup(long handle) throws MPIException; + private native long dup(long handle) throws MPIException; -/** - * Java binding of the MPI operation {@code MPI_INFO_FREE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public void free() throws MPIException -{ - MPI.check(); - handle = free(handle); -} + /** + * Java binding of the MPI operation {@code MPI_INFO_FREE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public void free() throws MPIException + { + MPI.check(); + handle = free(handle); + } -private native long free(long handle) throws MPIException; + private native long free(long handle) throws MPIException; -/** - * Tests if the info object is {@code MPI_INFO_NULL} (has been freed). - * @return true if the info object is {@code MPI_INFO_NULL}, false otherwise. - */ -public boolean isNull() -{ - return isNull(handle); -} + /** + * Tests if the info object is {@code MPI_INFO_NULL} (has been freed). + * @return true if the info object is {@code MPI_INFO_NULL}, false otherwise. + */ + public boolean isNull() + { + return isNull(handle); + } -private native boolean isNull(long handle); + private native boolean isNull(long handle); } // Info diff --git a/ompi/mpi/java/java/Int2.java b/ompi/mpi/java/java/Int2.java index 80ab29f8d0..0ba594d65c 100644 --- a/ompi/mpi/java/java/Int2.java +++ b/ompi/mpi/java/java/Int2.java @@ -25,103 +25,103 @@ package mpi; */ public final class Int2 extends Struct { -private final int iOff, iSize; + private final int iOff, iSize; -/** - * The struct object will be created only in MPI class. - * @param intOff int offset - * @param intSize int size - * @see MPI#int2 - */ -protected Int2(int intOff, int intSize) -{ - iSize = intSize; - int off = addIntField(); - assert off == 0; - setOffset(intOff); - iOff = addIntField(); - assert intOff == iOff; -} + /** + * The struct object will be created only in MPI class. + * @param intOff int offset + * @param intSize int size + * @see MPI#int2 + */ + protected Int2(int intOff, int intSize) + { + iSize = intSize; + int off = addIntField(); + assert off == 0; + setOffset(intOff); + iOff = addIntField(); + assert intOff == iOff; + } -private int addIntField() -{ - switch(iSize) - { - case 4: return addInt(); - case 8: return addLong(); - default: throw new AssertionError("Unsupported int size: "+ iSize); - } -} + private int addIntField() + { + switch(iSize) + { + case 4: return addInt(); + case 8: return addLong(); + default: throw new AssertionError("Unsupported int size: "+ iSize); + } + } -/** - * Creates a Data object. - * @return new Data object. - */ -@Override protected Int2.Data newData() -{ - return new Int2.Data(); -} + /** + * Creates a Data object. + * @return new Data object. + */ + @Override protected Int2.Data newData() + { + return new Int2.Data(); + } -/** - * Class for reading/writing data in a struct stored in a byte buffer. - */ -public final class Data extends Struct.Data -{ - /** - * Gets the first int. - * @return first int - */ - public int getValue() - { - return get(0); - } + /** + * Class for reading/writing data in a struct stored in a byte buffer. + */ + public final class Data extends Struct.Data + { + /** + * Gets the first int. + * @return first int + */ + public int getValue() + { + return get(0); + } - /** - * Gets the second int. - * @return second int - */ - public int getIndex() - { - return get(iOff); - } + /** + * Gets the second int. + * @return second int + */ + public int getIndex() + { + return get(iOff); + } - /** - * Puts the first int. - * @param v first value - */ - public void putValue(int v) - { - put(0, v); - } + /** + * Puts the first int. + * @param v first value + */ + public void putValue(int v) + { + put(0, v); + } - /** - * Puts the second int. - * @param v second int - */ - public void putIndex(int v) - { - put(iOff, v); - } + /** + * Puts the second int. + * @param v second int + */ + public void putIndex(int v) + { + put(iOff, v); + } - private int get(int off) - { - switch(iSize) - { - case 4: return getInt(off); - case 8: return (int)getLong(off); - default: throw new AssertionError(); - } - } + private int get(int off) + { + switch(iSize) + { + case 4: return getInt(off); + case 8: return (int)getLong(off); + default: throw new AssertionError(); + } + } - private void put(int off, int v) - { - switch(iSize) - { - case 4: putInt(off, v); break; - case 8: putLong(off, v); break; - default: throw new AssertionError(); - } - } -} // Data + private void put(int off, int v) + { + switch(iSize) + { + case 4: putInt(off, v); break; + case 8: putLong(off, v); break; + default: throw new AssertionError(); + } + } + } // Data } // Int2 diff --git a/ompi/mpi/java/java/Intercomm.java b/ompi/mpi/java/java/Intercomm.java index f40f664958..ae5af7f738 100644 --- a/ompi/mpi/java/java/Intercomm.java +++ b/ompi/mpi/java/java/Intercomm.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Intercomm.java * Author : Xinying Li * Created : Thu Apr 9 12:22:15 1998 @@ -52,117 +52,117 @@ package mpi; */ public final class Intercomm extends Comm { -protected Intercomm(long handle) -{ - super(handle); -} + protected Intercomm(long handle) + { + super(handle); + } -protected Intercomm(long[] commRequest) -{ - super(commRequest); -} + protected Intercomm(long[] commRequest) + { + super(commRequest); + } -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - *

It is recommended to use {@link #dup} instead of {@link #clone} - * because the last can't throw an {@link mpi.MPIException}. - * @return copy of this communicator - */ -@Override public Intercomm clone() -{ - try - { - return dup(); - } - catch(MPIException e) - { - throw new RuntimeException(e.getMessage()); - } -} + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + *

It is recommended to use {@link #dup} instead of {@link #clone} + * because the last can't throw an {@link mpi.MPIException}. + * @return copy of this communicator + */ + @Override public Intercomm clone() + { + try + { + return dup(); + } + catch(MPIException e) + { + throw new RuntimeException(e.getMessage()); + } + } -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public Intercomm dup() throws MPIException -{ - MPI.check(); - return new Intercomm(dup(handle)); -} + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public Intercomm dup() throws MPIException + { + MPI.check(); + return new Intercomm(dup(handle)); + } -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_IDUP}. - *

The new communicator can't be used before the operation completes. - * The request object must be obtained calling {@link #getRequest}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public Intercomm iDup() throws MPIException -{ - MPI.check(); - return new Intercomm(iDup(handle)); -} + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_IDUP}. + *

The new communicator can't be used before the operation completes. + * The request object must be obtained calling {@link #getRequest}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public Intercomm iDup() throws MPIException + { + MPI.check(); + return new Intercomm(iDup(handle)); + } -// Inter-Communication + // Inter-Communication -/** - * Size of remote group. - *

Java binding of the MPI operation {@code MPI_COMM_REMOTE_SIZE}. - * @return number of process in remote group of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getRemoteSize() throws MPIException -{ - MPI.check(); - return getRemoteSize_jni(); -} + /** + * Size of remote group. + *

Java binding of the MPI operation {@code MPI_COMM_REMOTE_SIZE}. + * @return number of process in remote group of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getRemoteSize() throws MPIException + { + MPI.check(); + return getRemoteSize_jni(); + } -private native int getRemoteSize_jni() throws MPIException; + private native int getRemoteSize_jni() throws MPIException; -/** - * Return the remote group. - *

Java binding of the MPI operation {@code MPI_COMM_REMOTE_GROUP}. - * @return remote group of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Group getRemoteGroup() throws MPIException -{ - MPI.check(); - return new Group(getRemoteGroup_jni()); -} + /** + * Return the remote group. + *

Java binding of the MPI operation {@code MPI_COMM_REMOTE_GROUP}. + * @return remote group of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Group getRemoteGroup() throws MPIException + { + MPI.check(); + return new Group(getRemoteGroup_jni()); + } -private native long getRemoteGroup_jni(); + private native long getRemoteGroup_jni(); -/** - * Creates an intracommuncator from an intercommunicator - *

Java binding of the MPI operation {@code MPI_INTERCOMM_MERGE}. - * @param high true if the local group has higher ranks in combined group - * @return new intra-communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Intracomm merge(boolean high) throws MPIException -{ - MPI.check(); - return new Intracomm(merge_jni(high)); -} + /** + * Creates an intracommuncator from an intercommunicator + *

Java binding of the MPI operation {@code MPI_INTERCOMM_MERGE}. + * @param high true if the local group has higher ranks in combined group + * @return new intra-communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Intracomm merge(boolean high) throws MPIException + { + MPI.check(); + return new Intracomm(merge_jni(high)); + } -private native long merge_jni(boolean high); + private native long merge_jni(boolean high); -/** - * Java binding of {@code MPI_COMM_GET_PARENT}. - * @return the parent communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Intercomm getParent() throws MPIException -{ - MPI.check(); - return new Intercomm(getParent_jni()); -} + /** + * Java binding of {@code MPI_COMM_GET_PARENT}. + * @return the parent communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Intercomm getParent() throws MPIException + { + MPI.check(); + return new Intercomm(getParent_jni()); + } -private native static long getParent_jni() throws MPIException; + private native static long getParent_jni() throws MPIException; } // Intercomm diff --git a/ompi/mpi/java/java/Intracomm.java b/ompi/mpi/java/java/Intracomm.java index d7cde64a66..f78266e027 100644 --- a/ompi/mpi/java/java/Intracomm.java +++ b/ompi/mpi/java/java/Intracomm.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Intracommm.java * Author : Sang Lim, Xinying Li, Bryan Carpenter * Created : Thu Apr 9 12:22:15 1998 @@ -43,9 +43,9 @@ * Updated : $Date: 2002/12/16 15:25:13 $ * Copyright: Northeast Parallel Architectures Center * at Syracuse University 1998 - */ - -/* + * + * + * * IMPLEMENTATION DETAILS * * All methods with buffers that can be direct or non direct have @@ -65,786 +65,786 @@ import static mpi.MPI.assertDirectBuffer; */ public class Intracomm extends Comm { -protected Intracomm() -{ -} - -protected Intracomm(long handle) -{ - super(handle); -} - -protected Intracomm(long[] commRequest) -{ - super(commRequest); -} - -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - *

It is recommended to use {@link #dup} instead of {@link #clone} - * because the last can't throw an {@link mpi.MPIException}. - * @return copy of this communicator - */ -@Override public Intracomm clone() -{ - try - { - return dup(); - } - catch(MPIException e) - { - throw new RuntimeException(e.getMessage()); - } -} - -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_DUP}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public Intracomm dup() throws MPIException -{ - MPI.check(); - return new Intracomm(dup(handle)); -} - -/** - * Duplicates this communicator. - *

Java binding of {@code MPI_COMM_IDUP}. - *

The new communicator can't be used before the operation completes. - * The request object must be obtained calling {@link #getRequest}. - * @return copy of this communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public Intracomm iDup() throws MPIException -{ - MPI.check(); - return new Intracomm(iDup(handle)); -} - -/** - * Partition the group associated with this communicator and create - * a new communicator within each subgroup. - *

Java binding of the MPI operation {@code MPI_COMM_SPLIT}. - * @param colour control of subset assignment - * @param key control of rank assignment - * @return new communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intracomm split(int colour, int key) throws MPIException -{ - MPI.check(); - return new Intracomm(split(handle, colour, key)); -} - -private native long split(long comm, int colour, int key) throws MPIException; - -/** - * Partition the group associated with this communicator and create - * a new communicator within each subgroup. - *

Java binding of the MPI operation {@code MPI_COMM_SPLIT_TYPE}. - * @param splitType type of processes to be grouped together - * @param key control of rank assignment - * @param info info argument - * @return new communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intracomm splitType(int splitType, int key, Info info) throws MPIException -{ - MPI.check(); - return new Intracomm(splitType(handle, splitType, key, info.handle)); -} - -private native long splitType(long comm, int colour, int key, long info) throws MPIException; - -/** - * Create a new communicator. - *

Java binding of the MPI operation {@code MPI_COMM_CREATE}. - * @param group group which is a subset of the group of this communicator - * @return new communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intracomm create(Group group) throws MPIException -{ - MPI.check(); - return new Intracomm(create(handle, group.handle)); -} - -private native long create(long comm, long group); - -// Topology Constructors - -/** - * Creates a communicator to which the Cartesian topology - * information is attached. - * Create a cartesian topology communicator whose group is a subset - * of the group of this communicator. - *

Java binding of the MPI operation {@code MPI_CART_CREATE}. - *

The number of dimensions of the Cartesian grid is taken to be the - * size of the {@code dims} argument. The array {@code periods} must - * be the same size. - * @param dims the number of processes in each dimension - * @param periods {@code true} if grid is periodic, - * {@code false} if not, in each dimension - * @param reorder {@code true} if ranking may be reordered, - * {@code false} if not - * @return new cartesian topology communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final CartComm createCart(int[] dims, boolean[] periods, boolean reorder) - throws MPIException -{ - MPI.check(); - return new CartComm(createCart(handle, dims, periods, reorder)); -} - -private native long createCart( - long comm, int[] dims, boolean[] periods, boolean reorder) - throws MPIException; - -/** - * Creates a communicator to which the graph topology information is attached. - *

Java binding of the MPI operation {@code MPI_GRAPH_CREATE}. - *

The number of nodes in the graph, nnodes, is taken - * to be size of the {@code index} argument. - * @param index node degrees - * @param edges graph edges - * @param reorder {@code true} if ranking may be reordered, - * {@code false} if not - * @return new graph topology communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final GraphComm createGraph(int[] index, int[] edges, boolean reorder) - throws MPIException -{ - MPI.check(); - return new GraphComm(createGraph(handle, index, edges, reorder)); -} - -private native long createGraph( - long comm, int[] index, int[] edges, boolean reorder) - throws MPIException; - -/** - * Creates a communicator to which the distributed graph topology - * information is attached. - *

Java binding of the MPI operation {@code MPI_DIST_GRAPH_CREATE}. - *

The number of source nodes is the size of the {@code sources} argument. - * @param sources source nodes for which this process specifies edges - * @param degrees number of destinations for each source node - * @param destinations destination nodes for the source nodes - * @param weights weights for source to destination edges - * @param info hints on optimization and interpretation of weights - * @param reorder the process may be reordered (true) or not (false) - * @return communicator with distributed graph topology - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final GraphComm createDistGraph( - int[] sources, int[] degrees, int[] destinations, - int[] weights, Info info, boolean reorder) - throws MPIException -{ - MPI.check(); - - return new GraphComm(createDistGraph( - handle, sources, degrees, destinations, - weights, info.handle, reorder, true)); -} - -/** - * Creates a communicator to which the distributed graph topology - * information is attached. - *

Java binding of the MPI operation {@code MPI_DIST_GRAPH_CREATE} - * using {@code MPI_UNWEIGHTED}. - *

The number of source nodes is the size of the {@code sources} argument. - * @param sources source nodes for which this process specifies edges - * @param degrees number of destinations for each source node - * @param destinations destination nodes for the source nodes - * @param info hints on optimization and interpretation of weights - * @param reorder the process may be reordered (true) or not (false) - * @return communicator with distributed graph topology - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final GraphComm createDistGraph( - int[] sources, int[] degrees, int[] destinations, - Info info, boolean reorder) - throws MPIException -{ - MPI.check(); - - return new GraphComm(createDistGraph( - handle, sources, degrees, destinations, - null, info.handle, reorder, false)); -} - -private native long createDistGraph( - long comm, int[] sources, int[] degrees, int[] destinations, - int[] weights, long info, boolean reorder, boolean weighted) - throws MPIException; - - -/** - * Creates a communicator to which the distributed graph topology - * information is attached. - *

Java binding of the MPI operation {@code MPI_DIST_GRAPH_CREATE_ADJACENT}. - *

The number of source/destination nodes is the size of the - * {@code sources}/{@code destinations} argument. - * @param sources ranks of processes for which the calling process - * is a destination - * @param sourceWeights weights of the edges into the calling process - * @param destinations ranks of processes for which the calling process - * is a source - * @param destWeights weights of the edges out of the calling process - * @param info hints on optimization and interpretation of weights - * @param reorder the process may be reordered (true) or not (false) - * @return communicator with distributed graph topology - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final GraphComm createDistGraphAdjacent( - int[] sources, int[] sourceWeights, - int[] destinations, int[] destWeights, Info info, boolean reorder) - throws MPIException -{ - MPI.check(); - - return new GraphComm(createDistGraphAdjacent( - handle, sources, sourceWeights, destinations, - destWeights, info.handle, reorder, true)); -} - -/** - * Creates a communicator to which the distributed graph topology - * information is attached. - *

Java binding of the MPI operation {@code MPI_DIST_GRAPH_CREATE_ADJACENT} - * using {@code MPI_UNWEIGHTED}. - *

The number of source/destination nodes is the size of the - * {@code sources}/{@code destinations} argument. - * @param sources ranks of processes for which the calling process - * is a destination - * @param destinations ranks of processes for which the calling process - * is a source - * @param info hints on optimization and interpretation of weights - * @param reorder the process may be reordered (true) or not (false) - * @return communicator with distributed graph topology - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final GraphComm createDistGraphAdjacent( - int[] sources, int[] destinations, Info info, boolean reorder) - throws MPIException -{ - MPI.check(); - - return new GraphComm(createDistGraphAdjacent( - handle, sources, null, destinations, null, - info.handle, reorder, false)); -} - -private native long createDistGraphAdjacent( - long comm, int[] sources, int []sourceweights, int[] destinations, - int[] distweights, long info, boolean reorder, boolean weighted) - throws MPIException; - - -/** - * Perform a prefix reduction on data distributed across the group. - *

Java binding of the MPI operation {@code MPI_SCAN}. - * @param sendbuf send buffer array - * @param recvbuf receive buffer array - * @param count number of items in input buffer - * @param type data type of each item in input buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void scan(Object sendbuf, Object recvbuf, - int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = type.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = type.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - op.setDatatype(type); - - scan(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, - count, type.handle, type.baseType, op, op.handle); -} - -/** - * Perform a prefix reduction on data distributed across the group. - *

Java binding of the MPI operation {@code MPI_SCAN} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param recvbuf receive buffer array - * @param count number of items in input buffer - * @param type data type of each item in input buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void scan(Object recvbuf, int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - int recvoff = 0; - boolean rdb = false; - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = type.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - op.setDatatype(type); - - scan(handle, null, false, 0, recvbuf, rdb, recvoff, - count, type.handle, type.baseType, op, op.handle); -} - -private native void scan( - long comm, Object sendbuf, boolean sdb, int sendoff, - Object recvbuf, boolean rdb, int recvoff, int count, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Perform a prefix reduction on data distributed across the group. - *

Java binding of the MPI operation {@code MPI_ISCAN}. - * @param sendbuf send buffer array - * @param recvbuf receive buffer array - * @param count number of items in input buffer - * @param type data type of each item in input buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iScan(Buffer sendbuf, Buffer recvbuf, - int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iScan(handle, sendbuf, recvbuf, count, - type.handle, type.baseType, op, op.handle)); -} - -/** - * Perform a prefix reduction on data distributed across the group. - *

Java binding of the MPI operation {@code MPI_ISCAN} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf send/receive buffer array - * @param count number of items in buffer - * @param type data type of each item in buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iScan(Buffer buf, int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - assertDirectBuffer(buf); - - return new Request(iScan( - handle, null, buf, count, - type.handle, type.baseType, op, op.handle)); -} - -private native long iScan( - long comm, Buffer sendbuf, Buffer recvbuf, int count, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Perform a prefix reduction on data distributed across the group. - *

Java binding of the MPI operation {@code MPI_EXSCAN}. - * @param sendbuf send buffer array - * @param recvbuf receive buffer array - * @param count number of items in input buffer - * @param type data type of each item in input buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void exScan(Object sendbuf, Object recvbuf, - int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - - int sendoff = 0, - recvoff = 0; - - boolean sdb = false, - rdb = false; - - if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) - { - sendoff = type.getOffset(sendbuf); - sendbuf = ((Buffer)sendbuf).array(); - } - - if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) - { - recvoff = type.getOffset(recvbuf); - recvbuf = ((Buffer)recvbuf).array(); - } - - op.setDatatype(type); - - exScan(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, - count, type.handle, type.baseType, op, op.handle); -} - -/** - * Perform a prefix reduction on data distributed across the group. - *

Java binding of the MPI operation {@code MPI_EXSCAN} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer array - * @param count number of items in input buffer - * @param type data type of each item in input buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void exScan(Object buf, int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } - - op.setDatatype(type); - - exScan(handle, null, false, 0, buf, db, off, count, - type.handle, type.baseType, op, op.handle); -} - -private native void exScan( - long comm, Object sendbuf, boolean sdb, int sendoff, - Object recvbuf, boolean rdb, int recvoff, int count, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Perform a prefix reduction on data distributed across the group. - *

Java binding of the MPI operation {@code MPI_IEXSCAN}. - * @param sendbuf send buffer array - * @param recvbuf receive buffer array - * @param count number of items in input buffer - * @param type data type of each item in input buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iExScan(Buffer sendbuf, Buffer recvbuf, - int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - assertDirectBuffer(sendbuf, recvbuf); - - return new Request(iExScan(handle, sendbuf, recvbuf, count, - type.handle, type.baseType, op, op.handle)); -} - -/** - * Perform a prefix reduction on data distributed across the group. - *

Java binding of the MPI operation {@code MPI_IEXSCAN} - * using {@code MPI_IN_PLACE} instead of the send buffer. - * @param buf receive buffer array - * @param count number of items in input buffer - * @param type data type of each item in input buffer - * @param op reduce operation - * @return communication request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request iExScan(Buffer buf, int count, Datatype type, Op op) - throws MPIException -{ - MPI.check(); - op.setDatatype(type); - assertDirectBuffer(buf); - - return new Request(iExScan( - handle, null, buf, count, - type.handle, type.baseType, op, op.handle)); -} - -private native long iExScan( - long comm, Buffer sendbuf, Buffer recvbuf, int count, - long type, int baseType, Op jOp, long hOp) throws MPIException; - -/** - * Java binding of {@code MPI_OPEN_PORT} using {@code MPI_INFO_NULL}. - * @return port name - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static String openPort() throws MPIException -{ - MPI.check(); - return openPort(Info.NULL); -} - -/** - * Java binding of {@code MPI_OPEN_PORT}. - * @param info implementation-specific information - * @return port name - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static String openPort(Info info) throws MPIException -{ - MPI.check(); - return openPort(info.handle); -} - -private native static String openPort(long info) throws MPIException; - -/** - * Java binding of {@code MPI_CLOSE_PORT}. - * @param name port name - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void closePort(String name) throws MPIException -{ - MPI.check(); - closePort_jni(name); -} - -private native static void closePort_jni(String name) throws MPIException; - -/** - * Java binding of {@code MPI_COMM_ACCEPT} using {@code MPI_INFO_NULL}. - * @param port port name - * @param root rank in comm of root node - * @return intercommunicator with client as remote group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intercomm accept(String port, int root) throws MPIException -{ - MPI.check(); - return new Intercomm(accept(handle, port, Info.NULL, root)); -} - -/** - * Java binding of {@code MPI_COMM_ACCEPT}. - * @param port port name - * @param info implementation-specific information - * @param root rank in comm of root node - * @return intercommunicator with client as remote group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intercomm accept(String port, Info info, int root) - throws MPIException -{ - MPI.check(); - return new Intercomm(accept(handle, port, info.handle, root)); -} - -private native long accept(long comm, String port, long info, int root) - throws MPIException; - -/** - * Java binding of {@code MPI_COMM_CONNECT} using {@code MPI_INFO_NULL}. - * @param port port name - * @param root rank in comm of root node - * @return intercommunicator with server as remote group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intercomm connect(String port, int root) throws MPIException -{ - MPI.check(); - return new Intercomm(connect(handle, port, Info.NULL, root)); -} - -/** - * Java binding of {@code MPI_COMM_CONNECT}. - * @param port port name - * @param info implementation-specific information - * @param root rank in comm of root node - * @return intercommunicator with server as remote group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intercomm connect(String port, Info info, int root) - throws MPIException -{ - MPI.check(); - return new Intercomm(connect(handle, port, info.handle, root)); -} - -private native long connect(long comm, String port, long info, int root) - throws MPIException; - -/** - * Java binding of {@code MPI_PUBLISH_NAME} using {@code MPI_INFO_NULL}. - * @param service service name - * @param port port name - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void publishName(String service, String port) - throws MPIException -{ - MPI.check(); - publishName(service, Info.NULL, port); -} - -/** - * Java binding of {@code MPI_PUBLISH_NAME}. - * @param service service name - * @param info implementation-specific information - * @param port port name - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void publishName(String service, Info info, String port) - throws MPIException -{ - MPI.check(); - publishName(service, info.handle, port); -} - -private native static void publishName(String service, long info, String port) - throws MPIException; - -/** - * Java binding of {@code MPI_UNPUBLISH_NAME} using {@code MPI_INFO_NULL}. - * @param service service name - * @param port port name - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void unpublishName(String service, String port) - throws MPIException -{ - MPI.check(); - unpublishName(service, Info.NULL, port); -} - -/** - * Java binding of {@code MPI_UNPUBLISH_NAME}. - * @param service service name - * @param info implementation-specific information - * @param port port name - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void unpublishName(String service, Info info, String port) - throws MPIException -{ - MPI.check(); - unpublishName(service, info.handle, port); -} - -private native static void unpublishName(String service, long info, String port) - throws MPIException; - -/** - * Java binding of {@code MPI_LOOKUP_NAME} using {@code MPI_INFO_NULL}. - * @param service service name - * @return port name - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static String lookupName(String service) throws MPIException -{ - MPI.check(); - return lookupName(service, Info.NULL); -} - -/** - * Java binding of {@code MPI_LOOKUP_NAME}. - * @param service service name - * @param info mplementation-specific information - * @return port name - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static String lookupName(String service, Info info) throws MPIException -{ - MPI.check(); - return lookupName(service, info.handle); -} - -private native static String lookupName(String service, long info) - throws MPIException; - -/** - * Java binding of {@code MPI_COMM_SPAWN}. - * This intracommunicator will contain the group of spawned processes. - * @param command name of program to be spawned - * @param argv arguments to command; if this parameter is null, - * {@code MPI_ARGV_NULL} will be used. - * @param maxprocs maximum number of processes to start - * @param info info object telling the runtime where - * and how to start the processes - * @param root rank of process in which previous arguments are examined - * @param errcodes one code per process; if this parameter is null, - * {@code MPI_ERRCODES_IGNORE} will be used. - * @return intercommunicator between original group and the newly spawned group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intercomm spawn(String command, String[] argv, int maxprocs, - Info info, int root, int[] errcodes) - throws MPIException -{ - MPI.check(); - - return new Intercomm(spawn(handle, command, argv, maxprocs, - info.handle, root, errcodes)); -} - -private native long spawn(long comm, String command, String[] argv, - int maxprocs, long info, int root, int[] errcodes) - throws MPIException; - -/** - * Java binding of {@code MPI_COMM_SPAWN_MULTIPLE}. - * This intracommunicator will contain the group of spawned processes. - * @param commands programs to be executed - * @param argv arguments for commands; if this parameter is null, - * {@code MPI_ARGVS_NULL} will be used. - * @param maxprocs maximum number of processes to start for each command - * @param info info objects telling the runtime where - * and how to start the processes - * @param root rank of process in which previous arguments are examined - * @param errcodes one code per process; if this parameter is null, - * {@code MPI_ERRCODES_IGNORE} will be used. - * @return intercommunicator between original group and the newly spawned group - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Intercomm spawnMultiple( - String[] commands, String[][] argv, int[] maxprocs, - Info[] info, int root, int[] errcodes) - throws MPIException -{ - MPI.check(); - - long hInfo[] = new long[info.length]; - - for(int i = 0; i < info.length; i++) - hInfo[i] = info[i].handle; - - return new Intercomm(spawnMultiple(handle, commands, argv, maxprocs, - hInfo, root, errcodes)); -} - -private native long spawnMultiple( - long comm, String[] commands, String[][] argv, int[] maxprocs, - long[] info, int root, int[] errcodes) throws MPIException; + protected Intracomm() + { + } + + protected Intracomm(long handle) + { + super(handle); + } + + protected Intracomm(long[] commRequest) + { + super(commRequest); + } + + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + *

It is recommended to use {@link #dup} instead of {@link #clone} + * because the last can't throw an {@link mpi.MPIException}. + * @return copy of this communicator + */ + @Override public Intracomm clone() + { + try + { + return dup(); + } + catch(MPIException e) + { + throw new RuntimeException(e.getMessage()); + } + } + + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_DUP}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public Intracomm dup() throws MPIException + { + MPI.check(); + return new Intracomm(dup(handle)); + } + + /** + * Duplicates this communicator. + *

Java binding of {@code MPI_COMM_IDUP}. + *

The new communicator can't be used before the operation completes. + * The request object must be obtained calling {@link #getRequest}. + * @return copy of this communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public Intracomm iDup() throws MPIException + { + MPI.check(); + return new Intracomm(iDup(handle)); + } + + /** + * Partition the group associated with this communicator and create + * a new communicator within each subgroup. + *

Java binding of the MPI operation {@code MPI_COMM_SPLIT}. + * @param colour control of subset assignment + * @param key control of rank assignment + * @return new communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intracomm split(int colour, int key) throws MPIException + { + MPI.check(); + return new Intracomm(split(handle, colour, key)); + } + + private native long split(long comm, int colour, int key) throws MPIException; + + /** + * Partition the group associated with this communicator and create + * a new communicator within each subgroup. + *

Java binding of the MPI operation {@code MPI_COMM_SPLIT_TYPE}. + * @param splitType type of processes to be grouped together + * @param key control of rank assignment + * @param info info argument + * @return new communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intracomm splitType(int splitType, int key, Info info) throws MPIException + { + MPI.check(); + return new Intracomm(splitType(handle, splitType, key, info.handle)); + } + + private native long splitType(long comm, int colour, int key, long info) throws MPIException; + + /** + * Create a new communicator. + *

Java binding of the MPI operation {@code MPI_COMM_CREATE}. + * @param group group which is a subset of the group of this communicator + * @return new communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intracomm create(Group group) throws MPIException + { + MPI.check(); + return new Intracomm(create(handle, group.handle)); + } + + private native long create(long comm, long group); + + // Topology Constructors + + /** + * Creates a communicator to which the Cartesian topology + * information is attached. + * Create a cartesian topology communicator whose group is a subset + * of the group of this communicator. + *

Java binding of the MPI operation {@code MPI_CART_CREATE}. + *

The number of dimensions of the Cartesian grid is taken to be the + * size of the {@code dims} argument. The array {@code periods} must + * be the same size. + * @param dims the number of processes in each dimension + * @param periods {@code true} if grid is periodic, + * {@code false} if not, in each dimension + * @param reorder {@code true} if ranking may be reordered, + * {@code false} if not + * @return new cartesian topology communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final CartComm createCart(int[] dims, boolean[] periods, boolean reorder) + throws MPIException + { + MPI.check(); + return new CartComm(createCart(handle, dims, periods, reorder)); + } + + private native long createCart( + long comm, int[] dims, boolean[] periods, boolean reorder) + throws MPIException; + + /** + * Creates a communicator to which the graph topology information is attached. + *

Java binding of the MPI operation {@code MPI_GRAPH_CREATE}. + *

The number of nodes in the graph, nnodes, is taken + * to be size of the {@code index} argument. + * @param index node degrees + * @param edges graph edges + * @param reorder {@code true} if ranking may be reordered, + * {@code false} if not + * @return new graph topology communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final GraphComm createGraph(int[] index, int[] edges, boolean reorder) + throws MPIException + { + MPI.check(); + return new GraphComm(createGraph(handle, index, edges, reorder)); + } + + private native long createGraph( + long comm, int[] index, int[] edges, boolean reorder) + throws MPIException; + + /** + * Creates a communicator to which the distributed graph topology + * information is attached. + *

Java binding of the MPI operation {@code MPI_DIST_GRAPH_CREATE}. + *

The number of source nodes is the size of the {@code sources} argument. + * @param sources source nodes for which this process specifies edges + * @param degrees number of destinations for each source node + * @param destinations destination nodes for the source nodes + * @param weights weights for source to destination edges + * @param info hints on optimization and interpretation of weights + * @param reorder the process may be reordered (true) or not (false) + * @return communicator with distributed graph topology + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final GraphComm createDistGraph( + int[] sources, int[] degrees, int[] destinations, + int[] weights, Info info, boolean reorder) + throws MPIException + { + MPI.check(); + + return new GraphComm(createDistGraph( + handle, sources, degrees, destinations, + weights, info.handle, reorder, true)); + } + + /** + * Creates a communicator to which the distributed graph topology + * information is attached. + *

Java binding of the MPI operation {@code MPI_DIST_GRAPH_CREATE} + * using {@code MPI_UNWEIGHTED}. + *

The number of source nodes is the size of the {@code sources} argument. + * @param sources source nodes for which this process specifies edges + * @param degrees number of destinations for each source node + * @param destinations destination nodes for the source nodes + * @param info hints on optimization and interpretation of weights + * @param reorder the process may be reordered (true) or not (false) + * @return communicator with distributed graph topology + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final GraphComm createDistGraph( + int[] sources, int[] degrees, int[] destinations, + Info info, boolean reorder) + throws MPIException + { + MPI.check(); + + return new GraphComm(createDistGraph( + handle, sources, degrees, destinations, + null, info.handle, reorder, false)); + } + + private native long createDistGraph( + long comm, int[] sources, int[] degrees, int[] destinations, + int[] weights, long info, boolean reorder, boolean weighted) + throws MPIException; + + + /** + * Creates a communicator to which the distributed graph topology + * information is attached. + *

Java binding of the MPI operation {@code MPI_DIST_GRAPH_CREATE_ADJACENT}. + *

The number of source/destination nodes is the size of the + * {@code sources}/{@code destinations} argument. + * @param sources ranks of processes for which the calling process + * is a destination + * @param sourceWeights weights of the edges into the calling process + * @param destinations ranks of processes for which the calling process + * is a source + * @param destWeights weights of the edges out of the calling process + * @param info hints on optimization and interpretation of weights + * @param reorder the process may be reordered (true) or not (false) + * @return communicator with distributed graph topology + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final GraphComm createDistGraphAdjacent( + int[] sources, int[] sourceWeights, + int[] destinations, int[] destWeights, Info info, boolean reorder) + throws MPIException + { + MPI.check(); + + return new GraphComm(createDistGraphAdjacent( + handle, sources, sourceWeights, destinations, + destWeights, info.handle, reorder, true)); + } + + /** + * Creates a communicator to which the distributed graph topology + * information is attached. + *

Java binding of the MPI operation {@code MPI_DIST_GRAPH_CREATE_ADJACENT} + * using {@code MPI_UNWEIGHTED}. + *

The number of source/destination nodes is the size of the + * {@code sources}/{@code destinations} argument. + * @param sources ranks of processes for which the calling process + * is a destination + * @param destinations ranks of processes for which the calling process + * is a source + * @param info hints on optimization and interpretation of weights + * @param reorder the process may be reordered (true) or not (false) + * @return communicator with distributed graph topology + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final GraphComm createDistGraphAdjacent( + int[] sources, int[] destinations, Info info, boolean reorder) + throws MPIException + { + MPI.check(); + + return new GraphComm(createDistGraphAdjacent( + handle, sources, null, destinations, null, + info.handle, reorder, false)); + } + + private native long createDistGraphAdjacent( + long comm, int[] sources, int []sourceweights, int[] destinations, + int[] distweights, long info, boolean reorder, boolean weighted) + throws MPIException; + + + /** + * Perform a prefix reduction on data distributed across the group. + *

Java binding of the MPI operation {@code MPI_SCAN}. + * @param sendbuf send buffer array + * @param recvbuf receive buffer array + * @param count number of items in input buffer + * @param type data type of each item in input buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void scan(Object sendbuf, Object recvbuf, + int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = type.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = type.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + op.setDatatype(type); + + scan(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, + count, type.handle, type.baseType, op, op.handle); + } + + /** + * Perform a prefix reduction on data distributed across the group. + *

Java binding of the MPI operation {@code MPI_SCAN} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param recvbuf receive buffer array + * @param count number of items in input buffer + * @param type data type of each item in input buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void scan(Object recvbuf, int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + int recvoff = 0; + boolean rdb = false; + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = type.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + op.setDatatype(type); + + scan(handle, null, false, 0, recvbuf, rdb, recvoff, + count, type.handle, type.baseType, op, op.handle); + } + + private native void scan( + long comm, Object sendbuf, boolean sdb, int sendoff, + Object recvbuf, boolean rdb, int recvoff, int count, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Perform a prefix reduction on data distributed across the group. + *

Java binding of the MPI operation {@code MPI_ISCAN}. + * @param sendbuf send buffer array + * @param recvbuf receive buffer array + * @param count number of items in input buffer + * @param type data type of each item in input buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iScan(Buffer sendbuf, Buffer recvbuf, + int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iScan(handle, sendbuf, recvbuf, count, + type.handle, type.baseType, op, op.handle)); + } + + /** + * Perform a prefix reduction on data distributed across the group. + *

Java binding of the MPI operation {@code MPI_ISCAN} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf send/receive buffer array + * @param count number of items in buffer + * @param type data type of each item in buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iScan(Buffer buf, int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + assertDirectBuffer(buf); + + return new Request(iScan( + handle, null, buf, count, + type.handle, type.baseType, op, op.handle)); + } + + private native long iScan( + long comm, Buffer sendbuf, Buffer recvbuf, int count, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Perform a prefix reduction on data distributed across the group. + *

Java binding of the MPI operation {@code MPI_EXSCAN}. + * @param sendbuf send buffer array + * @param recvbuf receive buffer array + * @param count number of items in input buffer + * @param type data type of each item in input buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void exScan(Object sendbuf, Object recvbuf, + int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + + int sendoff = 0, + recvoff = 0; + + boolean sdb = false, + rdb = false; + + if(sendbuf instanceof Buffer && !(sdb = ((Buffer)sendbuf).isDirect())) + { + sendoff = type.getOffset(sendbuf); + sendbuf = ((Buffer)sendbuf).array(); + } + + if(recvbuf instanceof Buffer && !(rdb = ((Buffer)recvbuf).isDirect())) + { + recvoff = type.getOffset(recvbuf); + recvbuf = ((Buffer)recvbuf).array(); + } + + op.setDatatype(type); + + exScan(handle, sendbuf, sdb, sendoff, recvbuf, rdb, recvoff, + count, type.handle, type.baseType, op, op.handle); + } + + /** + * Perform a prefix reduction on data distributed across the group. + *

Java binding of the MPI operation {@code MPI_EXSCAN} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer array + * @param count number of items in input buffer + * @param type data type of each item in input buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void exScan(Object buf, int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } + + op.setDatatype(type); + + exScan(handle, null, false, 0, buf, db, off, count, + type.handle, type.baseType, op, op.handle); + } + + private native void exScan( + long comm, Object sendbuf, boolean sdb, int sendoff, + Object recvbuf, boolean rdb, int recvoff, int count, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Perform a prefix reduction on data distributed across the group. + *

Java binding of the MPI operation {@code MPI_IEXSCAN}. + * @param sendbuf send buffer array + * @param recvbuf receive buffer array + * @param count number of items in input buffer + * @param type data type of each item in input buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iExScan(Buffer sendbuf, Buffer recvbuf, + int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + assertDirectBuffer(sendbuf, recvbuf); + + return new Request(iExScan(handle, sendbuf, recvbuf, count, + type.handle, type.baseType, op, op.handle)); + } + + /** + * Perform a prefix reduction on data distributed across the group. + *

Java binding of the MPI operation {@code MPI_IEXSCAN} + * using {@code MPI_IN_PLACE} instead of the send buffer. + * @param buf receive buffer array + * @param count number of items in input buffer + * @param type data type of each item in input buffer + * @param op reduce operation + * @return communication request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request iExScan(Buffer buf, int count, Datatype type, Op op) + throws MPIException + { + MPI.check(); + op.setDatatype(type); + assertDirectBuffer(buf); + + return new Request(iExScan( + handle, null, buf, count, + type.handle, type.baseType, op, op.handle)); + } + + private native long iExScan( + long comm, Buffer sendbuf, Buffer recvbuf, int count, + long type, int baseType, Op jOp, long hOp) throws MPIException; + + /** + * Java binding of {@code MPI_OPEN_PORT} using {@code MPI_INFO_NULL}. + * @return port name + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static String openPort() throws MPIException + { + MPI.check(); + return openPort(Info.NULL); + } + + /** + * Java binding of {@code MPI_OPEN_PORT}. + * @param info implementation-specific information + * @return port name + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static String openPort(Info info) throws MPIException + { + MPI.check(); + return openPort(info.handle); + } + + private native static String openPort(long info) throws MPIException; + + /** + * Java binding of {@code MPI_CLOSE_PORT}. + * @param name port name + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void closePort(String name) throws MPIException + { + MPI.check(); + closePort_jni(name); + } + + private native static void closePort_jni(String name) throws MPIException; + + /** + * Java binding of {@code MPI_COMM_ACCEPT} using {@code MPI_INFO_NULL}. + * @param port port name + * @param root rank in comm of root node + * @return intercommunicator with client as remote group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intercomm accept(String port, int root) throws MPIException + { + MPI.check(); + return new Intercomm(accept(handle, port, Info.NULL, root)); + } + + /** + * Java binding of {@code MPI_COMM_ACCEPT}. + * @param port port name + * @param info implementation-specific information + * @param root rank in comm of root node + * @return intercommunicator with client as remote group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intercomm accept(String port, Info info, int root) + throws MPIException + { + MPI.check(); + return new Intercomm(accept(handle, port, info.handle, root)); + } + + private native long accept(long comm, String port, long info, int root) + throws MPIException; + + /** + * Java binding of {@code MPI_COMM_CONNECT} using {@code MPI_INFO_NULL}. + * @param port port name + * @param root rank in comm of root node + * @return intercommunicator with server as remote group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intercomm connect(String port, int root) throws MPIException + { + MPI.check(); + return new Intercomm(connect(handle, port, Info.NULL, root)); + } + + /** + * Java binding of {@code MPI_COMM_CONNECT}. + * @param port port name + * @param info implementation-specific information + * @param root rank in comm of root node + * @return intercommunicator with server as remote group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intercomm connect(String port, Info info, int root) + throws MPIException + { + MPI.check(); + return new Intercomm(connect(handle, port, info.handle, root)); + } + + private native long connect(long comm, String port, long info, int root) + throws MPIException; + + /** + * Java binding of {@code MPI_PUBLISH_NAME} using {@code MPI_INFO_NULL}. + * @param service service name + * @param port port name + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void publishName(String service, String port) + throws MPIException + { + MPI.check(); + publishName(service, Info.NULL, port); + } + + /** + * Java binding of {@code MPI_PUBLISH_NAME}. + * @param service service name + * @param info implementation-specific information + * @param port port name + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void publishName(String service, Info info, String port) + throws MPIException + { + MPI.check(); + publishName(service, info.handle, port); + } + + private native static void publishName(String service, long info, String port) + throws MPIException; + + /** + * Java binding of {@code MPI_UNPUBLISH_NAME} using {@code MPI_INFO_NULL}. + * @param service service name + * @param port port name + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void unpublishName(String service, String port) + throws MPIException + { + MPI.check(); + unpublishName(service, Info.NULL, port); + } + + /** + * Java binding of {@code MPI_UNPUBLISH_NAME}. + * @param service service name + * @param info implementation-specific information + * @param port port name + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void unpublishName(String service, Info info, String port) + throws MPIException + { + MPI.check(); + unpublishName(service, info.handle, port); + } + + private native static void unpublishName(String service, long info, String port) + throws MPIException; + + /** + * Java binding of {@code MPI_LOOKUP_NAME} using {@code MPI_INFO_NULL}. + * @param service service name + * @return port name + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static String lookupName(String service) throws MPIException + { + MPI.check(); + return lookupName(service, Info.NULL); + } + + /** + * Java binding of {@code MPI_LOOKUP_NAME}. + * @param service service name + * @param info mplementation-specific information + * @return port name + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static String lookupName(String service, Info info) throws MPIException + { + MPI.check(); + return lookupName(service, info.handle); + } + + private native static String lookupName(String service, long info) + throws MPIException; + + /** + * Java binding of {@code MPI_COMM_SPAWN}. + * This intracommunicator will contain the group of spawned processes. + * @param command name of program to be spawned + * @param argv arguments to command; if this parameter is null, + * {@code MPI_ARGV_NULL} will be used. + * @param maxprocs maximum number of processes to start + * @param info info object telling the runtime where + * and how to start the processes + * @param root rank of process in which previous arguments are examined + * @param errcodes one code per process; if this parameter is null, + * {@code MPI_ERRCODES_IGNORE} will be used. + * @return intercommunicator between original group and the newly spawned group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intercomm spawn(String command, String[] argv, int maxprocs, + Info info, int root, int[] errcodes) + throws MPIException + { + MPI.check(); + + return new Intercomm(spawn(handle, command, argv, maxprocs, + info.handle, root, errcodes)); + } + + private native long spawn(long comm, String command, String[] argv, + int maxprocs, long info, int root, int[] errcodes) + throws MPIException; + + /** + * Java binding of {@code MPI_COMM_SPAWN_MULTIPLE}. + * This intracommunicator will contain the group of spawned processes. + * @param commands programs to be executed + * @param argv arguments for commands; if this parameter is null, + * {@code MPI_ARGVS_NULL} will be used. + * @param maxprocs maximum number of processes to start for each command + * @param info info objects telling the runtime where + * and how to start the processes + * @param root rank of process in which previous arguments are examined + * @param errcodes one code per process; if this parameter is null, + * {@code MPI_ERRCODES_IGNORE} will be used. + * @return intercommunicator between original group and the newly spawned group + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Intercomm spawnMultiple( + String[] commands, String[][] argv, int[] maxprocs, + Info[] info, int root, int[] errcodes) + throws MPIException + { + MPI.check(); + + long hInfo[] = new long[info.length]; + + for(int i = 0; i < info.length; i++) + hInfo[i] = info[i].handle; + + return new Intercomm(spawnMultiple(handle, commands, argv, maxprocs, + hInfo, root, errcodes)); + } + + private native long spawnMultiple( + long comm, String[] commands, String[][] argv, int[] maxprocs, + long[] info, int root, int[] errcodes) throws MPIException; } // Intracomm diff --git a/ompi/mpi/java/java/LongInt.java b/ompi/mpi/java/java/LongInt.java index 0e7b79c0e0..2d9a9143f3 100644 --- a/ompi/mpi/java/java/LongInt.java +++ b/ompi/mpi/java/java/LongInt.java @@ -25,110 +25,110 @@ package mpi; */ public final class LongInt extends Struct { -private final int lSize, iOff, iSize; + private final int lSize, iOff, iSize; -/** - * The struct object will be created only in MPI class. - * @param longSize size of long - * @param intOff int offset - * @param intSize int size - * @see MPI#longInt - */ -protected LongInt(int longSize, int intOff, int intSize) -{ - lSize = longSize; - iSize = intSize; - int lOff; + /** + * The struct object will be created only in MPI class. + * @param longSize size of long + * @param intOff int offset + * @param intSize int size + * @see MPI#longInt + */ + protected LongInt(int longSize, int intOff, int intSize) + { + lSize = longSize; + iSize = intSize; + int lOff; - switch(lSize) - { - case 4: lOff = addInt(); break; - case 8: lOff = addLong(); break; - default: throw new AssertionError("Unsupported long size: "+ lSize); - } + switch(lSize) + { + case 4: lOff = addInt(); break; + case 8: lOff = addLong(); break; + default: throw new AssertionError("Unsupported long size: "+ lSize); + } - assert lOff == 0; - setOffset(intOff); + assert lOff == 0; + setOffset(intOff); - switch(iSize) - { - case 4: iOff = addInt(); break; - case 8: iOff = addLong(); break; - default: throw new AssertionError("Unsupported int size: "+ iSize); - } + switch(iSize) + { + case 4: iOff = addInt(); break; + case 8: iOff = addLong(); break; + default: throw new AssertionError("Unsupported int size: "+ iSize); + } - assert(intOff == iOff); -} + assert(intOff == iOff); + } -/** - * Creates a Data object. - * @return new Data object. - */ -@Override protected LongInt.Data newData() -{ - return new LongInt.Data(); -} + /** + * Creates a Data object. + * @return new Data object. + */ + @Override protected LongInt.Data newData() + { + return new LongInt.Data(); + } -/** - * Class for reading/writing data in a struct stored in a byte buffer. - */ -public final class Data extends Struct.Data -{ - /** - * Gets the long value. - * @return long value - */ - public long getValue() - { - switch(lSize) - { - case 8: return getLong(0); - case 4: return getInt(0); - default: throw new AssertionError(); - } - } + /** + * Class for reading/writing data in a struct stored in a byte buffer. + */ + public final class Data extends Struct.Data + { + /** + * Gets the long value. + * @return long value + */ + public long getValue() + { + switch(lSize) + { + case 8: return getLong(0); + case 4: return getInt(0); + default: throw new AssertionError(); + } + } - /** - * Gets the int value. - * @return int value - */ - public int getIndex() - { - switch(iSize) - { - case 4: return getInt(iOff); - case 8: return (int)getLong(iOff); - default: throw new AssertionError(); - } - } + /** + * Gets the int value. + * @return int value + */ + public int getIndex() + { + switch(iSize) + { + case 4: return getInt(iOff); + case 8: return (int)getLong(iOff); + default: throw new AssertionError(); + } + } - /** - * Puts the long value. - * @param v long value - */ - public void putValue(long v) - { - switch(lSize) - { - case 8: putLong(0, v); break; - case 4: putInt(0, (int)v); break; - default: throw new AssertionError(); - } - } + /** + * Puts the long value. + * @param v long value + */ + public void putValue(long v) + { + switch(lSize) + { + case 8: putLong(0, v); break; + case 4: putInt(0, (int)v); break; + default: throw new AssertionError(); + } + } - /** - * Puts the int value. - * @param v int value - */ - public void putIndex(int v) - { - switch(iSize) - { - case 4: putInt(iOff, v); break; - case 8: putLong(iOff, v); break; - default: throw new AssertionError(); - } - } -} // Data + /** + * Puts the int value. + * @param v int value + */ + public void putIndex(int v) + { + switch(iSize) + { + case 4: putInt(iOff, v); break; + case 8: putLong(iOff, v); break; + default: throw new AssertionError(); + } + } + } // Data } // LongInt diff --git a/ompi/mpi/java/java/MPI.java b/ompi/mpi/java/java/MPI.java index d8a4ba1243..e0b63673c8 100644 --- a/ompi/mpi/java/java/MPI.java +++ b/ompi/mpi/java/java/MPI.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : MPI.java * Author : Sang Lim, Sung-Hoon Ko, Xinying Li, Bryan Carpenter * (contributions from MAEDA Atusi) @@ -56,947 +56,1865 @@ import java.nio.*; */ public final class MPI { -private static boolean initialized, finalized; -private static byte[] buffer = null; // Buffer allocation -private static final int MAX_PROCESSOR_NAME = 256; -private static final ByteOrder nativeOrder = ByteOrder.nativeOrder(); - -public static final Intracomm COMM_WORLD, COMM_SELF; - -public static final int THREAD_SINGLE, THREAD_FUNNELED, THREAD_SERIALIZED, - THREAD_MULTIPLE; - -public static final int GRAPH, DIST_GRAPH, CART; -public static final int ANY_SOURCE, ANY_TAG; - -public static final Op MAX, MIN, SUM, PROD, LAND, BAND, - LOR, BOR, LXOR, BXOR, REPLACE, NO_OP; - -/** - * Global minimum operator. - *

{@code MINLOC} and {@link #MAXLOC} can be used with each of the following - * datatypes: {@link #INT2}, {@link #SHORT_INT}, {@link #LONG_INT}, - * {@link #FLOAT_INT} and {@link #DOUBLE_INT}. - */ -public static final Op MINLOC; - -/** Global maximum operator. See {@link #MINLOC}.*/ -public static final Op MAXLOC; - -public static final Datatype DATATYPE_NULL; - -public static final Datatype BYTE, CHAR, SHORT, BOOLEAN, - INT, LONG, FLOAT, DOUBLE, PACKED, - FLOAT_COMPLEX, DOUBLE_COMPLEX; - -/** Struct which must be used with {@link #int2}. */ -public static final Datatype INT2; -/** Struct which must be used with {@link #shortInt}. */ -public static final Datatype SHORT_INT; -/** Struct which must be used with {@link #longInt}. */ -public static final Datatype LONG_INT; -/** Struct which must be used with {@link #floatInt}. */ -public static final Datatype FLOAT_INT; -/** Struct which must be used with {@link #doubleInt}. */ -public static final Datatype DOUBLE_INT; - -/** Struct object for {@link #INT2} datatype. */ -public static final Int2 int2; -/** Struct object for {@link #SHORT_INT} datatype. */ -public static final ShortInt shortInt; -/** Struct object for {@link #LONG_INT} datatype. */ -public static final LongInt longInt; -/** Struct object for {@link #FLOAT_INT} datatype. */ -public static final FloatInt floatInt; -/** Struct object for {@link #DOUBLE_INT} datatype. */ -public static final DoubleInt doubleInt; - -public static final Request REQUEST_NULL; -public static final Group GROUP_EMPTY; -public static final Info INFO_ENV, INFO_NULL; - -public static final int PROC_NULL; -public static final int UNDEFINED; -public static final int IDENT, CONGRUENT, SIMILAR, UNEQUAL; -public static final int TAG_UB, HOST, IO, WTIME_IS_GLOBAL; - -public static final int APPNUM, LASTUSEDCODE, UNIVERSE_SIZE, WIN_BASE, - WIN_SIZE, WIN_DISP_UNIT; - -public static final int VERSION, SUBVERSION; -public static final int ROOT, KEYVAL_INVALID, BSEND_OVERHEAD; -public static final int MAX_OBJECT_NAME, MAX_PORT_NAME, MAX_DATAREP_STRING; -public static final int MAX_INFO_KEY, MAX_INFO_VAL; -public static final int ORDER_C, ORDER_FORTRAN; -public static final int DISTRIBUTE_BLOCK, DISTRIBUTE_CYCLIC, DISTRIBUTE_NONE, - DISTRIBUTE_DFLT_DARG; - -public static final int MODE_CREATE, MODE_RDONLY, MODE_WRONLY, MODE_RDWR, - MODE_DELETE_ON_CLOSE, MODE_UNIQUE_OPEN, MODE_EXCL, - MODE_APPEND, MODE_SEQUENTIAL; -public static final int DISPLACEMENT_CURRENT; -public static final int SEEK_SET, SEEK_CUR, SEEK_END; - -public static final int MODE_NOCHECK, MODE_NOPRECEDE, MODE_NOPUT, - MODE_NOSTORE, MODE_NOSUCCEED; -public static final int LOCK_EXCLUSIVE, LOCK_SHARED; - -public static final Errhandler ERRORS_ARE_FATAL, ERRORS_RETURN; - -// Error classes and codes -public static final int SUCCESS; -public static final int ERR_BUFFER; -public static final int ERR_COUNT; -public static final int ERR_TYPE; -public static final int ERR_TAG; -public static final int ERR_COMM; -public static final int ERR_RANK; -public static final int ERR_REQUEST; -public static final int ERR_ROOT; -public static final int ERR_GROUP; -public static final int ERR_OP; -public static final int ERR_TOPOLOGY; -public static final int ERR_DIMS; -public static final int ERR_ARG; -public static final int ERR_UNKNOWN; -public static final int ERR_TRUNCATE; -public static final int ERR_OTHER; -public static final int ERR_INTERN; -public static final int ERR_IN_STATUS; -public static final int ERR_PENDING; -public static final int ERR_ACCESS; -public static final int ERR_AMODE; -public static final int ERR_ASSERT; -public static final int ERR_BAD_FILE; -public static final int ERR_BASE; -public static final int ERR_CONVERSION; -public static final int ERR_DISP; -public static final int ERR_DUP_DATAREP; -public static final int ERR_FILE_EXISTS; -public static final int ERR_FILE_IN_USE; -public static final int ERR_FILE; -public static final int ERR_INFO_KEY; -public static final int ERR_INFO_NOKEY; -public static final int ERR_INFO_VALUE; -public static final int ERR_INFO; -public static final int ERR_IO; -public static final int ERR_KEYVAL; -public static final int ERR_LOCKTYPE; -public static final int ERR_NAME; -public static final int ERR_NO_MEM; -public static final int ERR_NOT_SAME; -public static final int ERR_NO_SPACE; -public static final int ERR_NO_SUCH_FILE; -public static final int ERR_PORT; -public static final int ERR_QUOTA; -public static final int ERR_READ_ONLY; -public static final int ERR_RMA_CONFLICT; -public static final int ERR_RMA_SYNC; -public static final int ERR_SERVICE; -public static final int ERR_SIZE; -public static final int ERR_SPAWN; -public static final int ERR_UNSUPPORTED_DATAREP; -public static final int ERR_UNSUPPORTED_OPERATION; -public static final int ERR_WIN; -public static final int ERR_LASTCODE; -public static final int ERR_SYSRESOURCE; - -static -{ - System.loadLibrary("mpi_java"); - - DATATYPE_NULL = new Datatype(); - - BYTE = new Datatype(); - CHAR = new Datatype(); - SHORT = new Datatype(); - BOOLEAN = new Datatype(); - INT = new Datatype(); - LONG = new Datatype(); - FLOAT = new Datatype(); - DOUBLE = new Datatype(); - PACKED = new Datatype(); - INT2 = new Datatype(); - - SHORT_INT = new Datatype(); - LONG_INT = new Datatype(); - FLOAT_INT = new Datatype(); - DOUBLE_INT = new Datatype(); - FLOAT_COMPLEX = new Datatype(); - DOUBLE_COMPLEX = new Datatype(); - - int2 = newInt2(); - shortInt = newShortInt(); - longInt = newLongInt(); - floatInt = newFloatInt(); - doubleInt = newDoubleInt(); - - MAX = new Op(1); - MIN = new Op(2); - SUM = new Op(3); - PROD = new Op(4); - LAND = new Op(5); - BAND = new Op(6); - LOR = new Op(7); - BOR = new Op(8); - LXOR = new Op(9); - BXOR = new Op(10); - MINLOC = new Op(11); - MAXLOC = new Op(12); - REPLACE = new Op(13); - NO_OP = new Op(14); - - GROUP_EMPTY = new Group(Group.getEmpty()); - REQUEST_NULL = new Request(Request.getNull()); - INFO_ENV = Info.newEnv(); - INFO_NULL = new Info(Info.NULL); - - Constant c = new Constant(); - - THREAD_SINGLE = c.THREAD_SINGLE; - THREAD_FUNNELED = c.THREAD_FUNNELED; - THREAD_SERIALIZED = c.THREAD_SERIALIZED; - THREAD_MULTIPLE = c.THREAD_MULTIPLE; - - GRAPH = c.GRAPH; - DIST_GRAPH = c.DIST_GRAPH; - CART = c.CART; - - ANY_SOURCE = c.ANY_SOURCE; - ANY_TAG = c.ANY_TAG; - PROC_NULL = c.PROC_NULL; - - UNDEFINED = c.UNDEFINED; - - IDENT = c.IDENT; - CONGRUENT = c.CONGRUENT; - SIMILAR = c.SIMILAR; - UNEQUAL = c.UNEQUAL; - - TAG_UB = c.TAG_UB; - HOST = c.HOST; - IO = c.IO; - WTIME_IS_GLOBAL = c.WTIME_IS_GLOBAL; - - APPNUM = c.APPNUM; - LASTUSEDCODE = c.LASTUSEDCODE; - UNIVERSE_SIZE = c.UNIVERSE_SIZE; - WIN_BASE = c.WIN_BASE; - WIN_SIZE = c.WIN_SIZE; - WIN_DISP_UNIT = c.WIN_DISP_UNIT; - - VERSION = c.VERSION; - SUBVERSION = c.SUBVERSION; - - ROOT = c.ROOT; - KEYVAL_INVALID = c.KEYVAL_INVALID; - BSEND_OVERHEAD = c.BSEND_OVERHEAD; - - MAX_OBJECT_NAME = c.MAX_OBJECT_NAME; - MAX_PORT_NAME = c.MAX_PORT_NAME; - MAX_DATAREP_STRING = c.MAX_DATAREP_STRING; - - MAX_INFO_KEY = c.MAX_INFO_KEY; - MAX_INFO_VAL = c.MAX_INFO_VAL; - - ORDER_C = c.ORDER_C; - ORDER_FORTRAN = c.ORDER_FORTRAN; - - DISTRIBUTE_BLOCK = c.DISTRIBUTE_BLOCK; - DISTRIBUTE_CYCLIC = c.DISTRIBUTE_CYCLIC; - DISTRIBUTE_NONE = c.DISTRIBUTE_NONE; - DISTRIBUTE_DFLT_DARG = c.DISTRIBUTE_DFLT_DARG; - - MODE_CREATE = c.MODE_CREATE; - MODE_RDONLY = c.MODE_RDONLY; - MODE_WRONLY = c.MODE_WRONLY; - MODE_RDWR = c.MODE_RDWR; - MODE_DELETE_ON_CLOSE = c.MODE_DELETE_ON_CLOSE; - MODE_UNIQUE_OPEN = c.MODE_UNIQUE_OPEN; - MODE_EXCL = c.MODE_EXCL; - MODE_APPEND = c.MODE_APPEND; - MODE_SEQUENTIAL = c.MODE_SEQUENTIAL; - - DISPLACEMENT_CURRENT = c.DISPLACEMENT_CURRENT; - - SEEK_SET = c.SEEK_SET; - SEEK_CUR = c.SEEK_CUR; - SEEK_END = c.SEEK_END; - - MODE_NOCHECK = c.MODE_NOCHECK; - MODE_NOPRECEDE = c.MODE_NOPRECEDE; - MODE_NOPUT = c.MODE_NOPUT; - MODE_NOSTORE = c.MODE_NOSTORE; - MODE_NOSUCCEED = c.MODE_NOSUCCEED; - LOCK_EXCLUSIVE = c.LOCK_EXCLUSIVE; - LOCK_SHARED = c.LOCK_SHARED; - - ERRORS_ARE_FATAL = new Errhandler(Errhandler.getFatal()); - ERRORS_RETURN = new Errhandler(Errhandler.getReturn()); - - COMM_WORLD = new Intracomm(); - COMM_SELF = new Intracomm(); - - // Error classes and codes - SUCCESS = c.SUCCESS; - ERR_BUFFER = c.ERR_BUFFER; - ERR_COUNT = c.ERR_COUNT; - ERR_TYPE = c.ERR_TYPE; - ERR_TAG = c.ERR_TAG; - ERR_COMM = c.ERR_COMM; - ERR_RANK = c.ERR_RANK; - ERR_REQUEST = c.ERR_REQUEST; - ERR_ROOT = c.ERR_ROOT; - ERR_GROUP = c.ERR_GROUP; - ERR_OP = c.ERR_OP; - ERR_TOPOLOGY = c.ERR_TOPOLOGY; - ERR_DIMS = c.ERR_DIMS; - ERR_ARG = c.ERR_ARG; - ERR_UNKNOWN = c.ERR_UNKNOWN; - ERR_TRUNCATE = c.ERR_TRUNCATE; - ERR_OTHER = c.ERR_OTHER; - ERR_INTERN = c.ERR_INTERN; - ERR_IN_STATUS = c.ERR_IN_STATUS; - ERR_PENDING = c.ERR_PENDING; - ERR_ACCESS = c.ERR_ACCESS; - ERR_AMODE = c.ERR_AMODE; - ERR_ASSERT = c.ERR_ASSERT; - ERR_BAD_FILE = c.ERR_BAD_FILE; - ERR_BASE = c.ERR_BASE; - ERR_CONVERSION = c.ERR_CONVERSION; - ERR_DISP = c.ERR_DISP; - ERR_DUP_DATAREP = c.ERR_DUP_DATAREP; - ERR_FILE_EXISTS = c.ERR_FILE_EXISTS; - ERR_FILE_IN_USE = c.ERR_FILE_IN_USE; - ERR_FILE = c.ERR_FILE; - ERR_INFO_KEY = c.ERR_INFO_KEY; - ERR_INFO_NOKEY = c.ERR_INFO_NOKEY; - ERR_INFO_VALUE = c.ERR_INFO_VALUE; - ERR_INFO = c.ERR_INFO; - ERR_IO = c.ERR_IO; - ERR_KEYVAL = c.ERR_KEYVAL; - ERR_LOCKTYPE = c.ERR_LOCKTYPE; - ERR_NAME = c.ERR_NAME; - ERR_NO_MEM = c.ERR_NO_MEM; - ERR_NOT_SAME = c.ERR_NOT_SAME; - ERR_NO_SPACE = c.ERR_NO_SPACE; - ERR_NO_SUCH_FILE = c.ERR_NO_SUCH_FILE; - ERR_PORT = c.ERR_PORT; - ERR_QUOTA = c.ERR_QUOTA; - ERR_READ_ONLY = c.ERR_READ_ONLY; - ERR_RMA_CONFLICT = c.ERR_RMA_CONFLICT; - ERR_RMA_SYNC = c.ERR_RMA_SYNC; - ERR_SERVICE = c.ERR_SERVICE; - ERR_SIZE = c.ERR_SIZE; - ERR_SPAWN = c.ERR_SPAWN; - ERR_UNSUPPORTED_DATAREP = c.ERR_UNSUPPORTED_DATAREP; - ERR_UNSUPPORTED_OPERATION = c.ERR_UNSUPPORTED_OPERATION; - ERR_WIN = c.ERR_WIN; - ERR_LASTCODE = c.ERR_LASTCODE; - ERR_SYSRESOURCE = c.ERR_SYSRESOURCE; - - initVersion(); -} - -private static native Int2 newInt2(); -private static native ShortInt newShortInt(); -private static native LongInt newLongInt(); -private static native FloatInt newFloatInt(); -private static native DoubleInt newDoubleInt(); -private static native void initVersion(); - -private static void initCommon() throws MPIException -{ - initialized = true; - - DATATYPE_NULL.setBasic(Datatype.NULL); - - BYTE.setBasic(Datatype.BYTE); - CHAR.setBasic(Datatype.CHAR); - SHORT.setBasic(Datatype.SHORT); - BOOLEAN.setBasic(Datatype.BOOLEAN); - INT.setBasic(Datatype.INT); - LONG.setBasic(Datatype.LONG); - FLOAT.setBasic(Datatype.FLOAT); - DOUBLE.setBasic(Datatype.DOUBLE); - PACKED.setBasic(Datatype.PACKED); - - INT2.setBasic(Datatype.INT2, MPI.BYTE); - SHORT_INT.setBasic(Datatype.SHORT_INT, MPI.BYTE); - LONG_INT.setBasic(Datatype.LONG_INT, MPI.BYTE); - FLOAT_INT.setBasic(Datatype.FLOAT_INT, MPI.BYTE); - DOUBLE_INT.setBasic(Datatype.DOUBLE_INT, MPI.BYTE); - FLOAT_COMPLEX.setBasic(Datatype.FLOAT_COMPLEX, MPI.FLOAT); - DOUBLE_COMPLEX.setBasic(Datatype.DOUBLE_COMPLEX, MPI.DOUBLE); - - COMM_WORLD.setType(Intracomm.WORLD); - COMM_SELF.setType(Intracomm.SELF); -} - -/** - * Initialize MPI. - *

Java binding of the MPI operation {@code MPI_INIT}. - * @param args arguments to the {@code main} method. - * @return arguments - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static String[] Init(String[] args) throws MPIException -{ - if(initialized) - throw new MPIException("MPI is already initialized."); - - String[] newArgs = Init_jni(args); - initCommon(); - return newArgs; -} - -private static native String [] Init_jni(String[] args); - -/** - * Initialize MPI with threads. - *

Java binding of the MPI operation {@code MPI_INIT_THREAD}. - * @param args arguments to the {@code main} method. - * @param required desired level of thread support - * @return provided level of thread support - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int InitThread(String[] args, int required) throws MPIException -{ - if(initialized) - throw new MPIException("MPI is already initialized."); - - int provided = InitThread_jni(args, required); - initCommon(); - return provided; -} - -private static native int InitThread_jni(String[] args, int required) - throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_QUERY_THREAD}. - * @return provided level of thread support - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int queryThread() throws MPIException -{ - MPI.check(); - return queryThread_jni(); -} - -private static native int queryThread_jni() throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_IS_THREAD_MAIN}. - * @return true if it is the main thread - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static boolean isThreadMain() throws MPIException -{ - MPI.check(); - return isThreadMain_jni(); -} - -private static native boolean isThreadMain_jni() throws MPIException; - -/** - * Finalize MPI. - *

Java binding of the MPI operation {@code MPI_FINALIZE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void Finalize() throws MPIException -{ - check(); - Finalize_jni(); - finalized = true; -} - -private static native void Finalize_jni() throws MPIException; - -/** - * Returns an elapsed time on the calling processor. - *

Java binding of the MPI operation {@code MPI_WTIME}. - * @return time in seconds since an arbitrary time in the past. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static double wtime() throws MPIException -{ - check(); - return wtime_jni(); -} - -private static native double wtime_jni(); - -/** - * Returns resolution of timer. - *

Java binding of the MPI operation {MPI_WTICK}. - * @return resolution of {@code wtime} in seconds. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static double wtick() throws MPIException -{ - check(); - return wtick_jni(); -} - -private static native double wtick_jni(); - -/** - * Returns a version object representing the version of MPI being used. - *

Java binding of the MPI operation {@code MPI_GET_VERSION}. - * @return A version object representing the version and subversion of MPI being used. - */ -public static Version getVersion() { - return getVersionJNI(); -} - -private static native Version getVersionJNI(); - -/** - * Returns the version of the MPI Library - *

Java binding of the MPI operation {@code MPI_GET_LIBRARY_VERSION}. - * @return A string representation of the MPI Library - */ -public static String getLibVersion() { - return getLibVersionJNI(); -} - -private static native String getLibVersionJNI(); - -/** - * Returns the name of the processor on which it is called. - *

Java binding of the MPI operation {@code MPI_GET_PROCESSOR_NAME}. - * @return A unique specifier for the actual node. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -static public String getProcessorName() throws MPIException -{ - check(); - byte[] buf = new byte[MAX_PROCESSOR_NAME]; - int lengh = getProcessorName(buf); - return new String(buf,0,lengh); -} - -static private native int getProcessorName(byte[] buf); - -/** - * Test if MPI has been initialized. - *

Java binding of the MPI operation {@code MPI_INITIALIZED}. - * @return {@code true} if {@code Init} has been called, - * {@code false} otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -static public native boolean isInitialized() throws MPIException; - -/** - * Test if MPI has been finalized. - *

Java binding of the MPI operation {@code MPI_FINALIZED}. - * @return {@code true} if {@code Finalize} has been called, - * {@code false} otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -static public native boolean isFinalized() throws MPIException; - -/** - * Attaches a user-provided buffer for sending. - *

Java binding of the MPI operation {@code MPI_BUFFER_ATTACH}. - * @param buffer initial buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -static public void attachBuffer(byte[] buffer) throws MPIException -{ - check(); - MPI.buffer = buffer; - attachBuffer_jni(buffer); -} - -static private native void attachBuffer_jni(byte[] buffer); - -/** - * Removes an existing buffer (for use in sending). - *

Java binding of the MPI operation {@code MPI_BUFFER_DETACH}. - * @return initial buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -static public byte[] detachBuffer() throws MPIException -{ - check(); - detachBuffer_jni(buffer); - byte[] result = MPI.buffer; - MPI.buffer = null; - return result; -} - -static private native void detachBuffer_jni(byte[] buffer); - -/** - * Controls profiling. - *

This method is not implemented. - *

Java binding of the MPI operation {@code MPI_PCONTROL}. - * @param level Profiling level. - * @param obj Profiling information. - */ -public static void pControl(int level, Object obj) -{ - // Nothing to do here. -} - -/** - * Check if MPI has been initialized and hasn't been finalized. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -protected static void check() throws MPIException -{ - if(!initialized) - throw new MPIException("MPI is not initialized."); - - if(finalized) - throw new MPIException("MPI is finalized."); -} - -protected static byte[] attrSet(Object value) throws MPIException -{ - try - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream os = new ObjectOutputStream(baos); - os.writeObject(value); - os.close(); - return baos.toByteArray(); - } - catch(IOException ex) - { - MPIException mpiex = new MPIException(ex); - mpiex.setStackTrace(ex.getStackTrace()); - throw mpiex; - } -} - -protected static Object attrGet(byte[] value) throws MPIException -{ - if(value == null) - return null; - - try - { - ByteArrayInputStream bais = new ByteArrayInputStream(value); - ObjectInputStream is = new ObjectInputStream(bais); - Object obj = is.readObject(); - is.close(); - return obj; - } - catch(ClassNotFoundException ex) - { - throw new MPIException(ex); - } - catch(IOException ex) - { - throw new MPIException(ex); - } -} - -/** - * Allocates a new direct byte buffer. - * @param capacity The new buffer's capacity, in bytes - * @return The new byte buffer - */ -public static ByteBuffer newByteBuffer(int capacity) -{ - ByteBuffer buf = ByteBuffer.allocateDirect(capacity); - buf.order(nativeOrder); - return buf; -} - -/** - * Allocates a new direct char buffer. - * @param capacity The new buffer's capacity, in chars - * @return The new char buffer - */ -public static CharBuffer newCharBuffer(int capacity) -{ - assert capacity <= Integer.MAX_VALUE / 2; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 2); - buf.order(nativeOrder); - return buf.asCharBuffer(); -} - -/** - * Allocates a new direct short buffer. - * @param capacity The new buffer's capacity, in shorts - * @return The new short buffer - */ -public static ShortBuffer newShortBuffer(int capacity) -{ - assert capacity <= Integer.MAX_VALUE / 2; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 2); - buf.order(nativeOrder); - return buf.asShortBuffer(); -} - -/** - * Allocates a new direct int buffer. - * @param capacity The new buffer's capacity, in ints - * @return The new int buffer - */ -public static IntBuffer newIntBuffer(int capacity) -{ - assert capacity <= Integer.MAX_VALUE / 4; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 4); - buf.order(nativeOrder); - return buf.asIntBuffer(); -} - -/** - * Allocates a new direct long buffer. - * @param capacity The new buffer's capacity, in longs - * @return The new long buffer - */ -public static LongBuffer newLongBuffer(int capacity) -{ - assert capacity <= Integer.MAX_VALUE / 8; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 8); - buf.order(nativeOrder); - return buf.asLongBuffer(); -} - -/** - * Allocates a new direct float buffer. - * @param capacity The new buffer's capacity, in floats - * @return The new float buffer - */ -public static FloatBuffer newFloatBuffer(int capacity) -{ - assert capacity <= Integer.MAX_VALUE / 4; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 4); - buf.order(nativeOrder); - return buf.asFloatBuffer(); -} - -/** - * Allocates a new direct double buffer. - * @param capacity The new buffer's capacity, in doubles - * @return The new double buffer - */ -public static DoubleBuffer newDoubleBuffer(int capacity) -{ - assert capacity <= Integer.MAX_VALUE / 8; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 8); - buf.order(nativeOrder); - return buf.asDoubleBuffer(); -} - -/** - * Asserts that a buffer is direct. - * @param buf buffer - */ -protected static void assertDirectBuffer(Buffer buf) -{ - if(!buf.isDirect()) - throw new IllegalArgumentException("The buffer must be direct."); -} - -/** - * Asserts that buffers are direct. - * @param sendbuf The send buffer - * @param recvbuf The receive buffer - */ -protected static void assertDirectBuffer(Buffer sendbuf, Buffer recvbuf) -{ - if(!sendbuf.isDirect()) - throw new IllegalArgumentException("The send buffer must be direct."); - - if(!recvbuf.isDirect()) - throw new IllegalArgumentException("The recv. buffer must be direct."); -} - -/** - * Checks if an object is a direct buffer. - * @param obj object - * @return true if the object is a direct buffer - */ -protected static boolean isDirectBuffer(Object obj) -{ - return obj instanceof Buffer && ((Buffer)obj).isDirect(); -} - -/** - * Checks if an object is a heap buffer. - * @param obj object - * @return true if the object is a heap buffer - */ -protected static boolean isHeapBuffer(Object obj) -{ - return obj instanceof Buffer && !((Buffer)obj).isDirect(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static ByteBuffer slice(ByteBuffer buf, int offset) -{ - return ((ByteBuffer)buf.clear().position(offset)) - .slice().order(nativeOrder); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static CharBuffer slice(CharBuffer buf, int offset) -{ - return ((CharBuffer)buf.clear().position(offset)).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static ShortBuffer slice(ShortBuffer buf, int offset) -{ - return ((ShortBuffer)buf.clear().position(offset)).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static IntBuffer slice(IntBuffer buf, int offset) -{ - return ((IntBuffer)buf.clear().position(offset)).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static LongBuffer slice(LongBuffer buf, int offset) -{ - return ((LongBuffer)buf.clear().position(offset)).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static FloatBuffer slice(FloatBuffer buf, int offset) -{ - return ((FloatBuffer)buf.clear().position(offset)).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static DoubleBuffer slice(DoubleBuffer buf, int offset) -{ - return ((DoubleBuffer)buf.clear().position(offset)).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static ByteBuffer slice(byte[] buf, int offset) -{ - return ByteBuffer.wrap(buf, offset, buf.length - offset) - .slice().order(nativeOrder); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static CharBuffer slice(char[] buf, int offset) -{ - return CharBuffer.wrap(buf, offset, buf.length - offset).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static ShortBuffer slice(short[] buf, int offset) -{ - return ShortBuffer.wrap(buf, offset, buf.length - offset).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static IntBuffer slice(int[] buf, int offset) -{ - return IntBuffer.wrap(buf, offset, buf.length - offset).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static LongBuffer slice(long[] buf, int offset) -{ - return LongBuffer.wrap(buf, offset, buf.length - offset).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static FloatBuffer slice(float[] buf, int offset) -{ - return FloatBuffer.wrap(buf, offset, buf.length - offset).slice(); -} - -/** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ -public static DoubleBuffer slice(double[] buf, int offset) -{ - return DoubleBuffer.wrap(buf, offset, buf.length - offset).slice(); -} + private static boolean initialized, finalized; + private static byte[] buffer = null; // Buffer allocation + private static final int MAX_PROCESSOR_NAME = 256; + private static final ByteOrder nativeOrder = ByteOrder.nativeOrder(); + + public static final Intracomm COMM_WORLD, COMM_SELF; + + public static final int THREAD_SINGLE, THREAD_FUNNELED, THREAD_SERIALIZED, + THREAD_MULTIPLE; + + public static final int GRAPH, DIST_GRAPH, CART; + public static final int ANY_SOURCE, ANY_TAG; + + public static final Op MAX, MIN, SUM, PROD, LAND, BAND, + LOR, BOR, LXOR, BXOR, REPLACE, NO_OP; + + /** + * Global minimum operator. + *

{@code MINLOC} and {@link #MAXLOC} can be used with each of the following + * datatypes: {@link #INT2}, {@link #SHORT_INT}, {@link #LONG_INT}, + * {@link #FLOAT_INT} and {@link #DOUBLE_INT}. + */ + public static final Op MINLOC; + + /** Global maximum operator. See {@link #MINLOC}.*/ + public static final Op MAXLOC; + + public static final Datatype DATATYPE_NULL; + + public static final Datatype BYTE, CHAR, SHORT, BOOLEAN, + INT, LONG, FLOAT, DOUBLE, PACKED, + FLOAT_COMPLEX, DOUBLE_COMPLEX; + + /** Struct which must be used with {@link #int2}. */ + public static final Datatype INT2; + /** Struct which must be used with {@link #shortInt}. */ + public static final Datatype SHORT_INT; + /** Struct which must be used with {@link #longInt}. */ + public static final Datatype LONG_INT; + /** Struct which must be used with {@link #floatInt}. */ + public static final Datatype FLOAT_INT; + /** Struct which must be used with {@link #doubleInt}. */ + public static final Datatype DOUBLE_INT; + + /** Struct object for {@link #INT2} datatype. */ + public static final Int2 int2; + /** Struct object for {@link #SHORT_INT} datatype. */ + public static final ShortInt shortInt; + /** Struct object for {@link #LONG_INT} datatype. */ + public static final LongInt longInt; + /** Struct object for {@link #FLOAT_INT} datatype. */ + public static final FloatInt floatInt; + /** Struct object for {@link #DOUBLE_INT} datatype. */ + public static final DoubleInt doubleInt; + + public static final Request REQUEST_NULL; + public static final Group GROUP_EMPTY; + public static final Info INFO_ENV, INFO_NULL; + + public static final int PROC_NULL; + public static final int UNDEFINED; + public static final int IDENT, CONGRUENT, SIMILAR, UNEQUAL; + public static final int TAG_UB, HOST, IO, WTIME_IS_GLOBAL; + + public static final int APPNUM, LASTUSEDCODE, UNIVERSE_SIZE, WIN_BASE, + WIN_SIZE, WIN_DISP_UNIT; + + public static final int VERSION, SUBVERSION; + public static final int ROOT, KEYVAL_INVALID, BSEND_OVERHEAD; + public static final int MAX_OBJECT_NAME, MAX_PORT_NAME, MAX_DATAREP_STRING; + public static final int MAX_INFO_KEY, MAX_INFO_VAL; + public static final int ORDER_C, ORDER_FORTRAN; + public static final int DISTRIBUTE_BLOCK, DISTRIBUTE_CYCLIC, DISTRIBUTE_NONE, + DISTRIBUTE_DFLT_DARG; + + public static final int MODE_CREATE, MODE_RDONLY, MODE_WRONLY, MODE_RDWR, + MODE_DELETE_ON_CLOSE, MODE_UNIQUE_OPEN, MODE_EXCL, + MODE_APPEND, MODE_SEQUENTIAL; + public static final int DISPLACEMENT_CURRENT; + public static final int SEEK_SET, SEEK_CUR, SEEK_END; + + public static final int MODE_NOCHECK, MODE_NOPRECEDE, MODE_NOPUT, + MODE_NOSTORE, MODE_NOSUCCEED; + public static final int LOCK_EXCLUSIVE, LOCK_SHARED; + + public static final Errhandler ERRORS_ARE_FATAL, ERRORS_RETURN; + + // Error classes and codes + public static final int SUCCESS; + public static final int ERR_BUFFER; + public static final int ERR_COUNT; + public static final int ERR_TYPE; + public static final int ERR_TAG; + public static final int ERR_COMM; + public static final int ERR_RANK; + public static final int ERR_REQUEST; + public static final int ERR_ROOT; + public static final int ERR_GROUP; + public static final int ERR_OP; + public static final int ERR_TOPOLOGY; + public static final int ERR_DIMS; + public static final int ERR_ARG; + public static final int ERR_UNKNOWN; + public static final int ERR_TRUNCATE; + public static final int ERR_OTHER; + public static final int ERR_INTERN; + public static final int ERR_IN_STATUS; + public static final int ERR_PENDING; + public static final int ERR_ACCESS; + public static final int ERR_AMODE; + public static final int ERR_ASSERT; + public static final int ERR_BAD_FILE; + public static final int ERR_BASE; + public static final int ERR_CONVERSION; + public static final int ERR_DISP; + public static final int ERR_DUP_DATAREP; + public static final int ERR_FILE_EXISTS; + public static final int ERR_FILE_IN_USE; + public static final int ERR_FILE; + public static final int ERR_INFO_KEY; + public static final int ERR_INFO_NOKEY; + public static final int ERR_INFO_VALUE; + public static final int ERR_INFO; + public static final int ERR_IO; + public static final int ERR_KEYVAL; + public static final int ERR_LOCKTYPE; + public static final int ERR_NAME; + public static final int ERR_NO_MEM; + public static final int ERR_NOT_SAME; + public static final int ERR_NO_SPACE; + public static final int ERR_NO_SUCH_FILE; + public static final int ERR_PORT; + public static final int ERR_QUOTA; + public static final int ERR_READ_ONLY; + public static final int ERR_RMA_CONFLICT; + public static final int ERR_RMA_SYNC; + public static final int ERR_SERVICE; + public static final int ERR_SIZE; + public static final int ERR_SPAWN; + public static final int ERR_UNSUPPORTED_DATAREP; + public static final int ERR_UNSUPPORTED_OPERATION; + public static final int ERR_WIN; + public static final int ERR_LASTCODE; + public static final int ERR_SYSRESOURCE; + + static + { + System.loadLibrary("mpi_java"); + + DATATYPE_NULL = new Datatype(); + + BYTE = new Datatype(); + CHAR = new Datatype(); + SHORT = new Datatype(); + BOOLEAN = new Datatype(); + INT = new Datatype(); + LONG = new Datatype(); + FLOAT = new Datatype(); + DOUBLE = new Datatype(); + PACKED = new Datatype(); + INT2 = new Datatype(); + + SHORT_INT = new Datatype(); + LONG_INT = new Datatype(); + FLOAT_INT = new Datatype(); + DOUBLE_INT = new Datatype(); + FLOAT_COMPLEX = new Datatype(); + DOUBLE_COMPLEX = new Datatype(); + + int2 = newInt2(); + shortInt = newShortInt(); + longInt = newLongInt(); + floatInt = newFloatInt(); + doubleInt = newDoubleInt(); + + MAX = new Op(1); + MIN = new Op(2); + SUM = new Op(3); + PROD = new Op(4); + LAND = new Op(5); + BAND = new Op(6); + LOR = new Op(7); + BOR = new Op(8); + LXOR = new Op(9); + BXOR = new Op(10); + MINLOC = new Op(11); + MAXLOC = new Op(12); + REPLACE = new Op(13); + NO_OP = new Op(14); + + GROUP_EMPTY = new Group(Group.getEmpty()); + REQUEST_NULL = new Request(Request.getNull()); + INFO_ENV = Info.newEnv(); + INFO_NULL = new Info(Info.NULL); + + Constant c = new Constant(); + + THREAD_SINGLE = c.THREAD_SINGLE; + THREAD_FUNNELED = c.THREAD_FUNNELED; + THREAD_SERIALIZED = c.THREAD_SERIALIZED; + THREAD_MULTIPLE = c.THREAD_MULTIPLE; + + GRAPH = c.GRAPH; + DIST_GRAPH = c.DIST_GRAPH; + CART = c.CART; + + ANY_SOURCE = c.ANY_SOURCE; + ANY_TAG = c.ANY_TAG; + PROC_NULL = c.PROC_NULL; + + UNDEFINED = c.UNDEFINED; + + IDENT = c.IDENT; + CONGRUENT = c.CONGRUENT; + SIMILAR = c.SIMILAR; + UNEQUAL = c.UNEQUAL; + + TAG_UB = c.TAG_UB; + HOST = c.HOST; + IO = c.IO; + WTIME_IS_GLOBAL = c.WTIME_IS_GLOBAL; + + APPNUM = c.APPNUM; + LASTUSEDCODE = c.LASTUSEDCODE; + UNIVERSE_SIZE = c.UNIVERSE_SIZE; + WIN_BASE = c.WIN_BASE; + WIN_SIZE = c.WIN_SIZE; + WIN_DISP_UNIT = c.WIN_DISP_UNIT; + + VERSION = c.VERSION; + SUBVERSION = c.SUBVERSION; + + ROOT = c.ROOT; + KEYVAL_INVALID = c.KEYVAL_INVALID; + BSEND_OVERHEAD = c.BSEND_OVERHEAD; + + MAX_OBJECT_NAME = c.MAX_OBJECT_NAME; + MAX_PORT_NAME = c.MAX_PORT_NAME; + MAX_DATAREP_STRING = c.MAX_DATAREP_STRING; + + MAX_INFO_KEY = c.MAX_INFO_KEY; + MAX_INFO_VAL = c.MAX_INFO_VAL; + + ORDER_C = c.ORDER_C; + ORDER_FORTRAN = c.ORDER_FORTRAN; + + DISTRIBUTE_BLOCK = c.DISTRIBUTE_BLOCK; + DISTRIBUTE_CYCLIC = c.DISTRIBUTE_CYCLIC; + DISTRIBUTE_NONE = c.DISTRIBUTE_NONE; + DISTRIBUTE_DFLT_DARG = c.DISTRIBUTE_DFLT_DARG; + + MODE_CREATE = c.MODE_CREATE; + MODE_RDONLY = c.MODE_RDONLY; + MODE_WRONLY = c.MODE_WRONLY; + MODE_RDWR = c.MODE_RDWR; + MODE_DELETE_ON_CLOSE = c.MODE_DELETE_ON_CLOSE; + MODE_UNIQUE_OPEN = c.MODE_UNIQUE_OPEN; + MODE_EXCL = c.MODE_EXCL; + MODE_APPEND = c.MODE_APPEND; + MODE_SEQUENTIAL = c.MODE_SEQUENTIAL; + + DISPLACEMENT_CURRENT = c.DISPLACEMENT_CURRENT; + + SEEK_SET = c.SEEK_SET; + SEEK_CUR = c.SEEK_CUR; + SEEK_END = c.SEEK_END; + + MODE_NOCHECK = c.MODE_NOCHECK; + MODE_NOPRECEDE = c.MODE_NOPRECEDE; + MODE_NOPUT = c.MODE_NOPUT; + MODE_NOSTORE = c.MODE_NOSTORE; + MODE_NOSUCCEED = c.MODE_NOSUCCEED; + LOCK_EXCLUSIVE = c.LOCK_EXCLUSIVE; + LOCK_SHARED = c.LOCK_SHARED; + + ERRORS_ARE_FATAL = new Errhandler(Errhandler.getFatal()); + ERRORS_RETURN = new Errhandler(Errhandler.getReturn()); + + COMM_WORLD = new Intracomm(); + COMM_SELF = new Intracomm(); + + // Error classes and codes + SUCCESS = c.SUCCESS; + ERR_BUFFER = c.ERR_BUFFER; + ERR_COUNT = c.ERR_COUNT; + ERR_TYPE = c.ERR_TYPE; + ERR_TAG = c.ERR_TAG; + ERR_COMM = c.ERR_COMM; + ERR_RANK = c.ERR_RANK; + ERR_REQUEST = c.ERR_REQUEST; + ERR_ROOT = c.ERR_ROOT; + ERR_GROUP = c.ERR_GROUP; + ERR_OP = c.ERR_OP; + ERR_TOPOLOGY = c.ERR_TOPOLOGY; + ERR_DIMS = c.ERR_DIMS; + ERR_ARG = c.ERR_ARG; + ERR_UNKNOWN = c.ERR_UNKNOWN; + ERR_TRUNCATE = c.ERR_TRUNCATE; + ERR_OTHER = c.ERR_OTHER; + ERR_INTERN = c.ERR_INTERN; + ERR_IN_STATUS = c.ERR_IN_STATUS; + ERR_PENDING = c.ERR_PENDING; + ERR_ACCESS = c.ERR_ACCESS; + ERR_AMODE = c.ERR_AMODE; + ERR_ASSERT = c.ERR_ASSERT; + ERR_BAD_FILE = c.ERR_BAD_FILE; + ERR_BASE = c.ERR_BASE; + ERR_CONVERSION = c.ERR_CONVERSION; + ERR_DISP = c.ERR_DISP; + ERR_DUP_DATAREP = c.ERR_DUP_DATAREP; + ERR_FILE_EXISTS = c.ERR_FILE_EXISTS; + ERR_FILE_IN_USE = c.ERR_FILE_IN_USE; + ERR_FILE = c.ERR_FILE; + ERR_INFO_KEY = c.ERR_INFO_KEY; + ERR_INFO_NOKEY = c.ERR_INFO_NOKEY; + ERR_INFO_VALUE = c.ERR_INFO_VALUE; + ERR_INFO = c.ERR_INFO; + ERR_IO = c.ERR_IO; + ERR_KEYVAL = c.ERR_KEYVAL; + ERR_LOCKTYPE = c.ERR_LOCKTYPE; + ERR_NAME = c.ERR_NAME; + ERR_NO_MEM = c.ERR_NO_MEM; + ERR_NOT_SAME = c.ERR_NOT_SAME; + ERR_NO_SPACE = c.ERR_NO_SPACE; + ERR_NO_SUCH_FILE = c.ERR_NO_SUCH_FILE; + ERR_PORT = c.ERR_PORT; + ERR_QUOTA = c.ERR_QUOTA; + ERR_READ_ONLY = c.ERR_READ_ONLY; + ERR_RMA_CONFLICT = c.ERR_RMA_CONFLICT; + ERR_RMA_SYNC = c.ERR_RMA_SYNC; + ERR_SERVICE = c.ERR_SERVICE; + ERR_SIZE = c.ERR_SIZE; + ERR_SPAWN = c.ERR_SPAWN; + ERR_UNSUPPORTED_DATAREP = c.ERR_UNSUPPORTED_DATAREP; + ERR_UNSUPPORTED_OPERATION = c.ERR_UNSUPPORTED_OPERATION; + ERR_WIN = c.ERR_WIN; + ERR_LASTCODE = c.ERR_LASTCODE; + ERR_SYSRESOURCE = c.ERR_SYSRESOURCE; + + initVersion(); + } + + private static native Int2 newInt2(); + private static native ShortInt newShortInt(); + private static native LongInt newLongInt(); + private static native FloatInt newFloatInt(); + private static native DoubleInt newDoubleInt(); + private static native void initVersion(); + + private static void initCommon() throws MPIException + { + initialized = true; + + DATATYPE_NULL.setBasic(Datatype.NULL); + + BYTE.setBasic(Datatype.BYTE); + CHAR.setBasic(Datatype.CHAR); + SHORT.setBasic(Datatype.SHORT); + BOOLEAN.setBasic(Datatype.BOOLEAN); + INT.setBasic(Datatype.INT); + LONG.setBasic(Datatype.LONG); + FLOAT.setBasic(Datatype.FLOAT); + DOUBLE.setBasic(Datatype.DOUBLE); + PACKED.setBasic(Datatype.PACKED); + + INT2.setBasic(Datatype.INT2, MPI.BYTE); + SHORT_INT.setBasic(Datatype.SHORT_INT, MPI.BYTE); + LONG_INT.setBasic(Datatype.LONG_INT, MPI.BYTE); + FLOAT_INT.setBasic(Datatype.FLOAT_INT, MPI.BYTE); + DOUBLE_INT.setBasic(Datatype.DOUBLE_INT, MPI.BYTE); + FLOAT_COMPLEX.setBasic(Datatype.FLOAT_COMPLEX, MPI.FLOAT); + DOUBLE_COMPLEX.setBasic(Datatype.DOUBLE_COMPLEX, MPI.DOUBLE); + + COMM_WORLD.setType(Intracomm.WORLD); + COMM_SELF.setType(Intracomm.SELF); + } + + /** + * Initialize MPI. + *

Java binding of the MPI operation {@code MPI_INIT}. + * @param args arguments to the {@code main} method. + * @return arguments + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static String[] Init(String[] args) throws MPIException + { + if(initialized) + throw new MPIException("MPI is already initialized."); + + String[] newArgs = Init_jni(args); + initCommon(); + return newArgs; + } + + private static native String [] Init_jni(String[] args); + + /** + * Initialize MPI with threads. + *

Java binding of the MPI operation {@code MPI_INIT_THREAD}. + * @param args arguments to the {@code main} method. + * @param required desired level of thread support + * @return provided level of thread support + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int InitThread(String[] args, int required) throws MPIException + { + if(initialized) + throw new MPIException("MPI is already initialized."); + + int provided = InitThread_jni(args, required); + initCommon(); + return provided; + } + + private static native int InitThread_jni(String[] args, int required) + throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_QUERY_THREAD}. + * @return provided level of thread support + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int queryThread() throws MPIException + { + MPI.check(); + return queryThread_jni(); + } + + private static native int queryThread_jni() throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_IS_THREAD_MAIN}. + * @return true if it is the main thread + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static boolean isThreadMain() throws MPIException + { + MPI.check(); + return isThreadMain_jni(); + } + + private static native boolean isThreadMain_jni() throws MPIException; + + /** + * Finalize MPI. + *

Java binding of the MPI operation {@code MPI_FINALIZE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void Finalize() throws MPIException + { + check(); + Finalize_jni(); + finalized = true; + } + + private static native void Finalize_jni() throws MPIException; + + /** + * Returns an elapsed time on the calling processor. + *

Java binding of the MPI operation {@code MPI_WTIME}. + * @return time in seconds since an arbitrary time in the past. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static double wtime() throws MPIException + { + check(); + return wtime_jni(); + } + + private static native double wtime_jni(); + + /** + * Returns resolution of timer. + *

Java binding of the MPI operation {MPI_WTICK}. + * @return resolution of {@code wtime} in seconds. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static double wtick() throws MPIException + { + check(); + return wtick_jni(); + } + + private static native double wtick_jni(); + + /** + * Returns a version object representing the version of MPI being used. + *

Java binding of the MPI operation {@code MPI_GET_VERSION}. + * @return A version object representing the version and subversion of MPI being used. + */ + public static Version getVersion() { + return getVersionJNI(); + } + + private static native Version getVersionJNI(); + + /** + * Returns the version of the MPI Library + *

Java binding of the MPI operation {@code MPI_GET_LIBRARY_VERSION}. + * @return A string representation of the MPI Library + */ + public static String getLibVersion() { + return getLibVersionJNI(); + } + + private static native String getLibVersionJNI(); + + /** + * Returns the name of the processor on which it is called. + *

Java binding of the MPI operation {@code MPI_GET_PROCESSOR_NAME}. + * @return A unique specifier for the actual node. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public String getProcessorName() throws MPIException + { + check(); + byte[] buf = new byte[MAX_PROCESSOR_NAME]; + int lengh = getProcessorName(buf); + return new String(buf,0,lengh); + } + + static private native int getProcessorName(byte[] buf); + + /** + * Test if MPI has been initialized. + *

Java binding of the MPI operation {@code MPI_INITIALIZED}. + * @return {@code true} if {@code Init} has been called, + * {@code false} otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public native boolean isInitialized() throws MPIException; + + /** + * Test if MPI has been finalized. + *

Java binding of the MPI operation {@code MPI_FINALIZED}. + * @return {@code true} if {@code Finalize} has been called, + * {@code false} otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public native boolean isFinalized() throws MPIException; + + /** + * Attaches a user-provided buffer for sending. + *

Java binding of the MPI operation {@code MPI_BUFFER_ATTACH}. + * @param buffer initial buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public void attachBuffer(byte[] buffer) throws MPIException + { + check(); + MPI.buffer = buffer; + attachBuffer_jni(buffer); + } + + static private native void attachBuffer_jni(byte[] buffer); + + /** + * Removes an existing buffer (for use in sending). + *

Java binding of the MPI operation {@code MPI_BUFFER_DETACH}. + * @return initial buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public byte[] detachBuffer() throws MPIException + { + check(); + detachBuffer_jni(buffer); + byte[] result = MPI.buffer; + MPI.buffer = null; + return result; + } + + static private native void detachBuffer_jni(byte[] buffer); + + /** + * Controls profiling. + *

This method is not implemented. + *

Java binding of the MPI operation {@code MPI_PCONTROL}. + * @param level Profiling level. + * @param obj Profiling information. + */ + public static void pControl(int level, Object obj) + { + // Nothing to do here. + } + + /** + * Check if MPI has been initialized and hasn't been finalized. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + protected static void check() throws MPIException + { + if(!initialized) + throw new MPIException("MPI is not initialized."); + + if(finalized) + throw new MPIException("MPI is finalized."); + } + + protected static byte[] attrSet(Object value) throws MPIException + { + try + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream os = new ObjectOutputStream(baos); + os.writeObject(value); + os.close(); + return baos.toByteArray(); + } + catch(IOException ex) + { + MPIException mpiex = new MPIException(ex); + mpiex.setStackTrace(ex.getStackTrace()); + throw mpiex; + } + } + + protected static Object attrGet(byte[] value) throws MPIException + { + if(value == null) + return null; + + try + { + ByteArrayInputStream bais = new ByteArrayInputStream(value); + ObjectInputStream is = new ObjectInputStream(bais); + Object obj = is.readObject(); + is.close(); + return obj; + } + catch(ClassNotFoundException ex) + { + throw new MPIException(ex); + } + catch(IOException ex) + { + throw new MPIException(ex); + } + } + + /** + * Allocates a new direct byte buffer. + * @param capacity The new buffer's capacity, in bytes + * @return The new byte buffer + */ + public static ByteBuffer newByteBuffer(int capacity) + { + ByteBuffer buf = ByteBuffer.allocateDirect(capacity); + buf.order(nativeOrder); + return buf; + } + + /** + * Allocates a new direct char buffer. + * @param capacity The new buffer's capacity, in chars + * @return The new char buffer + */ + public static CharBuffer newCharBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 2; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 2); + buf.order(nativeOrder); + return buf.asCharBuffer(); + } + + /** + * Allocates a new direct short buffer. + * @param capacity The new buffer's capacity, in shorts + * @return The new short buffer + */ + public static ShortBuffer newShortBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 2; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 2); + buf.order(nativeOrder); + return buf.asShortBuffer(); + } + + /** + * Allocates a new direct int buffer. + * @param capacity The new buffer's capacity, in ints + * @return The new int buffer + */ + public static IntBuffer newIntBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 4; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 4); + buf.order(nativeOrder); + return buf.asIntBuffer(); + } + + /** + * Allocates a new direct long buffer. + * @param capacity The new buffer's capacity, in longs + * @return The new long buffer + */ + public static LongBuffer newLongBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 8; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 8); + buf.order(nativeOrder); + return buf.asLongBuffer(); + } + + /** + * Allocates a new direct float buffer. + * @param capacity The new buffer's capacity, in floats + * @return The new float buffer + */ + public static FloatBuffer newFloatBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 4; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 4); + buf.order(nativeOrder); + return buf.asFloatBuffer(); + } + + /** + * Allocates a new direct double buffer. + * @param capacity The new buffer's capacity, in doubles + * @return The new double buffer + */ + public static DoubleBuffer newDoubleBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 8; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 8); + buf.order(nativeOrder); + return buf.asDoubleBuffer(); + } + + /** + * Asserts that a buffer is direct. + * @param buf buffer + */ + protected static void assertDirectBuffer(Buffer buf) + { + if(!buf.isDirect()) + throw new IllegalArgumentException("The buffer must be direct."); + } + + /** + * Asserts that buffers are direct. + * @param sendbuf The send buffer + * @param recvbuf The receive buffer + */ + protected static void assertDirectBuffer(Buffer sendbuf, Buffer recvbuf) + { + if(!sendbuf.isDirect()) + throw new IllegalArgumentException("The send buffer must be direct."); + + if(!recvbuf.isDirect()) + throw new IllegalArgumentException("The recv. buffer must be direct."); + } + + /** + * Checks if an object is a direct buffer. + * @param obj object + * @return true if the object is a direct buffer + */ + protected static boolean isDirectBuffer(Object obj) + { + return obj instanceof Buffer && ((Buffer)obj).isDirect(); + } + + /** + * Checks if an object is a heap buffer. + * @param obj object + * @return true if the object is a heap buffer + */ + protected static boolean isHeapBuffer(Object obj) + { + return obj instanceof Buffer && !((Buffer)obj).isDirect(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static ByteBuffer slice(ByteBuffer buf, int offset) + { + return ((ByteBuffer)buf.clear().position(offset)) + .slice().order(nativeOrder); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static CharBuffer slice(CharBuffer buf, int offset) + { + return ((CharBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static ShortBuffer slice(ShortBuffer buf, int offset) + { + return ((ShortBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static IntBuffer slice(IntBuffer buf, int offset) + { + return ((IntBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static LongBuffer slice(LongBuffer buf, int offset) + { + return ((LongBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static FloatBuffer slice(FloatBuffer buf, int offset) + { + return ((FloatBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static DoubleBuffer slice(DoubleBuffer buf, int offset) + { + return ((DoubleBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static ByteBuffer slice(byte[] buf, int offset) + { + return ByteBuffer.wrap(buf, offset, buf.length - offset) + .slice().order(nativeOrder); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static CharBuffer slice(char[] buf, int offset) + { + return CharBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static ShortBuffer slice(short[] buf, int offset) + { + return ShortBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static IntBuffer slice(int[] buf, int offset) + { + return IntBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static LongBuffer slice(long[] buf, int offset) + { + return LongBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static FloatBuffer slice(float[] buf, int offset) + { + return FloatBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static DoubleBuffer slice(double[] buf, int offset) + { + return DoubleBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + ======= + private static boolean initialized, finalized; + private static byte[] buffer = null; // Buffer allocation + private static final int MAX_PROCESSOR_NAME = 256; + private static final ByteOrder nativeOrder = ByteOrder.nativeOrder(); + + public static final Intracomm COMM_WORLD, COMM_SELF; + + public static final int THREAD_SINGLE, THREAD_FUNNELED, THREAD_SERIALIZED, + THREAD_MULTIPLE; + + public static final int GRAPH, DIST_GRAPH, CART; + public static final int ANY_SOURCE, ANY_TAG; + + public static final Op MAX, MIN, SUM, PROD, LAND, BAND, + LOR, BOR, LXOR, BXOR, REPLACE, NO_OP; + + /** + * Global minimum operator. + *

{@code MINLOC} and {@link #MAXLOC} can be used with each of the following + * datatypes: {@link #INT2}, {@link #SHORT_INT}, {@link #LONG_INT}, + * {@link #FLOAT_INT} and {@link #DOUBLE_INT}. + */ + public static final Op MINLOC; + + /** Global maximum operator. See {@link #MINLOC}.*/ + public static final Op MAXLOC; + + public static final Datatype DATATYPE_NULL; + + public static final Datatype BYTE, CHAR, SHORT, BOOLEAN, + INT, LONG, FLOAT, DOUBLE, PACKED, + FLOAT_COMPLEX, DOUBLE_COMPLEX; + + /** Struct which must be used with {@link #int2}. */ + public static final Datatype INT2; + /** Struct which must be used with {@link #shortInt}. */ + public static final Datatype SHORT_INT; + /** Struct which must be used with {@link #longInt}. */ + public static final Datatype LONG_INT; + /** Struct which must be used with {@link #floatInt}. */ + public static final Datatype FLOAT_INT; + /** Struct which must be used with {@link #doubleInt}. */ + public static final Datatype DOUBLE_INT; + + /** Struct object for {@link #INT2} datatype. */ + public static final Int2 int2; + /** Struct object for {@link #SHORT_INT} datatype. */ + public static final ShortInt shortInt; + /** Struct object for {@link #LONG_INT} datatype. */ + public static final LongInt longInt; + /** Struct object for {@link #FLOAT_INT} datatype. */ + public static final FloatInt floatInt; + /** Struct object for {@link #DOUBLE_INT} datatype. */ + public static final DoubleInt doubleInt; + + public static final Request REQUEST_NULL; + public static final Group GROUP_EMPTY; + public static final Info INFO_ENV, INFO_NULL; + + public static final int PROC_NULL; + public static final int UNDEFINED; + public static final int IDENT, CONGRUENT, SIMILAR, UNEQUAL; + public static final int TAG_UB, HOST, IO, WTIME_IS_GLOBAL; + + public static final int APPNUM, LASTUSEDCODE, UNIVERSE_SIZE, WIN_BASE, + WIN_SIZE, WIN_DISP_UNIT; + + public static final int VERSION, SUBVERSION; + public static final int ROOT, KEYVAL_INVALID, BSEND_OVERHEAD; + public static final int MAX_OBJECT_NAME, MAX_PORT_NAME, MAX_DATAREP_STRING; + public static final int MAX_INFO_KEY, MAX_INFO_VAL; + public static final int ORDER_C, ORDER_FORTRAN; + public static final int DISTRIBUTE_BLOCK, DISTRIBUTE_CYCLIC, DISTRIBUTE_NONE, + DISTRIBUTE_DFLT_DARG; + + public static final int MODE_CREATE, MODE_RDONLY, MODE_WRONLY, MODE_RDWR, + MODE_DELETE_ON_CLOSE, MODE_UNIQUE_OPEN, MODE_EXCL, + MODE_APPEND, MODE_SEQUENTIAL; + public static final int DISPLACEMENT_CURRENT; + public static final int SEEK_SET, SEEK_CUR, SEEK_END; + + public static final int MODE_NOCHECK, MODE_NOPRECEDE, MODE_NOPUT, + MODE_NOSTORE, MODE_NOSUCCEED; + public static final int LOCK_EXCLUSIVE, LOCK_SHARED; + + public static final Errhandler ERRORS_ARE_FATAL, ERRORS_RETURN; + + // Error classes and codes + public static final int SUCCESS; + public static final int ERR_BUFFER; + public static final int ERR_COUNT; + public static final int ERR_TYPE; + public static final int ERR_TAG; + public static final int ERR_COMM; + public static final int ERR_RANK; + public static final int ERR_REQUEST; + public static final int ERR_ROOT; + public static final int ERR_GROUP; + public static final int ERR_OP; + public static final int ERR_TOPOLOGY; + public static final int ERR_DIMS; + public static final int ERR_ARG; + public static final int ERR_UNKNOWN; + public static final int ERR_TRUNCATE; + public static final int ERR_OTHER; + public static final int ERR_INTERN; + public static final int ERR_IN_STATUS; + public static final int ERR_PENDING; + public static final int ERR_ACCESS; + public static final int ERR_AMODE; + public static final int ERR_ASSERT; + public static final int ERR_BAD_FILE; + public static final int ERR_BASE; + public static final int ERR_CONVERSION; + public static final int ERR_DISP; + public static final int ERR_DUP_DATAREP; + public static final int ERR_FILE_EXISTS; + public static final int ERR_FILE_IN_USE; + public static final int ERR_FILE; + public static final int ERR_INFO_KEY; + public static final int ERR_INFO_NOKEY; + public static final int ERR_INFO_VALUE; + public static final int ERR_INFO; + public static final int ERR_IO; + public static final int ERR_KEYVAL; + public static final int ERR_LOCKTYPE; + public static final int ERR_NAME; + public static final int ERR_NO_MEM; + public static final int ERR_NOT_SAME; + public static final int ERR_NO_SPACE; + public static final int ERR_NO_SUCH_FILE; + public static final int ERR_PORT; + public static final int ERR_QUOTA; + public static final int ERR_READ_ONLY; + public static final int ERR_RMA_CONFLICT; + public static final int ERR_RMA_SYNC; + public static final int ERR_SERVICE; + public static final int ERR_SIZE; + public static final int ERR_SPAWN; + public static final int ERR_UNSUPPORTED_DATAREP; + public static final int ERR_UNSUPPORTED_OPERATION; + public static final int ERR_WIN; + public static final int ERR_LASTCODE; + public static final int ERR_SYSRESOURCE; + + static + { + System.loadLibrary("mpi_java"); + + DATATYPE_NULL = new Datatype(); + + BYTE = new Datatype(); + CHAR = new Datatype(); + SHORT = new Datatype(); + BOOLEAN = new Datatype(); + INT = new Datatype(); + LONG = new Datatype(); + FLOAT = new Datatype(); + DOUBLE = new Datatype(); + PACKED = new Datatype(); + INT2 = new Datatype(); + + SHORT_INT = new Datatype(); + LONG_INT = new Datatype(); + FLOAT_INT = new Datatype(); + DOUBLE_INT = new Datatype(); + FLOAT_COMPLEX = new Datatype(); + DOUBLE_COMPLEX = new Datatype(); + + int2 = newInt2(); + shortInt = newShortInt(); + longInt = newLongInt(); + floatInt = newFloatInt(); + doubleInt = newDoubleInt(); + + MAX = new Op(1); + MIN = new Op(2); + SUM = new Op(3); + PROD = new Op(4); + LAND = new Op(5); + BAND = new Op(6); + LOR = new Op(7); + BOR = new Op(8); + LXOR = new Op(9); + BXOR = new Op(10); + MINLOC = new Op(11); + MAXLOC = new Op(12); + REPLACE = new Op(13); + NO_OP = new Op(14); + + GROUP_EMPTY = new Group(Group.getEmpty()); + REQUEST_NULL = new Request(Request.getNull()); + INFO_ENV = Info.newEnv(); + INFO_NULL = new Info(Info.NULL); + + Constant c = new Constant(); + + THREAD_SINGLE = c.THREAD_SINGLE; + THREAD_FUNNELED = c.THREAD_FUNNELED; + THREAD_SERIALIZED = c.THREAD_SERIALIZED; + THREAD_MULTIPLE = c.THREAD_MULTIPLE; + + GRAPH = c.GRAPH; + DIST_GRAPH = c.DIST_GRAPH; + CART = c.CART; + + ANY_SOURCE = c.ANY_SOURCE; + ANY_TAG = c.ANY_TAG; + PROC_NULL = c.PROC_NULL; + + UNDEFINED = c.UNDEFINED; + + IDENT = c.IDENT; + CONGRUENT = c.CONGRUENT; + SIMILAR = c.SIMILAR; + UNEQUAL = c.UNEQUAL; + + TAG_UB = c.TAG_UB; + HOST = c.HOST; + IO = c.IO; + WTIME_IS_GLOBAL = c.WTIME_IS_GLOBAL; + + APPNUM = c.APPNUM; + LASTUSEDCODE = c.LASTUSEDCODE; + UNIVERSE_SIZE = c.UNIVERSE_SIZE; + WIN_BASE = c.WIN_BASE; + WIN_SIZE = c.WIN_SIZE; + WIN_DISP_UNIT = c.WIN_DISP_UNIT; + + VERSION = c.VERSION; + SUBVERSION = c.SUBVERSION; + + ROOT = c.ROOT; + KEYVAL_INVALID = c.KEYVAL_INVALID; + BSEND_OVERHEAD = c.BSEND_OVERHEAD; + + MAX_OBJECT_NAME = c.MAX_OBJECT_NAME; + MAX_PORT_NAME = c.MAX_PORT_NAME; + MAX_DATAREP_STRING = c.MAX_DATAREP_STRING; + + MAX_INFO_KEY = c.MAX_INFO_KEY; + MAX_INFO_VAL = c.MAX_INFO_VAL; + + ORDER_C = c.ORDER_C; + ORDER_FORTRAN = c.ORDER_FORTRAN; + + DISTRIBUTE_BLOCK = c.DISTRIBUTE_BLOCK; + DISTRIBUTE_CYCLIC = c.DISTRIBUTE_CYCLIC; + DISTRIBUTE_NONE = c.DISTRIBUTE_NONE; + DISTRIBUTE_DFLT_DARG = c.DISTRIBUTE_DFLT_DARG; + + MODE_CREATE = c.MODE_CREATE; + MODE_RDONLY = c.MODE_RDONLY; + MODE_WRONLY = c.MODE_WRONLY; + MODE_RDWR = c.MODE_RDWR; + MODE_DELETE_ON_CLOSE = c.MODE_DELETE_ON_CLOSE; + MODE_UNIQUE_OPEN = c.MODE_UNIQUE_OPEN; + MODE_EXCL = c.MODE_EXCL; + MODE_APPEND = c.MODE_APPEND; + MODE_SEQUENTIAL = c.MODE_SEQUENTIAL; + + DISPLACEMENT_CURRENT = c.DISPLACEMENT_CURRENT; + + SEEK_SET = c.SEEK_SET; + SEEK_CUR = c.SEEK_CUR; + SEEK_END = c.SEEK_END; + + MODE_NOCHECK = c.MODE_NOCHECK; + MODE_NOPRECEDE = c.MODE_NOPRECEDE; + MODE_NOPUT = c.MODE_NOPUT; + MODE_NOSTORE = c.MODE_NOSTORE; + MODE_NOSUCCEED = c.MODE_NOSUCCEED; + LOCK_EXCLUSIVE = c.LOCK_EXCLUSIVE; + LOCK_SHARED = c.LOCK_SHARED; + + ERRORS_ARE_FATAL = new Errhandler(Errhandler.getFatal()); + ERRORS_RETURN = new Errhandler(Errhandler.getReturn()); + + COMM_WORLD = new Intracomm(); + COMM_SELF = new Intracomm(); + + // Error classes and codes + SUCCESS = c.SUCCESS; + ERR_BUFFER = c.ERR_BUFFER; + ERR_COUNT = c.ERR_COUNT; + ERR_TYPE = c.ERR_TYPE; + ERR_TAG = c.ERR_TAG; + ERR_COMM = c.ERR_COMM; + ERR_RANK = c.ERR_RANK; + ERR_REQUEST = c.ERR_REQUEST; + ERR_ROOT = c.ERR_ROOT; + ERR_GROUP = c.ERR_GROUP; + ERR_OP = c.ERR_OP; + ERR_TOPOLOGY = c.ERR_TOPOLOGY; + ERR_DIMS = c.ERR_DIMS; + ERR_ARG = c.ERR_ARG; + ERR_UNKNOWN = c.ERR_UNKNOWN; + ERR_TRUNCATE = c.ERR_TRUNCATE; + ERR_OTHER = c.ERR_OTHER; + ERR_INTERN = c.ERR_INTERN; + ERR_IN_STATUS = c.ERR_IN_STATUS; + ERR_PENDING = c.ERR_PENDING; + ERR_ACCESS = c.ERR_ACCESS; + ERR_AMODE = c.ERR_AMODE; + ERR_ASSERT = c.ERR_ASSERT; + ERR_BAD_FILE = c.ERR_BAD_FILE; + ERR_BASE = c.ERR_BASE; + ERR_CONVERSION = c.ERR_CONVERSION; + ERR_DISP = c.ERR_DISP; + ERR_DUP_DATAREP = c.ERR_DUP_DATAREP; + ERR_FILE_EXISTS = c.ERR_FILE_EXISTS; + ERR_FILE_IN_USE = c.ERR_FILE_IN_USE; + ERR_FILE = c.ERR_FILE; + ERR_INFO_KEY = c.ERR_INFO_KEY; + ERR_INFO_NOKEY = c.ERR_INFO_NOKEY; + ERR_INFO_VALUE = c.ERR_INFO_VALUE; + ERR_INFO = c.ERR_INFO; + ERR_IO = c.ERR_IO; + ERR_KEYVAL = c.ERR_KEYVAL; + ERR_LOCKTYPE = c.ERR_LOCKTYPE; + ERR_NAME = c.ERR_NAME; + ERR_NO_MEM = c.ERR_NO_MEM; + ERR_NOT_SAME = c.ERR_NOT_SAME; + ERR_NO_SPACE = c.ERR_NO_SPACE; + ERR_NO_SUCH_FILE = c.ERR_NO_SUCH_FILE; + ERR_PORT = c.ERR_PORT; + ERR_QUOTA = c.ERR_QUOTA; + ERR_READ_ONLY = c.ERR_READ_ONLY; + ERR_RMA_CONFLICT = c.ERR_RMA_CONFLICT; + ERR_RMA_SYNC = c.ERR_RMA_SYNC; + ERR_SERVICE = c.ERR_SERVICE; + ERR_SIZE = c.ERR_SIZE; + ERR_SPAWN = c.ERR_SPAWN; + ERR_UNSUPPORTED_DATAREP = c.ERR_UNSUPPORTED_DATAREP; + ERR_UNSUPPORTED_OPERATION = c.ERR_UNSUPPORTED_OPERATION; + ERR_WIN = c.ERR_WIN; + ERR_LASTCODE = c.ERR_LASTCODE; + ERR_SYSRESOURCE = c.ERR_SYSRESOURCE; + } + + private static native Int2 newInt2(); + private static native ShortInt newShortInt(); + private static native LongInt newLongInt(); + private static native FloatInt newFloatInt(); + private static native DoubleInt newDoubleInt(); + + private static void initCommon() throws MPIException + { + initialized = true; + + DATATYPE_NULL.setBasic(Datatype.NULL); + + BYTE.setBasic(Datatype.BYTE); + CHAR.setBasic(Datatype.CHAR); + SHORT.setBasic(Datatype.SHORT); + BOOLEAN.setBasic(Datatype.BOOLEAN); + INT.setBasic(Datatype.INT); + LONG.setBasic(Datatype.LONG); + FLOAT.setBasic(Datatype.FLOAT); + DOUBLE.setBasic(Datatype.DOUBLE); + PACKED.setBasic(Datatype.PACKED); + + INT2.setBasic(Datatype.INT2, MPI.BYTE); + SHORT_INT.setBasic(Datatype.SHORT_INT, MPI.BYTE); + LONG_INT.setBasic(Datatype.LONG_INT, MPI.BYTE); + FLOAT_INT.setBasic(Datatype.FLOAT_INT, MPI.BYTE); + DOUBLE_INT.setBasic(Datatype.DOUBLE_INT, MPI.BYTE); + FLOAT_COMPLEX.setBasic(Datatype.FLOAT_COMPLEX, MPI.FLOAT); + DOUBLE_COMPLEX.setBasic(Datatype.DOUBLE_COMPLEX, MPI.DOUBLE); + + COMM_WORLD.setType(Intracomm.WORLD); + COMM_SELF.setType(Intracomm.SELF); + } + + /** + * Initialize MPI. + *

Java binding of the MPI operation {@code MPI_INIT}. + * @param args arguments to the {@code main} method. + * @return arguments + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static String[] Init(String[] args) throws MPIException + { + if(initialized) + throw new MPIException("MPI is already initialized."); + + String[] newArgs = Init_jni(args); + initCommon(); + return newArgs; + } + + private static native String [] Init_jni(String[] args); + + /** + * Initialize MPI with threads. + *

Java binding of the MPI operation {@code MPI_INIT_THREAD}. + * @param args arguments to the {@code main} method. + * @param required desired level of thread support + * @return provided level of thread support + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int InitThread(String[] args, int required) throws MPIException + { + if(initialized) + throw new MPIException("MPI is already initialized."); + + int provided = InitThread_jni(args, required); + initCommon(); + return provided; + } + + private static native int InitThread_jni(String[] args, int required) + throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_QUERY_THREAD}. + * @return provided level of thread support + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int queryThread() throws MPIException + { + MPI.check(); + return queryThread_jni(); + } + + private static native int queryThread_jni() throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_IS_THREAD_MAIN}. + * @return true if it is the main thread + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static boolean isThreadMain() throws MPIException + { + MPI.check(); + return isThreadMain_jni(); + } + + private static native boolean isThreadMain_jni() throws MPIException; + + /** + * Finalize MPI. + *

Java binding of the MPI operation {@code MPI_FINALIZE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void Finalize() throws MPIException + { + check(); + Finalize_jni(); + finalized = true; + } + + private static native void Finalize_jni() throws MPIException; + + /** + * Returns an elapsed time on the calling processor. + *

Java binding of the MPI operation {@code MPI_WTIME}. + * @return time in seconds since an arbitrary time in the past. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static double wtime() throws MPIException + { + check(); + return wtime_jni(); + } + + private static native double wtime_jni(); + + /** + * Returns resolution of timer. + *

Java binding of the MPI operation {MPI_WTICK}. + * @return resolution of {@code wtime} in seconds. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static double wtick() throws MPIException + { + check(); + return wtick_jni(); + } + + private static native double wtick_jni(); + + /** + * Returns the name of the processor on which it is called. + *

Java binding of the MPI operation {@code MPI_GET_PROCESSOR_NAME}. + * @return A unique specifier for the actual node. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public String getProcessorName() throws MPIException + { + check(); + byte[] buf = new byte[MAX_PROCESSOR_NAME]; + int lengh = getProcessorName(buf); + return new String(buf,0,lengh); + } + + static private native int getProcessorName(byte[] buf); + + /** + * Test if MPI has been initialized. + *

Java binding of the MPI operation {@code MPI_INITIALIZED}. + * @return {@code true} if {@code Init} has been called, + * {@code false} otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public native boolean isInitialized() throws MPIException; + + /** + * Test if MPI has been finalized. + *

Java binding of the MPI operation {@code MPI_FINALIZED}. + * @return {@code true} if {@code Finalize} has been called, + * {@code false} otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public native boolean isFinalized() throws MPIException; + + /** + * Attaches a user-provided buffer for sending. + *

Java binding of the MPI operation {@code MPI_BUFFER_ATTACH}. + * @param buffer initial buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public void attachBuffer(byte[] buffer) throws MPIException + { + check(); + MPI.buffer = buffer; + attachBuffer_jni(buffer); + } + + static private native void attachBuffer_jni(byte[] buffer); + + /** + * Removes an existing buffer (for use in sending). + *

Java binding of the MPI operation {@code MPI_BUFFER_DETACH}. + * @return initial buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + static public byte[] detachBuffer() throws MPIException + { + check(); + detachBuffer_jni(buffer); + byte[] result = MPI.buffer; + MPI.buffer = null; + return result; + } + + static private native void detachBuffer_jni(byte[] buffer); + + /** + * Controls profiling. + *

This method is not implemented. + *

Java binding of the MPI operation {@code MPI_PCONTROL}. + * @param level Profiling level. + * @param obj Profiling information. + */ + public static void pControl(int level, Object obj) + { + // Nothing to do here. + } + + /** + * Check if MPI has been initialized and hasn't been finalized. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + protected static void check() throws MPIException + { + if(!initialized) + throw new MPIException("MPI is not initialized."); + + if(finalized) + throw new MPIException("MPI is finalized."); + } + + protected static byte[] attrSet(Object value) throws MPIException + { + try + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream os = new ObjectOutputStream(baos); + os.writeObject(value); + os.close(); + return baos.toByteArray(); + } + catch(IOException ex) + { + MPIException mpiex = new MPIException(ex); + mpiex.setStackTrace(ex.getStackTrace()); + throw mpiex; + } + } + + protected static Object attrGet(byte[] value) throws MPIException + { + if(value == null) + return null; + + try + { + ByteArrayInputStream bais = new ByteArrayInputStream(value); + ObjectInputStream is = new ObjectInputStream(bais); + Object obj = is.readObject(); + is.close(); + return obj; + } + catch(ClassNotFoundException ex) + { + throw new MPIException(ex); + } + catch(IOException ex) + { + throw new MPIException(ex); + } + } + + /** + * Allocates a new direct byte buffer. + * @param capacity The new buffer's capacity, in bytes + * @return The new byte buffer + */ + public static ByteBuffer newByteBuffer(int capacity) + { + ByteBuffer buf = ByteBuffer.allocateDirect(capacity); + buf.order(nativeOrder); + return buf; + } + + /** + * Allocates a new direct char buffer. + * @param capacity The new buffer's capacity, in chars + * @return The new char buffer + */ + public static CharBuffer newCharBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 2; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 2); + buf.order(nativeOrder); + return buf.asCharBuffer(); + } + + /** + * Allocates a new direct short buffer. + * @param capacity The new buffer's capacity, in shorts + * @return The new short buffer + */ + public static ShortBuffer newShortBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 2; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 2); + buf.order(nativeOrder); + return buf.asShortBuffer(); + } + + /** + * Allocates a new direct int buffer. + * @param capacity The new buffer's capacity, in ints + * @return The new int buffer + */ + public static IntBuffer newIntBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 4; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 4); + buf.order(nativeOrder); + return buf.asIntBuffer(); + } + + /** + * Allocates a new direct long buffer. + * @param capacity The new buffer's capacity, in longs + * @return The new long buffer + */ + public static LongBuffer newLongBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 8; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 8); + buf.order(nativeOrder); + return buf.asLongBuffer(); + } + + /** + * Allocates a new direct float buffer. + * @param capacity The new buffer's capacity, in floats + * @return The new float buffer + */ + public static FloatBuffer newFloatBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 4; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 4); + buf.order(nativeOrder); + return buf.asFloatBuffer(); + } + + /** + * Allocates a new direct double buffer. + * @param capacity The new buffer's capacity, in doubles + * @return The new double buffer + */ + public static DoubleBuffer newDoubleBuffer(int capacity) + { + assert capacity <= Integer.MAX_VALUE / 8; + ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 8); + buf.order(nativeOrder); + return buf.asDoubleBuffer(); + } + + /** + * Asserts that a buffer is direct. + * @param buf buffer + */ + protected static void assertDirectBuffer(Buffer buf) + { + if(!buf.isDirect()) + throw new IllegalArgumentException("The buffer must be direct."); + } + + /** + * Asserts that buffers are direct. + * @param sendbuf The send buffer + * @param recvbuf The receive buffer + */ + protected static void assertDirectBuffer(Buffer sendbuf, Buffer recvbuf) + { + if(!sendbuf.isDirect()) + throw new IllegalArgumentException("The send buffer must be direct."); + + if(!recvbuf.isDirect()) + throw new IllegalArgumentException("The recv. buffer must be direct."); + } + + /** + * Checks if an object is a direct buffer. + * @param obj object + * @return true if the object is a direct buffer + */ + protected static boolean isDirectBuffer(Object obj) + { + return obj instanceof Buffer && ((Buffer)obj).isDirect(); + } + + /** + * Checks if an object is a heap buffer. + * @param obj object + * @return true if the object is a heap buffer + */ + protected static boolean isHeapBuffer(Object obj) + { + return obj instanceof Buffer && !((Buffer)obj).isDirect(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static ByteBuffer slice(ByteBuffer buf, int offset) + { + return ((ByteBuffer)buf.clear().position(offset)) + .slice().order(nativeOrder); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static CharBuffer slice(CharBuffer buf, int offset) + { + return ((CharBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static ShortBuffer slice(ShortBuffer buf, int offset) + { + return ((ShortBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static IntBuffer slice(IntBuffer buf, int offset) + { + return ((IntBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static LongBuffer slice(LongBuffer buf, int offset) + { + return ((LongBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static FloatBuffer slice(FloatBuffer buf, int offset) + { + return ((FloatBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static DoubleBuffer slice(DoubleBuffer buf, int offset) + { + return ((DoubleBuffer)buf.clear().position(offset)).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static ByteBuffer slice(byte[] buf, int offset) + { + return ByteBuffer.wrap(buf, offset, buf.length - offset) + .slice().order(nativeOrder); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static CharBuffer slice(char[] buf, int offset) + { + return CharBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static ShortBuffer slice(short[] buf, int offset) + { + return ShortBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static IntBuffer slice(int[] buf, int offset) + { + return IntBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static LongBuffer slice(long[] buf, int offset) + { + return LongBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static FloatBuffer slice(float[] buf, int offset) + { + return FloatBuffer.wrap(buf, offset, buf.length - offset).slice(); + } + + /** + * Creates a new buffer whose content is a shared subsequence of a buffer. + *

The content of the new buffer will start at the specified offset. + * @param buf buffer + * @param offset offset + * @return the new buffer. + */ + public static DoubleBuffer slice(double[] buf, int offset) + { + return DoubleBuffer.wrap(buf, offset, buf.length - offset).slice(); + } } // MPI diff --git a/ompi/mpi/java/java/MPIException.java b/ompi/mpi/java/java/MPIException.java index 64c621a6ce..e50c742dad 100644 --- a/ompi/mpi/java/java/MPIException.java +++ b/ompi/mpi/java/java/MPIException.java @@ -9,31 +9,33 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : MPIException.java * Author : Bryan Carpenter * Created : Tue Sep 14 13:03:57 EDT 1999 @@ -52,50 +54,50 @@ package mpi; */ public final class MPIException extends Exception { -private int errorCode, errorClass; + private int errorCode, errorClass; -protected MPIException(int code, int clazz, String message) -{ - super(message); - errorCode = code; - errorClass = clazz; -} + protected MPIException(int code, int clazz, String message) + { + super(message); + errorCode = code; + errorClass = clazz; + } -/** - * Creates an exception. - * @param message message associated to the exception - */ -public MPIException(String message) -{ - super(message); -} + /** + * Creates an exception. + * @param message message associated to the exception + */ + public MPIException(String message) + { + super(message); + } -/** - * Creates an exception: - * @param cause cause associated to the exception - */ -public MPIException(Throwable cause) -{ - super(cause); - setStackTrace(cause.getStackTrace()); -} + /** + * Creates an exception: + * @param cause cause associated to the exception + */ + public MPIException(Throwable cause) + { + super(cause); + setStackTrace(cause.getStackTrace()); + } -/** - * Gets the MPI error code. - * @return error code - */ -public int getErrorCode() -{ - return errorCode; -} + /** + * Gets the MPI error code. + * @return error code + */ + public int getErrorCode() + { + return errorCode; + } -/** - * Gets the MPI error class. - * @return error class - */ -public int getErrorClass() -{ - return errorClass; -} + /** + * Gets the MPI error class. + * @return error class + */ + public int getErrorClass() + { + return errorClass; + } } // MPIException diff --git a/ompi/mpi/java/java/Message.java b/ompi/mpi/java/java/Message.java index fe52342acb..c2307c6994 100644 --- a/ompi/mpi/java/java/Message.java +++ b/ompi/mpi/java/java/Message.java @@ -16,8 +16,8 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * IMPLEMENTATION DETAILS * * All methods with buffers that can be direct or non direct have @@ -36,126 +36,126 @@ import static mpi.MPI.assertDirectBuffer; */ public final class Message { -protected long handle; -private static long NULL, NO_PROC; + protected long handle; + private static long NULL, NO_PROC; -static -{ - init(); -} + static + { + init(); + } -private static native void init(); + private static native void init(); -/** - * Creates a {@code MPI_MESSAGE_NULL}. - */ -public Message() -{ - handle = NULL; -} + /** + * Creates a {@code MPI_MESSAGE_NULL}. + */ + public Message() + { + handle = NULL; + } -/** - * Tests if the message is {@code MPI_MESSAGE_NULL}. - * @return true if the message is {@code MPI_MESSAGE_NULL}. - */ -public boolean isNull() -{ - return handle == NULL; -} + /** + * Tests if the message is {@code MPI_MESSAGE_NULL}. + * @return true if the message is {@code MPI_MESSAGE_NULL}. + */ + public boolean isNull() + { + return handle == NULL; + } -/** - * Tests if the message is {@code MPI_MESSAGE_NO_PROC}. - * @return true if the message is {@code MPI_MESSAGE_NO_PROC}. - */ -public boolean isNoProc() -{ - return handle == NO_PROC; -} + /** + * Tests if the message is {@code MPI_MESSAGE_NO_PROC}. + * @return true if the message is {@code MPI_MESSAGE_NO_PROC}. + */ + public boolean isNoProc() + { + return handle == NO_PROC; + } -/** - * Java binding of {@code MPI_MPROBE}. - * @param source rank of the source - * @param tag message tag - * @param comm communicator - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status mProbe(int source, int tag, Comm comm) throws MPIException -{ - MPI.check(); - Status status = new Status(); - handle = mProbe(source, tag, comm.handle, status.data); - return status; -} + /** + * Java binding of {@code MPI_MPROBE}. + * @param source rank of the source + * @param tag message tag + * @param comm communicator + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status mProbe(int source, int tag, Comm comm) throws MPIException + { + MPI.check(); + Status status = new Status(); + handle = mProbe(source, tag, comm.handle, status.data); + return status; + } -private native long mProbe(int source, int tag, long comm, long[] status) - throws MPIException; + private native long mProbe(int source, int tag, long comm, long[] status) + throws MPIException; -/** - * Java binding of {@code MPI_IMPROBE}. - * @param source rank of the source - * @param tag message tag - * @param comm communicator - * @return status object if there is a message, {@code null} otherwise - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status imProbe(int source, int tag, Comm comm) throws MPIException -{ - MPI.check(); - return imProbe(source, tag, comm.handle); -} + /** + * Java binding of {@code MPI_IMPROBE}. + * @param source rank of the source + * @param tag message tag + * @param comm communicator + * @return status object if there is a message, {@code null} otherwise + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status imProbe(int source, int tag, Comm comm) throws MPIException + { + MPI.check(); + return imProbe(source, tag, comm.handle); + } -private native Status imProbe(int source, int tag, long comm) - throws MPIException; + private native Status imProbe(int source, int tag, long comm) + throws MPIException; -/** - * Java binding of {@code MPI_MRECV}. - * @param buf receive buffer - * @param count number of elements in receve buffer - * @param type datatype of each receive buffer element - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Status mRecv(Object buf, int count, Datatype type) throws MPIException -{ - MPI.check(); - int off = 0; - boolean db = false; - Status status = new Status(); + /** + * Java binding of {@code MPI_MRECV}. + * @param buf receive buffer + * @param count number of elements in receve buffer + * @param type datatype of each receive buffer element + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Status mRecv(Object buf, int count, Datatype type) throws MPIException + { + MPI.check(); + int off = 0; + boolean db = false; + Status status = new Status(); - if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) - { - off = type.getOffset(buf); - buf = ((Buffer)buf).array(); - } + if(buf instanceof Buffer && !(db = ((Buffer)buf).isDirect())) + { + off = type.getOffset(buf); + buf = ((Buffer)buf).array(); + } - handle = mRecv(handle, buf, db, off, count, - type.handle, type.baseType, status.data); + handle = mRecv(handle, buf, db, off, count, + type.handle, type.baseType, status.data); - return status; -} + return status; + } -private native long mRecv( - long message, Object buf, boolean db, int offset, int count, - long type, int baseType, long[] status) throws MPIException; + private native long mRecv( + long message, Object buf, boolean db, int offset, int count, + long type, int baseType, long[] status) throws MPIException; -/** - * Java binding of {@code MPI_IMRECV}. - * @param buf receive buffer - * @param count number of elements in receve buffer - * @param type datatype of each receive buffer element - * @return request object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Request imRecv(Buffer buf, int count, Datatype type) - throws MPIException -{ - MPI.check(); - assertDirectBuffer(buf); - return new Request(imRecv(handle, buf, count, type.handle)); -} + /** + * Java binding of {@code MPI_IMRECV}. + * @param buf receive buffer + * @param count number of elements in receve buffer + * @param type datatype of each receive buffer element + * @return request object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Request imRecv(Buffer buf, int count, Datatype type) + throws MPIException + { + MPI.check(); + assertDirectBuffer(buf); + return new Request(imRecv(handle, buf, count, type.handle)); + } -private native long imRecv(long message, Object buf, int count, long type) - throws MPIException; + private native long imRecv(long message, Object buf, int count, long type) + throws MPIException; } // Message diff --git a/ompi/mpi/java/java/Op.java b/ompi/mpi/java/java/Op.java index cde980e7cf..eb3ccd8663 100644 --- a/ompi/mpi/java/java/Op.java +++ b/ompi/mpi/java/java/Op.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Op.java * Author : Xinying Li, Sang LIm * Created : Thu Apr 9 12:22:15 1998 @@ -54,80 +54,80 @@ import java.nio.*; */ public final class Op implements Freeable { -protected final UserFunction uf; -private boolean commute; -private Datatype datatype; -protected long handle; + protected final UserFunction uf; + private boolean commute; + private Datatype datatype; + protected long handle; -static -{ - init(); -} + static + { + init(); + } -private static native void init(); + private static native void init(); -protected Op(int type) -{ - getOp(type); - uf = null; - commute = true; -} + protected Op(int type) + { + getOp(type); + uf = null; + commute = true; + } -private native void getOp(int type); + private native void getOp(int type); -/** - * Bind a user-defined global reduction operation to an {@code Op} object. - *

Java binding of the MPI operation {@code MPI_OP_CREATE}. - * @param function user defined function - * @param commute {@code true} if commutative, {@code false} otherwise - */ -public Op(UserFunction function, boolean commute) -{ - handle = 0; // When JNI code gets the handle it will be initialized. - uf = function; - this.commute = commute; -} + /** + * Bind a user-defined global reduction operation to an {@code Op} object. + *

Java binding of the MPI operation {@code MPI_OP_CREATE}. + * @param function user defined function + * @param commute {@code true} if commutative, {@code false} otherwise + */ + public Op(UserFunction function, boolean commute) + { + handle = 0; // When JNI code gets the handle it will be initialized. + uf = function; + this.commute = commute; + } -protected void setDatatype(Datatype t) -{ - datatype = t; -} + protected void setDatatype(Datatype t) + { + datatype = t; + } -protected void call(Object invec, Object inoutvec, int count) - throws MPIException -{ - if(datatype.baseType == Datatype.BOOLEAN) - { - uf.call(invec, inoutvec, count, datatype); - } - else - { - uf.call(((ByteBuffer)invec).order(ByteOrder.nativeOrder()), - ((ByteBuffer)inoutvec).order(ByteOrder.nativeOrder()), - count, datatype); - } -} + protected void call(Object invec, Object inoutvec, int count) + throws MPIException + { + if(datatype.baseType == Datatype.BOOLEAN) + { + uf.call(invec, inoutvec, count, datatype); + } + else + { + uf.call(((ByteBuffer)invec).order(ByteOrder.nativeOrder()), + ((ByteBuffer)inoutvec).order(ByteOrder.nativeOrder()), + count, datatype); + } + } -/** - * Test if the operation is conmutative. - *

Java binding of the MPI operation {@code MPI_OP_COMMUTATIVE}. - * @return {@code true} if commutative, {@code false} otherwise - */ -public boolean isCommutative() -{ - return commute; -} + /** + * Test if the operation is conmutative. + *

Java binding of the MPI operation {@code MPI_OP_COMMUTATIVE}. + * @return {@code true} if commutative, {@code false} otherwise + */ + public boolean isCommutative() + { + return commute; + } -/** - * Java binding of the MPI operation {@code MPI_OP_FREE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public native void free() throws MPIException; + /** + * Java binding of the MPI operation {@code MPI_OP_FREE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public native void free() throws MPIException; -/** - * Test if operation object is null. - * @return true if the operation object is null, false otherwise - */ -public native boolean isNull(); + /** + * Test if operation object is null. + * @return true if the operation object is null, false otherwise + */ + public native boolean isNull(); } // Op diff --git a/ompi/mpi/java/java/Prequest.java b/ompi/mpi/java/java/Prequest.java index 15bdf6b6ab..94b3697839 100644 --- a/ompi/mpi/java/java/Prequest.java +++ b/ompi/mpi/java/java/Prequest.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Prequest.java * Author : Sang Lim, Xinying Li, Bryan Carpenter * Created : Thu Apr 9 12:22:15 1998 @@ -52,45 +52,45 @@ package mpi; */ public final class Prequest extends Request { -/** - * Constructor used by {@code sendInit}, etc. - * @param handle Handle for the Prequest object - */ -protected Prequest(long handle) -{ - super(handle); -} + /** + * Constructor used by {@code sendInit}, etc. + * @param handle Handle for the Prequest object + */ + protected Prequest(long handle) + { + super(handle); + } -/** - * Activate a persistent communication request. - *

Java binding of the MPI operation {@code MPI_START}. - * The communication is completed by using the request in - * one of the {@code wait} or {@code test} operations. - * On successful completion the request becomes inactive again. - * It can be reactivated by a further call to {@code Start}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void start() throws MPIException -{ - handle = start(handle); -} + /** + * Activate a persistent communication request. + *

Java binding of the MPI operation {@code MPI_START}. + * The communication is completed by using the request in + * one of the {@code wait} or {@code test} operations. + * On successful completion the request becomes inactive again. + * It can be reactivated by a further call to {@code Start}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void start() throws MPIException + { + handle = start(handle); + } -private native long start(long request) throws MPIException; + private native long start(long request) throws MPIException; -/** - * Activate a list of communication requests. - *

Java binding of the MPI operation {@code MPI_STARTALL}. - * @param requests array of requests - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void startAll(Prequest[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - startAll(r); - setHandles(requests, r); -} + /** + * Activate a list of communication requests. + *

Java binding of the MPI operation {@code MPI_STARTALL}. + * @param requests array of requests + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void startAll(Prequest[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + startAll(r); + setHandles(requests, r); + } -private native static void startAll(long[] requests) throws MPIException; + private native static void startAll(long[] requests) throws MPIException; } // Prequest diff --git a/ompi/mpi/java/java/Request.java b/ompi/mpi/java/java/Request.java index 49da46e3aa..11e279090d 100644 --- a/ompi/mpi/java/java/Request.java +++ b/ompi/mpi/java/java/Request.java @@ -16,35 +16,35 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* File : Request.java + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * File : Request.java * Author : Sang Lim, Xinying Li, Bryan Carpenter * Created : Thu Apr 9 12:22:15 1998 * Revision : $Revision: 1.11 $ * Updated : $Date: 2001/08/07 16:36:25 $ * Copyright: Northeast Parallel Architectures Center * at Syracuse University 1998 - */ - -/* + * + * + * * Note: in a send request for a buffer containing objects, the primary * `MPI_Request' referenced by `handle' is the request to send the data. * The request to send the header is in the secondary field, `hdrReq'. @@ -52,9 +52,9 @@ * the primary `MPI_Request' is the request to send the header. * The receive of the data is not initiated until a `wait' or `test' * operation succeeds. - */ - -/* + * + * + * * Probably `Request' should be an abstract class, and there should * be several concrete subclasses. At the moment requests are created * in a few different ways, and the differently constructed requests are @@ -68,402 +68,402 @@ package mpi; */ public class Request implements Freeable { -protected long handle; + protected long handle; -static -{ - init(); -} + static + { + init(); + } -private static native void init(); + private static native void init(); -protected static native long getNull(); + protected static native long getNull(); -protected Request(long handle) -{ - this.handle = handle; -} + protected Request(long handle) + { + this.handle = handle; + } -/** - * Set the request object to be void. - * Java binding of the MPI operation {@code MPI_REQUEST_FREE}. - */ -@Override public void free() throws MPIException -{ - if(!isNull()) - { - MPI.check(); - handle = free(handle); - } -} + /** + * Set the request object to be void. + * Java binding of the MPI operation {@code MPI_REQUEST_FREE}. + */ + @Override public void free() throws MPIException + { + if(!isNull()) + { + MPI.check(); + handle = free(handle); + } + } -private native long free(long req) throws MPIException; + private native long free(long req) throws MPIException; -/** - * Mark a pending nonblocking communication for cancellation. - * Java binding of the MPI operation {@code MPI_CANCEL}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void cancel() throws MPIException -{ - MPI.check(); - cancel(handle); -} + /** + * Mark a pending nonblocking communication for cancellation. + * Java binding of the MPI operation {@code MPI_CANCEL}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void cancel() throws MPIException + { + MPI.check(); + cancel(handle); + } -private native void cancel(long request) throws MPIException; + private native void cancel(long request) throws MPIException; -/** - * Test if request object is null. - * @return true if the request object is null, false otherwise - */ -public final boolean isNull() -{ - return handle == 0 || handle == MPI.REQUEST_NULL.handle; -} + /** + * Test if request object is null. + * @return true if the request object is null, false otherwise + */ + public final boolean isNull() + { + return handle == 0 || handle == MPI.REQUEST_NULL.handle; + } -/** - * Blocks until the operation identified by the request is complete. - *

Java binding of the MPI operation {@code MPI_WAIT}. - *

After the call returns, the request object becomes inactive. - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Status waitStatus() throws MPIException -{ - MPI.check(); - Status status = new Status(); - handle = waitStatus(handle, status.data); - return status; -} + /** + * Blocks until the operation identified by the request is complete. + *

Java binding of the MPI operation {@code MPI_WAIT}. + *

After the call returns, the request object becomes inactive. + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Status waitStatus() throws MPIException + { + MPI.check(); + Status status = new Status(); + handle = waitStatus(handle, status.data); + return status; + } -private native long waitStatus(long request, long[] stat) throws MPIException; + private native long waitStatus(long request, long[] stat) throws MPIException; -/** - * Blocks until the operation identified by the request is complete. - *

Java binding of the MPI operation {@code MPI_WAIT}. - *

After the call returns, the request object becomes inactive. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final void waitFor() throws MPIException -{ - MPI.check(); - handle = waitFor(handle); -} + /** + * Blocks until the operation identified by the request is complete. + *

Java binding of the MPI operation {@code MPI_WAIT}. + *

After the call returns, the request object becomes inactive. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final void waitFor() throws MPIException + { + MPI.check(); + handle = waitFor(handle); + } -private native long waitFor(long request) throws MPIException; + private native long waitFor(long request) throws MPIException; -/** - * Returns a status object if the operation identified by the request - * is complete, or a null reference otherwise. - *

Java binding of the MPI operation {@code MPI_TEST}. - *

After the call, if the operation is complete (ie, if the return - * value is non-null), the request object becomes inactive. - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Status testStatus() throws MPIException -{ - MPI.check(); - return testStatus(handle); -} + /** + * Returns a status object if the operation identified by the request + * is complete, or a null reference otherwise. + *

Java binding of the MPI operation {@code MPI_TEST}. + *

After the call, if the operation is complete (ie, if the return + * value is non-null), the request object becomes inactive. + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Status testStatus() throws MPIException + { + MPI.check(); + return testStatus(handle); + } -private native Status testStatus(long request) throws MPIException; + private native Status testStatus(long request) throws MPIException; -/** - * Returns true if the operation identified by the request - * is complete, or false otherwise. - *

Java binding of the MPI operation {@code MPI_TEST}. - *

After the call, if the operation is complete (ie, if the return - * value is true), the request object becomes inactive. - * @return true if the operation identified by the request, false otherwise - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final boolean test() throws MPIException -{ - MPI.check(); - return test(handle); -} + /** + * Returns true if the operation identified by the request + * is complete, or false otherwise. + *

Java binding of the MPI operation {@code MPI_TEST}. + *

After the call, if the operation is complete (ie, if the return + * value is true), the request object becomes inactive. + * @return true if the operation identified by the request, false otherwise + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final boolean test() throws MPIException + { + MPI.check(); + return test(handle); + } -private native boolean test(long handle) throws MPIException; + private native boolean test(long handle) throws MPIException; -/** - * Blocks until one of the operations associated with the active - * requests in the array has completed. - *

Java binding of the MPI operation {@code MPI_WAITANY}. - *

The index in array of {@code requests} for the request that - * completed can be obtained from the returned status object through - * the {@code Status.getIndex()} method. The corresponding element - * of array of {@code requests} becomes inactive. - * @param requests array of requests - * @return status object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Status waitAnyStatus(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - Status status = new Status(); - waitAnyStatus(r, status.data); - setHandles(requests, r); - return status; -} + /** + * Blocks until one of the operations associated with the active + * requests in the array has completed. + *

Java binding of the MPI operation {@code MPI_WAITANY}. + *

The index in array of {@code requests} for the request that + * completed can be obtained from the returned status object through + * the {@code Status.getIndex()} method. The corresponding element + * of array of {@code requests} becomes inactive. + * @param requests array of requests + * @return status object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Status waitAnyStatus(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + Status status = new Status(); + waitAnyStatus(r, status.data); + setHandles(requests, r); + return status; + } -private static native void waitAnyStatus(long[] requests, long[] status) - throws MPIException; + private static native void waitAnyStatus(long[] requests, long[] status) + throws MPIException; -/** - * Blocks until one of the operations associated with the active - * requests in the array has completed. - *

Java binding of the MPI operation {@code MPI_WAITANY}. - *

The request that completed becomes inactive. - * @param requests array of requests - * @return The index in array of {@code requests} for the request that - * completed. If all of the requests are MPI_REQUEST_NULL, then index - * is returned as {@code MPI.UNDEFINED}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int waitAny(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - int index = waitAny(r); - setHandles(requests, r); - return index; -} + /** + * Blocks until one of the operations associated with the active + * requests in the array has completed. + *

Java binding of the MPI operation {@code MPI_WAITANY}. + *

The request that completed becomes inactive. + * @param requests array of requests + * @return The index in array of {@code requests} for the request that + * completed. If all of the requests are MPI_REQUEST_NULL, then index + * is returned as {@code MPI.UNDEFINED}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int waitAny(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + int index = waitAny(r); + setHandles(requests, r); + return index; + } -private static native int waitAny(long[] requests) throws MPIException; + private static native int waitAny(long[] requests) throws MPIException; -/** - * Tests for completion of either one or none of the operations - * associated with active requests. - *

Java binding of the MPI operation {@code MPI_TESTANY}. - *

If some request completed, the index in array of {@code requests} - * for that request can be obtained from the returned status object. - * The corresponding element in array of {@code requests} becomes inactive. - * If no request completed, {testAny} returns {@code null}. - * @param requests array of requests - * @return status object if one request completed, {@code null} otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Status testAnyStatus(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - Status status = testAnyStatus(r); - setHandles(requests, r); - return status; -} + /** + * Tests for completion of either one or none of the operations + * associated with active requests. + *

Java binding of the MPI operation {@code MPI_TESTANY}. + *

If some request completed, the index in array of {@code requests} + * for that request can be obtained from the returned status object. + * The corresponding element in array of {@code requests} becomes inactive. + * If no request completed, {testAny} returns {@code null}. + * @param requests array of requests + * @return status object if one request completed, {@code null} otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Status testAnyStatus(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + Status status = testAnyStatus(r); + setHandles(requests, r); + return status; + } -private static native Status testAnyStatus(long[] requests) throws MPIException; + private static native Status testAnyStatus(long[] requests) throws MPIException; -/** - * Tests for completion of either one or none of the operations - * associated with active requests. - *

Java binding of the MPI operation {@code MPI_TESTANY}. - *

If some request completed, ii becomes inactive. - * @param requests array of requests - * @return index of operation that completed, or {@code MPI.UNDEFINED} - * if none completed. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int testAny(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - int index = testAny(r); - setHandles(requests, r); - return index; -} + /** + * Tests for completion of either one or none of the operations + * associated with active requests. + *

Java binding of the MPI operation {@code MPI_TESTANY}. + *

If some request completed, ii becomes inactive. + * @param requests array of requests + * @return index of operation that completed, or {@code MPI.UNDEFINED} + * if none completed. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int testAny(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + int index = testAny(r); + setHandles(requests, r); + return index; + } -private static native int testAny(long[] requests) throws MPIException; + private static native int testAny(long[] requests) throws MPIException; -/** - * Blocks until all of the operations associated with the active - * requests in the array have completed. - *

Java binding of the MPI operation {@code MPI_WAITALL}. - *

On exit, requests become inactive. If the input value of - * array of {@code requests} contains inactive requests, corresponding - * elements of the status array will contain null status references. - * @param requests array of requests - * @return array of statuses - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Status[] waitAllStatus(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - Status[] status = waitAllStatus(r); - setHandles(requests, r); - return status; -} + /** + * Blocks until all of the operations associated with the active + * requests in the array have completed. + *

Java binding of the MPI operation {@code MPI_WAITALL}. + *

On exit, requests become inactive. If the input value of + * array of {@code requests} contains inactive requests, corresponding + * elements of the status array will contain null status references. + * @param requests array of requests + * @return array of statuses + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Status[] waitAllStatus(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + Status[] status = waitAllStatus(r); + setHandles(requests, r); + return status; + } -private static native Status[] waitAllStatus(long[] requests) - throws MPIException; + private static native Status[] waitAllStatus(long[] requests) + throws MPIException; -/** - * Blocks until all of the operations associated with the active - * requests in the array have completed. - *

Java binding of the MPI operation {@code MPI_WAITALL}. - * @param requests array of requests - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void waitAll(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - waitAll(r); - setHandles(requests, r); -} + /** + * Blocks until all of the operations associated with the active + * requests in the array have completed. + *

Java binding of the MPI operation {@code MPI_WAITALL}. + * @param requests array of requests + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void waitAll(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + waitAll(r); + setHandles(requests, r); + } -private static native void waitAll(long[] requests) throws MPIException; + private static native void waitAll(long[] requests) throws MPIException; -/** - * Tests for completion of all of the operations associated - * with active requests. - *

Java binding of the MPI operation {@code MPI_TESTALL}. - *

If all operations have completed, the exit value of the argument array - * is as for {@code waitAllStatus}. - * @param requests array of requests - * @return array of statuses if all operations have completed, - * {@code null} otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Status[] testAllStatus(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - Status[] status = testAllStatus(r); - setHandles(requests, r); - return status; -} + /** + * Tests for completion of all of the operations associated + * with active requests. + *

Java binding of the MPI operation {@code MPI_TESTALL}. + *

If all operations have completed, the exit value of the argument array + * is as for {@code waitAllStatus}. + * @param requests array of requests + * @return array of statuses if all operations have completed, + * {@code null} otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Status[] testAllStatus(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + Status[] status = testAllStatus(r); + setHandles(requests, r); + return status; + } -private static native Status[] testAllStatus(long[] requests) - throws MPIException; + private static native Status[] testAllStatus(long[] requests) + throws MPIException; -/** - * Tests for completion of all of the operations associated - * with active requests. - *

Java binding of the MPI operation {@code MPI_TESTALL}. - * @param requests array of requests - * @return {@code true} if all operations have completed, - * {@code false} otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static boolean testAll(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - boolean completed = testAll(r); - setHandles(requests, r); - return completed; -} + /** + * Tests for completion of all of the operations associated + * with active requests. + *

Java binding of the MPI operation {@code MPI_TESTALL}. + * @param requests array of requests + * @return {@code true} if all operations have completed, + * {@code false} otherwise. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static boolean testAll(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + boolean completed = testAll(r); + setHandles(requests, r); + return completed; + } -private static native boolean testAll(long[] requests) throws MPIException; + private static native boolean testAll(long[] requests) throws MPIException; -/** - * Blocks until at least one of the operations associated with the active - * requests in the array has completed. - *

Java binding of the MPI operation {@code MPI_WAITSOME}. - *

The size of the result array will be the number of operations that - * completed. The index in array of {@code requests} for each request that - * completed can be obtained from the returned status objects through the - * {@code Status.getIndex()} method. The corresponding element in - * array of {@code requests} becomes inactive. - * @param requests array of requests - * @return array of statuses or {@code null} if the number of operations - * completed is {@code MPI_UNDEFINED}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Status[] waitSomeStatus(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - Status[] status = waitSomeStatus(r); - setHandles(requests, r); - return status; -} + /** + * Blocks until at least one of the operations associated with the active + * requests in the array has completed. + *

Java binding of the MPI operation {@code MPI_WAITSOME}. + *

The size of the result array will be the number of operations that + * completed. The index in array of {@code requests} for each request that + * completed can be obtained from the returned status objects through the + * {@code Status.getIndex()} method. The corresponding element in + * array of {@code requests} becomes inactive. + * @param requests array of requests + * @return array of statuses or {@code null} if the number of operations + * completed is {@code MPI_UNDEFINED}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Status[] waitSomeStatus(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + Status[] status = waitSomeStatus(r); + setHandles(requests, r); + return status; + } -private static native Status[] waitSomeStatus(long[] requests) - throws MPIException; + private static native Status[] waitSomeStatus(long[] requests) + throws MPIException; -/** - * Blocks until at least one of the operations associated with the active - * active requests in the array has completed. - *

Java binding of the MPI operation {@code MPI_WAITSOME}. - *

The size of the result array will be the number of operations that - * completed. The corresponding element in array of {@code requests} becomes - * inactive. - * @param requests array of requests - * @return array of indexes of {@code requests} that completed or {@code null} - * if the number of operations completed is {@code MPI_UNDEFINED}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int[] waitSome(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - int[] indexes = waitSome(r); - setHandles(requests, r); - return indexes; -} + /** + * Blocks until at least one of the operations associated with the active + * active requests in the array has completed. + *

Java binding of the MPI operation {@code MPI_WAITSOME}. + *

The size of the result array will be the number of operations that + * completed. The corresponding element in array of {@code requests} becomes + * inactive. + * @param requests array of requests + * @return array of indexes of {@code requests} that completed or {@code null} + * if the number of operations completed is {@code MPI_UNDEFINED}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int[] waitSome(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + int[] indexes = waitSome(r); + setHandles(requests, r); + return indexes; + } -private static native int[] waitSome(long[] requests) throws MPIException; + private static native int[] waitSome(long[] requests) throws MPIException; -/** - * Behaves like {@code waitSome}, except that it returns immediately. - *

Java binding of the MPI operation {@code MPI_TESTSOME}. - *

If no operation has completed, {@code testSome} returns an array of - * length zero, otherwise the return value are as for {@code waitSome}. - * @param requests array of requests - * @return array of statuses - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static Status[] testSomeStatus(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - Status[] status = testSomeStatus(r); - setHandles(requests, r); - return status; -} + /** + * Behaves like {@code waitSome}, except that it returns immediately. + *

Java binding of the MPI operation {@code MPI_TESTSOME}. + *

If no operation has completed, {@code testSome} returns an array of + * length zero, otherwise the return value are as for {@code waitSome}. + * @param requests array of requests + * @return array of statuses + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static Status[] testSomeStatus(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + Status[] status = testSomeStatus(r); + setHandles(requests, r); + return status; + } -private static native Status[] testSomeStatus(long[] requests) - throws MPIException; + private static native Status[] testSomeStatus(long[] requests) + throws MPIException; -/** - * Behaves like {@code waitSome}, except that it returns immediately. - *

Java binding of the MPI operation {@code MPI_TESTSOME}. - *

If no operation has completed, {@code testSome} returns an array of - * length zero, otherwise the return value are as for {@code waitSome}. - * @param requests array of requests - * @return array of indexes of {@code requests} that completed. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int[] testSome(Request[] requests) throws MPIException -{ - MPI.check(); - long[] r = getHandles(requests); - int[] indexes = testSome(r); - setHandles(requests, r); - return indexes; -} + /** + * Behaves like {@code waitSome}, except that it returns immediately. + *

Java binding of the MPI operation {@code MPI_TESTSOME}. + *

If no operation has completed, {@code testSome} returns an array of + * length zero, otherwise the return value are as for {@code waitSome}. + * @param requests array of requests + * @return array of indexes of {@code requests} that completed. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int[] testSome(Request[] requests) throws MPIException + { + MPI.check(); + long[] r = getHandles(requests); + int[] indexes = testSome(r); + setHandles(requests, r); + return indexes; + } -private static native int[] testSome(long[] requests) throws MPIException; + private static native int[] testSome(long[] requests) throws MPIException; -protected static long[] getHandles(Request[] r) -{ - long[] h = new long[r.length]; + protected static long[] getHandles(Request[] r) + { + long[] h = new long[r.length]; - for(int i = 0; i < r.length; i++) - h[i] = r[i].handle; + for(int i = 0; i < r.length; i++) + h[i] = r[i].handle; - return h; -} + return h; + } -protected static void setHandles(Request[] r, long[] h) -{ - for(int i = 0; i < r.length; i++) - r[i].handle = h[i]; -} + protected static void setHandles(Request[] r, long[] h) + { + for(int i = 0; i < r.length; i++) + r[i].handle = h[i]; + } } // Request diff --git a/ompi/mpi/java/java/ShiftParms.java b/ompi/mpi/java/java/ShiftParms.java index b580f404d1..37f26572e9 100644 --- a/ompi/mpi/java/java/ShiftParms.java +++ b/ompi/mpi/java/java/ShiftParms.java @@ -9,31 +9,33 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2015 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : ShiftParms.java * Author : Xinying Li * Created : Thu Apr 9 12:22:15 1998 @@ -50,31 +52,31 @@ package mpi; */ public final class ShiftParms { -private final int rankSource; -private final int rankDest; + private final int rankSource; + private final int rankDest; -protected ShiftParms(int rankSource, int rankDest) -{ - this.rankSource = rankSource; - this.rankDest = rankDest; -} + protected ShiftParms(int rankSource, int rankDest) + { + this.rankSource = rankSource; + this.rankDest = rankDest; + } -/** - * Gets the source rank. - * @return source rank - */ -public int getRankSource() -{ - return rankSource; -} + /** + * Gets the source rank. + * @return source rank + */ + public int getRankSource() + { + return rankSource; + } -/** - * Gets the destination rank. - * @return destination rank - */ -public int getRankDest() -{ - return rankDest; -} + /** + * Gets the destination rank. + * @return destination rank + */ + public int getRankDest() + { + return rankDest; + } } // ShiftParms diff --git a/ompi/mpi/java/java/ShortInt.java b/ompi/mpi/java/java/ShortInt.java index 92e840a20e..18c1a421f0 100644 --- a/ompi/mpi/java/java/ShortInt.java +++ b/ompi/mpi/java/java/ShortInt.java @@ -25,113 +25,113 @@ package mpi; */ public final class ShortInt extends Struct { -private final int sSize, iOff, iSize; + private final int sSize, iOff, iSize; -/** - * The struct object will be created only in MPI class. - * @param shortSize short size - * @param intOff int offset - * @param intSize int size - * @see MPI#shortInt - */ -protected ShortInt(int shortSize, int intOff, int intSize) -{ - sSize = shortSize; - iSize = intSize; - int sOff; + /** + * The struct object will be created only in MPI class. + * @param shortSize short size + * @param intOff int offset + * @param intSize int size + * @see MPI#shortInt + */ + protected ShortInt(int shortSize, int intOff, int intSize) + { + sSize = shortSize; + iSize = intSize; + int sOff; - switch(sSize) - { - case 2: sOff = addShort(); break; - case 4: sOff = addInt(); break; - case 8: sOff = addLong(); break; - default: throw new AssertionError("Unsupported short size: "+ sSize); - } + switch(sSize) + { + case 2: sOff = addShort(); break; + case 4: sOff = addInt(); break; + case 8: sOff = addLong(); break; + default: throw new AssertionError("Unsupported short size: "+ sSize); + } - assert sOff == 0; - setOffset(intOff); + assert sOff == 0; + setOffset(intOff); - switch(iSize) - { - case 4: iOff = addInt(); break; - case 8: iOff = addLong(); break; - default: throw new AssertionError("Unsupported int size: "+ iSize); - } + switch(iSize) + { + case 4: iOff = addInt(); break; + case 8: iOff = addLong(); break; + default: throw new AssertionError("Unsupported int size: "+ iSize); + } - assert(intOff == iOff); -} + assert(intOff == iOff); + } -/** - * Creates a Data object. - * @return new Data object. - */ -@Override protected Data newData() -{ - return new Data(); -} + /** + * Creates a Data object. + * @return new Data object. + */ + @Override protected Data newData() + { + return new Data(); + } -/** - * Class for reading/writing data in a struct stored in a byte buffer. - */ -public final class Data extends Struct.Data -{ - /** - * Gets the short value. - * @return short value - */ - public short getValue() - { - switch(sSize) - { - case 2: return getShort(0); - case 4: return (short)getInt(0); - case 8: return (short)getLong(0); - default: throw new AssertionError(); - } - } + /** + * Class for reading/writing data in a struct stored in a byte buffer. + */ + public final class Data extends Struct.Data + { + /** + * Gets the short value. + * @return short value + */ + public short getValue() + { + switch(sSize) + { + case 2: return getShort(0); + case 4: return (short)getInt(0); + case 8: return (short)getLong(0); + default: throw new AssertionError(); + } + } - /** - * Gets the int value. - * @return int value - */ - public int getIndex() - { - switch(iSize) - { - case 4: return getInt(iOff); - case 8: return (int)getLong(iOff); - default: throw new AssertionError(); - } - } + /** + * Gets the int value. + * @return int value + */ + public int getIndex() + { + switch(iSize) + { + case 4: return getInt(iOff); + case 8: return (int)getLong(iOff); + default: throw new AssertionError(); + } + } - /** - * Puts the short value. - * @param v short value - */ - public void putValue(short v) - { - switch(sSize) - { - case 2: putShort(0, v); break; - case 4: putInt(0, v); break; - case 8: putLong(0, v); break; - default: throw new AssertionError(); - } - } + /** + * Puts the short value. + * @param v short value + */ + public void putValue(short v) + { + switch(sSize) + { + case 2: putShort(0, v); break; + case 4: putInt(0, v); break; + case 8: putLong(0, v); break; + default: throw new AssertionError(); + } + } - /** - * Puts the int value. - * @param v int value - */ - public void putIndex(int v) - { - switch(iSize) - { - case 4: putInt(iOff, v); break; - case 8: putLong(iOff, v); break; - default: throw new AssertionError(); - } - } -} // Data + /** + * Puts the int value. + * @param v int value + */ + public void putIndex(int v) + { + switch(iSize) + { + case 4: putInt(iOff, v); break; + case 8: putLong(iOff, v); break; + default: throw new AssertionError(); + } + } + } // Data } // ShortInt diff --git a/ompi/mpi/java/java/Status.java b/ompi/mpi/java/java/Status.java index 0e55359cc4..98ae76b524 100644 --- a/ompi/mpi/java/java/Status.java +++ b/ompi/mpi/java/java/Status.java @@ -16,26 +16,26 @@ * Additional copyrights may follow * * $HEADER$ - */ -/* + * + * * This file is almost a complete re-write for Open MPI compared to the * original mpiJava package. Its license and copyright are listed below. * See for more information. - */ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -/* + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * * File : Status.java * Author : Sang Lim, Sung-Hoon Ko, Xinying Li, Bryan Carpenter * Created : Thu Apr 9 12:22:15 1998 @@ -52,127 +52,127 @@ package mpi; */ public final class Status { -protected final long[] data; + protected final long[] data; -static -{ - init(); -} + static + { + init(); + } -private static native void init(); + private static native void init(); -/** - * Status objects must be created only by the MPI methods. - */ -protected Status() -{ - data = new long[6]; -} + /** + * Status objects must be created only by the MPI methods. + */ + protected Status() + { + data = new long[6]; + } -/** - * Returns the number of received entries. - *

Java binding of the MPI operation {@code MPI_GET_COUNT}. - * @param datatype datatype of each item in receive buffer - * @return number of received entries - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getCount(Datatype datatype) throws MPIException -{ - MPI.check(); - int i = 0; - int source = (int)data[i++]; - int tag = (int)data[i++]; - int error = (int)data[i++]; - int cancelled = (int)data[i++]; - long ucount = data[i++]; - return getCount(source, tag, error, cancelled, ucount, datatype.handle); -} + /** + * Returns the number of received entries. + *

Java binding of the MPI operation {@code MPI_GET_COUNT}. + * @param datatype datatype of each item in receive buffer + * @return number of received entries + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getCount(Datatype datatype) throws MPIException + { + MPI.check(); + int i = 0; + int source = (int)data[i++]; + int tag = (int)data[i++]; + int error = (int)data[i++]; + int cancelled = (int)data[i++]; + long ucount = data[i++]; + return getCount(source, tag, error, cancelled, ucount, datatype.handle); + } -private native int getCount( - int source, int tag, int error, - int cancelled, long ucount, long datatype) throws MPIException; + private native int getCount( + int source, int tag, int error, + int cancelled, long ucount, long datatype) throws MPIException; -/** - * Tests if the communication was cancelled. - *

Java binding of the MPI operation {@code MPI_TEST_CANCELLED}. - * @return true if the operation was succesfully cancelled, false otherwise - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public boolean isCancelled() throws MPIException -{ - MPI.check(); - int i = 0; - int source = (int)data[i++]; - int tag = (int)data[i++]; - int error = (int)data[i++]; - int cancelled = (int)data[i++]; - long ucount = data[i++]; - return isCancelled(source, tag, error, cancelled, ucount); -} + /** + * Tests if the communication was cancelled. + *

Java binding of the MPI operation {@code MPI_TEST_CANCELLED}. + * @return true if the operation was succesfully cancelled, false otherwise + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public boolean isCancelled() throws MPIException + { + MPI.check(); + int i = 0; + int source = (int)data[i++]; + int tag = (int)data[i++]; + int error = (int)data[i++]; + int cancelled = (int)data[i++]; + long ucount = data[i++]; + return isCancelled(source, tag, error, cancelled, ucount); + } -private native boolean isCancelled( - int source, int tag, int error, int cancelled, long ucount) - throws MPIException; + private native boolean isCancelled( + int source, int tag, int error, int cancelled, long ucount) + throws MPIException; -/** - * Retrieves the number of basic elements from status. - *

Java binding of the MPI operation {@code MPI_GET_ELEMENTS}. - * @param datatype datatype used by receive operation - * @return number of received basic elements - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public int getElements(Datatype datatype) throws MPIException -{ - MPI.check(); - int i = 0; - int source = (int)data[i++]; - int tag = (int)data[i++]; - int error = (int)data[i++]; - int cancelled = (int)data[i++]; - long ucount = data[i++]; - return getElements(source, tag, error, cancelled, ucount, datatype.handle); -} + /** + * Retrieves the number of basic elements from status. + *

Java binding of the MPI operation {@code MPI_GET_ELEMENTS}. + * @param datatype datatype used by receive operation + * @return number of received basic elements + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public int getElements(Datatype datatype) throws MPIException + { + MPI.check(); + int i = 0; + int source = (int)data[i++]; + int tag = (int)data[i++]; + int error = (int)data[i++]; + int cancelled = (int)data[i++]; + long ucount = data[i++]; + return getElements(source, tag, error, cancelled, ucount, datatype.handle); + } -private native int getElements( - int source, int tag, int error, - int cancelled, long ucount, long datatype) throws MPIException; + private native int getElements( + int source, int tag, int error, + int cancelled, long ucount, long datatype) throws MPIException; -/** - * Returns the "source" of message. - *

Java binding of the MPI value {@code MPI_SOURCE}. - * @return source of message - */ -public int getSource() -{ - return (int)data[0]; -} + /** + * Returns the "source" of message. + *

Java binding of the MPI value {@code MPI_SOURCE}. + * @return source of message + */ + public int getSource() + { + return (int)data[0]; + } -/** - * Returns the "tag" of message. - *

Java binding of the MPI value {@code MPI_TAG}. - * @return tag of message - */ -public int getTag() -{ - return (int)data[1]; -} + /** + * Returns the "tag" of message. + *

Java binding of the MPI value {@code MPI_TAG}. + * @return tag of message + */ + public int getTag() + { + return (int)data[1]; + } -/** - * Returns the {@code MPI_ERROR} of message. - * @return error of message. - */ -public int getError() -{ - return (int)data[2]; -} + /** + * Returns the {@code MPI_ERROR} of message. + * @return error of message. + */ + public int getError() + { + return (int)data[2]; + } -/** - * Returns the index of message. - * @return index of message. - */ -public int getIndex() -{ - return (int)data[5]; -} + /** + * Returns the index of message. + * @return index of message. + */ + public int getIndex() + { + return (int)data[5]; + } } // Status diff --git a/ompi/mpi/java/java/Struct.java b/ompi/mpi/java/java/Struct.java index 96b2b38c64..b7dfefe4d4 100644 --- a/ompi/mpi/java/java/Struct.java +++ b/ompi/mpi/java/java/Struct.java @@ -28,775 +28,775 @@ import java.util.*; */ public abstract class Struct { -private int extent; -private ArrayList fields = new ArrayList(); - -private Datatype datatype, types[]; -private int offsets[], lengths[]; -private static final String typeMismatch = "Type mismatch"; - -private void commit() throws MPIException -{ - if(datatype == null) - createStruct(); -} - -private void createStruct() throws MPIException -{ - int count = fields.size(); - types = new Datatype[count]; - offsets = new int[count]; - lengths = new int[count]; - - for(int i = 0; i < count; i++) - { - Field f = fields.get(i); - - types[i] = f.type instanceof Struct ? ((Struct)f.type).datatype - : (Datatype)f.type; - offsets[i] = f.offset; - lengths[i] = f.length; - } - - datatype = Datatype.createStruct(lengths, offsets, types); - datatype.commit(); - extent = datatype.getExtent(); -} - -/** - * Returns the extent of the struct data type. - * @return Extent of the struct data type. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int getExtent() throws MPIException -{ - commit(); - return extent; -} - -/** - * Returns the data type of the struct. - * @return The data type of the struct. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Datatype getType() throws MPIException -{ - commit(); - return datatype; -} - -/** - * Creates a Data object. - * @return New Data object. - */ -protected abstract Data newData(); - -@SuppressWarnings("unchecked") -private T newData(ByteBuffer buffer, int offset) -{ - Data d = newData(); - d.buffer = buffer; - d.offset = offset; - return (T)d; -} - -@SuppressWarnings("javadoc") -/** - * Gets a Data object in order to access to the buffer. - * @param buffer the Data object will read/write on this buffer. - * @return Data object - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final T getData(ByteBuffer buffer) throws MPIException -{ - commit(); - return newData(buffer, 0); -} - -@SuppressWarnings("javadoc") -/** - * Gets a Data object in order to access to the struct at the - * specified position of a struct array stored in a Buffer. - * @param buffer The Data object will read/write on this buffer. - * @param index Index of the struct in the buffer. - * @return Data object. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final T getData(ByteBuffer buffer, int index) - throws MPIException -{ - commit(); - return newData(buffer, index * extent); -} - -@SuppressWarnings("javadoc") -/** - * Gets a Data object in order to access to the byte array. - * @param array The Data object will read/write on this byte array. - * @return Data object. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final T getData(byte[] array) throws MPIException -{ - ByteBuffer buffer = ByteBuffer.wrap(array); - buffer.order(ByteOrder.nativeOrder()); - return getData(buffer); -} - -@SuppressWarnings("javadoc") -/** - * Gets a Data object in order to access to the struct at the - * specified position of a struct array stored in a byte array. - * @param array The Data object will read/write on this byte array. - * @param index Index of the struct in the array. - * @return Data object. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final T getData(byte[] array, int index) - throws MPIException -{ - ByteBuffer buffer = ByteBuffer.wrap(array); - buffer.order(ByteOrder.nativeOrder()); - return getData(buffer, index); -} - -private int addField(Object type, int typeExtent, int length) -{ - if(datatype != null) - throw new AssertionError("The struct data type was committed."); - - int offset = extent; - extent += typeExtent * length; - fields.add(new Field(type, offset, length)); - return offset; -} - -/** - * Sets the offset of the next field. - *

The offset must be greater or equal to the accumulated extent. - * @param offset offset of the next field - * @return this object in order to allow adding fields in a chained expression - */ -public final Struct setOffset(int offset) -{ - if(datatype != null) - throw new AssertionError("The struct data type was committed."); - - if(offset < extent) - { - throw new IllegalArgumentException( - "The offset must be greater or equal to the accumulated extent."); - } - - extent = offset; - return this; -} - -/** - * Adds a byte field to this struct. - * @return Offset of the new field. - */ -public final int addByte() -{ - return addByte(1); -} - -/** - * Adds a byte array to this struct. - * @param length Length of the array. - * @return Offset of the new field. - */ -public final int addByte(int length) -{ - return addField(MPI.BYTE, 1, length); -} - -/** - * Adds a char field to this struct. - * @return Offset of the new field. - */ -public final int addChar() -{ - return addChar(1); -} - -/** - * Adds a char array to this struct. - * @param length Length of the array. - * @return Offset of the new field. - */ -public final int addChar(int length) -{ - return addField(MPI.CHAR, 2, length); -} - -/** - * Adds a short field to this struct. - * @return Offset of the new field. - */ -public final int addShort() -{ - return addShort(1); -} - -/** - * Adds a short array to this struct. - * @param length Length of the array. - * @return Offset of the new field. - */ -public final int addShort(int length) -{ - return addField(MPI.SHORT, 2, length); -} - -/** - * Adds an int field to this struct. - * @return Offset of the new field. - */ -public final int addInt() -{ - return addInt(1); -} - -/** - * Adds an int array to this struct. - * @param length Length of the array. - * @return Offset of the new field. - */ -public final int addInt(int length) -{ - return addField(MPI.INT, 4, length); -} - -/** - * Adds a long field to this struct. - * @return Offset of the new field. - */ -public final int addLong() -{ - return addLong(1); -} - -/** - * Adds a long array to this struct. - * @param length Length of the array. - * @return Offset of the new field. - */ -public final int addLong(int length) -{ - return addField(MPI.LONG, 8, length); -} - -/** - * Adds a float field to this struct. - * @return Offset of the new field. - */ -public final int addFloat() -{ - return addFloat(1); -} - -/** - * Adds a float array to this struct. - * @param length Length of the array. - * @return Offset of the new field. - */ -public final int addFloat(int length) -{ - return addField(MPI.FLOAT, 4, length); -} - -/** - * Adds a double field to this struct. - * @return Offset of the new field. - */ -public final int addDouble() -{ - return addDouble(1); -} - -/** - * Adds a double array to this struct. - * @param length Length of the array. - * @return Offset of the new field. - */ -public final int addDouble(int length) -{ - return addField(MPI.DOUBLE, 8, length); -} - -/** - * Adds a struct field to this struct. - * @param struct Type of the field. - * @return Offset of the new field. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int addStruct(Struct struct) throws MPIException -{ - return addStruct(struct, 1); -} - -/** - * Adds an array of structs to this struct. - * @param struct Type of the array. - * @param length Length of the array. - * @return Offset of the new field. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int addStruct(Struct struct, int length) throws MPIException -{ - struct.commit(); - return addField(struct, struct.extent, length); -} - -/** - * Adds a field of the specified data type. - * @param type Data type. - * @return Offset of the new field. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int addData(Datatype type) throws MPIException -{ - return addData(type, 1); -} - -/** - * Adds an array of the specified data type. - * @param type Data type. - * @param length Length of the array. - * @return Offset of the new field. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final int addData(Datatype type, int length) throws MPIException -{ - return addField(type, type.getExtent() * type.baseSize, length); -} - -private boolean validType(int fieldOffset, int index, Datatype type) -{ - int i = Arrays.binarySearch(offsets, fieldOffset); - return index >= 0 && index < lengths[i] && type == types[i]; -} - -private static class Field -{ - private Object type; - private int offset, length; - - private Field(Object type, int offset, int length) - { - this.type = type; - this.offset = offset; - this.length = length; - } - -} // Field - -/** - * Base class for reading/writing data in a struct stored in a byte buffer. - */ -public abstract class Data -{ - private ByteBuffer buffer; - private int offset; - - /** - * Gets the buffer where this struct data is stored. - *

The buffer can be used in {@code send}/{@code recv} operations. - * @return Buffer where the struct data is stored. - */ - public final ByteBuffer getBuffer() - { - return offset == 0 ? buffer : MPI.slice(buffer, offset); - } - - /** - * Gets the byte value of a field. - * @param field Offset of the field. - * @return Byte value. - */ - protected final byte getByte(int field) - { - assert validType(field, 0, MPI.BYTE) : typeMismatch; - return buffer.get(offset + field); - } - - /** - * Gets the byte value at the specified position of a byte array. - * @param field Offset of the byte array. - * @param index Index of the byte in the array. - * @return Byte value. - */ - protected final byte getByte(int field, int index) - { - assert validType(field, index, MPI.BYTE) : typeMismatch; - return buffer.get(offset + field + index); - } - - /** - * Puts a byte value in a field. - * @param field Offset of the field. - * @param v Byte value. - */ - protected final void putByte(int field, byte v) - { - assert validType(field, 0, MPI.BYTE) : typeMismatch; - buffer.put(offset + field, v); - } - - /** - * Puts a byte value at the specified position of a byte array. - * @param field Offset of the byte array. - * @param index Index of the byte in the array. - * @param v Byte value. - */ - protected final void putByte(int field, int index, byte v) - { - assert validType(field, index, MPI.BYTE) : typeMismatch; - buffer.put(offset + field + index, v); - } - - /** - * Gets the char value of a field. - * @param field Offset of the field. - * @return Char value. - */ - protected final char getChar(int field) - { - assert validType(field, 0, MPI.CHAR) : typeMismatch; - return buffer.getChar(offset + field); - } - - /** - * Gets the char value at the specified position of a char array. - * @param field Offset of the char array. - * @param index Index of the char in the array. - * @return Char value. - */ - protected final char getChar(int field, int index) - { - assert validType(field, index, MPI.CHAR) : typeMismatch; - return buffer.getChar(offset + field + index * 2); - } - - /** - * Puts a char value in a field. - * @param field Offset of the field. - * @param v Char value. - */ - protected final void putChar(int field, char v) - { - assert validType(field, 0, MPI.CHAR) : typeMismatch; - buffer.putChar(offset + field, v); - } - - /** - * Puts a char value at the specified position of a char array. - * @param field Offset of the char array. - * @param index Index of the char in the array. - * @param v Char value. - */ - protected final void putChar(int field, int index, char v) - { - assert validType(field, index, MPI.CHAR) : typeMismatch; - buffer.putChar(offset + field + index * 2, v); - } - - /** - * Gets the short value of a field. - * @param field Offset of the field. - * @return Short value. - */ - protected final short getShort(int field) - { - assert validType(field, 0, MPI.SHORT) : typeMismatch; - return buffer.getShort(offset + field); - } - - /** - * Gets the short value at the specified position of a short array. - * @param field Offset of the short array. - * @param index Index of the short in the array. - * @return Short value. - */ - protected final short getShort(int field, int index) - { - assert validType(field, index, MPI.SHORT) : typeMismatch; - return buffer.getShort(offset + field + index * 2); - } - - /** - * Puts a short value in a field. - * @param field Offset of the field. - * @param v Short value. - */ - protected final void putShort(int field, short v) - { - assert validType(field, 0, MPI.SHORT) : typeMismatch; - buffer.putShort(offset + field, v); - } - - /** - * Puts a short value at the specified position of a short array. - * @param field Offset of the short array. - * @param index Index of the short in the array. - * @param v Short value. - */ - protected final void putShort(int field, int index, short v) - { - assert validType(field, index, MPI.SHORT) : typeMismatch; - buffer.putShort(offset + field + index * 2, v); - } - - /** - * Gets the int value of a field. - * @param field Offset of the field. - * @return Int value. - */ - protected final int getInt(int field) - { - assert validType(field, 0, MPI.INT) : typeMismatch; - return buffer.getInt(offset + field); - } - - /** - * Gets the int value at the specified position of an int array. - * @param field Offset of the int array. - * @param index Index of the int in the array. - * @return Int value. - */ - protected final int getInt(int field, int index) - { - assert validType(field, index, MPI.INT) : typeMismatch; - return buffer.getInt(offset + field + index * 4); - } - - /** - * Puts an int value in a field. - * @param field Offset of the field. - * @param v Int value. - */ - protected final void putInt(int field, int v) - { - assert validType(field, 0, MPI.INT) : typeMismatch; - buffer.putInt(offset + field, v); - } - - /** - * Puts an int value at the specified position of an int array. - * @param field Offset of the int array. - * @param index Index of the int in the array. - * @param v Int value. - */ - protected final void putInt(int field, int index, int v) - { - assert validType(field, index, MPI.INT) : typeMismatch; - buffer.putInt(offset + field + index * 4, v); - } - - /** - * Gets the long value of a field. - * @param field Offset of the field. - * @return Long value. - */ - protected final long getLong(int field) - { - assert validType(field, 0, MPI.LONG) : typeMismatch; - return buffer.getLong(offset + field); - } - - /** - * Gets the long value at the specified position of a long array. - * @param field Offset of the long array. - * @param index Index of the long in the array. - * @return Long value. - */ - protected final long getLong(int field, int index) - { - assert validType(field, index, MPI.LONG) : typeMismatch; - return buffer.getLong(offset + field + index * 8); - } - - /** - * Puts a long value in a field. - * @param field Offset of the field. - * @param v Long value. - */ - protected final void putLong(int field, long v) - { - assert validType(field, 0, MPI.LONG) : typeMismatch; - buffer.putLong(offset + field, v); - } - - /** - * Puts a long value at the specified position of a long array. - * @param field Offset of the long array. - * @param index Index of the long in the array. - * @param v Long value. - */ - protected final void putLong(int field, int index, long v) - { - assert validType(field, index, MPI.LONG) : typeMismatch; - buffer.putLong(offset + field + index * 8, v); - } - - /** - * Gets the float value of a field. - * @param field Offset of the field. - * @return Float value. - */ - protected final float getFloat(int field) - { - assert validType(field, 0, MPI.FLOAT) : typeMismatch; - return buffer.getFloat(offset + field); - } - - /** - * Gets the float value at the specified position of a float array. - * @param field Offset of the float array. - * @param index Index of the float in the array. - * @return Float value. - */ - protected final float getFloat(int field, int index) - { - assert validType(field, index, MPI.FLOAT) : typeMismatch; - return buffer.getFloat(offset + field + index * 4); - } - - /** - * Puts a float value in a field. - * @param field Offset of the field. - * @param v Float value. - */ - protected final void putFloat(int field, float v) - { - assert validType(field, 0, MPI.FLOAT) : typeMismatch; - buffer.putFloat(offset + field, v); - } - - /** - * Puts a float value at the specified position of a float array. - * @param field Offset of the float array. - * @param index Index of the float in the array. - * @param v Float value. - */ - protected final void putFloat(int field, int index, float v) - { - assert validType(field, index, MPI.FLOAT) : typeMismatch; - buffer.putFloat(offset + field + index * 4, v); - } - - /** - * Gets the double value of a field. - * @param field Offset of the field. - * @return Double value. - */ - protected final double getDouble(int field) - { - assert validType(field, 0, MPI.DOUBLE) : typeMismatch; - return buffer.getDouble(offset + field); - } - - /** - * Gets the double value at the specified position of a double array. - * @param field Offset of the double array. - * @param index Index of the double in the array. - * @return Double value. - */ - protected final double getDouble(int field, int index) - { - assert validType(field, index, MPI.DOUBLE) : typeMismatch; - return buffer.getDouble(offset + field + index * 8); - } - - /** - * Puts a double value in a field. - * @param field Offset of the field. - * @param v Double value. - */ - protected final void putDouble(int field, double v) - { - assert validType(field, 0, MPI.DOUBLE) : typeMismatch; - buffer.putDouble(offset + field, v); - } - - /** - * Puts a double value at the specified position of a double array. - * @param field Offset of the double array. - * @param index Index of the double in the array. - * @param v Double value. - */ - protected final void putDouble(int field, int index, double v) - { - assert validType(field, index, MPI.DOUBLE) : typeMismatch; - buffer.putDouble(offset + field + index * 8, v); - } - - @SuppressWarnings("javadoc") - /** - * Gets the struct data of a field. - * @param struct Struct type. - * @param field Offset of the field. - * @return Struct data. - */ - protected final - D getData(S struct, int field) - { - Struct s = (Struct)struct; - assert validType(field, 0, s.datatype) : typeMismatch; - return s.newData(buffer, offset + field); - } - - @SuppressWarnings("javadoc") - /** - * Gets the struct data at the specified position of a struct array. - * @param struct Struct type. - * @param field Offset of the struct array. - * @param index Index of the struct in the array. - * @return Struct data. - */ - protected final - D getData(S struct, int field, int index) - { - Struct s = (Struct)struct; - assert validType(field, index, s.datatype) : typeMismatch; - return s.newData(buffer, offset + field + index * s.extent); - } - - /** - * Gets the buffer of a field. - *

The buffer can be used in {@code send}/{@code recv} operations. - * @param type Data type of the buffer. - * @param field Offset of the field. - * @return Buffer object. - */ - protected final ByteBuffer getBuffer(Datatype type, int field) - { - assert validType(field, 0, type) : typeMismatch; - int position = offset + field; - return position == 0 ? buffer : MPI.slice(buffer, position); - } - - /** - * Gets the buffer data at the specified position of a buffer array. - *

The buffer can be used in {@code send}/{@code recv} operations. - * @param type Data type of the buffer. - * @param field Offset of the buffer array. - * @param index Index of the buffer in the array. - * @return Buffer object. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - protected final ByteBuffer getBuffer(Datatype type, int field, int index) - throws MPIException - { - assert validType(field, index, type) : typeMismatch; - - int extent = type.getExtent() * type.baseSize, - position = offset + field + index * extent; - - return position == 0 ? buffer : MPI.slice(buffer, position); - } - -} // Data + private int extent; + private ArrayList fields = new ArrayList(); + + private Datatype datatype, types[]; + private int offsets[], lengths[]; + private static final String typeMismatch = "Type mismatch"; + + private void commit() throws MPIException + { + if(datatype == null) + createStruct(); + } + + private void createStruct() throws MPIException + { + int count = fields.size(); + types = new Datatype[count]; + offsets = new int[count]; + lengths = new int[count]; + + for(int i = 0; i < count; i++) + { + Field f = fields.get(i); + + types[i] = f.type instanceof Struct ? ((Struct)f.type).datatype + : (Datatype)f.type; + offsets[i] = f.offset; + lengths[i] = f.length; + } + + datatype = Datatype.createStruct(lengths, offsets, types); + datatype.commit(); + extent = datatype.getExtent(); + } + + /** + * Returns the extent of the struct data type. + * @return Extent of the struct data type. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int getExtent() throws MPIException + { + commit(); + return extent; + } + + /** + * Returns the data type of the struct. + * @return The data type of the struct. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Datatype getType() throws MPIException + { + commit(); + return datatype; + } + + /** + * Creates a Data object. + * @return New Data object. + */ + protected abstract Data newData(); + + @SuppressWarnings("unchecked") + private T newData(ByteBuffer buffer, int offset) + { + Data d = newData(); + d.buffer = buffer; + d.offset = offset; + return (T)d; + } + + @SuppressWarnings("javadoc") + /** + * Gets a Data object in order to access to the buffer. + * @param buffer the Data object will read/write on this buffer. + * @return Data object + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final T getData(ByteBuffer buffer) throws MPIException + { + commit(); + return newData(buffer, 0); + } + + @SuppressWarnings("javadoc") + /** + * Gets a Data object in order to access to the struct at the + * specified position of a struct array stored in a Buffer. + * @param buffer The Data object will read/write on this buffer. + * @param index Index of the struct in the buffer. + * @return Data object. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final T getData(ByteBuffer buffer, int index) + throws MPIException + { + commit(); + return newData(buffer, index * extent); + } + + @SuppressWarnings("javadoc") + /** + * Gets a Data object in order to access to the byte array. + * @param array The Data object will read/write on this byte array. + * @return Data object. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final T getData(byte[] array) throws MPIException + { + ByteBuffer buffer = ByteBuffer.wrap(array); + buffer.order(ByteOrder.nativeOrder()); + return getData(buffer); + } + + @SuppressWarnings("javadoc") + /** + * Gets a Data object in order to access to the struct at the + * specified position of a struct array stored in a byte array. + * @param array The Data object will read/write on this byte array. + * @param index Index of the struct in the array. + * @return Data object. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final T getData(byte[] array, int index) + throws MPIException + { + ByteBuffer buffer = ByteBuffer.wrap(array); + buffer.order(ByteOrder.nativeOrder()); + return getData(buffer, index); + } + + private int addField(Object type, int typeExtent, int length) + { + if(datatype != null) + throw new AssertionError("The struct data type was committed."); + + int offset = extent; + extent += typeExtent * length; + fields.add(new Field(type, offset, length)); + return offset; + } + + /** + * Sets the offset of the next field. + *

The offset must be greater or equal to the accumulated extent. + * @param offset offset of the next field + * @return this object in order to allow adding fields in a chained expression + */ + public final Struct setOffset(int offset) + { + if(datatype != null) + throw new AssertionError("The struct data type was committed."); + + if(offset < extent) + { + throw new IllegalArgumentException( + "The offset must be greater or equal to the accumulated extent."); + } + + extent = offset; + return this; + } + + /** + * Adds a byte field to this struct. + * @return Offset of the new field. + */ + public final int addByte() + { + return addByte(1); + } + + /** + * Adds a byte array to this struct. + * @param length Length of the array. + * @return Offset of the new field. + */ + public final int addByte(int length) + { + return addField(MPI.BYTE, 1, length); + } + + /** + * Adds a char field to this struct. + * @return Offset of the new field. + */ + public final int addChar() + { + return addChar(1); + } + + /** + * Adds a char array to this struct. + * @param length Length of the array. + * @return Offset of the new field. + */ + public final int addChar(int length) + { + return addField(MPI.CHAR, 2, length); + } + + /** + * Adds a short field to this struct. + * @return Offset of the new field. + */ + public final int addShort() + { + return addShort(1); + } + + /** + * Adds a short array to this struct. + * @param length Length of the array. + * @return Offset of the new field. + */ + public final int addShort(int length) + { + return addField(MPI.SHORT, 2, length); + } + + /** + * Adds an int field to this struct. + * @return Offset of the new field. + */ + public final int addInt() + { + return addInt(1); + } + + /** + * Adds an int array to this struct. + * @param length Length of the array. + * @return Offset of the new field. + */ + public final int addInt(int length) + { + return addField(MPI.INT, 4, length); + } + + /** + * Adds a long field to this struct. + * @return Offset of the new field. + */ + public final int addLong() + { + return addLong(1); + } + + /** + * Adds a long array to this struct. + * @param length Length of the array. + * @return Offset of the new field. + */ + public final int addLong(int length) + { + return addField(MPI.LONG, 8, length); + } + + /** + * Adds a float field to this struct. + * @return Offset of the new field. + */ + public final int addFloat() + { + return addFloat(1); + } + + /** + * Adds a float array to this struct. + * @param length Length of the array. + * @return Offset of the new field. + */ + public final int addFloat(int length) + { + return addField(MPI.FLOAT, 4, length); + } + + /** + * Adds a double field to this struct. + * @return Offset of the new field. + */ + public final int addDouble() + { + return addDouble(1); + } + + /** + * Adds a double array to this struct. + * @param length Length of the array. + * @return Offset of the new field. + */ + public final int addDouble(int length) + { + return addField(MPI.DOUBLE, 8, length); + } + + /** + * Adds a struct field to this struct. + * @param struct Type of the field. + * @return Offset of the new field. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int addStruct(Struct struct) throws MPIException + { + return addStruct(struct, 1); + } + + /** + * Adds an array of structs to this struct. + * @param struct Type of the array. + * @param length Length of the array. + * @return Offset of the new field. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int addStruct(Struct struct, int length) throws MPIException + { + struct.commit(); + return addField(struct, struct.extent, length); + } + + /** + * Adds a field of the specified data type. + * @param type Data type. + * @return Offset of the new field. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int addData(Datatype type) throws MPIException + { + return addData(type, 1); + } + + /** + * Adds an array of the specified data type. + * @param type Data type. + * @param length Length of the array. + * @return Offset of the new field. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final int addData(Datatype type, int length) throws MPIException + { + return addField(type, type.getExtent() * type.baseSize, length); + } + + private boolean validType(int fieldOffset, int index, Datatype type) + { + int i = Arrays.binarySearch(offsets, fieldOffset); + return index >= 0 && index < lengths[i] && type == types[i]; + } + + private static class Field + { + private Object type; + private int offset, length; + + private Field(Object type, int offset, int length) + { + this.type = type; + this.offset = offset; + this.length = length; + } + + } // Field + + /** + * Base class for reading/writing data in a struct stored in a byte buffer. + */ + public abstract class Data + { + private ByteBuffer buffer; + private int offset; + + /** + * Gets the buffer where this struct data is stored. + *

The buffer can be used in {@code send}/{@code recv} operations. + * @return Buffer where the struct data is stored. + */ + public final ByteBuffer getBuffer() + { + return offset == 0 ? buffer : MPI.slice(buffer, offset); + } + + /** + * Gets the byte value of a field. + * @param field Offset of the field. + * @return Byte value. + */ + protected final byte getByte(int field) + { + assert validType(field, 0, MPI.BYTE) : typeMismatch; + return buffer.get(offset + field); + } + + /** + * Gets the byte value at the specified position of a byte array. + * @param field Offset of the byte array. + * @param index Index of the byte in the array. + * @return Byte value. + */ + protected final byte getByte(int field, int index) + { + assert validType(field, index, MPI.BYTE) : typeMismatch; + return buffer.get(offset + field + index); + } + + /** + * Puts a byte value in a field. + * @param field Offset of the field. + * @param v Byte value. + */ + protected final void putByte(int field, byte v) + { + assert validType(field, 0, MPI.BYTE) : typeMismatch; + buffer.put(offset + field, v); + } + + /** + * Puts a byte value at the specified position of a byte array. + * @param field Offset of the byte array. + * @param index Index of the byte in the array. + * @param v Byte value. + */ + protected final void putByte(int field, int index, byte v) + { + assert validType(field, index, MPI.BYTE) : typeMismatch; + buffer.put(offset + field + index, v); + } + + /** + * Gets the char value of a field. + * @param field Offset of the field. + * @return Char value. + */ + protected final char getChar(int field) + { + assert validType(field, 0, MPI.CHAR) : typeMismatch; + return buffer.getChar(offset + field); + } + + /** + * Gets the char value at the specified position of a char array. + * @param field Offset of the char array. + * @param index Index of the char in the array. + * @return Char value. + */ + protected final char getChar(int field, int index) + { + assert validType(field, index, MPI.CHAR) : typeMismatch; + return buffer.getChar(offset + field + index * 2); + } + + /** + * Puts a char value in a field. + * @param field Offset of the field. + * @param v Char value. + */ + protected final void putChar(int field, char v) + { + assert validType(field, 0, MPI.CHAR) : typeMismatch; + buffer.putChar(offset + field, v); + } + + /** + * Puts a char value at the specified position of a char array. + * @param field Offset of the char array. + * @param index Index of the char in the array. + * @param v Char value. + */ + protected final void putChar(int field, int index, char v) + { + assert validType(field, index, MPI.CHAR) : typeMismatch; + buffer.putChar(offset + field + index * 2, v); + } + + /** + * Gets the short value of a field. + * @param field Offset of the field. + * @return Short value. + */ + protected final short getShort(int field) + { + assert validType(field, 0, MPI.SHORT) : typeMismatch; + return buffer.getShort(offset + field); + } + + /** + * Gets the short value at the specified position of a short array. + * @param field Offset of the short array. + * @param index Index of the short in the array. + * @return Short value. + */ + protected final short getShort(int field, int index) + { + assert validType(field, index, MPI.SHORT) : typeMismatch; + return buffer.getShort(offset + field + index * 2); + } + + /** + * Puts a short value in a field. + * @param field Offset of the field. + * @param v Short value. + */ + protected final void putShort(int field, short v) + { + assert validType(field, 0, MPI.SHORT) : typeMismatch; + buffer.putShort(offset + field, v); + } + + /** + * Puts a short value at the specified position of a short array. + * @param field Offset of the short array. + * @param index Index of the short in the array. + * @param v Short value. + */ + protected final void putShort(int field, int index, short v) + { + assert validType(field, index, MPI.SHORT) : typeMismatch; + buffer.putShort(offset + field + index * 2, v); + } + + /** + * Gets the int value of a field. + * @param field Offset of the field. + * @return Int value. + */ + protected final int getInt(int field) + { + assert validType(field, 0, MPI.INT) : typeMismatch; + return buffer.getInt(offset + field); + } + + /** + * Gets the int value at the specified position of an int array. + * @param field Offset of the int array. + * @param index Index of the int in the array. + * @return Int value. + */ + protected final int getInt(int field, int index) + { + assert validType(field, index, MPI.INT) : typeMismatch; + return buffer.getInt(offset + field + index * 4); + } + + /** + * Puts an int value in a field. + * @param field Offset of the field. + * @param v Int value. + */ + protected final void putInt(int field, int v) + { + assert validType(field, 0, MPI.INT) : typeMismatch; + buffer.putInt(offset + field, v); + } + + /** + * Puts an int value at the specified position of an int array. + * @param field Offset of the int array. + * @param index Index of the int in the array. + * @param v Int value. + */ + protected final void putInt(int field, int index, int v) + { + assert validType(field, index, MPI.INT) : typeMismatch; + buffer.putInt(offset + field + index * 4, v); + } + + /** + * Gets the long value of a field. + * @param field Offset of the field. + * @return Long value. + */ + protected final long getLong(int field) + { + assert validType(field, 0, MPI.LONG) : typeMismatch; + return buffer.getLong(offset + field); + } + + /** + * Gets the long value at the specified position of a long array. + * @param field Offset of the long array. + * @param index Index of the long in the array. + * @return Long value. + */ + protected final long getLong(int field, int index) + { + assert validType(field, index, MPI.LONG) : typeMismatch; + return buffer.getLong(offset + field + index * 8); + } + + /** + * Puts a long value in a field. + * @param field Offset of the field. + * @param v Long value. + */ + protected final void putLong(int field, long v) + { + assert validType(field, 0, MPI.LONG) : typeMismatch; + buffer.putLong(offset + field, v); + } + + /** + * Puts a long value at the specified position of a long array. + * @param field Offset of the long array. + * @param index Index of the long in the array. + * @param v Long value. + */ + protected final void putLong(int field, int index, long v) + { + assert validType(field, index, MPI.LONG) : typeMismatch; + buffer.putLong(offset + field + index * 8, v); + } + + /** + * Gets the float value of a field. + * @param field Offset of the field. + * @return Float value. + */ + protected final float getFloat(int field) + { + assert validType(field, 0, MPI.FLOAT) : typeMismatch; + return buffer.getFloat(offset + field); + } + + /** + * Gets the float value at the specified position of a float array. + * @param field Offset of the float array. + * @param index Index of the float in the array. + * @return Float value. + */ + protected final float getFloat(int field, int index) + { + assert validType(field, index, MPI.FLOAT) : typeMismatch; + return buffer.getFloat(offset + field + index * 4); + } + + /** + * Puts a float value in a field. + * @param field Offset of the field. + * @param v Float value. + */ + protected final void putFloat(int field, float v) + { + assert validType(field, 0, MPI.FLOAT) : typeMismatch; + buffer.putFloat(offset + field, v); + } + + /** + * Puts a float value at the specified position of a float array. + * @param field Offset of the float array. + * @param index Index of the float in the array. + * @param v Float value. + */ + protected final void putFloat(int field, int index, float v) + { + assert validType(field, index, MPI.FLOAT) : typeMismatch; + buffer.putFloat(offset + field + index * 4, v); + } + + /** + * Gets the double value of a field. + * @param field Offset of the field. + * @return Double value. + */ + protected final double getDouble(int field) + { + assert validType(field, 0, MPI.DOUBLE) : typeMismatch; + return buffer.getDouble(offset + field); + } + + /** + * Gets the double value at the specified position of a double array. + * @param field Offset of the double array. + * @param index Index of the double in the array. + * @return Double value. + */ + protected final double getDouble(int field, int index) + { + assert validType(field, index, MPI.DOUBLE) : typeMismatch; + return buffer.getDouble(offset + field + index * 8); + } + + /** + * Puts a double value in a field. + * @param field Offset of the field. + * @param v Double value. + */ + protected final void putDouble(int field, double v) + { + assert validType(field, 0, MPI.DOUBLE) : typeMismatch; + buffer.putDouble(offset + field, v); + } + + /** + * Puts a double value at the specified position of a double array. + * @param field Offset of the double array. + * @param index Index of the double in the array. + * @param v Double value. + */ + protected final void putDouble(int field, int index, double v) + { + assert validType(field, index, MPI.DOUBLE) : typeMismatch; + buffer.putDouble(offset + field + index * 8, v); + } + + @SuppressWarnings("javadoc") + /** + * Gets the struct data of a field. + * @param struct Struct type. + * @param field Offset of the field. + * @return Struct data. + */ + protected final + D getData(S struct, int field) + { + Struct s = (Struct)struct; + assert validType(field, 0, s.datatype) : typeMismatch; + return s.newData(buffer, offset + field); + } + + @SuppressWarnings("javadoc") + /** + * Gets the struct data at the specified position of a struct array. + * @param struct Struct type. + * @param field Offset of the struct array. + * @param index Index of the struct in the array. + * @return Struct data. + */ + protected final + D getData(S struct, int field, int index) + { + Struct s = (Struct)struct; + assert validType(field, index, s.datatype) : typeMismatch; + return s.newData(buffer, offset + field + index * s.extent); + } + + /** + * Gets the buffer of a field. + *

The buffer can be used in {@code send}/{@code recv} operations. + * @param type Data type of the buffer. + * @param field Offset of the field. + * @return Buffer object. + */ + protected final ByteBuffer getBuffer(Datatype type, int field) + { + assert validType(field, 0, type) : typeMismatch; + int position = offset + field; + return position == 0 ? buffer : MPI.slice(buffer, position); + } + + /** + * Gets the buffer data at the specified position of a buffer array. + *

The buffer can be used in {@code send}/{@code recv} operations. + * @param type Data type of the buffer. + * @param field Offset of the buffer array. + * @param index Index of the buffer in the array. + * @return Buffer object. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + protected final ByteBuffer getBuffer(Datatype type, int field, int index) + throws MPIException + { + assert validType(field, index, type) : typeMismatch; + + int extent = type.getExtent() * type.baseSize, + position = offset + field + index * extent; + + return position == 0 ? buffer : MPI.slice(buffer, position); + } + + } // Data } // Struct diff --git a/ompi/mpi/java/java/UserFunction.java b/ompi/mpi/java/java/UserFunction.java index 7c948cc799..13a98d67c1 100644 --- a/ompi/mpi/java/java/UserFunction.java +++ b/ompi/mpi/java/java/UserFunction.java @@ -34,7 +34,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -*/ + */ /* * File : User_function.java * Author : Xinying Li @@ -54,158 +54,158 @@ import java.nio.*; */ public abstract class UserFunction { -/** - * User-defined function for a new {@code Op}. - * @param inVec array of values to combine with {@code inoutvec} elements - * @param inOutVec in-out array of accumulator locations - * @param count number of items in arrays - * @param datatype type of each item - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void call(Object inVec, Object inOutVec, int count, Datatype datatype) - throws MPIException -{ - throw new UnsupportedOperationException("Not supported yet."); -} + /** + * User-defined function for a new {@code Op}. + * @param inVec array of values to combine with {@code inoutvec} elements + * @param inOutVec in-out array of accumulator locations + * @param count number of items in arrays + * @param datatype type of each item + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void call(Object inVec, Object inOutVec, int count, Datatype datatype) + throws MPIException + { + throw new UnsupportedOperationException("Not supported yet."); + } -/** - * User-defined function for a new {@code Op}. - * @param in direct byte buffer to combine with {@code inOut} buffer - * @param inOut in-out direct byte buffer of accumulator locations - * @param count number of items in buffers - * @param datatype type of each item - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void call(ByteBuffer in, ByteBuffer inOut, int count, Datatype datatype) - throws MPIException -{ - switch(datatype.baseType) - { - case Datatype.BYTE: - vCall(in, inOut, count, datatype); - break; - case Datatype.CHAR: - vCall(in.asCharBuffer(), inOut.asCharBuffer(), count, datatype); - break; - case Datatype.SHORT: - vCall(in.asShortBuffer(), inOut.asShortBuffer(), count, datatype); - break; - case Datatype.INT: - vCall(in.asIntBuffer(), inOut.asIntBuffer(), count, datatype); - break; - case Datatype.LONG: - vCall(in.asLongBuffer(), inOut.asLongBuffer(), count, datatype); - break; - case Datatype.FLOAT: - vCall(in.asFloatBuffer(), inOut.asFloatBuffer(), count, datatype); - break; - case Datatype.DOUBLE: - vCall(in.asDoubleBuffer(), inOut.asDoubleBuffer(), count, datatype); - break; - case Datatype.PACKED: - vCall(in, inOut, count, datatype); - break; - default: - throw new IllegalArgumentException("Unsupported datatype."); - } -} + /** + * User-defined function for a new {@code Op}. + * @param in direct byte buffer to combine with {@code inOut} buffer + * @param inOut in-out direct byte buffer of accumulator locations + * @param count number of items in buffers + * @param datatype type of each item + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void call(ByteBuffer in, ByteBuffer inOut, int count, Datatype datatype) + throws MPIException + { + switch(datatype.baseType) + { + case Datatype.BYTE: + vCall(in, inOut, count, datatype); + break; + case Datatype.CHAR: + vCall(in.asCharBuffer(), inOut.asCharBuffer(), count, datatype); + break; + case Datatype.SHORT: + vCall(in.asShortBuffer(), inOut.asShortBuffer(), count, datatype); + break; + case Datatype.INT: + vCall(in.asIntBuffer(), inOut.asIntBuffer(), count, datatype); + break; + case Datatype.LONG: + vCall(in.asLongBuffer(), inOut.asLongBuffer(), count, datatype); + break; + case Datatype.FLOAT: + vCall(in.asFloatBuffer(), inOut.asFloatBuffer(), count, datatype); + break; + case Datatype.DOUBLE: + vCall(in.asDoubleBuffer(), inOut.asDoubleBuffer(), count, datatype); + break; + case Datatype.PACKED: + vCall(in, inOut, count, datatype); + break; + default: + throw new IllegalArgumentException("Unsupported datatype."); + } + } -private void vCall(ByteBuffer in, ByteBuffer inOut, - int count, Datatype datatype) throws MPIException -{ - int extent = datatype.getExtent(); - byte[] inVec = new byte[count * extent], - inOutVec = new byte[count * extent]; + private void vCall(ByteBuffer in, ByteBuffer inOut, + int count, Datatype datatype) throws MPIException + { + int extent = datatype.getExtent(); + byte[] inVec = new byte[count * extent], + inOutVec = new byte[count * extent]; - in.get(inVec); - inOut.get(inOutVec); - call(inVec, inOutVec, count, datatype); - inOut.clear(); - inOut.put(inOutVec); -} + in.get(inVec); + inOut.get(inOutVec); + call(inVec, inOutVec, count, datatype); + inOut.clear(); + inOut.put(inOutVec); + } -private void vCall(CharBuffer inBuf, CharBuffer inOutBuf, - int count, Datatype datatype) throws MPIException -{ - int extent = datatype.getExtent(); - char[] inVec = new char[count * extent], - inOutVec = new char[count * extent]; + private void vCall(CharBuffer inBuf, CharBuffer inOutBuf, + int count, Datatype datatype) throws MPIException + { + int extent = datatype.getExtent(); + char[] inVec = new char[count * extent], + inOutVec = new char[count * extent]; - inBuf.get(inVec); - inOutBuf.get(inOutVec); - call(inVec, inOutVec, count, datatype); - inOutBuf.clear(); - inOutBuf.put(inOutVec); -} + inBuf.get(inVec); + inOutBuf.get(inOutVec); + call(inVec, inOutVec, count, datatype); + inOutBuf.clear(); + inOutBuf.put(inOutVec); + } -private void vCall(ShortBuffer inBuf, ShortBuffer inOutBuf, - int count, Datatype datatype) throws MPIException -{ - int extent = datatype.getExtent(); - short[] inVec = new short[count * extent], - inOutVec = new short[count * extent]; + private void vCall(ShortBuffer inBuf, ShortBuffer inOutBuf, + int count, Datatype datatype) throws MPIException + { + int extent = datatype.getExtent(); + short[] inVec = new short[count * extent], + inOutVec = new short[count * extent]; - inBuf.get(inVec); - inOutBuf.get(inOutVec); - call(inVec, inOutVec, count, datatype); - inOutBuf.clear(); - inOutBuf.put(inOutVec); -} + inBuf.get(inVec); + inOutBuf.get(inOutVec); + call(inVec, inOutVec, count, datatype); + inOutBuf.clear(); + inOutBuf.put(inOutVec); + } -private void vCall(IntBuffer inBuf, IntBuffer inOutBuf, - int count, Datatype datatype) throws MPIException -{ - int extent = datatype.getExtent(); - int[] inVec = new int[count * extent], - inOutVec = new int[count * extent]; + private void vCall(IntBuffer inBuf, IntBuffer inOutBuf, + int count, Datatype datatype) throws MPIException + { + int extent = datatype.getExtent(); + int[] inVec = new int[count * extent], + inOutVec = new int[count * extent]; - inBuf.get(inVec); - inOutBuf.get(inOutVec); - call(inVec, inOutVec, count, datatype); - inOutBuf.clear(); - inOutBuf.put(inOutVec); -} + inBuf.get(inVec); + inOutBuf.get(inOutVec); + call(inVec, inOutVec, count, datatype); + inOutBuf.clear(); + inOutBuf.put(inOutVec); + } -private void vCall(LongBuffer inBuf, LongBuffer inOutBuf, - int count, Datatype datatype) throws MPIException -{ - int extent = datatype.getExtent(); - long[] inVec = new long[count * extent], - inOutVec = new long[count * extent]; + private void vCall(LongBuffer inBuf, LongBuffer inOutBuf, + int count, Datatype datatype) throws MPIException + { + int extent = datatype.getExtent(); + long[] inVec = new long[count * extent], + inOutVec = new long[count * extent]; - inBuf.get(inVec); - inOutBuf.get(inOutVec); - call(inVec, inOutVec, count, datatype); - inOutBuf.clear(); - inOutBuf.put(inOutVec); -} + inBuf.get(inVec); + inOutBuf.get(inOutVec); + call(inVec, inOutVec, count, datatype); + inOutBuf.clear(); + inOutBuf.put(inOutVec); + } -private void vCall(FloatBuffer inBuf, FloatBuffer inOutBuf, - int count, Datatype datatype) throws MPIException -{ - int extent = datatype.getExtent(); - float[] inVec = new float[count * extent], - inOutVec = new float[count * extent]; + private void vCall(FloatBuffer inBuf, FloatBuffer inOutBuf, + int count, Datatype datatype) throws MPIException + { + int extent = datatype.getExtent(); + float[] inVec = new float[count * extent], + inOutVec = new float[count * extent]; - inBuf.get(inVec); - inOutBuf.get(inOutVec); - call(inVec, inOutVec, count, datatype); - inOutBuf.clear(); - inOutBuf.put(inOutVec); -} + inBuf.get(inVec); + inOutBuf.get(inOutVec); + call(inVec, inOutVec, count, datatype); + inOutBuf.clear(); + inOutBuf.put(inOutVec); + } -private void vCall(DoubleBuffer inBuf, DoubleBuffer inOutBuf, - int count, Datatype datatype) throws MPIException -{ - int extent = datatype.getExtent(); - double[] inVec = new double[count * extent], - inOutVec = new double[count * extent]; + private void vCall(DoubleBuffer inBuf, DoubleBuffer inOutBuf, + int count, Datatype datatype) throws MPIException + { + int extent = datatype.getExtent(); + double[] inVec = new double[count * extent], + inOutVec = new double[count * extent]; - inBuf.get(inVec); - inOutBuf.get(inOutVec); - call(inVec, inOutVec, count, datatype); - inOutBuf.clear(); - inOutBuf.put(inOutVec); -} + inBuf.get(inVec); + inOutBuf.get(inOutVec); + call(inVec, inOutVec, count, datatype); + inOutBuf.clear(); + inOutBuf.put(inOutVec); + } } // UserFunction diff --git a/ompi/mpi/java/java/Win.java b/ompi/mpi/java/java/Win.java index 402f0d2e6d..850abd5974 100644 --- a/ompi/mpi/java/java/Win.java +++ b/ompi/mpi/java/java/Win.java @@ -29,875 +29,875 @@ import java.nio.*; */ public final class Win implements Freeable { -private long handle; -public static final int WIN_NULL = 0; -public static final int FLAVOR_PRIVATE = 0; -public static final int FLAVOR_SHARED = 1; - -/** - * Java binding of {@code MPI_WIN_CREATE}. - * @param base initial address of window - * @param size size of window (buffer elements) - * @param dispUnit local unit size for displacements (buffer elements) - * @param info info object - * @param comm communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Win(Buffer base, int size, int dispUnit, Info info, Comm comm) - throws MPIException -{ - if(!base.isDirect()) - throw new IllegalArgumentException("The buffer must be direct."); - - int baseSize; - - if(base instanceof ByteBuffer) - baseSize = 1; - else if(base instanceof CharBuffer || base instanceof ShortBuffer) - baseSize = 2; - else if(base instanceof IntBuffer || base instanceof FloatBuffer) - baseSize = 4; - else if(base instanceof LongBuffer || base instanceof DoubleBuffer) - baseSize = 8; - else - throw new AssertionError(); - - int sizeBytes = size * baseSize, - dispBytes = dispUnit * baseSize; - - handle = createWin(base, sizeBytes, dispBytes, info.handle, comm.handle); -} - -private native long createWin( - Buffer base, int size, int dispUnit, long info, long comm) - throws MPIException; - -/** - * Java binding of {@code MPI_WIN_ALLOCATE} and {@code MPI_WIN_ALLOCATE_SHARED}. - * @param size size of window (buffer elements) - * @param dispUnit local unit size for displacements (buffer elements) - * @param info info object - * @param comm communicator - * @param base initial address of window - * @param flavor FLAVOR_PRIVATE or FLAVOR_SHARED - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Win(int size, int dispUnit, Info info, Comm comm, Buffer base, int flavor) - throws MPIException -{ - if(!base.isDirect()) - throw new IllegalArgumentException("The buffer must be direct."); - - int baseSize; - - if(base instanceof ByteBuffer) - baseSize = 1; - else if(base instanceof CharBuffer || base instanceof ShortBuffer) - baseSize = 2; - else if(base instanceof IntBuffer || base instanceof FloatBuffer) - baseSize = 4; - else if(base instanceof LongBuffer || base instanceof DoubleBuffer) - baseSize = 8; - else - throw new AssertionError(); - - int sizeBytes = size * baseSize, - dispBytes = dispUnit * baseSize; - - if(flavor == 0) { - handle = allocateWin(sizeBytes, dispBytes, info.handle, comm.handle, base); - } else if(flavor == 1) { - handle = allocateSharedWin(sizeBytes, dispBytes, info.handle, comm.handle, base); - } -} - -private native long allocateWin( - int size, int dispUnit, long info, long comm, Buffer base) - throws MPIException; - -private native long allocateSharedWin( - int size, int dispUnit, long info, long comm, Buffer base) - throws MPIException; - -/** - * Java binding of {@code MPI_WIN_CREATE_DYNAMIC}. - * @param info info object - * @param comm communicator - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Win(Info info, Comm comm) - throws MPIException -{ - handle = createDynamicWin(info.handle, comm.handle); -} - -private native long createDynamicWin( - long info, long comm) - throws MPIException; - -private int getBaseType(Datatype orgType, Datatype targetType) -{ - int baseType = orgType.baseType; - - if(baseType != targetType.baseType) - { - throw new IllegalArgumentException( - "Both datatype arguments must be constructed "+ - "from the same predefined datatype."); - } - - return baseType; -} - -/** - * Java binding of {@code MPI_WIN_ATTACH}. - * @param base initial address of window - * @param size size of window (buffer elements) - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void attach(Buffer base, int size) throws MPIException -{ - MPI.check(); - if(!base.isDirect()) - throw new IllegalArgumentException("The buffer must be direct."); - - int baseSize; - - if(base instanceof ByteBuffer) - baseSize = 1; - else if(base instanceof CharBuffer || base instanceof ShortBuffer) - baseSize = 2; - else if(base instanceof IntBuffer || base instanceof FloatBuffer) - baseSize = 4; - else if(base instanceof LongBuffer || base instanceof DoubleBuffer) - baseSize = 8; - else - throw new AssertionError(); - - int sizeBytes = size * baseSize; - - attach(handle, base, sizeBytes); -} - -private native void attach(long win, Buffer base, int size) throws MPIException; - -/** - * Java binding of {@code MPI_WIN_DETACH}. - * @param base initial address of window - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void detach(Buffer base) throws MPIException -{ - MPI.check(); - if(!base.isDirect()) - throw new IllegalArgumentException("The buffer must be direct."); - - detach(handle, base); -} - -private native void detach(long win, Buffer base) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_GET_GROUP}. - * @return group of processes which share access to the window - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Group getGroup() throws MPIException -{ - MPI.check(); - return new Group(getGroup(handle)); -} - -private native long getGroup(long win) throws MPIException; - -/** - * Java binding of {@code MPI_PUT}. - * @param origin origin buffer - * @param orgCount number of entries in origin buffer - * @param orgType datatype of each entry in origin buffer - * @param targetRank rank of target - * @param targetDisp displacement from start of window to target buffer - * @param targetCount number of entries in target buffer - * @param targetType datatype of each entry in target buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void put(Buffer origin, int orgCount, Datatype orgType, - int targetRank, int targetDisp, int targetCount, - Datatype targetType) - throws MPIException -{ - MPI.check(); - - if(!origin.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - put(handle, origin, orgCount, orgType.handle, - targetRank, targetDisp, targetCount, targetType.handle, - getBaseType(orgType, targetType)); -} - -private native void put( - long win, Buffer origin, int orgCount, long orgType, - int targetRank, int targetDisp, int targetCount, long targetType, - int baseType) throws MPIException; - -/** - * Java binding of {@code MPI_GET}. - * @param origin origin buffer - * @param orgCount number of entries in origin buffer - * @param orgType datatype of each entry in origin buffer - * @param targetRank rank of target - * @param targetDisp displacement from start of window to target buffer - * @param targetCount number of entries in target buffer - * @param targetType datatype of each entry in target buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void get(Buffer origin, int orgCount, Datatype orgType, - int targetRank, int targetDisp, int targetCount, - Datatype targetType) - throws MPIException -{ - MPI.check(); - - if(!origin.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - get(handle, origin, orgCount, orgType.handle, - targetRank, targetDisp, targetCount, targetType.handle, - getBaseType(orgType, targetType)); -} - -private native void get( - long win, Buffer origin, int orgCount, long orgType, - int targetRank, int targetDisp, int targetCount, long targetType, - int baseType) throws MPIException; - -/** - * Java binding of {@code MPI_ACCUMULATE}. - * @param origin origin buffer - * @param orgCount number of entries in origin buffer - * @param orgType datatype of each entry in origin buffer - * @param targetRank rank of target - * @param targetDisp displacement from start of window to target buffer - * @param targetCount number of entries in target buffer - * @param targetType datatype of each entry in target buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void accumulate(Buffer origin, int orgCount, Datatype orgType, - int targetRank, int targetDisp, int targetCount, - Datatype targetType, Op op) - throws MPIException -{ - MPI.check(); - - if(!origin.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - accumulate(handle, origin, orgCount, orgType.handle, - targetRank, targetDisp, targetCount, targetType.handle, - op, op.handle, getBaseType(orgType, targetType)); -} - -private native void accumulate( - long win, Buffer origin, int orgCount, long orgType, - int targetRank, int targetDisp, int targetCount, long targetType, - Op jOp, long hOp, int baseType) throws MPIException; - -/** - * Java binding of {@code MPI_WIN_FENCE}. - * @param assertion program assertion - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void fence(int assertion) throws MPIException -{ - MPI.check(); - fence(handle, assertion); -} - -private native void fence(long win, int assertion) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_START}. - * @param group group of target processes - * @param assertion program assertion - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void start(Group group, int assertion) throws MPIException -{ - MPI.check(); - start(handle, group.handle, assertion); -} - -private native void start(long win, long group, int assertion) - throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_COMPLETE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void complete() throws MPIException -{ - MPI.check(); - complete(handle); -} - -private native void complete(long win) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_POST}. - * @param group group of origin processes - * @param assertion program assertion - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void post(Group group, int assertion) throws MPIException -{ - MPI.check(); - post(handle, group.handle, assertion); -} - -private native void post(long win, long group, int assertion) - throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_WAIT}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void waitFor() throws MPIException -{ - MPI.check(); - waitFor(handle); -} - -private native void waitFor(long win) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_TEST}. - * @return true if success - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public boolean test() throws MPIException -{ - MPI.check(); - return test(handle); -} - -private native boolean test(long win) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_LOCK}. - * @param lockType either MPI.LOCK_EXCLUSIVE or MPI.LOCK_SHARED - * @param rank rank of locked window - * @param assertion program assertion - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void lock(int lockType, int rank, int assertion) throws MPIException -{ - MPI.check(); - lock(handle, lockType, rank, assertion); -} - -private native void lock(long win, int lockType, int rank, int assertion) - throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_UNLOCK}. - * @param rank rank of window - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void unlock(int rank) throws MPIException -{ - MPI.check(); - unlock(handle, rank); -} - -private native void unlock(long win, int rank) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_SET_ERRHANDLER}. - * @param errhandler new MPI error handler for window - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setErrhandler(Errhandler errhandler) throws MPIException -{ - MPI.check(); - setErrhandler(handle, errhandler.handle); -} - -private native void setErrhandler(long win, long errhandler) - throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_CALL_ERRHANDLER}. - * @param errorCode error code - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void callErrhandler(int errorCode) throws MPIException -{ - callErrhandler(handle, errorCode); -} - -private native void callErrhandler(long handle, int errorCode) - throws MPIException; - -/** - * Create a new attribute key. - *

Java binding of the MPI operation {@code MPI_WIN_CREATE_KEYVAL}. - * @return attribute key for future access - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static int createKeyval() throws MPIException -{ - MPI.check(); - return createKeyval_jni(); -} - -private static native int createKeyval_jni() throws MPIException; - -/** - * Frees an attribute key. - *

Java binding of the MPI operation {@code MPI_WIN_FREE_KEYVAL}. - * @param keyval attribute key - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public static void freeKeyval(int keyval) throws MPIException -{ - MPI.check(); - freeKeyval_jni(keyval); -} - -private static native void freeKeyval_jni(int keyval) throws MPIException; - -/** - * Stores attribute value associated with a key. - *

Java binding of the MPI operation {@code MPI_WIN_SET_ATTR}. - * @param keyval attribute key - * @param value attribute value - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setAttr(int keyval, Object value) throws MPIException -{ - MPI.check(); - setAttr(handle, keyval, MPI.attrSet(value)); -} - -private native void setAttr(long win, int keyval, byte[] value) - throws MPIException; - -/** - * Retrieves attribute value by key. - *

Java binding of the MPI operation {@code MPI_WIN_GET_ATTR}. - * @param keyval attribute key - * @return attribute value or null if no attribute is associated with the key. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Object getAttr(int keyval) throws MPIException -{ - MPI.check(); - Object obj = getAttr(handle, keyval); - return obj instanceof byte[] ? MPI.attrGet((byte[])obj) : obj; -} - -private native Object getAttr(long win, int keyval) throws MPIException; - -/** - * Deletes an attribute value associated with a key. - *

Java binding of the MPI operation {@code MPI_WIN_DELETE_ATTR}. - * @param keyval attribute key - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void deleteAttr(int keyval) throws MPIException -{ - MPI.check(); - deleteAttr(handle, keyval); -} - -private native void deleteAttr(long win, int keyval) throws MPIException; - -/** - * Java binding of {@code MPI_WIN_FREE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -@Override public void free() throws MPIException -{ - MPI.check(); - handle = free(handle); -} - -private native long free(long win) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_GET_INFO}. - * @return Info Info object associated with this window - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Info getInfo() throws MPIException -{ - MPI.check(); - return new Info(getInfo(handle)); -} - -private native long getInfo(long win) - throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_SET_INFO}. - * @param info the new info - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setInfo(Info info) throws MPIException -{ - MPI.check(); - setInfo(handle, info.handle); -} - -private native void setInfo(long win, long info) - throws MPIException; - -/** - *

Java binding of the MPI operation {@code MPI_RPUT}. - * @param origin_addr initial address of origin buffer - * @param origin_count number of entries in origin buffer - * @param origin_datatype datatype of each entry in origin buffer - * @param target_rank rank of target - * @param target_disp displacement from start of window to target buffer - * @param target_count number of entries in target buffer - * @param target_datatype datatype of each entry in target buffer - * @return RMA request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request rPut(Buffer origin_addr, int origin_count, - Datatype origin_datatype, int target_rank, int target_disp, - int target_count, Datatype target_datatype) - throws MPIException -{ - if(!origin_addr.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - return new Request(rPut(handle, origin_addr, origin_count, - origin_datatype.handle, target_rank, target_disp, - target_count, target_datatype.handle, getBaseType(origin_datatype, target_datatype))); -} - -private native long rPut(long win, Buffer origin_addr, int origin_count, - long origin_datatype, int target_rank, int target_disp, - int target_count, long target_datatype, int baseType) - throws MPIException; - -/** - * Java binding of {@code MPI_RGET}. - * @param origin origin buffer - * @param orgCount number of entries in origin buffer - * @param orgType datatype of each entry in origin buffer - * @param targetRank rank of target - * @param targetDisp displacement from start of window to target buffer - * @param targetCount number of entries in target buffer - * @param targetType datatype of each entry in target buffer - * @return RMA request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public final Request rGet(Buffer origin, int orgCount, Datatype orgType, - int targetRank, int targetDisp, int targetCount, - Datatype targetType) - throws MPIException -{ - MPI.check(); - - if(!origin.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - return new Request(rGet(handle, origin, orgCount, orgType.handle, - targetRank, targetDisp, targetCount, targetType.handle, - getBaseType(orgType, targetType))); -} - -private native long rGet( - long win, Buffer origin, int orgCount, long orgType, - int targetRank, int targetDisp, int targetCount, long targetType, - int baseType) throws MPIException; - -/** - * Java binding of {@code MPI_RACCUMULATE}. - * @param origin origin buffer - * @param orgCount number of entries in origin buffer - * @param orgType datatype of each entry in origin buffer - * @param targetRank rank of target - * @param targetDisp displacement from start of window to target buffer - * @param targetCount number of entries in target buffer - * @param targetType datatype of each entry in target buffer - * @param op reduce operation - * @return RMA request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public Request rAccumulate(Buffer origin, int orgCount, Datatype orgType, - int targetRank, int targetDisp, int targetCount, - Datatype targetType, Op op) - throws MPIException -{ - MPI.check(); - - if(!origin.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - return new Request(rAccumulate(handle, origin, orgCount, orgType.handle, - targetRank, targetDisp, targetCount, targetType.handle, - op, op.handle, getBaseType(orgType, targetType))); -} - -private native long rAccumulate( - long win, Buffer origin, int orgCount, long orgType, - int targetRank, int targetDisp, int targetCount, long targetType, - Op jOp, long hOp, int baseType) throws MPIException; - -/** - * Java binding of {@code MPI_GET_ACCUMULATE}. - * @param origin origin buffer - * @param orgCount number of entries in origin buffer - * @param orgType datatype of each entry in origin buffer - * @param resultAddr result buffer - * @param resultCount number of entries in result buffer - * @param resultType datatype of each entry in result buffer - * @param targetRank rank of target - * @param targetDisp displacement from start of window to target buffer - * @param targetCount number of entries in target buffer - * @param targetType datatype of each entry in target buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - -public void getAccumulate(Buffer origin, int orgCount, Datatype orgType, - Buffer resultAddr, int resultCount, Datatype resultType, - int targetRank, int targetDisp, int targetCount, - Datatype targetType, Op op) - throws MPIException -{ - MPI.check(); - - if(!origin.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - getAccumulate(handle, origin, orgCount, orgType.handle, - resultAddr, resultCount, resultType.handle, - targetRank, targetDisp, targetCount, targetType.handle, - op, op.handle, getBaseType(orgType, targetType)); -} - -private native void getAccumulate( - long win, Buffer origin, int orgCount, long orgType, - Buffer resultAddr, int resultCount, long resultType, - int targetRank, int targetDisp, int targetCount, long targetType, - Op jOp, long hOp, int baseType) throws MPIException; - -/** - * Java binding of {@code MPI_RGET_ACCUMULATE}. - * @param origin origin buffer - * @param orgCount number of entries in origin buffer - * @param orgType datatype of each entry in origin buffer - * @param resultAddr result buffer - * @param resultCount number of entries in result buffer - * @param resultType datatype of each entry in result buffer - * @param targetRank rank of target - * @param targetDisp displacement from start of window to target buffer - * @param targetCount number of entries in target buffer - * @param targetType datatype of each entry in target buffer - * @param op reduce operation - * @return RMA request - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - -public Request rGetAccumulate(Buffer origin, int orgCount, Datatype orgType, - Buffer resultAddr, int resultCount, Datatype resultType, - int targetRank, int targetDisp, int targetCount, - Datatype targetType, Op op) - throws MPIException -{ - MPI.check(); - - if(!origin.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - return new Request(rGetAccumulate(handle, origin, orgCount, orgType.handle, - resultAddr, resultCount, resultType.handle, - targetRank, targetDisp, targetCount, targetType.handle, - op, op.handle, getBaseType(orgType, targetType))); -} - -private native long rGetAccumulate( - long win, Buffer origin, int orgCount, long orgType, - Buffer resultAddr, int resultCount, long resultType, - int targetRank, int targetDisp, int targetCount, long targetType, - Op jOp, long hOp, int baseType) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_LOCK_ALL}. - * @param assertion program assertion - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void lockAll(int assertion) throws MPIException -{ - MPI.check(); - lockAll(handle, assertion); -} - -private native void lockAll(long win, int assertion) - throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_UNLOCK_ALL}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void unlockAll() throws MPIException -{ - MPI.check(); - unlockAll(handle); -} - -private native void unlockAll(long win) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_SYNC}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void sync() throws MPIException -{ - MPI.check(); - sync(handle); -} - -private native void sync(long win) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_FLUSH}. - * @param targetRank rank of target window - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void flush(int targetRank) throws MPIException -{ - MPI.check(); - flush(handle, targetRank); -} - -private native void flush(long win, int targetRank) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_FLUSH_ALL}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void flushAll() throws MPIException -{ - MPI.check(); - flushAll(handle); -} - -private native void flushAll(long win) throws MPIException; - -/** - * Java binding of {@code MPI_COMPARE_AND_SWAP}. - * @param origin origin buffer - * @param compareAddr compare buffer - * @param resultAddr result buffer - * @param targetType datatype of each entry in target buffer - * @param targetRank rank of target - * @param targetDisp displacement from start of window to target buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - -public void compareAndSwap(Buffer origin, Buffer compareAddr, Buffer resultAddr, - Datatype targetType, int targetRank, int targetDisp) - throws MPIException -{ - MPI.check(); - - if(!origin.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - compareAndSwap(handle, origin, compareAddr, resultAddr, - targetType.handle, targetRank, targetDisp); -} - -private native void compareAndSwap( - long win, Buffer origin, Buffer compareAddr, Buffer resultAddr, - long targetType, int targetRank, int targetDisp) throws MPIException; - -/** - * Java binding of {@code MPI_FETCH_AND_OP}. - * @param origin origin buffer - * @param resultAddr result buffer - * @param dataType datatype of entry in origin, result, and target buffers - * @param targetRank rank of target - * @param targetDisp displacement from start of window to target buffer - * @param op reduce operation - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - -public void fetchAndOp(Buffer origin, Buffer resultAddr, Datatype dataType, - int targetRank, int targetDisp, Op op) - throws MPIException -{ - MPI.check(); - - if(!origin.isDirect()) - throw new IllegalArgumentException("The origin must be direct buffer."); - - fetchAndOp(handle, origin, resultAddr, dataType.handle, targetRank, - targetDisp, op, op.handle, getBaseType(dataType, dataType)); -} - -private native void fetchAndOp( - long win, Buffer origin, Buffer resultAddr, long targetType, int targetRank, - int targetDisp, Op jOp, long hOp, int baseType) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL}. - * @param targetRank rank of target window - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - -public void flushLocal(int targetRank) throws MPIException -{ - MPI.check(); - flushLocal(handle, targetRank); -} - -private native void flushLocal(long win, int targetRank) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL_ALL}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - -public void flushLocalAll() throws MPIException -{ - MPI.check(); - flushLocalAll(handle); -} - -private native void flushLocalAll(long win) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_GET_NAME}. - * @return the name associated with this window - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public String getName() throws MPIException -{ - MPI.check(); - return getName(handle); -} - -private native String getName(long handle) throws MPIException; - -/** - * Java binding of the MPI operation {@code MPI_WIN_SET_NAME}. - * @param name the name to associate with this window - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ -public void setName(String name) throws MPIException -{ - MPI.check(); - setName(handle, name); -} - -private native void setName(long handle, String name) throws MPIException; + private long handle; + public static final int WIN_NULL = 0; + public static final int FLAVOR_PRIVATE = 0; + public static final int FLAVOR_SHARED = 1; + + /** + * Java binding of {@code MPI_WIN_CREATE}. + * @param base initial address of window + * @param size size of window (buffer elements) + * @param dispUnit local unit size for displacements (buffer elements) + * @param info info object + * @param comm communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Win(Buffer base, int size, int dispUnit, Info info, Comm comm) + throws MPIException + { + if(!base.isDirect()) + throw new IllegalArgumentException("The buffer must be direct."); + + int baseSize; + + if(base instanceof ByteBuffer) + baseSize = 1; + else if(base instanceof CharBuffer || base instanceof ShortBuffer) + baseSize = 2; + else if(base instanceof IntBuffer || base instanceof FloatBuffer) + baseSize = 4; + else if(base instanceof LongBuffer || base instanceof DoubleBuffer) + baseSize = 8; + else + throw new AssertionError(); + + int sizeBytes = size * baseSize, + dispBytes = dispUnit * baseSize; + + handle = createWin(base, sizeBytes, dispBytes, info.handle, comm.handle); + } + + private native long createWin( + Buffer base, int size, int dispUnit, long info, long comm) + throws MPIException; + + /** + * Java binding of {@code MPI_WIN_ALLOCATE} and {@code MPI_WIN_ALLOCATE_SHARED}. + * @param size size of window (buffer elements) + * @param dispUnit local unit size for displacements (buffer elements) + * @param info info object + * @param comm communicator + * @param base initial address of window + * @param flavor FLAVOR_PRIVATE or FLAVOR_SHARED + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Win(int size, int dispUnit, Info info, Comm comm, Buffer base, int flavor) + throws MPIException + { + if(!base.isDirect()) + throw new IllegalArgumentException("The buffer must be direct."); + + int baseSize; + + if(base instanceof ByteBuffer) + baseSize = 1; + else if(base instanceof CharBuffer || base instanceof ShortBuffer) + baseSize = 2; + else if(base instanceof IntBuffer || base instanceof FloatBuffer) + baseSize = 4; + else if(base instanceof LongBuffer || base instanceof DoubleBuffer) + baseSize = 8; + else + throw new AssertionError(); + + int sizeBytes = size * baseSize, + dispBytes = dispUnit * baseSize; + + if(flavor == 0) { + handle = allocateWin(sizeBytes, dispBytes, info.handle, comm.handle, base); + } else if(flavor == 1) { + handle = allocateSharedWin(sizeBytes, dispBytes, info.handle, comm.handle, base); + } + } + + private native long allocateWin( + int size, int dispUnit, long info, long comm, Buffer base) + throws MPIException; + + private native long allocateSharedWin( + int size, int dispUnit, long info, long comm, Buffer base) + throws MPIException; + + /** + * Java binding of {@code MPI_WIN_CREATE_DYNAMIC}. + * @param info info object + * @param comm communicator + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Win(Info info, Comm comm) + throws MPIException + { + handle = createDynamicWin(info.handle, comm.handle); + } + + private native long createDynamicWin( + long info, long comm) + throws MPIException; + + private int getBaseType(Datatype orgType, Datatype targetType) + { + int baseType = orgType.baseType; + + if(baseType != targetType.baseType) + { + throw new IllegalArgumentException( + "Both datatype arguments must be constructed "+ + "from the same predefined datatype."); + } + + return baseType; + } + + /** + * Java binding of {@code MPI_WIN_ATTACH}. + * @param base initial address of window + * @param size size of window (buffer elements) + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void attach(Buffer base, int size) throws MPIException + { + MPI.check(); + if(!base.isDirect()) + throw new IllegalArgumentException("The buffer must be direct."); + + int baseSize; + + if(base instanceof ByteBuffer) + baseSize = 1; + else if(base instanceof CharBuffer || base instanceof ShortBuffer) + baseSize = 2; + else if(base instanceof IntBuffer || base instanceof FloatBuffer) + baseSize = 4; + else if(base instanceof LongBuffer || base instanceof DoubleBuffer) + baseSize = 8; + else + throw new AssertionError(); + + int sizeBytes = size * baseSize; + + attach(handle, base, sizeBytes); + } + + private native void attach(long win, Buffer base, int size) throws MPIException; + + /** + * Java binding of {@code MPI_WIN_DETACH}. + * @param base initial address of window + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void detach(Buffer base) throws MPIException + { + MPI.check(); + if(!base.isDirect()) + throw new IllegalArgumentException("The buffer must be direct."); + + detach(handle, base); + } + + private native void detach(long win, Buffer base) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_GET_GROUP}. + * @return group of processes which share access to the window + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Group getGroup() throws MPIException + { + MPI.check(); + return new Group(getGroup(handle)); + } + + private native long getGroup(long win) throws MPIException; + + /** + * Java binding of {@code MPI_PUT}. + * @param origin origin buffer + * @param orgCount number of entries in origin buffer + * @param orgType datatype of each entry in origin buffer + * @param targetRank rank of target + * @param targetDisp displacement from start of window to target buffer + * @param targetCount number of entries in target buffer + * @param targetType datatype of each entry in target buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void put(Buffer origin, int orgCount, Datatype orgType, + int targetRank, int targetDisp, int targetCount, + Datatype targetType) + throws MPIException + { + MPI.check(); + + if(!origin.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + put(handle, origin, orgCount, orgType.handle, + targetRank, targetDisp, targetCount, targetType.handle, + getBaseType(orgType, targetType)); + } + + private native void put( + long win, Buffer origin, int orgCount, long orgType, + int targetRank, int targetDisp, int targetCount, long targetType, + int baseType) throws MPIException; + + /** + * Java binding of {@code MPI_GET}. + * @param origin origin buffer + * @param orgCount number of entries in origin buffer + * @param orgType datatype of each entry in origin buffer + * @param targetRank rank of target + * @param targetDisp displacement from start of window to target buffer + * @param targetCount number of entries in target buffer + * @param targetType datatype of each entry in target buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void get(Buffer origin, int orgCount, Datatype orgType, + int targetRank, int targetDisp, int targetCount, + Datatype targetType) + throws MPIException + { + MPI.check(); + + if(!origin.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + get(handle, origin, orgCount, orgType.handle, + targetRank, targetDisp, targetCount, targetType.handle, + getBaseType(orgType, targetType)); + } + + private native void get( + long win, Buffer origin, int orgCount, long orgType, + int targetRank, int targetDisp, int targetCount, long targetType, + int baseType) throws MPIException; + + /** + * Java binding of {@code MPI_ACCUMULATE}. + * @param origin origin buffer + * @param orgCount number of entries in origin buffer + * @param orgType datatype of each entry in origin buffer + * @param targetRank rank of target + * @param targetDisp displacement from start of window to target buffer + * @param targetCount number of entries in target buffer + * @param targetType datatype of each entry in target buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void accumulate(Buffer origin, int orgCount, Datatype orgType, + int targetRank, int targetDisp, int targetCount, + Datatype targetType, Op op) + throws MPIException + { + MPI.check(); + + if(!origin.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + accumulate(handle, origin, orgCount, orgType.handle, + targetRank, targetDisp, targetCount, targetType.handle, + op, op.handle, getBaseType(orgType, targetType)); + } + + private native void accumulate( + long win, Buffer origin, int orgCount, long orgType, + int targetRank, int targetDisp, int targetCount, long targetType, + Op jOp, long hOp, int baseType) throws MPIException; + + /** + * Java binding of {@code MPI_WIN_FENCE}. + * @param assertion program assertion + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void fence(int assertion) throws MPIException + { + MPI.check(); + fence(handle, assertion); + } + + private native void fence(long win, int assertion) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_START}. + * @param group group of target processes + * @param assertion program assertion + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void start(Group group, int assertion) throws MPIException + { + MPI.check(); + start(handle, group.handle, assertion); + } + + private native void start(long win, long group, int assertion) + throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_COMPLETE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void complete() throws MPIException + { + MPI.check(); + complete(handle); + } + + private native void complete(long win) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_POST}. + * @param group group of origin processes + * @param assertion program assertion + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void post(Group group, int assertion) throws MPIException + { + MPI.check(); + post(handle, group.handle, assertion); + } + + private native void post(long win, long group, int assertion) + throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_WAIT}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void waitFor() throws MPIException + { + MPI.check(); + waitFor(handle); + } + + private native void waitFor(long win) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_TEST}. + * @return true if success + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public boolean test() throws MPIException + { + MPI.check(); + return test(handle); + } + + private native boolean test(long win) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_LOCK}. + * @param lockType either MPI.LOCK_EXCLUSIVE or MPI.LOCK_SHARED + * @param rank rank of locked window + * @param assertion program assertion + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void lock(int lockType, int rank, int assertion) throws MPIException + { + MPI.check(); + lock(handle, lockType, rank, assertion); + } + + private native void lock(long win, int lockType, int rank, int assertion) + throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_UNLOCK}. + * @param rank rank of window + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void unlock(int rank) throws MPIException + { + MPI.check(); + unlock(handle, rank); + } + + private native void unlock(long win, int rank) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_SET_ERRHANDLER}. + * @param errhandler new MPI error handler for window + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setErrhandler(Errhandler errhandler) throws MPIException + { + MPI.check(); + setErrhandler(handle, errhandler.handle); + } + + private native void setErrhandler(long win, long errhandler) + throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_CALL_ERRHANDLER}. + * @param errorCode error code + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void callErrhandler(int errorCode) throws MPIException + { + callErrhandler(handle, errorCode); + } + + private native void callErrhandler(long handle, int errorCode) + throws MPIException; + + /** + * Create a new attribute key. + *

Java binding of the MPI operation {@code MPI_WIN_CREATE_KEYVAL}. + * @return attribute key for future access + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static int createKeyval() throws MPIException + { + MPI.check(); + return createKeyval_jni(); + } + + private static native int createKeyval_jni() throws MPIException; + + /** + * Frees an attribute key. + *

Java binding of the MPI operation {@code MPI_WIN_FREE_KEYVAL}. + * @param keyval attribute key + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public static void freeKeyval(int keyval) throws MPIException + { + MPI.check(); + freeKeyval_jni(keyval); + } + + private static native void freeKeyval_jni(int keyval) throws MPIException; + + /** + * Stores attribute value associated with a key. + *

Java binding of the MPI operation {@code MPI_WIN_SET_ATTR}. + * @param keyval attribute key + * @param value attribute value + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setAttr(int keyval, Object value) throws MPIException + { + MPI.check(); + setAttr(handle, keyval, MPI.attrSet(value)); + } + + private native void setAttr(long win, int keyval, byte[] value) + throws MPIException; + + /** + * Retrieves attribute value by key. + *

Java binding of the MPI operation {@code MPI_WIN_GET_ATTR}. + * @param keyval attribute key + * @return attribute value or null if no attribute is associated with the key. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Object getAttr(int keyval) throws MPIException + { + MPI.check(); + Object obj = getAttr(handle, keyval); + return obj instanceof byte[] ? MPI.attrGet((byte[])obj) : obj; + } + + private native Object getAttr(long win, int keyval) throws MPIException; + + /** + * Deletes an attribute value associated with a key. + *

Java binding of the MPI operation {@code MPI_WIN_DELETE_ATTR}. + * @param keyval attribute key + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void deleteAttr(int keyval) throws MPIException + { + MPI.check(); + deleteAttr(handle, keyval); + } + + private native void deleteAttr(long win, int keyval) throws MPIException; + + /** + * Java binding of {@code MPI_WIN_FREE}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + @Override public void free() throws MPIException + { + MPI.check(); + handle = free(handle); + } + + private native long free(long win) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_GET_INFO}. + * @return Info Info object associated with this window + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Info getInfo() throws MPIException + { + MPI.check(); + return new Info(getInfo(handle)); + } + + private native long getInfo(long win) + throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_SET_INFO}. + * @param info the new info + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setInfo(Info info) throws MPIException + { + MPI.check(); + setInfo(handle, info.handle); + } + + private native void setInfo(long win, long info) + throws MPIException; + + /** + *

Java binding of the MPI operation {@code MPI_RPUT}. + * @param origin_addr initial address of origin buffer + * @param origin_count number of entries in origin buffer + * @param origin_datatype datatype of each entry in origin buffer + * @param target_rank rank of target + * @param target_disp displacement from start of window to target buffer + * @param target_count number of entries in target buffer + * @param target_datatype datatype of each entry in target buffer + * @return RMA request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request rPut(Buffer origin_addr, int origin_count, + Datatype origin_datatype, int target_rank, int target_disp, + int target_count, Datatype target_datatype) + throws MPIException + { + if(!origin_addr.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + return new Request(rPut(handle, origin_addr, origin_count, + origin_datatype.handle, target_rank, target_disp, + target_count, target_datatype.handle, getBaseType(origin_datatype, target_datatype))); + } + + private native long rPut(long win, Buffer origin_addr, int origin_count, + long origin_datatype, int target_rank, int target_disp, + int target_count, long target_datatype, int baseType) + throws MPIException; + + /** + * Java binding of {@code MPI_RGET}. + * @param origin origin buffer + * @param orgCount number of entries in origin buffer + * @param orgType datatype of each entry in origin buffer + * @param targetRank rank of target + * @param targetDisp displacement from start of window to target buffer + * @param targetCount number of entries in target buffer + * @param targetType datatype of each entry in target buffer + * @return RMA request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public final Request rGet(Buffer origin, int orgCount, Datatype orgType, + int targetRank, int targetDisp, int targetCount, + Datatype targetType) + throws MPIException + { + MPI.check(); + + if(!origin.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + return new Request(rGet(handle, origin, orgCount, orgType.handle, + targetRank, targetDisp, targetCount, targetType.handle, + getBaseType(orgType, targetType))); + } + + private native long rGet( + long win, Buffer origin, int orgCount, long orgType, + int targetRank, int targetDisp, int targetCount, long targetType, + int baseType) throws MPIException; + + /** + * Java binding of {@code MPI_RACCUMULATE}. + * @param origin origin buffer + * @param orgCount number of entries in origin buffer + * @param orgType datatype of each entry in origin buffer + * @param targetRank rank of target + * @param targetDisp displacement from start of window to target buffer + * @param targetCount number of entries in target buffer + * @param targetType datatype of each entry in target buffer + * @param op reduce operation + * @return RMA request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public Request rAccumulate(Buffer origin, int orgCount, Datatype orgType, + int targetRank, int targetDisp, int targetCount, + Datatype targetType, Op op) + throws MPIException + { + MPI.check(); + + if(!origin.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + return new Request(rAccumulate(handle, origin, orgCount, orgType.handle, + targetRank, targetDisp, targetCount, targetType.handle, + op, op.handle, getBaseType(orgType, targetType))); + } + + private native long rAccumulate( + long win, Buffer origin, int orgCount, long orgType, + int targetRank, int targetDisp, int targetCount, long targetType, + Op jOp, long hOp, int baseType) throws MPIException; + + /** + * Java binding of {@code MPI_GET_ACCUMULATE}. + * @param origin origin buffer + * @param orgCount number of entries in origin buffer + * @param orgType datatype of each entry in origin buffer + * @param resultAddr result buffer + * @param resultCount number of entries in result buffer + * @param resultType datatype of each entry in result buffer + * @param targetRank rank of target + * @param targetDisp displacement from start of window to target buffer + * @param targetCount number of entries in target buffer + * @param targetType datatype of each entry in target buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + + public void getAccumulate(Buffer origin, int orgCount, Datatype orgType, + Buffer resultAddr, int resultCount, Datatype resultType, + int targetRank, int targetDisp, int targetCount, + Datatype targetType, Op op) + throws MPIException + { + MPI.check(); + + if(!origin.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + getAccumulate(handle, origin, orgCount, orgType.handle, + resultAddr, resultCount, resultType.handle, + targetRank, targetDisp, targetCount, targetType.handle, + op, op.handle, getBaseType(orgType, targetType)); + } + + private native void getAccumulate( + long win, Buffer origin, int orgCount, long orgType, + Buffer resultAddr, int resultCount, long resultType, + int targetRank, int targetDisp, int targetCount, long targetType, + Op jOp, long hOp, int baseType) throws MPIException; + + /** + * Java binding of {@code MPI_RGET_ACCUMULATE}. + * @param origin origin buffer + * @param orgCount number of entries in origin buffer + * @param orgType datatype of each entry in origin buffer + * @param resultAddr result buffer + * @param resultCount number of entries in result buffer + * @param resultType datatype of each entry in result buffer + * @param targetRank rank of target + * @param targetDisp displacement from start of window to target buffer + * @param targetCount number of entries in target buffer + * @param targetType datatype of each entry in target buffer + * @param op reduce operation + * @return RMA request + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + + public Request rGetAccumulate(Buffer origin, int orgCount, Datatype orgType, + Buffer resultAddr, int resultCount, Datatype resultType, + int targetRank, int targetDisp, int targetCount, + Datatype targetType, Op op) + throws MPIException + { + MPI.check(); + + if(!origin.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + return new Request(rGetAccumulate(handle, origin, orgCount, orgType.handle, + resultAddr, resultCount, resultType.handle, + targetRank, targetDisp, targetCount, targetType.handle, + op, op.handle, getBaseType(orgType, targetType))); + } + + private native long rGetAccumulate( + long win, Buffer origin, int orgCount, long orgType, + Buffer resultAddr, int resultCount, long resultType, + int targetRank, int targetDisp, int targetCount, long targetType, + Op jOp, long hOp, int baseType) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_LOCK_ALL}. + * @param assertion program assertion + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void lockAll(int assertion) throws MPIException + { + MPI.check(); + lockAll(handle, assertion); + } + + private native void lockAll(long win, int assertion) + throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_UNLOCK_ALL}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void unlockAll() throws MPIException + { + MPI.check(); + unlockAll(handle); + } + + private native void unlockAll(long win) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_SYNC}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void sync() throws MPIException + { + MPI.check(); + sync(handle); + } + + private native void sync(long win) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_FLUSH}. + * @param targetRank rank of target window + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void flush(int targetRank) throws MPIException + { + MPI.check(); + flush(handle, targetRank); + } + + private native void flush(long win, int targetRank) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_FLUSH_ALL}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void flushAll() throws MPIException + { + MPI.check(); + flushAll(handle); + } + + private native void flushAll(long win) throws MPIException; + + /** + * Java binding of {@code MPI_COMPARE_AND_SWAP}. + * @param origin origin buffer + * @param compareAddr compare buffer + * @param resultAddr result buffer + * @param targetType datatype of each entry in target buffer + * @param targetRank rank of target + * @param targetDisp displacement from start of window to target buffer + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + + public void compareAndSwap(Buffer origin, Buffer compareAddr, Buffer resultAddr, + Datatype targetType, int targetRank, int targetDisp) + throws MPIException + { + MPI.check(); + + if(!origin.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + compareAndSwap(handle, origin, compareAddr, resultAddr, + targetType.handle, targetRank, targetDisp); + } + + private native void compareAndSwap( + long win, Buffer origin, Buffer compareAddr, Buffer resultAddr, + long targetType, int targetRank, int targetDisp) throws MPIException; + + /** + * Java binding of {@code MPI_FETCH_AND_OP}. + * @param origin origin buffer + * @param resultAddr result buffer + * @param dataType datatype of entry in origin, result, and target buffers + * @param targetRank rank of target + * @param targetDisp displacement from start of window to target buffer + * @param op reduce operation + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + + public void fetchAndOp(Buffer origin, Buffer resultAddr, Datatype dataType, + int targetRank, int targetDisp, Op op) + throws MPIException + { + MPI.check(); + + if(!origin.isDirect()) + throw new IllegalArgumentException("The origin must be direct buffer."); + + fetchAndOp(handle, origin, resultAddr, dataType.handle, targetRank, + targetDisp, op, op.handle, getBaseType(dataType, dataType)); + } + + private native void fetchAndOp( + long win, Buffer origin, Buffer resultAddr, long targetType, int targetRank, + int targetDisp, Op jOp, long hOp, int baseType) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL}. + * @param targetRank rank of target window + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + + public void flushLocal(int targetRank) throws MPIException + { + MPI.check(); + flushLocal(handle, targetRank); + } + + private native void flushLocal(long win, int targetRank) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_FLUSH_LOCAL_ALL}. + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + + public void flushLocalAll() throws MPIException + { + MPI.check(); + flushLocalAll(handle); + } + + private native void flushLocalAll(long win) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_GET_NAME}. + * @return the name associated with this window + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public String getName() throws MPIException + { + MPI.check(); + return getName(handle); + } + + private native String getName(long handle) throws MPIException; + + /** + * Java binding of the MPI operation {@code MPI_WIN_SET_NAME}. + * @param name the name to associate with this window + * @throws MPIException Signals that an MPI exception of some sort has occurred. + */ + public void setName(String name) throws MPIException + { + MPI.check(); + setName(handle, name); + } + + private native void setName(long handle, String name) throws MPIException; } // Win From f87c41e926ee0d19e671cc0db1340b1ea174dce6 Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Fri, 24 Jul 2015 11:54:52 -0600 Subject: [PATCH 2/2] Fix a compile issue in MPI.java A conflict was not fully resolved in the previous merge. This fixes the issue that was created. Signed-off-by: Nathaniel Graham --- ompi/mpi/java/java/MPI.java | 921 +----------------------------------- 1 file changed, 1 insertion(+), 920 deletions(-) diff --git a/ompi/mpi/java/java/MPI.java b/ompi/mpi/java/java/MPI.java index e0b63673c8..a0eaaa680e 100644 --- a/ompi/mpi/java/java/MPI.java +++ b/ompi/mpi/java/java/MPI.java @@ -45,7 +45,6 @@ * Copyright: Northeast Parallel Architectures Center * at Syracuse University 1998 */ - package mpi; import java.io.*; @@ -998,923 +997,5 @@ public final class MPI { return DoubleBuffer.wrap(buf, offset, buf.length - offset).slice(); } - ======= - private static boolean initialized, finalized; - private static byte[] buffer = null; // Buffer allocation - private static final int MAX_PROCESSOR_NAME = 256; - private static final ByteOrder nativeOrder = ByteOrder.nativeOrder(); - public static final Intracomm COMM_WORLD, COMM_SELF; - - public static final int THREAD_SINGLE, THREAD_FUNNELED, THREAD_SERIALIZED, - THREAD_MULTIPLE; - - public static final int GRAPH, DIST_GRAPH, CART; - public static final int ANY_SOURCE, ANY_TAG; - - public static final Op MAX, MIN, SUM, PROD, LAND, BAND, - LOR, BOR, LXOR, BXOR, REPLACE, NO_OP; - - /** - * Global minimum operator. - *

{@code MINLOC} and {@link #MAXLOC} can be used with each of the following - * datatypes: {@link #INT2}, {@link #SHORT_INT}, {@link #LONG_INT}, - * {@link #FLOAT_INT} and {@link #DOUBLE_INT}. - */ - public static final Op MINLOC; - - /** Global maximum operator. See {@link #MINLOC}.*/ - public static final Op MAXLOC; - - public static final Datatype DATATYPE_NULL; - - public static final Datatype BYTE, CHAR, SHORT, BOOLEAN, - INT, LONG, FLOAT, DOUBLE, PACKED, - FLOAT_COMPLEX, DOUBLE_COMPLEX; - - /** Struct which must be used with {@link #int2}. */ - public static final Datatype INT2; - /** Struct which must be used with {@link #shortInt}. */ - public static final Datatype SHORT_INT; - /** Struct which must be used with {@link #longInt}. */ - public static final Datatype LONG_INT; - /** Struct which must be used with {@link #floatInt}. */ - public static final Datatype FLOAT_INT; - /** Struct which must be used with {@link #doubleInt}. */ - public static final Datatype DOUBLE_INT; - - /** Struct object for {@link #INT2} datatype. */ - public static final Int2 int2; - /** Struct object for {@link #SHORT_INT} datatype. */ - public static final ShortInt shortInt; - /** Struct object for {@link #LONG_INT} datatype. */ - public static final LongInt longInt; - /** Struct object for {@link #FLOAT_INT} datatype. */ - public static final FloatInt floatInt; - /** Struct object for {@link #DOUBLE_INT} datatype. */ - public static final DoubleInt doubleInt; - - public static final Request REQUEST_NULL; - public static final Group GROUP_EMPTY; - public static final Info INFO_ENV, INFO_NULL; - - public static final int PROC_NULL; - public static final int UNDEFINED; - public static final int IDENT, CONGRUENT, SIMILAR, UNEQUAL; - public static final int TAG_UB, HOST, IO, WTIME_IS_GLOBAL; - - public static final int APPNUM, LASTUSEDCODE, UNIVERSE_SIZE, WIN_BASE, - WIN_SIZE, WIN_DISP_UNIT; - - public static final int VERSION, SUBVERSION; - public static final int ROOT, KEYVAL_INVALID, BSEND_OVERHEAD; - public static final int MAX_OBJECT_NAME, MAX_PORT_NAME, MAX_DATAREP_STRING; - public static final int MAX_INFO_KEY, MAX_INFO_VAL; - public static final int ORDER_C, ORDER_FORTRAN; - public static final int DISTRIBUTE_BLOCK, DISTRIBUTE_CYCLIC, DISTRIBUTE_NONE, - DISTRIBUTE_DFLT_DARG; - - public static final int MODE_CREATE, MODE_RDONLY, MODE_WRONLY, MODE_RDWR, - MODE_DELETE_ON_CLOSE, MODE_UNIQUE_OPEN, MODE_EXCL, - MODE_APPEND, MODE_SEQUENTIAL; - public static final int DISPLACEMENT_CURRENT; - public static final int SEEK_SET, SEEK_CUR, SEEK_END; - - public static final int MODE_NOCHECK, MODE_NOPRECEDE, MODE_NOPUT, - MODE_NOSTORE, MODE_NOSUCCEED; - public static final int LOCK_EXCLUSIVE, LOCK_SHARED; - - public static final Errhandler ERRORS_ARE_FATAL, ERRORS_RETURN; - - // Error classes and codes - public static final int SUCCESS; - public static final int ERR_BUFFER; - public static final int ERR_COUNT; - public static final int ERR_TYPE; - public static final int ERR_TAG; - public static final int ERR_COMM; - public static final int ERR_RANK; - public static final int ERR_REQUEST; - public static final int ERR_ROOT; - public static final int ERR_GROUP; - public static final int ERR_OP; - public static final int ERR_TOPOLOGY; - public static final int ERR_DIMS; - public static final int ERR_ARG; - public static final int ERR_UNKNOWN; - public static final int ERR_TRUNCATE; - public static final int ERR_OTHER; - public static final int ERR_INTERN; - public static final int ERR_IN_STATUS; - public static final int ERR_PENDING; - public static final int ERR_ACCESS; - public static final int ERR_AMODE; - public static final int ERR_ASSERT; - public static final int ERR_BAD_FILE; - public static final int ERR_BASE; - public static final int ERR_CONVERSION; - public static final int ERR_DISP; - public static final int ERR_DUP_DATAREP; - public static final int ERR_FILE_EXISTS; - public static final int ERR_FILE_IN_USE; - public static final int ERR_FILE; - public static final int ERR_INFO_KEY; - public static final int ERR_INFO_NOKEY; - public static final int ERR_INFO_VALUE; - public static final int ERR_INFO; - public static final int ERR_IO; - public static final int ERR_KEYVAL; - public static final int ERR_LOCKTYPE; - public static final int ERR_NAME; - public static final int ERR_NO_MEM; - public static final int ERR_NOT_SAME; - public static final int ERR_NO_SPACE; - public static final int ERR_NO_SUCH_FILE; - public static final int ERR_PORT; - public static final int ERR_QUOTA; - public static final int ERR_READ_ONLY; - public static final int ERR_RMA_CONFLICT; - public static final int ERR_RMA_SYNC; - public static final int ERR_SERVICE; - public static final int ERR_SIZE; - public static final int ERR_SPAWN; - public static final int ERR_UNSUPPORTED_DATAREP; - public static final int ERR_UNSUPPORTED_OPERATION; - public static final int ERR_WIN; - public static final int ERR_LASTCODE; - public static final int ERR_SYSRESOURCE; - - static - { - System.loadLibrary("mpi_java"); - - DATATYPE_NULL = new Datatype(); - - BYTE = new Datatype(); - CHAR = new Datatype(); - SHORT = new Datatype(); - BOOLEAN = new Datatype(); - INT = new Datatype(); - LONG = new Datatype(); - FLOAT = new Datatype(); - DOUBLE = new Datatype(); - PACKED = new Datatype(); - INT2 = new Datatype(); - - SHORT_INT = new Datatype(); - LONG_INT = new Datatype(); - FLOAT_INT = new Datatype(); - DOUBLE_INT = new Datatype(); - FLOAT_COMPLEX = new Datatype(); - DOUBLE_COMPLEX = new Datatype(); - - int2 = newInt2(); - shortInt = newShortInt(); - longInt = newLongInt(); - floatInt = newFloatInt(); - doubleInt = newDoubleInt(); - - MAX = new Op(1); - MIN = new Op(2); - SUM = new Op(3); - PROD = new Op(4); - LAND = new Op(5); - BAND = new Op(6); - LOR = new Op(7); - BOR = new Op(8); - LXOR = new Op(9); - BXOR = new Op(10); - MINLOC = new Op(11); - MAXLOC = new Op(12); - REPLACE = new Op(13); - NO_OP = new Op(14); - - GROUP_EMPTY = new Group(Group.getEmpty()); - REQUEST_NULL = new Request(Request.getNull()); - INFO_ENV = Info.newEnv(); - INFO_NULL = new Info(Info.NULL); - - Constant c = new Constant(); - - THREAD_SINGLE = c.THREAD_SINGLE; - THREAD_FUNNELED = c.THREAD_FUNNELED; - THREAD_SERIALIZED = c.THREAD_SERIALIZED; - THREAD_MULTIPLE = c.THREAD_MULTIPLE; - - GRAPH = c.GRAPH; - DIST_GRAPH = c.DIST_GRAPH; - CART = c.CART; - - ANY_SOURCE = c.ANY_SOURCE; - ANY_TAG = c.ANY_TAG; - PROC_NULL = c.PROC_NULL; - - UNDEFINED = c.UNDEFINED; - - IDENT = c.IDENT; - CONGRUENT = c.CONGRUENT; - SIMILAR = c.SIMILAR; - UNEQUAL = c.UNEQUAL; - - TAG_UB = c.TAG_UB; - HOST = c.HOST; - IO = c.IO; - WTIME_IS_GLOBAL = c.WTIME_IS_GLOBAL; - - APPNUM = c.APPNUM; - LASTUSEDCODE = c.LASTUSEDCODE; - UNIVERSE_SIZE = c.UNIVERSE_SIZE; - WIN_BASE = c.WIN_BASE; - WIN_SIZE = c.WIN_SIZE; - WIN_DISP_UNIT = c.WIN_DISP_UNIT; - - VERSION = c.VERSION; - SUBVERSION = c.SUBVERSION; - - ROOT = c.ROOT; - KEYVAL_INVALID = c.KEYVAL_INVALID; - BSEND_OVERHEAD = c.BSEND_OVERHEAD; - - MAX_OBJECT_NAME = c.MAX_OBJECT_NAME; - MAX_PORT_NAME = c.MAX_PORT_NAME; - MAX_DATAREP_STRING = c.MAX_DATAREP_STRING; - - MAX_INFO_KEY = c.MAX_INFO_KEY; - MAX_INFO_VAL = c.MAX_INFO_VAL; - - ORDER_C = c.ORDER_C; - ORDER_FORTRAN = c.ORDER_FORTRAN; - - DISTRIBUTE_BLOCK = c.DISTRIBUTE_BLOCK; - DISTRIBUTE_CYCLIC = c.DISTRIBUTE_CYCLIC; - DISTRIBUTE_NONE = c.DISTRIBUTE_NONE; - DISTRIBUTE_DFLT_DARG = c.DISTRIBUTE_DFLT_DARG; - - MODE_CREATE = c.MODE_CREATE; - MODE_RDONLY = c.MODE_RDONLY; - MODE_WRONLY = c.MODE_WRONLY; - MODE_RDWR = c.MODE_RDWR; - MODE_DELETE_ON_CLOSE = c.MODE_DELETE_ON_CLOSE; - MODE_UNIQUE_OPEN = c.MODE_UNIQUE_OPEN; - MODE_EXCL = c.MODE_EXCL; - MODE_APPEND = c.MODE_APPEND; - MODE_SEQUENTIAL = c.MODE_SEQUENTIAL; - - DISPLACEMENT_CURRENT = c.DISPLACEMENT_CURRENT; - - SEEK_SET = c.SEEK_SET; - SEEK_CUR = c.SEEK_CUR; - SEEK_END = c.SEEK_END; - - MODE_NOCHECK = c.MODE_NOCHECK; - MODE_NOPRECEDE = c.MODE_NOPRECEDE; - MODE_NOPUT = c.MODE_NOPUT; - MODE_NOSTORE = c.MODE_NOSTORE; - MODE_NOSUCCEED = c.MODE_NOSUCCEED; - LOCK_EXCLUSIVE = c.LOCK_EXCLUSIVE; - LOCK_SHARED = c.LOCK_SHARED; - - ERRORS_ARE_FATAL = new Errhandler(Errhandler.getFatal()); - ERRORS_RETURN = new Errhandler(Errhandler.getReturn()); - - COMM_WORLD = new Intracomm(); - COMM_SELF = new Intracomm(); - - // Error classes and codes - SUCCESS = c.SUCCESS; - ERR_BUFFER = c.ERR_BUFFER; - ERR_COUNT = c.ERR_COUNT; - ERR_TYPE = c.ERR_TYPE; - ERR_TAG = c.ERR_TAG; - ERR_COMM = c.ERR_COMM; - ERR_RANK = c.ERR_RANK; - ERR_REQUEST = c.ERR_REQUEST; - ERR_ROOT = c.ERR_ROOT; - ERR_GROUP = c.ERR_GROUP; - ERR_OP = c.ERR_OP; - ERR_TOPOLOGY = c.ERR_TOPOLOGY; - ERR_DIMS = c.ERR_DIMS; - ERR_ARG = c.ERR_ARG; - ERR_UNKNOWN = c.ERR_UNKNOWN; - ERR_TRUNCATE = c.ERR_TRUNCATE; - ERR_OTHER = c.ERR_OTHER; - ERR_INTERN = c.ERR_INTERN; - ERR_IN_STATUS = c.ERR_IN_STATUS; - ERR_PENDING = c.ERR_PENDING; - ERR_ACCESS = c.ERR_ACCESS; - ERR_AMODE = c.ERR_AMODE; - ERR_ASSERT = c.ERR_ASSERT; - ERR_BAD_FILE = c.ERR_BAD_FILE; - ERR_BASE = c.ERR_BASE; - ERR_CONVERSION = c.ERR_CONVERSION; - ERR_DISP = c.ERR_DISP; - ERR_DUP_DATAREP = c.ERR_DUP_DATAREP; - ERR_FILE_EXISTS = c.ERR_FILE_EXISTS; - ERR_FILE_IN_USE = c.ERR_FILE_IN_USE; - ERR_FILE = c.ERR_FILE; - ERR_INFO_KEY = c.ERR_INFO_KEY; - ERR_INFO_NOKEY = c.ERR_INFO_NOKEY; - ERR_INFO_VALUE = c.ERR_INFO_VALUE; - ERR_INFO = c.ERR_INFO; - ERR_IO = c.ERR_IO; - ERR_KEYVAL = c.ERR_KEYVAL; - ERR_LOCKTYPE = c.ERR_LOCKTYPE; - ERR_NAME = c.ERR_NAME; - ERR_NO_MEM = c.ERR_NO_MEM; - ERR_NOT_SAME = c.ERR_NOT_SAME; - ERR_NO_SPACE = c.ERR_NO_SPACE; - ERR_NO_SUCH_FILE = c.ERR_NO_SUCH_FILE; - ERR_PORT = c.ERR_PORT; - ERR_QUOTA = c.ERR_QUOTA; - ERR_READ_ONLY = c.ERR_READ_ONLY; - ERR_RMA_CONFLICT = c.ERR_RMA_CONFLICT; - ERR_RMA_SYNC = c.ERR_RMA_SYNC; - ERR_SERVICE = c.ERR_SERVICE; - ERR_SIZE = c.ERR_SIZE; - ERR_SPAWN = c.ERR_SPAWN; - ERR_UNSUPPORTED_DATAREP = c.ERR_UNSUPPORTED_DATAREP; - ERR_UNSUPPORTED_OPERATION = c.ERR_UNSUPPORTED_OPERATION; - ERR_WIN = c.ERR_WIN; - ERR_LASTCODE = c.ERR_LASTCODE; - ERR_SYSRESOURCE = c.ERR_SYSRESOURCE; - } - - private static native Int2 newInt2(); - private static native ShortInt newShortInt(); - private static native LongInt newLongInt(); - private static native FloatInt newFloatInt(); - private static native DoubleInt newDoubleInt(); - - private static void initCommon() throws MPIException - { - initialized = true; - - DATATYPE_NULL.setBasic(Datatype.NULL); - - BYTE.setBasic(Datatype.BYTE); - CHAR.setBasic(Datatype.CHAR); - SHORT.setBasic(Datatype.SHORT); - BOOLEAN.setBasic(Datatype.BOOLEAN); - INT.setBasic(Datatype.INT); - LONG.setBasic(Datatype.LONG); - FLOAT.setBasic(Datatype.FLOAT); - DOUBLE.setBasic(Datatype.DOUBLE); - PACKED.setBasic(Datatype.PACKED); - - INT2.setBasic(Datatype.INT2, MPI.BYTE); - SHORT_INT.setBasic(Datatype.SHORT_INT, MPI.BYTE); - LONG_INT.setBasic(Datatype.LONG_INT, MPI.BYTE); - FLOAT_INT.setBasic(Datatype.FLOAT_INT, MPI.BYTE); - DOUBLE_INT.setBasic(Datatype.DOUBLE_INT, MPI.BYTE); - FLOAT_COMPLEX.setBasic(Datatype.FLOAT_COMPLEX, MPI.FLOAT); - DOUBLE_COMPLEX.setBasic(Datatype.DOUBLE_COMPLEX, MPI.DOUBLE); - - COMM_WORLD.setType(Intracomm.WORLD); - COMM_SELF.setType(Intracomm.SELF); - } - - /** - * Initialize MPI. - *

Java binding of the MPI operation {@code MPI_INIT}. - * @param args arguments to the {@code main} method. - * @return arguments - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - public static String[] Init(String[] args) throws MPIException - { - if(initialized) - throw new MPIException("MPI is already initialized."); - - String[] newArgs = Init_jni(args); - initCommon(); - return newArgs; - } - - private static native String [] Init_jni(String[] args); - - /** - * Initialize MPI with threads. - *

Java binding of the MPI operation {@code MPI_INIT_THREAD}. - * @param args arguments to the {@code main} method. - * @param required desired level of thread support - * @return provided level of thread support - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - public static int InitThread(String[] args, int required) throws MPIException - { - if(initialized) - throw new MPIException("MPI is already initialized."); - - int provided = InitThread_jni(args, required); - initCommon(); - return provided; - } - - private static native int InitThread_jni(String[] args, int required) - throws MPIException; - - /** - * Java binding of the MPI operation {@code MPI_QUERY_THREAD}. - * @return provided level of thread support - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - public static int queryThread() throws MPIException - { - MPI.check(); - return queryThread_jni(); - } - - private static native int queryThread_jni() throws MPIException; - - /** - * Java binding of the MPI operation {@code MPI_IS_THREAD_MAIN}. - * @return true if it is the main thread - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - public static boolean isThreadMain() throws MPIException - { - MPI.check(); - return isThreadMain_jni(); - } - - private static native boolean isThreadMain_jni() throws MPIException; - - /** - * Finalize MPI. - *

Java binding of the MPI operation {@code MPI_FINALIZE}. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - public static void Finalize() throws MPIException - { - check(); - Finalize_jni(); - finalized = true; - } - - private static native void Finalize_jni() throws MPIException; - - /** - * Returns an elapsed time on the calling processor. - *

Java binding of the MPI operation {@code MPI_WTIME}. - * @return time in seconds since an arbitrary time in the past. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - public static double wtime() throws MPIException - { - check(); - return wtime_jni(); - } - - private static native double wtime_jni(); - - /** - * Returns resolution of timer. - *

Java binding of the MPI operation {MPI_WTICK}. - * @return resolution of {@code wtime} in seconds. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - public static double wtick() throws MPIException - { - check(); - return wtick_jni(); - } - - private static native double wtick_jni(); - - /** - * Returns the name of the processor on which it is called. - *

Java binding of the MPI operation {@code MPI_GET_PROCESSOR_NAME}. - * @return A unique specifier for the actual node. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - static public String getProcessorName() throws MPIException - { - check(); - byte[] buf = new byte[MAX_PROCESSOR_NAME]; - int lengh = getProcessorName(buf); - return new String(buf,0,lengh); - } - - static private native int getProcessorName(byte[] buf); - - /** - * Test if MPI has been initialized. - *

Java binding of the MPI operation {@code MPI_INITIALIZED}. - * @return {@code true} if {@code Init} has been called, - * {@code false} otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - static public native boolean isInitialized() throws MPIException; - - /** - * Test if MPI has been finalized. - *

Java binding of the MPI operation {@code MPI_FINALIZED}. - * @return {@code true} if {@code Finalize} has been called, - * {@code false} otherwise. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - static public native boolean isFinalized() throws MPIException; - - /** - * Attaches a user-provided buffer for sending. - *

Java binding of the MPI operation {@code MPI_BUFFER_ATTACH}. - * @param buffer initial buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - static public void attachBuffer(byte[] buffer) throws MPIException - { - check(); - MPI.buffer = buffer; - attachBuffer_jni(buffer); - } - - static private native void attachBuffer_jni(byte[] buffer); - - /** - * Removes an existing buffer (for use in sending). - *

Java binding of the MPI operation {@code MPI_BUFFER_DETACH}. - * @return initial buffer - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - static public byte[] detachBuffer() throws MPIException - { - check(); - detachBuffer_jni(buffer); - byte[] result = MPI.buffer; - MPI.buffer = null; - return result; - } - - static private native void detachBuffer_jni(byte[] buffer); - - /** - * Controls profiling. - *

This method is not implemented. - *

Java binding of the MPI operation {@code MPI_PCONTROL}. - * @param level Profiling level. - * @param obj Profiling information. - */ - public static void pControl(int level, Object obj) - { - // Nothing to do here. - } - - /** - * Check if MPI has been initialized and hasn't been finalized. - * @throws MPIException Signals that an MPI exception of some sort has occurred. - */ - protected static void check() throws MPIException - { - if(!initialized) - throw new MPIException("MPI is not initialized."); - - if(finalized) - throw new MPIException("MPI is finalized."); - } - - protected static byte[] attrSet(Object value) throws MPIException - { - try - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream os = new ObjectOutputStream(baos); - os.writeObject(value); - os.close(); - return baos.toByteArray(); - } - catch(IOException ex) - { - MPIException mpiex = new MPIException(ex); - mpiex.setStackTrace(ex.getStackTrace()); - throw mpiex; - } - } - - protected static Object attrGet(byte[] value) throws MPIException - { - if(value == null) - return null; - - try - { - ByteArrayInputStream bais = new ByteArrayInputStream(value); - ObjectInputStream is = new ObjectInputStream(bais); - Object obj = is.readObject(); - is.close(); - return obj; - } - catch(ClassNotFoundException ex) - { - throw new MPIException(ex); - } - catch(IOException ex) - { - throw new MPIException(ex); - } - } - - /** - * Allocates a new direct byte buffer. - * @param capacity The new buffer's capacity, in bytes - * @return The new byte buffer - */ - public static ByteBuffer newByteBuffer(int capacity) - { - ByteBuffer buf = ByteBuffer.allocateDirect(capacity); - buf.order(nativeOrder); - return buf; - } - - /** - * Allocates a new direct char buffer. - * @param capacity The new buffer's capacity, in chars - * @return The new char buffer - */ - public static CharBuffer newCharBuffer(int capacity) - { - assert capacity <= Integer.MAX_VALUE / 2; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 2); - buf.order(nativeOrder); - return buf.asCharBuffer(); - } - - /** - * Allocates a new direct short buffer. - * @param capacity The new buffer's capacity, in shorts - * @return The new short buffer - */ - public static ShortBuffer newShortBuffer(int capacity) - { - assert capacity <= Integer.MAX_VALUE / 2; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 2); - buf.order(nativeOrder); - return buf.asShortBuffer(); - } - - /** - * Allocates a new direct int buffer. - * @param capacity The new buffer's capacity, in ints - * @return The new int buffer - */ - public static IntBuffer newIntBuffer(int capacity) - { - assert capacity <= Integer.MAX_VALUE / 4; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 4); - buf.order(nativeOrder); - return buf.asIntBuffer(); - } - - /** - * Allocates a new direct long buffer. - * @param capacity The new buffer's capacity, in longs - * @return The new long buffer - */ - public static LongBuffer newLongBuffer(int capacity) - { - assert capacity <= Integer.MAX_VALUE / 8; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 8); - buf.order(nativeOrder); - return buf.asLongBuffer(); - } - - /** - * Allocates a new direct float buffer. - * @param capacity The new buffer's capacity, in floats - * @return The new float buffer - */ - public static FloatBuffer newFloatBuffer(int capacity) - { - assert capacity <= Integer.MAX_VALUE / 4; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 4); - buf.order(nativeOrder); - return buf.asFloatBuffer(); - } - - /** - * Allocates a new direct double buffer. - * @param capacity The new buffer's capacity, in doubles - * @return The new double buffer - */ - public static DoubleBuffer newDoubleBuffer(int capacity) - { - assert capacity <= Integer.MAX_VALUE / 8; - ByteBuffer buf = ByteBuffer.allocateDirect(capacity * 8); - buf.order(nativeOrder); - return buf.asDoubleBuffer(); - } - - /** - * Asserts that a buffer is direct. - * @param buf buffer - */ - protected static void assertDirectBuffer(Buffer buf) - { - if(!buf.isDirect()) - throw new IllegalArgumentException("The buffer must be direct."); - } - - /** - * Asserts that buffers are direct. - * @param sendbuf The send buffer - * @param recvbuf The receive buffer - */ - protected static void assertDirectBuffer(Buffer sendbuf, Buffer recvbuf) - { - if(!sendbuf.isDirect()) - throw new IllegalArgumentException("The send buffer must be direct."); - - if(!recvbuf.isDirect()) - throw new IllegalArgumentException("The recv. buffer must be direct."); - } - - /** - * Checks if an object is a direct buffer. - * @param obj object - * @return true if the object is a direct buffer - */ - protected static boolean isDirectBuffer(Object obj) - { - return obj instanceof Buffer && ((Buffer)obj).isDirect(); - } - - /** - * Checks if an object is a heap buffer. - * @param obj object - * @return true if the object is a heap buffer - */ - protected static boolean isHeapBuffer(Object obj) - { - return obj instanceof Buffer && !((Buffer)obj).isDirect(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static ByteBuffer slice(ByteBuffer buf, int offset) - { - return ((ByteBuffer)buf.clear().position(offset)) - .slice().order(nativeOrder); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static CharBuffer slice(CharBuffer buf, int offset) - { - return ((CharBuffer)buf.clear().position(offset)).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static ShortBuffer slice(ShortBuffer buf, int offset) - { - return ((ShortBuffer)buf.clear().position(offset)).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static IntBuffer slice(IntBuffer buf, int offset) - { - return ((IntBuffer)buf.clear().position(offset)).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static LongBuffer slice(LongBuffer buf, int offset) - { - return ((LongBuffer)buf.clear().position(offset)).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static FloatBuffer slice(FloatBuffer buf, int offset) - { - return ((FloatBuffer)buf.clear().position(offset)).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static DoubleBuffer slice(DoubleBuffer buf, int offset) - { - return ((DoubleBuffer)buf.clear().position(offset)).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static ByteBuffer slice(byte[] buf, int offset) - { - return ByteBuffer.wrap(buf, offset, buf.length - offset) - .slice().order(nativeOrder); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static CharBuffer slice(char[] buf, int offset) - { - return CharBuffer.wrap(buf, offset, buf.length - offset).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static ShortBuffer slice(short[] buf, int offset) - { - return ShortBuffer.wrap(buf, offset, buf.length - offset).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static IntBuffer slice(int[] buf, int offset) - { - return IntBuffer.wrap(buf, offset, buf.length - offset).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static LongBuffer slice(long[] buf, int offset) - { - return LongBuffer.wrap(buf, offset, buf.length - offset).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static FloatBuffer slice(float[] buf, int offset) - { - return FloatBuffer.wrap(buf, offset, buf.length - offset).slice(); - } - - /** - * Creates a new buffer whose content is a shared subsequence of a buffer. - *

The content of the new buffer will start at the specified offset. - * @param buf buffer - * @param offset offset - * @return the new buffer. - */ - public static DoubleBuffer slice(double[] buf, int offset) - { - return DoubleBuffer.wrap(buf, offset, buf.length - offset).slice(); - } - -} // MPI +} // MPI \ No newline at end of file