OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimMpiSlaveOverviewSequencer.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: David Burken
6 //
7 // Description: Class definition for mpi slave sequencer for building
8 // overview files.
9 //
10 //----------------------------------------------------------------------------
11 // $Id: ossimMpiSlaveOverviewSequencer.cpp 17870 2010-08-12 13:12:32Z sbortman $
12 
14 #include <ossim/ossimConfig.h> /* To pick up OSSIM_HAS_MPI. */
15 #include <ossim/base/ossimCommon.h> /* For get byte order. */
16 #include <ossim/base/ossimEndian.h>
17 #include <ossim/base/ossimRefPtr.h>
19 
20 
21 
22 #if OSSIM_HAS_MPI
23 # include <mpi.h>
24 #endif
25 
27  :
29  m_rank(0),
30  m_numberOfProcessors(1)
31 {
32 #if OSSIM_HAS_MPI
33  MPI_Comm_rank(MPI_COMM_WORLD, &m_rank);
34  MPI_Comm_size(MPI_COMM_WORLD, &m_numberOfProcessors);
35 #endif
36 
37  if( m_rank != 0 )
38  {
39  //---
40  // Master process (rank 0) does not resample tiles so our process rank
41  // is 1 then we'll start at tile 0, rank 2 starts at 1, rank 3 starts
42  // at 2 and so on...
43  //---
45  }
46  else
47  {
49  }
50 }
51 
53 {
54 }
55 
57 {
58  return false;
59 }
60 
62 {
64 
66 }
67 
69 {
70  if(m_rank != 0)
71  {
72  //---
73  // Subtract one since the masters job is just writing and not issue
74  // getTiles.
75  //---
77  }
78  else
79  {
80  // the master will start at 0
82  }
83 }
84 
86 {
87 #if OSSIM_HAS_MPI
88 
89  //---
90  // Bytes must be swapped to big endian (network byte order) if the scalar
91  // type is not 8 bit and the system byte order is little endian. We will
92  // use the endian pointer itself as a flag to swap.
93  //---
94  ossimEndian* endian = 0;
95  if (m_imageHandler.valid())
96  {
98  {
100  {
101  endian = new ossimEndian();
102  }
103  }
104  }
105 
106  // Total number of tiles for all processes.
107  ossim_uint32 numberOfTiles = getNumberOfTiles();
108 
109  int errorValue; // Needed for MPI_Isend and MPI_Wait.
110  MPI_Request request; // Needed for MPI_Isend and MPI_Wait.
111 
112  while(m_currentTileNumber < numberOfTiles)
113  {
115 
116  void* buf = data->getBuf();
117 
118  // Data always sent in big endian byte order.
119  if (endian)
120  {
121  endian->swap(m_tile->getScalarType(), buf, m_tile->getSize());
122  }
123 
124  // Send the buffer to the master process.
125  request = MPI_REQUEST_NULL;
126  errorValue = MPI_Isend(buf,
127  data->getSizeInBytes(),
128  MPI_UNSIGNED_CHAR,
129  0,
130  0,
131  MPI_COMM_WORLD,
132  &request);
133 
134  //---
135  // Wait for send to complete before we overwrite the buffer with the
136  // next tile.
137  //---
138  errorValue = MPI_Wait(&request, MPI_STATUS_IGNORE);
139 
140  //---
141  // If we have eight processes only seven are used for resampling tiles,
142  // so we would process every seventh tile.
143  //
144  // The call to getNextTile has already incremented m_currentTileNumber
145  // by one so adjust accordingly.
146  //---
147  if (m_numberOfProcessors>2)
148  {
150  }
151 
152  } // End of while loop through number of tiles.
153 
154  // cleanup...
155  if (endian)
156  {
157  delete endian;
158  endian = 0;
159  }
160 
161 #endif /* End of #if OSSIM_HAS_MPI */
162 
163 }
bool valid() const
Definition: ossimRefPtr.h:75
ossimRefPtr< ossimImageData > m_tile
ossimRefPtr< ossimImageHandler > m_imageHandler
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
ossim_uint32 getNumberOfTiles() const
virtual void initialize()
This must be called.
virtual ossim_uint32 getSizeInBytes() const
Returns the total number of bytes for all bands.
unsigned int ossim_uint32
virtual void slaveProcessTiles()
This is a trigger to start resampling tiles.
virtual ossimRefPtr< ossimImageData > getNextTile()
Will allow you to get the next tile in the sequence.
virtual ossimScalarType getScalarType() const
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual ~ossimMpiSlaveOverviewSequencer()
virtual destructor
virtual ossim_uint32 getSize() const
Returns the total number of pixels in a tile for all bands.
virtual const void * getBuf() const
8 bit unsigned integer
virtual void setToStartOfSequence()
Will set the internal pointers to the upperleft tile number.
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
virtual void initialize()
This must be called.