OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimMpiMasterOverviewSequencer.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 master sequencer for building
8 // overview files.
9 //
10 //----------------------------------------------------------------------------
11 // $Id: ossimMpiMasterOverviewSequencer.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/ossimEndian.h>
16 
17 #if OSSIM_HAS_MPI
18 # include <mpi.h>
19 #endif
20 
22  :
24  m_rank(0),
25  m_numberOfProcessors(1)
26 {
27 #if OSSIM_HAS_MPI
28  MPI_Comm_rank(MPI_COMM_WORLD, &m_rank);
29  MPI_Comm_size(MPI_COMM_WORLD, &m_numberOfProcessors);
30 #endif
31 
32  //---
33  // Since this is the master sequencer it should always be rank 0; else,
34  // we have a coding error. Since we have the getNextTile implemented to
35  // recieve from the slave processes we always start the tile count at 0.
36  //---
38 }
39 
41 {
42 }
43 
45 {
47 }
48 
50 {
52 }
53 
55 {
56  if ( m_dirtyFlag )
57  {
58  //---
59  // If this happens we have a coding error. Someone started sequencing
60  // without initializing us properly.
61  //---
63  }
64 
65 #if OSSIM_HAS_MPI
66 
67  //---
68  // Using mpi. The slaves will send us tiles to be returned by this method.
69  // They will alway be sent in big endian (network byte order) so we must
70  // swap back if the scalar type is not 8 bit and the system byte order is
71  // little endian. We will use the endian pointer itself as a flag to swap.
72  //---
73  ossimEndian* endian = 0;
74  if (m_imageHandler.valid())
75  {
77  {
79  {
80  endian = new ossimEndian();
81  }
82  }
83  }
84 
85  int errorValue;
86 
87  // Buffer to receive the data from slaves.
88  void* buf = m_tile->getBuf();
89 
90  // Total number of tiles to process...
91  ossim_uint32 numberOfTiles = getNumberOfTiles();
92 
93  if(m_currentTileNumber >= numberOfTiles)
94  {
96  }
97 
98  errorValue = MPI_Recv(buf,
100  MPI_UNSIGNED_CHAR,
102  0,
103  MPI_COMM_WORLD,
104  MPI_STATUS_IGNORE);
105 
106  // Data always sent in big endian order.
107  if ( endian )
108  {
109  endian->swap(m_tile->getScalarType(), buf, m_tile->getSize());
110  }
111 
112  // Get the output rectangle.
113  ossimIrect outputRect;
114  getOutputTileRectangle(outputRect);
115 
116  // Capture the output rectangle.
117  m_tile->setImageRectangle(outputRect);
118 
119  // Set the tile status.
120  m_tile->validate();
121 
122  // Increment the tile index.
124 
125  // cleanup...
126  if ( endian )
127  {
128  delete endian;
129  endian = 0;
130  }
131 
132  return m_tile;
133 
134 #else
135 
136  // Not compiled with mpi.
138 
139 #endif /* End of #if OSSIM_HAS_MPI */
140 
141 }
virtual void setImageRectangle(const ossimIrect &rect)
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
bool m_dirtyFlag
Dirty flag - if true, this object is not initialized.
virtual ossim_uint32 getSizeInBytes() const
Returns the total number of bytes for all bands.
virtual ossimDataObjectStatus validate() const
unsigned int ossim_uint32
virtual ~ossimMpiMasterOverviewSequencer()
virtual destructor
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 ossim_uint32 getSize() const
Returns the total number of pixels in a tile for all bands.
virtual const void * getBuf() const
virtual ossimRefPtr< ossimImageData > getNextTile()
Will allow you to get the next tile in the sequence.
virtual void setToStartOfSequence()
Will set the internal pointers to the upperleft tile number.
virtual void initialize()
This must be called.
8 bit unsigned integer
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
void getOutputTileRectangle(ossimIrect &outputRect) const
Gets the image rectangle for the output tile for theCurrentTileNumber.
virtual void initialize()
This must be called.