communicatorenvironment.cc 1.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/*
 * @file:   communicatorenvironment.cc
 * @author: Jordan P. Lefebvre, lefebvrejp@ornl.gov
 *
 * Created on August 30, 2013, 12:41 PM
 */

#include "communicatorenvironment.hh"
#ifdef USE_MPI
#include <mpi.h>
#endif

13
namespace radix {
14

15
namespace Private {
16
#ifdef USE_MPI
17
18
MPIEnvironment::MPIEnvironment(int &argc, char **&argv)
    : owner(false) {
19
20
21
22
23
24
25
26
27
28
  if (initialized() == false) {
    owner = true;
    MPI_Init(&argc, &argv);
  }
}  // MPIEnironment::MPIEnvironment

MPIEnvironment::~MPIEnvironment() {
  if (finalized() == false && owner) {
    MPI_Finalize();
  }
29
}
30

31
32
void MPIEnvironment::abort(int error_code) {
  MPI_Abort(MPI_COMM_WORLD, error_code);
33
}
34

35
36
37
38
39
40
41
42
43
44
45
bool MPIEnvironment::initialized() {
  int flag = 0;
  MPI_Initialized(&flag);
  return (flag != 0);
}  // initialized

bool MPIEnvironment::finalized() {
  int flag = 0;
  MPI_Finalized(&flag);
  return (flag != 0);
}  // finalized
46
47
#else

48
49
50
SerialEnvironment::SerialEnvironment(int &argc, char **&argv) {
  //            printf("Serial initialized\n");
}  // SerialEnironment::SerialEnvironment
51

52
SerialEnvironment::~SerialEnvironment() {}
53

54
void SerialEnvironment::abort(int error_code) {}
55

56
bool SerialEnvironment::initialized() { return false; }  // initialized
57

58
bool SerialEnvironment::finalized() { return false; }  // finalized
59
#endif
60
}  // namespace Private
61

62
}  // namespace radix