Commit e26071bd authored by remicres's avatar remicres
Browse files

ADD: add MPI routines. TODO: move them in appropriate class

parent ea904bc0
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#ifdef OTB_USE_MPI #ifdef OTB_USE_MPI
#include "otbMPIConfig.h" #include "otbMPIConfig.h"
#include "mpi.h" // TODO: implement needed methods inside otbMPIConfig.h
#endif #endif
/* /*
...@@ -25,7 +26,7 @@ bool MyTurn(int div = 0) ...@@ -25,7 +26,7 @@ bool MyTurn(int div = 0)
{ {
#ifdef OTB_USE_MPI #ifdef OTB_USE_MPI
otb::MPIConfig::Pointer mpiConfig = otb::MPIConfig::Instance(); otb::MPIConfig::Pointer mpiConfig = otb::MPIConfig::Instance();
int proc = 0; unsigned int proc = 0;
if (mpiConfig->GetNbProcs() != 0) if (mpiConfig->GetNbProcs() != 0)
proc = div % mpiConfig->GetNbProcs(); proc = div % mpiConfig->GetNbProcs();
return (proc == mpiConfig->GetMyRank()); return (proc == mpiConfig->GetMyRank());
...@@ -37,33 +38,32 @@ bool MyTurn(int div = 0) ...@@ -37,33 +38,32 @@ bool MyTurn(int div = 0)
* This function gather the given value in other process, and update it * This function gather the given value in other process, and update it
* TODO: MPI implementation using OTB MPI Wrapper * TODO: MPI implementation using OTB MPI Wrapper
*/ */
/*
template<typename T> template<typename T>
void GatherMe(T& x, MPI_Datatype dataType) void GatherMe(T& x, MPI_Datatype dataType)
{ {
if (myrank == 0) if (otb::MPIConfig::Instance()->GetMyRank() == 0)
{ {
// Master process // Master process
// Gather // Gather
for (unsigned int p = 1 ; p < nprocs ; p++) for (unsigned int p = 1 ; p < otb::MPIConfig::Instance()->GetNbProcs() ; p++)
{ {
T partial_sum; T partial_sum;
MPI_Recv( &partial_sum, 1, dataType, p, TAG_PIECE, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv( &partial_sum, 1, dataType, p, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
x += partial_sum; x += partial_sum;
} }
// Dispatch // Dispatch
for (unsigned int p = 1 ; p < nprocs ; p++) for (unsigned int p = 1 ; p < otb::MPIConfig::Instance()->GetNbProcs() ; p++)
MPI_Send(&x, 1, dataType, p, TAG_PIECE, MPI_COMM_WORLD); MPI_Send(&x, 1, dataType, p, MPI_ANY_TAG, MPI_COMM_WORLD);
} }
else else
{ {
// Slave process // Slave process
MPI_Send(&x, 1, dataType, 0, TAG_PIECE, MPI_COMM_WORLD); MPI_Send(&x, 1, dataType, 0, MPI_ANY_TAG, MPI_COMM_WORLD);
MPI_Recv(&x, 1, dataType, 0, TAG_PIECE, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(&x, 1, dataType, 0, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
} }
} }
*/
/* /*
* Gather accumulatedMemory and isFusion variables * Gather accumulatedMemory and isFusion variables
...@@ -71,20 +71,16 @@ void GatherMe(T& x, MPI_Datatype dataType) ...@@ -71,20 +71,16 @@ void GatherMe(T& x, MPI_Datatype dataType)
*/ */
void GatherUsefulVariables(unsigned long long int& accumulatedMemory, bool& isFusion) void GatherUsefulVariables(unsigned long long int& accumulatedMemory, bool& isFusion)
{ {
/* otb::MPIConfig::Instance()->barrier();
MPI_Barrier(MPI_COMM_WORLD);
int isFusionInteger = 0; int isFusionInteger = 0;
long long int accumulatedMemoryLLI = static_cast<long long int>(accumulatedMemory); long long int accumulatedMemoryLLI = static_cast<long long int>(accumulatedMemory);
if (isFusion) if (isFusion)
isFusionInteger = 1; isFusionInteger = 1;
GatherMe<int>(isFusionInteger, MPI_INT, myrank, nprocs); GatherMe<int>(isFusionInteger, MPI_INT);
GatherMe<long long int>(accumulatedMemoryLLI, MPI_LONG_LONG_INT, myrank, nprocs); GatherMe<long long int>(accumulatedMemoryLLI, MPI_LONG_LONG_INT);
accumulatedMemory = static_cast<long long unsigned int>(accumulatedMemoryLLI); accumulatedMemory = static_cast<long long unsigned int>(accumulatedMemoryLLI);
if (isFusionInteger>0) if (isFusionInteger>0)
isFusion = true; isFusion = true;
if (myrank == 0)
std::cout << "Accumulated memory " << accumulatedMemory << " bytes, there is fusion "<< isFusion << std::endl;
*/
} }
/* /*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment