Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
teuchosCommTest.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // Test to evaluate the performance of Teuchos::Comm's reduceAll versus
11 // direct MPI invocation of MPI_Allreduce for common data types int, double.
12 
13 #include <mpi.h>
14 #include "Teuchos_CommHelpers.hpp"
15 #include "Teuchos_DefaultComm.hpp"
16 #include "Teuchos_RCP.hpp"
17 
18 
19 int main(int narg, char **arg)
20 {
21  Teuchos::GlobalMPISession mpiSession(&narg,&arg);
22 
23  Teuchos::RCP<const Teuchos::Comm<int> >
24  comm = Teuchos::DefaultComm<int>::getComm();
25  int me = comm->getRank();
26 
27  if (me == 0)
28  std::cout << std::endl
29  << "Usage: Zoltan2_teuchosCommTest.exe [#_of_allreduces_to_do]"
30  << std::endl
31  << " default number is 4000"
32  << std::endl
33  << std::endl;
34 
35  int niter = 4000;
36  if (narg > 1) niter = atoi(arg[1]);
37 
38  double tstart, tend;
39 
40  int iin = me, iout;
41  double din = me * 2., dout;
42 
43  tstart = MPI_Wtime();
44  for (int i = 0; i < niter; i++) {
45  reduceAll(*comm, Teuchos::REDUCE_SUM, 1, &iin, &iout);
46  reduceAll(*comm, Teuchos::REDUCE_SUM, 1, &din, &dout);
47  }
48  tend = MPI_Wtime();
49  if (me == 0)
50  std::cout << "reduceAll time using Teuchos::Comm = "
51  << tend - tstart << std::endl;
52 
53  tstart = MPI_Wtime();
54  for (int i = 0; i < niter; i++) {
55  MPI_Allreduce(&iin, &iout, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
56  MPI_Allreduce(&din, &dout, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
57  }
58  tend = MPI_Wtime();
59  if (me == 0)
60  std::cout << "Allreduce time using MPI_Allreduce = "
61  << tend - tstart << std::endl;
62 
63  if (me == 0)
64  std::cout << std::endl << "PASS" << std::endl;
65 
66  return 0;
67 }
int main(int narg, char **arg)
Definition: coloring1.cpp:164