Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
comm
test
Comm
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
>
8
#include <
Teuchos_DefaultComm.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
32
Teuchos::reduceAll<int, double>
(*comm,
Teuchos::REDUCE_SUM
,
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);
43
Teuchos::RCP<const Teuchos::Comm<int>
>
44
comm =
Teuchos::DefaultComm<int>::getComm
();
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
}
Teuchos_CommHelpers.hpp
Teuchos_Comm.hpp
Teuchos_DefaultComm.hpp
Teuchos_RCP.hpp
Reference-counted pointer class and non-member templated function implementations.
Teuchos::Comm
Abstract interface for distributed-memory communication.
Definition
Teuchos_Comm.hpp:314
Teuchos::DefaultComm::getComm
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
Definition
Teuchos_DefaultComm.hpp:212
Teuchos::GlobalMPISession
Initialize, finalize, and query the global MPI session.
Definition
Teuchos_GlobalMPISession.hpp:114
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
main
int main()
Definition
evilMain.cpp:75
Teuchos::reduceAll< int, double >
void reduceAll< int, double >(const Comm< int > &comm, const EReductionType reductType, const int count, const double sendBuffer[], double globalReducts[])
Definition
Teuchos_CommHelpers.cpp:980
Teuchos::REDUCE_SUM
@ REDUCE_SUM
Sum.
Definition
Teuchos_EReductionType.hpp:72
runTest
void runTest(int ndoubles, Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Definition
waterman_teuchoscomm.cpp:12
Generated by
1.17.0