Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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>
11
12void 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
40int 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}
Reference-counted pointer class and non-member templated function implementations.
Abstract interface for distributed-memory communication.
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
Initialize, finalize, and query the global MPI session.
Smart reference counting pointer class for automatic garbage collection.
int main()
Definition: evilMain.cpp:75
void reduceAll< int, double >(const Comm< int > &comm, const EReductionType reductType, const int count, const double sendBuffer[], double globalReducts[])
void runTest(int ndoubles, Teuchos::RCP< const Teuchos::Comm< int > > &comm)