OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageMpiSWriterSequenceConnection.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 // License: See top level LICENSE.txt file.
3 //
4 // Author: Garrett Potts
5 //
6 // $Id: ossimImageMpiSWriterSequenceConnection.cpp 17206 2010-04-25 23:20:40Z dburken $
7 //----------------------------------------------------------------------------
8 
9 #include <ossim/ossimConfig.h> /* To pick up OSSIM_HAS_MPI. */
10 
11 #ifdef OSSIM_HAS_MPI
12 # if OSSIM_HAS_MPI
13 # include <mpi.h>
14 # endif
15 #endif
16 
21 #include <ossim/base/ossimTrace.h>
22 #include <ossim/base/ossimEndian.h>
24 
25 static ossimTrace traceDebug = ossimTrace("ossimImageMpiSWriterSequenceConnection:debug");
26 
27 RTTI_DEF1(ossimImageMpiSWriterSequenceConnection, "ossimImageMpiSWriterSequenceConnection", ossimImageSourceSequencer)
28 
30  long numberOfTilesToBuffer)
32  owner),
33  theNumberOfTilesToBuffer(numberOfTilesToBuffer),
34  theOutputTile(NULL)
35 {
36  theRank = 0;
37  theNumberOfProcessors = 1;
38  theNumberOfTilesToBuffer = ((theNumberOfTilesToBuffer>0)?theNumberOfTilesToBuffer:2);
39 
40 #ifdef OSSIM_HAS_MPI
41 # if OSSIM_HAS_MPI
42  MPI_Comm_rank(MPI_COMM_WORLD, &theRank);
43  MPI_Comm_size(MPI_COMM_WORLD, &theNumberOfProcessors);
44 # endif
45 #endif
46 
47  if(theRank!=0)
48  {
49  theCurrentTileNumber = theRank -1;
50  }
51  else
52  {
53  theCurrentTileNumber = 0;
54  }
55 }
56 
58  ossimObject* owner,
59  long numberOfTilesToBuffer)
60  :ossimImageSourceSequencer(inputSource,
61  owner),
62  theNumberOfTilesToBuffer(numberOfTilesToBuffer),
63  theOutputTile(NULL)
64 {
65  theRank = 0;
68 #if OSSIM_HAS_MPI
69  MPI_Comm_rank(MPI_COMM_WORLD, &theRank);
70  MPI_Comm_size(MPI_COMM_WORLD, &theNumberOfProcessors);
71 #endif
72  if(theRank!=0)
73  {
75  }
76  else
77  {
79  }
80 }
81 
83 {
85 }
86 
88 {
89  if(theOutputTile)
90  {
91  delete [] theOutputTile;
92  theOutputTile = NULL;
93  }
94 }
95 
97 {
99 
101  if(theOutputTile)
102  {
104  }
105 
107  {
109 
110  for(long index = 0; index < theNumberOfTilesToBuffer; ++index)
111  {
113  this);
114  theOutputTile[index]->initialize();
115  }
116  }
117 }
118 
120 {
122  if(theRank != 0)
123  {
124  // we will subtract one since the masters job is just
125  // writting and not issue getTiles.
127 
128  }
129  else
130  {
131  // the master will start at 0
133  }
134 }
135 
137 {
138 #ifdef OSSIM_HAS_MPI
139 # if OSSIM_HAS_MPI
140  ossimEndian endian;
141  ossim_uint32 numberOfTiles = getNumberOfTiles();
142  long currentSendRequest = 0;
143  //long numberOfTilesSent = 0;
144  int errorValue= 0;
145  MPI_Request *requests = new MPI_Request[theNumberOfTilesToBuffer];
146  for (int i = 0; i < theNumberOfTilesToBuffer; ++i)
147  {
148  requests[i] = MPI_REQUEST_NULL;
149  }
150 
151  if(traceDebug())
152  {
153  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimImageMpiSWriterSequenceConnection::slaveProcessTiles(): entering slave and will look at " << numberOfTiles << " tiles" << std::endl;
154  }
155  while(theCurrentTileNumber < numberOfTiles)
156  {
158 
159  // if the current send requests have looped around
160  // make sure we wait to see if it was sent
161  //
162  errorValue = MPI_Wait(&requests[currentSendRequest], MPI_STATUS_IGNORE);
163  requests[currentSendRequest] = MPI_REQUEST_NULL;
164  if(data.valid() &&
165  (data->getDataObjectStatus()!=OSSIM_NULL)&&
166  (data->getDataObjectStatus()!=OSSIM_EMPTY))
167  {
168  theOutputTile[currentSendRequest]->setImageRectangle(data->getImageRectangle());
169  theOutputTile[currentSendRequest]->initialize();
170 
171  theOutputTile[currentSendRequest]->loadTile(data.get());
172  theOutputTile[currentSendRequest]->setDataObjectStatus(data->getDataObjectStatus());
173 
174  if(traceDebug())
175  {
176  if(data->getDataObjectStatus() == OSSIM_EMPTY)
177  {
179  << "DEBUG ossimImageMpiSWriterSequenceConnection::slaveProcessTiles(): In salve = "
180  << theRank << " tile is empty" << std::endl;
181  }
182  }
183  }
184  else
185  {
186  if(traceDebug())
187  {
188  if(!data)
189  {
191  << "DEBUG ossimImageMpiSWriterSequenceConnection::slaveProcessTiles(): In slave = "
192  << theRank << " ptr is null " << std::endl;
193  }
194  else
195  {
197  << "DEBUG ossimImageMpiSWriterSequenceConnection::slaveProcessTiles(): In slave = " << theRank << " tile is empty" << std::endl;
198  }
199  }
200  theOutputTile[currentSendRequest]->makeBlank();
201  }
202 
203  void* buf = theOutputTile[currentSendRequest]->getBuf();
204  if((endian.getSystemEndianType()!=OSSIM_BIG_ENDIAN)&&
205  (theOutputTile[currentSendRequest]->getScalarType()!=OSSIM_UINT8))
206  {
207  endian.swap(theOutputTile[currentSendRequest]->getScalarType(),
208  buf,
209  theOutputTile[currentSendRequest]->getSize());
210  }
211  errorValue = MPI_Isend(buf,
212  theOutputTile[currentSendRequest]->getSizeInBytes(),
213  MPI_UNSIGNED_CHAR,
214  0,
215  0,
216  MPI_COMM_WORLD,
217  &requests[currentSendRequest]);
218 #if 0
219  switch(theOutputTile[currentSendRequest]->getScalarType())
220  {
221  case OSSIM_UINT8:
222  {
223  errorValue = MPI_Isend(buf,
224  theOutputTile[currentSendRequest]->getSize(),
225  MPI_UNSIGNED_CHAR,
226  0,
227  0,
228  MPI_COMM_WORLD,
229  &requests[currentSendRequest]);
230  break;
231  }
232  case OSSIM_SINT8:
233  {
234  errorValue = MPI_Isend(buf,
235  theOutputTile[currentSendRequest]->getSize(),
236  MPI_CHAR,
237  0,
238  0,
239  MPI_COMM_WORLD,
240  &requests[currentSendRequest]);
241  break;
242  }
243  case OSSIM_UINT16:
244  {
245  errorValue = MPI_Isend(buf,
246  theOutputTile[currentSendRequest]->getSize(),
247  MPI_UNSIGNED_SHORT,
248  0,
249  0,
250  MPI_COMM_WORLD,
251  &requests[currentSendRequest]);
252  break;
253  }
254  case OSSIM_SINT16:
255  {
256  errorValue = MPI_Isend(buf,
257  theOutputTile[currentSendRequest]->getSize(),
258  MPI_SHORT,
259  0,
260  0,
261  MPI_COMM_WORLD,
262  &requests[currentSendRequest]);
263  break;
264  }
265  case OSSIM_UINT32:
266  {
267  errorValue = MPI_Isend(buf,
268  theOutputTile[currentSendRequest]->getSize(),
269  MPI_UNSIGNED_LONG,
270  0,
271  0,
272  MPI_COMM_WORLD,
273  &requests[currentSendRequest]);
274  break;
275  }
276  case OSSIM_SINT32:
277  {
278  errorValue = MPI_Isend(buf,
279  theOutputTile[currentSendRequest]->getSize(),
280  MPI_LONG,
281  0,
282  0,
283  MPI_COMM_WORLD,
284  &requests[currentSendRequest]);
285  break;
286  }
287  case OSSIM_FLOAT32:
289  {
290  errorValue = MPI_Isend(buf,
291  theOutputTile[currentSendRequest]->getSize(),
292  MPI_FLOAT,
293  0,
294  0,
295  MPI_COMM_WORLD,
296  &requests[currentSendRequest]);
297  break;
298  }
299  case OSSIM_FLOAT64:
301  {
302  errorValue = MPI_Isend(buf,
303  theOutputTile[currentSendRequest]->getSize(),
304  MPI_DOUBLE,
305  0,
306  0,
307  MPI_COMM_WORLD,
308  &requests[currentSendRequest]);
309  break;
310  }
311  default:
312  break;
313  }
314 #endif
316  //numberOfTilesSent++;
317  currentSendRequest++;
318  currentSendRequest %= theNumberOfTilesToBuffer;
319  }
320  ossim_int32 tempCount = 0;
321  // must wait in the correct order
322  //
323  while(tempCount < theNumberOfTilesToBuffer)
324  {
325  errorValue = MPI_Wait(&requests[currentSendRequest], MPI_STATUS_IGNORE);
326  currentSendRequest++;
327  currentSendRequest %= theNumberOfTilesToBuffer;
328 
329  ++tempCount;
330  }
331 
332 // MPI_Waitall(theNumberOfTilesToBuffer,
333 // requests,
334 // MPI_STATUS_IGNORE);
335 
336  delete [] requests;
337 # endif
338 #endif
339 }
340 
341 
343  ossim_uint32 /* resLevel */)
344 {
346  << "FATAL ossimImageMpiSWriterSequenceConnection::getNextTile(): "
347  << "should not be called" << std::endl;
349 }
350 
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
8 bit signed integer
64 bit floating point
virtual void setImageRectangle(const ossimIrect &rect)
16 bit unsigned integer
bool valid() const
Definition: ossimRefPtr.h:75
ossimScalarType getScalarType(const H5::DataSet *dataset)
16 bit signed integer
virtual ossimDataObjectStatus getDataObjectStatus() const
32 bit floating point
32 bit unsigned integer
virtual void initialize()
Initialize the data buffer.
ossimImageMpiSWriterSequenceConnection(ossimObject *owner=NULL, long numberOfTilesToBuffer=2)
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
static ossimImageDataFactory * instance()
32 bit signed integer
unsigned int ossim_uint32
32 bit normalized floating point
virtual ossimIrect getImageRectangle() const
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossimByteOrder getSystemEndianType() const
Definition: ossimEndian.h:78
virtual void makeBlank()
Initializes data to null pixel values.
64 bit normalized floating point
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
virtual const void * getBuf() const
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
8 bit unsigned integer
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32