⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paws_test7.cpp

📁 强大的并行科学计算软件包
💻 CPP
字号:
// -*- 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, and to allow others to do so.
// The public may copy and use this SOFTWARE, FOR NONCOMMERCIAL USE ONLY,
// 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@acl.lanl.gov,
// or visit the POOMA web page at http://www.acl.lanl.gov/pooma/.
// ----------------------------------------------------------------------
// ACL:license
//-----------------------------------------------------------------------------
// Paws test 7: Send and Receive an int and double set of scalars,
//              plus a dynamic array, in conjunction with test 8.
//-----------------------------------------------------------------------------

#include "Pooma/Pooma.h"
#include "Pooma/Paws.h"
#include "Pooma/DynamicArrays.h"
#include "Pooma/Domains.h"
#include "Utilities/Tester.h"


int main(int argc, char *argv[])
{
  // Initialize POOMA and output stream, using Tester class

  Pooma::initialize(argc, argv);
  Pooma::Tester tester(argc, argv);
  tester.out() << argv[0] << ": Paws DynmaicArray send/receive test A\n";
  tester.out() << "----------------------------------------------------";
  tester.out() << std::endl;

  // Some scalars to send and receive

  int s1 = 1, origs1 = 1;
  double s2 = 2.5, origs2 = 2.5;
  int iters = 10;

  // DynamicArrays to send and receive ...

  GridLayout<1> layout(Interval<1>(100), Loc<1>(4));
  DynamicArray<float, MultiPatch<GridTag,Brick> > a1(layout);
  DynamicArray<int, MultiPatch<GridTag,Brick> > a2(layout);
  DynamicArray<double, Brick> a3(30);

  // Initialize the arrays

  a1 = 1 + iota(a1.domain()).comp(0);
  a2 = 1000 + a1;
  a3 = 4.5;
  Pooma::blockAndEvaluate();

  // Create a Paws connection

  tester.out() << "Creating PawsConnection object ..." << std::endl;
  Connection<Paws> *paws = new Connection<Paws>("test7", argc, argv);
  tester.out() << "Finished creating PawsConnection object." << std::endl;

  // Establish connections for the two scalars

  tester.out() << "Connecting s1 = " << s1 << " for output ..." << std::endl;
  ConnectorBase *s1p = paws->connectScalar("s1", s1, ConnectionBase::out);
  tester.out() << "Connecting s2 = " << s2 << " for input ..." << std::endl;
  ConnectorBase *s2p = paws->connectScalar("s2", s2, ConnectionBase::in);
  tester.out() << "Connecting iters = " << iters << " for output ...";
  tester.out() << std::endl;
  ConnectorBase *iterp=paws->connectScalar("iters",iters,ConnectionBase::out);

  // Establish connections for the arrays

  tester.out() << "Connecting a1 = " << a1 << " for output ..." << std::endl;
  paws->connect("a1", a1, ConnectionBase::out);
  tester.out() << "Connecting a2 = " << a2 << " for output ..." << std::endl;
  paws->connect("a2", a2, ConnectionBase::out);
  tester.out() << "Connecting a3 = " << a3 << " for output ..." << std::endl;
  paws->connect("a3", a3, ConnectionBase::out);

  // Wait for everything to be ready to proceed

  tester.out() << "Waiting for ready signal ..." << std::endl;
  paws->ready();
  tester.out() << "Ready complete, moving on." << std::endl;

  // Modify s2, and update

  s2 *= 2;
  tester.out() << "Updating current s1 = " << s1 << " and s2 = " << s2;
  tester.out() << ", plus arrays ..." << std::endl;
  paws->update();

  // Report the results

  tester.out() << "Received update.  New values:" << std::endl;
  tester.out() << "  s1 = " << s1 << " (should be " << origs1 << ")\n";
  tester.out() << "  s2 = " << s2 << " (should be " << origs2 << ")\n";
  tester.out() << std::endl;
  tester.check("s1 OK", s1 == origs1);
  tester.check("s2 OK", s2 == origs2);

  // Disconnect the scalars

  int connections = paws->size();
  tester.out() << "Disconnecting scalars ..." << std::endl;
  delete s1p;
  delete s2p;
  delete iterp;
  tester.check("3 less connections", paws->size() == (connections - 3));

  // Do, in a loop, updates of the receiver. Add one to the arrays each time,
  // plus delete the second element.

  int myiters = iters;
  while (myiters-- > 0)
    {
      a1 += 1;
      a2 += 1;
      a3 += 1;
      Pooma::blockAndEvaluate();
      a1.destroy(Interval<1>(1,1), ShiftUp());
      a1.sync();

      tester.out() << "Sending for iters = " << myiters << std::endl;
      paws->update();
    }

  // Delete PAWS connection, disconnecting us from the other code.

  tester.out() << "Deleting Connection<Paws> object ..." << std::endl;
  delete paws;

  // Finish up and report results

  tester.out() << "-------------------------------------------" << std::endl;
  int retval = tester.results("Paws DynamicArray send/receive test A");
  Pooma::finalize();
  return retval;
}

// ACL:rcsinfo
// ----------------------------------------------------------------------
// $RCSfile: paws_test7.cpp,v $   $Author: bfh $
// $Revision: 1.2 $   $Date: 1999/10/27 22:33:34 $
// ----------------------------------------------------------------------
// ACL:rcsinfo

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -