lsgrmHeader.h 2.35 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"
#endif
 * This function returns TRUE if it's to the process #myrank to do the
 * work on the yard #div in a pool of #nprocs threads
bool MyTurn(int div = 0)
#ifdef OTB_USE_MPI
  otb::MPIConfig::Pointer mpiConfig = otb::MPIConfig::Instance();
  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
template<typename T>
void GatherMe(T& x, MPI_Datatype dataType)
  if (myrank == 0)
    // Master process
    // Gather
    for (unsigned int p = 1 ; p < nprocs ; p++)
      T partial_sum;
      MPI_Recv( &partial_sum, 1, dataType, p, TAG_PIECE, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
      x += partial_sum;
    // Dispatch
    for (unsigned int p = 1 ; p < nprocs ; p++)
      MPI_Send(&x, 1, dataType, p, TAG_PIECE, MPI_COMM_WORLD);
  else
    // Slave process
    MPI_Send(&x, 1, dataType, 0, TAG_PIECE, MPI_COMM_WORLD);
    MPI_Recv(&x, 1, dataType, 0, TAG_PIECE, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
 * Gather accumulatedMemory and isFusion variables
void GatherUsefulVariables(unsigned long long int& accumulatedMemory, bool& isFusion)
717273747576777879808182838485868788899091929394959697
{ /* MPI_Barrier(MPI_COMM_WORLD); int isFusionInteger = 0; long long int accumulatedMemoryLLI = static_cast<long long int>(accumulatedMemory); if (isFusion) isFusionInteger = 1; GatherMe<int>(isFusionInteger, MPI_INT, myrank, nprocs); GatherMe<long long int>(accumulatedMemoryLLI, MPI_LONG_LONG_INT, myrank, nprocs); accumulatedMemory = static_cast<long long unsigned int>(accumulatedMemoryLLI); if (isFusionInteger>0) isFusion = true; if (myrank == 0) std::cout << "Accumulated memory " << accumulatedMemory << " bytes, there is fusion "<< isFusion << std::endl; */ } /* * Print time elapsed */ void ShowTime(boost::timer t) { std::cout << "--- Process duration : " << std::floor(t.elapsed()) << " s" << std::endl; t.restart(); } #endif