freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Re: [pooma-dev] [BUG] ScalarCode does not work for Arrays


From: Richard Guenther
Subject: [PATCH] Re: [pooma-dev] [BUG] ScalarCode does not work for Arrays
Date: Wed, 15 Jan 2003 17:24:52 +0100 (CET)

On Wed, 15 Jan 2003, Richard Guenther wrote:

> So I propose to make Engine's domain access interface match FieldEngine's,
> i.e. add Engine->physicalDomain(), make Array.physicalDomain() call that
> and return Layout->innerDomain() for this.

I looked at the various engines and a physicalDomain() method can not
consitently defined for all of them, so I decided to go the simple way
of just fixing Array.physicalDomain().

The following patch does exactly this and introduces a testcase that fails
before and succeeds after the patch (test with assertions on).

Ok? (dont know if changing Array.physicalDomain() has any negative impact
on user code - the testsuite doesnt care)

Richard.

diff -Nru a/r2/src/Array/Array.h b/r2/src/Array/Array.h
--- a/r2/src/Array/Array.h      Wed Jan 15 17:12:42 2003
+++ b/r2/src/Array/Array.h      Wed Jan 15 17:12:42 2003
@@ -1810,7 +1810,7 @@

   inline Domain_t physicalDomain() const
     {
-      return engine_m.domain();
+      return engine_m.layout().innerDomain();
     }

   inline Domain_t totalDomain() const
