[PATCH] Fix and test (unused) CollectFromContexts
Richard Guenther
rguenth at tat.physik.uni-tuebingen.de
Mon Dec 8 12:31:12 UTC 2003
Hi!
This patch fixes bugs in CollectFromContexts and adds a testcase for it.
It's currently unused, but see the next patch.
Ok?
Richard.
2003Dec08 Richard Guenther <richard.guenther at uni-tuebingen.de>
* src/Tulip/CollectFromContexts.h: pack/unpack CollectionValue
correctly, cleanup object, if valid.
* src/Tulip/tests/CollectFromContextsTest.cpp: new.
* src/Tulip/tests/makefile: add CollectFromContextsTest.
===== CollectFromContexts.h 1.3 vs edited =====
--- 1.3/r2/src/Tulip/CollectFromContexts.h Wed Dec 3 12:30:45 2003
+++ edited/CollectFromContexts.h Mon Dec 8 13:21:43 2003
@@ -34,7 +34,7 @@
/** @file
* @ingroup Tulip
* @brief
- * Undocumented.
+ * CollectFromContext encapsulates functionality like MPI_Gather.
*/
#ifndef POOMA_MESSAGING_COLLECTFROMCONTEXTS_H
@@ -136,7 +136,7 @@
static inline int pack(const CollectionValue<T> &v, char *buffer)
{
int nBytes = Serialize<CHEETAH, bool>::pack(v.valid(), buffer);
- nBytes += Serialize<CHEETAH, int>::pack(v.context(), buffer);
+ nBytes += Serialize<CHEETAH, int>::pack(v.context(), buffer + nBytes);
if (v.valid())
{
@@ -154,7 +154,7 @@
int nBytes = Serialize<CHEETAH, bool>::unpack(pvalid, buffer);
- nBytes += Serialize<CHEETAH, int>::unpack(pcon, buffer);
+ nBytes += Serialize<CHEETAH, int>::unpack(pcon, buffer + nBytes);
if (*pvalid)
{
@@ -163,6 +163,9 @@
vp = new CollectionValue<T>(*pvalid, *pval, *pcon);
+ if (*pvalid)
+ Serialize<CHEETAH, T>::cleanup(pval);
+
return nBytes;
}
--- /dev/null Fri Mar 14 14:07:09 2003
+++ tests/CollectFromContextsTest.cpp Mon Dec 8 12:50:01 2003
@@ -0,0 +1,82 @@
+// -*- 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 pooma at acl.lanl.gov,
+// or visit the POOMA web page at http://www.acl.lanl.gov/pooma/.
+// ----------------------------------------------------------------------
+// ACL:license
+
+//-----------------------------------------------------------------------------
+// Test of PatchSizeSyncer
+//-----------------------------------------------------------------------------
+
+// Include files
+
+#include "Tulip/Messaging.h"
+#include "Tulip/CollectFromContexts.h"
+#include "Pooma/Pooma.h"
+#include "Utilities/Tester.h"
+
+
+int main(int argc, char *argv[])
+{
+ Pooma::initialize(argc, argv);
+ Pooma::Tester tester(argc, argv);
+
+ const int numContexts = Pooma::contexts();
+ const int myContext = Pooma::context();
+
+ tester.out() << "Running with " << numContexts << " contexts." << std::endl;
+
+ CollectFromContexts<int> ranks(2*(Pooma::context()+1));
+ if (Pooma::context() == 0) {
+ bool check = true;
+ for (int i=0; i<Pooma::contexts(); ++i)
+ if (ranks[i] != 2*(i+1)) {
+ tester.out() << "[" << i << "] should be "
+ << 2*(i+1) << ", but is " << ranks[i] << "\n";
+ check = false;
+ }
+ tester.check("Collecting ranks", check);
+ }
+
+ CollectFromContexts<int> ranks2(Pooma::context()+1, 0,
+ Pooma::context() > 0
+ && Pooma::context() < Pooma::contexts()-1);
+ if (Pooma::context() == 0) {
+ bool check = true;
+ for (int i=1; i<Pooma::contexts()-1; ++i)
+ if (ranks2[i] != i+1) {
+ tester.out() << "[" << i << "] should be "
+ << (i+1) << ", but is " << ranks[i] << "\n";
+ check = false;
+ }
+ tester.check("Collecting ranks, but not first and last", check);
+ }
+
+ int ret = tester.results("CollectFromContextsTest");
+ Pooma::finalize();
+
+ return ret;
+}
+
===== tests/makefile 1.3 vs edited =====
--- 1.3/r2/src/Tulip/tests/makefile Wed Jan 8 10:27:36 2003
+++ edited/tests/makefile Fri Dec 5 16:03:32 2003
@@ -36,7 +36,7 @@
TESTS = ReduceOverContextsTest GridMessageTest \
GridBroadcastTest PatchSizeSyncerTest \
- VectorBroadcastTest
+ VectorBroadcastTest CollectFromContextsTest
default:: build
More information about the pooma-dev
mailing list