lsgrmHeader.h 2.49 KiB
#ifndef __LSGRM_HEADER_H
#define __LSGRM_HEADER_H
#include <cassert>
#include <cstdlib>
#include <string>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <stack>
#include <boost/algorithm/string.hpp>
#include <boost/progress.hpp>
#ifdef OTB_USE_MPI
#include "otbMPIConfig.h"
#include "mpi.h" // TODO: implement needed methods inside otbMPIConfig.h
#endif
 * This function returns TRUE if the process #myrank is assigned
 * to the task #div in a pool of #nprocs processes
bool MyTurn(int div = 0)
#ifdef OTB_USE_MPI
  otb::MPIConfig::Pointer mpiConfig = otb::MPIConfig::Instance();
  unsigned int proc = 0;
  if (mpiConfig->GetNbProcs() != 0)
    proc = div % mpiConfig->GetNbProcs();
  return (proc == mpiConfig->GetMyRank());
#endif
  return true;
 * This function gather the given value in other process, and update it
 * TODO: MPI implementation using OTB MPI Wrapper
#ifdef OTB_USE_MPI
template<typename T>
void GatherMe(T& x, MPI_Datatype dataType)
  if (otb::MPIConfig::Instance()->GetMyRank() == 0)
    // Master process
    // Gather
    for (unsigned int p = 1 ; p < otb::MPIConfig::Instance()->GetNbProcs() ; p++)
      T partial_sum;
      MPI_Recv( &partial_sum, 1, dataType, p, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
      x += partial_sum;
    // Dispatch
    for (unsigned int p = 1 ; p < otb::MPIConfig::Instance()->GetNbProcs() ; p++)
      MPI_Send(&x, 1, dataType, p, 0, MPI_COMM_WORLD);
  else
    // Slave process
    MPI_Send(&x, 1, dataType, 0, 0, MPI_COMM_WORLD);
    MPI_Recv(&x, 1, dataType, 0, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
#endif
7172737475767778798081828384858687888990919293949596979899
* Gather accumulatedMemory and isFusion variables * TODO: MPI implementation using OTB MPI Wrapper */ void GatherUsefulVariables(unsigned long long int& accumulatedMemory, bool& isFusion) { #ifdef OTB_USE_MPI otb::MPIConfig::Instance()->barrier(); int isFusionInteger = 0; long long int accumulatedMemoryLLI = static_cast<long long int>(accumulatedMemory); if (isFusion) isFusionInteger = 1; GatherMe<int>(isFusionInteger, MPI_INT); GatherMe<long long int>(accumulatedMemoryLLI, MPI_LONG_LONG_INT); accumulatedMemory = static_cast<long long unsigned int>(accumulatedMemoryLLI); if (isFusionInteger>0) isFusion = true; #endif } /* * Print time elapsed */ void ShowTime(boost::timer t) { std::cout << "--- Process duration : " << std::floor(t.elapsed()) << " s" << std::endl; t.restart(); } #endif