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