#ifndef __LSGRM_HEADER_H #define __LSGRM_HEADER_H #include #include #include #include #include #include #include #include #include #include #include #ifdef OTB_USE_MPI #include "otbMPIConfig.h" #include "mpi.h" // TODO: implement needed methods inside 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(); 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 */ template 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, MPI_ANY_TAG, MPI_COMM_WORLD); } else { // Slave process MPI_Send(&x, 1, dataType, 0, MPI_ANY_TAG, MPI_COMM_WORLD); MPI_Recv(&x, 1, dataType, 0, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } /* * Gather accumulatedMemory and isFusion variables * TODO: MPI implementation using OTB MPI Wrapper */ void GatherUsefulVariables(unsigned long long int& accumulatedMemory, bool& isFusion) { otb::MPIConfig::Instance()->barrier(); int isFusionInteger = 0; long long int accumulatedMemoryLLI = static_cast(accumulatedMemory); if (isFusion) isFusionInteger = 1; GatherMe(isFusionInteger, MPI_INT); GatherMe(accumulatedMemoryLLI, MPI_LONG_LONG_INT); accumulatedMemory = static_cast(accumulatedMemoryLLI); if (isFusionInteger>0) isFusion = true; } /* * Print time elapsed */ void ShowTime(boost::timer t) { std::cout << "--- Process duration : " << std::floor(t.elapsed()) << " s" << std::endl; t.restart(); } #endif