View Javadoc
1   //******************************************************************************
2   //
3   // File:    ObjectOp.java
4   // Package: edu.rit.pj.reduction
5   // Unit:    Class edu.rit.pj.reduction.ObjectOp
6   //
7   // This Java source file is copyright (C) 2008 by Alan Kaminsky. All rights
8   // reserved. For further information, contact the author, Alan Kaminsky, at
9   // ark@cs.rit.edu.
10  //
11  // This Java source file is part of the Parallel Java Library ("PJ"). PJ is free
12  // software; you can redistribute it and/or modify it under the terms of the GNU
13  // General Public License as published by the Free Software Foundation; either
14  // version 3 of the License, or (at your option) any later version.
15  //
16  // PJ is distributed in the hope that it will be useful, but WITHOUT ANY
17  // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18  // A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19  //
20  // Linking this library statically or dynamically with other modules is making a
21  // combined work based on this library. Thus, the terms and conditions of the GNU
22  // General Public License cover the whole combination.
23  //
24  // As a special exception, the copyright holders of this library give you
25  // permission to link this library with independent modules to produce an
26  // executable, regardless of the license terms of these independent modules, and
27  // to copy and distribute the resulting executable under terms of your choice,
28  // provided that you also meet, for each linked independent module, the terms
29  // and conditions of the license of that module. An independent module is a module
30  // which is not derived from or based on this library. If you modify this library,
31  // you may extend this exception to your version of the library, but you are not
32  // obligated to do so. If you do not wish to do so, delete this exception
33  // statement from your version.
34  //
35  // A copy of the GNU General Public License is provided in the file gpl.txt. You
36  // may also obtain a copy of the GNU General Public License on the World Wide
37  // Web at http://www.gnu.org/licenses/gpl.html.
38  //
39  //******************************************************************************
40  package edu.rit.pj.reduction;
41  
42  /**
43   * Class ObjectOp is the abstract base class for a binary operation on object
44   * values, used to do reduction in a parallel program.
45   * <P>
46   * When classes in the Parallel Java Library call the <code>op(x,y)</code> method
47   * during a reduction operation, the <code>x</code> argument is the value of the
48   * reduction variable, and the <code>y</code> argument is the value to be combined
49   * with the reduction variable. The value returned by the <code>op(x,y)</code>
50   * method is stored back into the reduction variable.
51   * <P>
52   * The <code>op(x,y)</code> method in any subclass of class ObjectOp must obey the
53   * following requirements, which are assumed by classes in the Parallel Java
54   * Library:
55   * <UL>
56   * <LI>
57   * If as a result of the binary operation the state of the reduction variable
58   * will not change, the <code>op(x,y)</code> method must return <code>x</code>.
59   *
60   * <LI>
61   * If as a result of the binary operation the state of the reduction variable
62   * will change, the <code>op(x,y)</code> method must return a newly created object
63   * containing the desired state.
64   *
65   * <LI>
66   * The <code>op(x,y)</code> method must neither change the state of <code>x</code> nor
67   * change the state of <code>y</code>; that is, the <code>op(x,y)</code> method must
68   * have no side effects.
69   * </UL>
70   *
71   * @param <T> Object data type.
72   * @author Alan Kaminsky
73   * @version 30-Mar-2008
74   */
75  public abstract class ObjectOp<T>
76          extends Op {
77  
78  // Hidden constructors.
79      /**
80       * Construct a new object binary operation.
81       */
82      protected ObjectOp() {
83          super();
84      }
85  
86  // Exported operations.
87      /**
88       * Perform this binary operation.
89       *
90       * @param x First argument.
91       * @param y Second argument.
92       * @return (<code>x</code> <I>op</I> <code>y</code>), where <I>op</I> stands for
93       * this binary operation.
94       */
95      public abstract T op(T x,
96              T y);
97  
98  }