OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimMpi.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //*************************************************************************
9 // $Id: ossimMpi.cpp 23002 2014-11-24 17:11:17Z dburken $
10 
12 #include <ossim/base/ossimTrace.h>
14 #include <time.h>
15 #if OSSIM_HAS_MPI
16 # include <mpi.h>
17 #endif
18 
19 #if OSSIM_ID_ENABLED
20 static const char OSSIM_ID[] = "$Id: ossimMpi.cpp 23002 2014-11-24 17:11:17Z dburken $";
21 #endif
22 
23 static ossimTrace traceDebug = ossimTrace("ossimMpi:debug");
24 
26 
28 {
29  if(!theInstance)
30  {
31  theInstance = new ossimMpi;
32  }
33 
34  return theInstance;
35 }
36 
38 {
39  return theEnabledFlag;
40 }
41 
43 {
44 #if OSSIM_HAS_MPI
45  if(theEnabledFlag)
46  {
47  // Blocks until all processes have reached this routine.
48  MPI_Barrier( MPI_COMM_WORLD );
49  }
50 #endif
51 }
52 
54 {
55 #if OSSIM_HAS_MPI
56  if(theEnabledFlag)
57  {
58  return MPI_Wtime();
59  }
60  else
61  {
62  return time(0);
63  }
64 #else
65  return time(0);
66 #endif
67 }
68 
69 #if OSSIM_HAS_MPI
70 void ossimMpi::initialize(int* argc, char*** argv)
71 {
72  int success=0;
73  success = MPI_Init(argc, argv);
74  if(success == MPI_SUCCESS)
75  {
76  theEnabledFlag = true;
77  if(traceDebug())
78  {
80  << "DEBUG ossimMpi::initialize\n"
81  << "MPI is initialized and running with "
83  << " processors..."
84  << std::endl;
85  }
86  }
87  else
88  {
89  theEnabledFlag = false;
90  if(traceDebug())
91  {
93  << "DEBUG ossimMpi::initialize: MPI is not initialized."
94  << std::endl;
95  }
96  }
97 }
98 #else
99 void ossimMpi::initialize(int* /* argc */, char*** /* argv */)
100 {
101  if(traceDebug())
102  {
104  << "DEBUG ossimMpi::initialize: Not compiled with mpi!"
105  << std::endl;
106  }
107 }
108 #endif
109 
111 {
112  theEnabledFlag = flag;
113 }
114 
116 {
117 #if OSSIM_HAS_MPI
118  if(theEnabledFlag)
119  {
120  int success;
121  success = MPI_Finalize();
122  if(traceDebug())
123  {
124  if(success == MPI_SUCCESS)
125  {
127  << "DEBUG ossimMpi::finalize(): mpi is finalized" << std::endl;
128  }
129  else
130  {
132  << "DEBUG ossimMpi::finalize(): "
133  << "mpi is not finalized successfully" << std::endl;
134  }
135  }
136  }
137 #endif
138 }
139 
141 {
142  int result = 0;
143 
144 #if OSSIM_HAS_MPI
145  if(theEnabledFlag)
146  {
147  MPI_Comm_rank(MPI_COMM_WORLD, &result);
148  }
149 #endif
150 
151  return result;
152 }
153 
155 {
156  int result = 1;
157 
158 #if OSSIM_HAS_MPI
159  if(theEnabledFlag)
160  {
161  MPI_Comm_size(MPI_COMM_WORLD, &result);
162  }
163 #endif
164 
165  return result;
166 }
167 
169  : theEnabledFlag(false)
170 {
171  if(traceDebug())
172  {
174  << "ossimMpi::ossimMpi entered..."
175  << std::endl;
176 #ifdef OSSIM_ID_ENABLED
178  << "OSSIM_ID = " << OSSIM_ID << std::endl;
179 #endif
180  }
181 }
182 
184  : theEnabledFlag(obj.theEnabledFlag)
185 {}
186 
188 {
190 }
void barrier()
MPI Barrier method.
Definition: ossimMpi.cpp:42
void operator=(const ossimMpi &)
Definition: ossimMpi.cpp:187
double ossim_float64
bool isEnabled() const
Definition: ossimMpi.cpp:37
bool theEnabledFlag
Definition: ossimMpi.h:57
int getNumberOfProcessors() const
Definition: ossimMpi.cpp:154
ossim_float64 getTime() const
Definition: ossimMpi.cpp:53
int getRank() const
Definition: ossimMpi.cpp:140
static ossimMpi * theInstance
Definition: ossimMpi.h:56
void finalize()
Definition: ossimMpi.cpp:115
void initialize(int *argc, char ***argv)
Definition: ossimMpi.cpp:99
static ossimMpi * instance()
Definition: ossimMpi.cpp:27
void setEnabledFlag(bool flag)
Definition: ossimMpi.cpp:110
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)