f83f9d56b72341d44a04cec72fea32e40d8cbeac
[IRC.git] / Robust / src / Benchmarks / SingleTM / SSCA2 / CreatePartition.java
1 /* =============================================================================
2  *
3  * createPartition.java
4  *
5  * =============================================================================
6  * 
7  * For the license of ssca2, please see ssca2/COPYRIGHT
8  * 
9  * ------------------------------------------------------------------------
10  * Unless otherwise noted, the following license applies to STAMP files:
11  * 
12  * Copyright (c) 2007, Stanford University
13  * All rights reserved.
14  * 
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met:
18  * 
19  *     * Redistributions of source code must retain the above copyright
20  *       notice, this list of conditions and the following disclaimer.
21  * 
22  *     * Redistributions in binary form must reproduce the above copyright
23  *       notice, this list of conditions and the following disclaimer in
24  *       the documentation and/or other materials provided with the
25  *       distribution.
26  * 
27  *     * Neither the name of Stanford University nor the names of its
28  *       contributors may be used to endorse or promote products derived
29  *       from this software without specific prior written permission.
30  * 
31  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
32  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
35  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
41  * THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * =============================================================================
44  */
45
46 public class CreatePartition {
47   public CreatePartition() {
48   }
49
50   /* =============================================================================
51    * createPartition
52    * =============================================================================
53    */
54   public static void
55     createPartition (int min, int max, int id, int n, LocalStartStop lss)
56     {
57       int range = max - min;
58       int chunk = MAX(1, ((range + n/2) / n)); /* rounded */
59       int start = min + chunk * id;
60       int stop;
61       if (id == (n-1)) {
62         stop = max;
63       } else {
64         stop = MIN(max, (start + chunk));
65       }
66
67       lss.start = start;
68       lss.stop = stop;
69     }
70
71   public static int MAX(int a, int b) {
72     int val = (a > b) ? (a) : (b);
73     return val;
74   }
75
76   public static int MIN(int a, int b) {
77     int val = (a < b) ? (a) : (b); 
78     return val;
79   }
80 }
81 /* =============================================================================
82  *
83  * End of createPartition.java
84  *
85  * =============================================================================
86  */