OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageMpiMWriterSequenceConnection.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //
7 // Description:
8 //
9 // This class is specific to the Master connection and is optimized
10 // for the writer sequence and batch processing chain. For the Slave
11 // implementation look for the ossimImageMpiSWriterSequenceConnection.cc and .h
12 // files. The Master connection is currently implemented to allways do
13 // a recieve and does no processing itself. The slave connection does
14 // all the actual work and processing.
15 //
16 //*******************************************************************
17 // $Id: ossimImageMpiMWriterSequenceConnection.cpp 12099 2007-12-01 16:09:36Z dburken $
18 
19 
20 #include <ossim/ossimConfig.h> /* To pick up OSSIM_HAS_MPI. */
21 
22 #ifdef OSSIM_HAS_MPI
23 # if OSSIM_HAS_MPI
24 # include <mpi.h>
25 # endif
26 #endif
27 
32 #include <ossim/base/ossimTrace.h>
33 #include <ossim/base/ossimEndian.h>
34 
35 static ossimTrace traceDebug = ossimTrace("ossimImageMpiMWriterSequenceConnection:debug");
36 
37 RTTI_DEF1(ossimImageMpiMWriterSequenceConnection, "ossimImageMpiMWriterSequenceConnection", ossimImageSourceSequencer)
38 
39 
41  ossimImageSource* inputSource,
42  ossimObject* owner)
43  :ossimImageSourceSequencer(inputSource, owner),
44  theOutputTile(NULL)
45 {
46  theRank = 0;
47  theNumberOfProcessors = 1;
48 
49 #ifdef OSSIM_HAS_MPI
50 # if OSSIM_HAS_MPI
51  MPI_Comm_rank(MPI_COMM_WORLD, &theRank);
52  MPI_Comm_size(MPI_COMM_WORLD, &theNumberOfProcessors);
53 # endif
54 #endif
55 
56  if(theRank!=0)
57  {
58  theCurrentTileNumber = theRank -1;
59  }
60  else
61  {
62  theCurrentTileNumber = 0;
63  }
64  theNeedToSendRequest = true;
65 }
66 
68  :ossimImageSourceSequencer(NULL, owner),
69  theOutputTile(NULL)
70 {
71  theRank = 0;
73 
74 #ifdef OSSIM_HAS_MPI
75 # if OSSIM_HAS_MPI
76  MPI_Comm_rank(MPI_COMM_WORLD, &theRank);
77  MPI_Comm_size(MPI_COMM_WORLD, &theNumberOfProcessors);
78 # endif
79 #endif
80 
81  if(theRank!=0)
82  {
84  }
85  else
86  {
88  }
89  theNeedToSendRequest = true;
90 }
91 
93 {
94 }
95 
97 {
99 
101  theOutputTile = NULL;
102 
104  {
107  }
108 }
109 
111 {
113  if(theRank != 0)
114  {
115  // we will subtract one since the masters job is just
116  // writting and not issue getTiles.
118 
119  }
120  else
121  {
122  // the master will start at 0
124  }
125 }
126 
131 {
132 #if OSSIM_HAS_MPI
133  ossimEndian endian;
134  if(!theOutputTile)
135  {
136  initialize();
137  if (!theOutputTile)
138  {
139  return theOutputTile;
140  }
141  }
142 
143  void* buf = theOutputTile->getBuf();
144 
145  ossim_uint32 numberOfTiles = getNumberOfTiles();
146  int errorValue = 0;
147 
148  if(theCurrentTileNumber >= numberOfTiles)
149  {
150  return NULL;
151  }
152  errorValue = MPI_Recv(buf,
154  MPI_UNSIGNED_CHAR,
156  0,
157  MPI_COMM_WORLD,
158  MPI_STATUS_IGNORE);
159  if((endian.getSystemEndianType()!=OSSIM_BIG_ENDIAN)&&
161  {
162  endian.swap(theOutputTile->getScalarType(),
163  buf,
165  }
166 
167 #if 0
168  // Since MPI can run on different platforms
169  // I am not sure if MPI has built in byte
170  // swap. If so I will name each datatype
171  // so it can handle byte swap. Does anyone
172  // know if MPI does byte swapping.
173  switch(theOutputTile->getScalarType())
174  {
175  case OSSIM_UINT8:
176  {
177  // we add 1 to the rank so we don't wait on a message
178  // to ourself (rank = 0).
179  errorValue = MPI_Recv(buf,
181  MPI_UNSIGNED_CHAR,
183  0,
184  MPI_COMM_WORLD,
185  MPI_STATUS_IGNORE);
186  break;
187  }
188  case OSSIM_SINT8:
189  {
190  // we add 1 to the rank so we don't wait on a message
191  // to ourself (rank = 0).
192  errorValue = MPI_Recv(buf,
194  MPI_CHAR,
196  0,
197  MPI_COMM_WORLD,
198  MPI_STATUS_IGNORE);
199  break;
200  }
201  case OSSIM_UINT16:
202  case OSSIM_USHORT11:
203  case OSSIM_USHORT12:
204  case OSSIM_USHORT13:
205  case OSSIM_USHORT14:
206  case OSSIM_USHORT15:
207  {
208  errorValue = MPI_Recv(buf,
210  MPI_UNSIGNED_SHORT,
212  0,
213  MPI_COMM_WORLD,
214  MPI_STATUS_IGNORE);
215  break;
216  }
217  case OSSIM_SINT16:
218  {
219  errorValue = MPI_Recv(buf,
221  MPI_SHORT,
223  0,
224  MPI_COMM_WORLD,
225  MPI_STATUS_IGNORE);
226  break;
227  }
228  case OSSIM_SINT32:
229  {
230  errorValue = MPI_Recv(buf,
232  MPI_LONG,
234  0,
235  MPI_COMM_WORLD,
236  MPI_STATUS_IGNORE);
237  break;
238  }
239  case OSSIM_UINT32:
240  {
241  errorValue = MPI_Recv(buf,
243  MPI_UNSIGNED_LONG,
245  0,
246  MPI_COMM_WORLD,
247  MPI_STATUS_IGNORE);
248  break;
249  }
250  case OSSIM_FLOAT32:
252  {
253  errorValue = MPI_Recv(buf,
255  MPI_FLOAT,
257  0,
258  MPI_COMM_WORLD,
259  MPI_STATUS_IGNORE);
260  break;
261  }
262  case OSSIM_FLOAT64:
264  {
265  errorValue = MPI_Recv(buf,
267  MPI_DOUBLE,
269  0,
270  MPI_COMM_WORLD,
271  MPI_STATUS_IGNORE);
272  break;
273  }
274  default:
275  {
276  break;
277  }
278  }
279 #endif
280  ossimIpt origin;
282  origin);
283  theOutputTile->setOrigin(origin);
286  return theOutputTile;
287 #else
289 #endif
290 
291 }
16 bit unsigned integer (15 bits used)
8 bit signed integer
64 bit floating point
16 bit unsigned integer
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
16 bit signed integer
16 bit unsigned integer (14 bits used)
16 bit unsigned integer (13 bits used)
32 bit floating point
32 bit unsigned integer
virtual void initialize()
Initialize the data buffer.
static ossimImageDataFactory * instance()
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
virtual ossim_uint32 getSizeInBytes() const
Returns the total number of bytes for all bands.
virtual ossimDataObjectStatus validate() const
virtual bool getTileOrigin(ossim_int64 id, ossimIpt &origin) const
32 bit signed integer
unsigned int ossim_uint32
32 bit normalized floating point
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossimByteOrder getSystemEndianType() const
Definition: ossimEndian.h:78
virtual void setOrigin(const ossimIpt &origin)
virtual ossimScalarType getScalarType() const
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
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
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
16 bit unsigned integer (12 bits used)