diff -Nru a/r2/src/Evaluator/tests/evaluatorTest2.cpp 
b/r2/src/Evaluator/tests/evaluatorTest2.cpp
--- /dev/null   Wed Dec 31 16:00:00 1969
+++ b/r2/src/Evaluator/tests/evaluatorTest2.cpp Wed Jan 15 17:12:42 2003
@@ -0,0 +1,173 @@
+// -*- C++ -*-
+// ACL:license
+// ----------------------------------------------------------------------
+// This software and ancillary information (herein called "SOFTWARE")
+// called POOMA (Parallel Object-Oriented Methods and Applications) is
+// made available under the terms described here.  The SOFTWARE has been
+// approved for release with associated LA-CC Number LA-CC-98-65.
+//
+// Unless otherwise indicated, this SOFTWARE has been authored by an
+// employee or employees of the University of California, operator of the
+// Los Alamos National Laboratory under Contract No. W-7405-ENG-36 with
+// the U.S. Department of Energy.  The U.S. Government has rights to use,
+// reproduce, and distribute this SOFTWARE. The public may copy, distribute,
+// prepare derivative works and publicly display this SOFTWARE without
+// charge, provided that this Notice and any statement of authorship are
+// reproduced on all copies.  Neither the Government nor the University
+// makes any warranty, express or implied, or assumes any liability or
+// responsibility for the use of this SOFTWARE.
+//
+// If SOFTWARE is modified to produce derivative works, such modified
+// SOFTWARE should be clearly marked, so as not to confuse it with the
+// version available from LANL.
+//
+// For more information about POOMA, send e-mail to address@hidden,
+// or visit the POOMA web page at http://www.acl.lanl.gov/pooma/.
+// ----------------------------------------------------------------------
+// ACL:license
+
+//-----------------------------------------------------------------------------
+// evaluatorTest2 - a simple patch function using ScalarCode
+//-----------------------------------------------------------------------------
+
+#include "Pooma/Pooma.h"
+#include "Pooma/Arrays.h"
+#include "Pooma/Fields.h" // for PerformUpdateTag() only!
+#include "Evaluator/ScalarCode.h"
+#include "Utilities/Tester.h"
+#include <iostream>
+
+// This really simple example doesn't do anything a stencil couldn't do,
+// but you could imagine writing something more complicated.
+
+struct MyFunction
+{
+  MyFunction() {}
+
+  template<class A>
+  void operator()(const A &a, const Loc<1> &i) const
+  {
+    if (a(i)>5.0)
+      {
+       a(i) /= 4.0;
+      }
+  }
+
+  void scalarCodeInfo(ScalarCodeInfo& i) const
+  {
+    i.arguments(1);
+    i.dimensions(1);
+    i.lowerExtent(0) = 0;
+    i.upperExtent(0) = 0;
+    i.write(0, true);
+    i.useGuards(0, false);
+  }
+};
+
+struct MyFunction2
+{
+  MyFunction2() {}
+
+  template<class Array1, class Array2>
+  void operator()(const Array1 &a, const Array2 &b, const Loc<2> &i) const
+  {
+    Loc<2> dx(1, 0), dy(0, 1);
+    a(i) = 0.25 * (b(i-dx) + b(i+dx) + b(i-dy) + b(i+dy));
+  }
+
+  void scalarCodeInfo(ScalarCodeInfo& i) const
+  {
+    i.arguments(2);
+    i.dimensions(2);
+    i.lowerExtent(0) = 1;
+    i.upperExtent(0) = 1;
+    i.lowerExtent(1) = 1;
+    i.upperExtent(1) = 1;
+    i.write(0, true);
+    i.write(1, false);
+    i.useGuards(0, false);
+    i.useGuards(1, true);
+  }
+};
+
+int main(int argc, char *argv[])
+{
+  // Initialize POOMA and output stream, using Tester class
+  Pooma::initialize(argc, argv);
+  Pooma::Tester tester(argc, argv);
+
+  {
+    int size = 120;
+
+    Interval<1> domain(size);
+    UniformGridPartition<1> partition(Loc<1>(10));
+    UniformGridLayout<1> layout(domain, partition, ReplicatedTag());
+
+    Array<1,double,MultiPatch<UniformTag, Brick> > a(layout),b(layout);
+
+    int i;
+    for (i = 0; i < size; ++i )
+      {
+       a(i) = i;
+      }
+    b = where(a>5.0,a/4.0,a);
+
+    ScalarCode<MyFunction>()(a);
+
+    tester.out() << a << std::endl;
+    tester.out() << b << std::endl;
+
+    tester.check(sum((a-b)*(a-b))<0.001);
+  }
+
+  {
+    Interval<2> domain(9, 9);
+    UniformGridLayout<2> layout(domain, Loc<2>(3, 3),
+                               GuardLayers<2>(1), ReplicatedTag());
+
+    Array<2, double, MultiPatch<UniformTag, Brick> > a(layout), b(layout), 
c(layout);
+
+    a(a.domain()) = 1.0;
+    b(b.domain()) = iota(b.domain()).comp(0) + iota(b.domain()).comp(1);
+    c(domain) = 0.25 * (b(domain - Loc<2>(1, 0)) + b(domain + Loc<2>(1, 0))
+                       + b(domain - Loc<2>(0, 1)) + b(domain + Loc<2>(0, 1)));
+    ScalarCode<MyFunction2>()(a, b);
+
+    tester.out() << a << std::endl;
+    tester.out() << c << std::endl;
+
+    tester.check("MultiPatch setup", all(a(domain) == c(domain)));
+  }
+
+  {
+    Interval<2> domain(9, 9);
+    UniformGridLayout<2> layout(domain, Loc<2>(3, 3),
+                               GuardLayers<2>(1), DistributedTag());
+
+    Array<2, double, MultiPatch<UniformTag, Remote<Brick> > > a(layout), 
b(layout), c(layout);
+
+    a(a.domain()) = 1.0;
+    b(b.domain()) = iota(b.domain()).comp(0) + iota(b.domain()).comp(1);
+    c(domain) = 0.25 * (b(domain - Loc<2>(1, 0)) + b(domain + Loc<2>(1, 0))
+                       + b(domain - Loc<2>(0, 1)) + b(domain + Loc<2>(0, 1)));
+    ScalarCode<MyFunction2>()(a, b);
+
+    tester.out() << a << std::endl;
+    tester.out() << c << std::endl;
+
+    tester.check("Remote MultiPatch setup", all(a(domain) == c(domain)));
+  }
+
+  int retval = tester.results("evaluatorTest2 (ScalarCode)");
+
+  Pooma::finalize();
+
+  return retval;
+}
+
+// ACL:rcsinfo
+// ----------------------------------------------------------------------
+// $RCSfile: evaluatorTest3.cpp,v $   $Author: sa_smith $
+// $Revision: 1.13 $   $Date: 2000/06/05 18:03:35 $
+// ----------------------------------------------------------------------
+// ACL:rcsinfo
diff -Nru a/r2/src/Evaluator/tests/makefile b/r2/src/Evaluator/tests/makefile
--- a/r2/src/Evaluator/tests/makefile   Wed Jan 15 17:12:42 2003
+++ b/r2/src/Evaluator/tests/makefile   Wed Jan 15 17:12:42 2003
@@ -34,7 +34,8 @@
 PASS=APP


-TESTS = compressibleTest1 evaluatorTest1 evaluatorTest3 \
+TESTS = compressibleTest1 \
+       evaluatorTest1 evaluatorTest2 evaluatorTest3 \
        ReductionTest1 ReductionTest2 ReductionTest3 ReductionTest4

 default:: build

reply via email to

[Prev in Thread] Current Thread [Next in Thread]