root/trunk/ProjectFortress/demos/DemoGenerator22D.fss

Revision 3923, 3.2 KB (checked in by sukyoungryu, 5 months ago)

[copyright] Fixed the copyright notices in Kento's code.

Line 
1(*******************************************************************************
2  Generator-of-Generators Library is copyrighted free software by Kento Emoto
3  <emoto[at]ipl.t.u-tokyo.ac.jp> developed under the collaborative
4  research on Fortress Programming Language between Sun Microsystems,
5  Inc. and the University of Tokyo.
6
7  You can redistribute it and/or modify it under the following
8  BSD-style license or the Sun Contributor Agreement that Kento Emoto signed.
9
10  Copyright 2009 by Kento Emoto
11  All rights reserved.
12
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions
15  are met:
16
17      * Redistributions of source code must retain the above copyright
18        notice, this list of conditions and the following disclaimer.
19      * Redistributions in binary form must reproduce the above copyright
20        notice, this list of conditions and the following disclaimer
21        in the documentation and/or other materials provided with the
22        distribution.
23      * Neither the name of Kento Emoto nor the names of its
24        contributors may be used to endorse or promote products derived
25        from this software without specific prior written permission.
26
27  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39 ******************************************************************************)
40
41component DemoGenerator22D
42
43import Generator22D.{...}
44import List.{...}
45
46export Executable
47
48sizes = <|[\ZZ32\] 4, 8 |>
49
50
51run() = do
52  i : ZZ32 := 0
53  while i < |sizes| do
54    rundemo(i)
55    i += 1
56  end
57end
58
59(* the optimization works well *)
60rundemo(i) = do
61  xs = array[\Number\]( (sizes[i],sizes[i]) ).fill(fn (ij):ZZ32 => |\random(10)-5/|)
62  demo() = do
63    st = nanoTime()
64    ans=BIG MAX[\Number\] <|[\Number\] SUM[\Number\] r | r <- rects xs |>
65    et = nanoTime()
66    t = et - st
67    ss = t / 1000000000.0
68
69    n = sizes[i]
70    println("mrs of " n "x" n " in " t " ns ( " ss " s) (the answer is " ans")")
71  end
72  println ("xs = " xs)
73  println ("rows xs = " (rows xs) )
74  println ("cols xs = " (cols xs) )
75  println ("rects xs = " (rects xs))
76
77  println ("")
78
79  println ("computing the maximum rectangle sum (mrs) : BIG MAX <| SUM r | r <- rects xs |>")
80
81  switchDispatching(false)
82  println("without optimization...")
83  demo()
84
85  switchDispatching(true)
86  println("with optimization...")
87  demo()
88
89  switchDispatching(false)
90  println("without optimization...")
91  demo()
92
93  switchDispatching(true)
94  println("with optimization...")
95  demo()
96
97  println ("The optimization works well?\n")
98end
99
100end
Note: See TracBrowser for help on using the browser.