Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_mpiIsInitialized.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Tpetra_Details_mpiIsInitialized.hpp"
11 #ifdef HAVE_TPETRACORE_MPI
12 #include "mpi.h"
13 #include <iostream>
14 #endif // HAVE_TPETRACORE_MPI
15 
16 namespace Tpetra {
17 namespace Details {
18 
20 #ifdef HAVE_TPETRACORE_MPI
21  int isInitialized = 0;
22  const int errCode = MPI_Initialized(&isInitialized);
23  // If the call failed, then assume MPI wasn't implemented
24  // correctly and return false.
25  return errCode == MPI_SUCCESS && (isInitialized != 0);
26 #else
27  return false; // Tpetra was not built with MPI support
28 #endif // HAVE_TPETRACORE_MPI
29 }
30 
32 #ifdef HAVE_TPETRACORE_MPI
33  int isFinalized = 0;
34  const int errCode = MPI_Finalized(&isFinalized);
35  // If the call failed, then assume MPI wasn't implemented
36  // correctly and return false.
37  return errCode == MPI_SUCCESS && (isFinalized != 0);
38 #else
39  return false; // Tpetra was not built with MPI support
40 #endif // HAVE_TPETRACORE_MPI
41 }
42 
43 } // namespace Details
44 } // namespace Tpetra
bool isInitialized()
Whether Tpetra is in an initialized state.
bool mpiIsFinalized()
Has MPI_Finalize been called (on this process)?
bool mpiIsInitialized()
Has MPI_Init been called (on this process)?