Anasazi  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AnasaziOutputStreamTraits.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Anasazi: Block Eigensolvers Package
4 //
5 // Copyright 2004 NTESS and the Anasazi contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ANASAZI_OUTPUT_STREAM_TRAITS_HPP
11 #define ANASAZI_OUTPUT_STREAM_TRAITS_HPP
12 
17 #include "AnasaziConfigDefs.hpp"
18 #include "AnasaziTypes.hpp"
19 
20 #include "Teuchos_FancyOStream.hpp"
21 #include "Teuchos_RCP.hpp"
22 
23 #ifdef HAVE_MPI
24 #include <mpi.h>
25 #include "AnasaziGlobalComm.hpp"
26 #endif
27 
37 namespace Anasazi {
38 
39 template<class OperatorType>
41 
42  // The input argument, op, is presumed to be a valid object that can be queried to
43  // determine the correct output stream.
45  getOutputStream (const OperatorType& /* op */, int rootRank = 0)
46  {
47  Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
48 
49 #ifdef HAVE_MPI
50  // The default implementation will output on processor 0, if parallel.
51  int myRank = 0;
52  int numProcs = 1;
53  // Initialize MPI
54  int mpiStarted = 0;
55  MPI_Initialized(&mpiStarted);
56  if (mpiStarted)
57  {
58  MPI_Comm_rank(get_global_comm(), &myRank);
59  MPI_Comm_size(get_global_comm(), &numProcs);
60  }
61  fos->setProcRankAndSize(myRank, numProcs);
62  fos->setOutputToRootOnly(rootRank);
63 #endif
64 
65  return fos;
66  }
67 };
68 
69 
70 } // end Anasazi namespace
71 
72 #endif
73 
74 // end of file AnasaziOutputStreamTraits.hpp
basic_FancyOStream & setProcRankAndSize(const int procRank, const int numProcs)
Output managers remove the need for the eigensolver to know any information about the required output...
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Types and exceptions used within Anasazi solvers and interfaces.