Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
waterman_teuchoscomm.cpp
Go to the documentation of this file.
1 // Program demonstrating the Teuchos::Comm issues causing #3331.
2 // On waterman, this test passes if it skips the call to
3 // Teuchos::Comm::duplicate, but segfaults if Teuchos::Comm::duplicate
4 // is called.
5 #include <iostream>
6 #include <fstream>
7 #include <Teuchos_RCP.hpp>
9 #include <Teuchos_Comm.hpp>
10 #include <Teuchos_CommHelpers.hpp>
11 
12 void runTest(int ndoubles, Teuchos::RCP<const Teuchos::Comm<int> > &comm)
13 {
14  int me = comm->getRank();
15  int np = comm->getSize();
16 
17  double *sendBuf = new double[ndoubles];
18  for (int i = 0; i < ndoubles; i++) sendBuf[i] = 0.;
19  int nMy = ndoubles / np + (me < (ndoubles % np));
20  int myBegin = (ndoubles / np) * me;
21  myBegin += ((ndoubles % np) < me ? (ndoubles % np) : me);
22  int myEnd = myBegin + nMy;
23  for (int i = myBegin; i < myEnd; ++i) sendBuf[i] = me;
24 
25  double *recvBuf = new double[ndoubles];
26 
27  if (me == 0)
28  std::cout << "Trying reduceAll with ndoubles = " << ndoubles << std::endl;
29 
30  std::cout << *comm << std::endl;
31 
33  ndoubles, sendBuf, recvBuf);
34 
35  delete [] recvBuf;
36  delete [] sendBuf;
37 }
38 
39 
40 int main(int narg, char **arg)
41 {
42  Teuchos::GlobalMPISession mpiSession(&narg,&arg);
45 
46  int me = comm->getRank();
47 
48  if (narg != 2) {
49  if (me == 0)
50  std::cout << "Usage: a.out [Y|N] \n"
51  << " a.out Y ==> duplicate communicator \n"
52  << " a.out N ==> do not duplicate communicator \n"
53  << std::endl;
54  return -1;
55  }
56 
57  bool dupComm = (arg[1][0] == 'Y' ? true : false);
58 
59  if (dupComm)
60  Teuchos::RCP<const Teuchos::Comm<int> > commdup = comm->duplicate();
61 
62  runTest(512, comm);
63 
64  if (me == 0)
65  std::cout << "PASSED with "
66  << (dupComm ? "comm duplication " : "no comm duplication ")
67  << std::endl;
68  return 0;
69 }
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
Initialize, finalize, and query the global MPI session.
void runTest(int ndoubles, MPI_Comm &comm)
Definition: waterman_mpi.cpp:7
void reduceAll< int, double >(const Comm< int > &comm, const EReductionType reductType, const int count, const double sendBuffer[], double globalReducts[])
int main(int argc, char *argv[])
Abstract interface for distributed-memory communication.
Smart reference counting pointer class for automatic garbage collection.
Reference-counted pointer class and non-member templated function implementations.