Commit e26071bd authored by remicres's avatar remicres

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

parent ea904bc0
......@@ -15,6 +15,7 @@
#ifdef OTB_USE_MPI
#include "otbMPIConfig.h"
#include "mpi.h" // TODO: implement needed methods inside otbMPIConfig.h
#endif
/*
......@@ -25,7 +26,7 @@ bool MyTurn(int div = 0)
{
#ifdef OTB_USE_MPI
otb::MPIConfig::Pointer mpiConfig = otb::MPIConfig::Instance();
int proc = 0;
unsigned int proc = 0;
if (mpiConfig->GetNbProcs() != 0)
proc = div % mpiConfig->GetNbProcs();
return (proc == mpiConfig->GetMyRank());
......@@ -37,33 +38,32 @@ bool MyTurn(int div = 0)
* This function gather the given value in other process, and update it
* TODO: MPI implementation using OTB MPI Wrapper
*/
/*
template<typename T>
void GatherMe(T& x, MPI_Datatype dataType)
{
if (myrank == 0)
if (otb::MPIConfig::Instance()->GetMyRank() == 0)
{
// Master process
// Gather
for (unsigned int p = 1 ; p < nprocs ; p++)
for (unsigned int p = 1 ; p < otb::MPIConfig::Instance()->GetNbProcs() ; p++)
{
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;
}
// Dispatch
for (unsigned int p = 1 ; p < nprocs ; p++)
MPI_Send(&x, 1, dataType, p, TAG_PIECE, MPI_COMM_WORLD);
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, TAG_PIECE, MPI_COMM_WORLD);
MPI_Recv(&x, 1, dataType, 0, TAG_PIECE, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
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
......@@ -71,20 +71,16 @@ void GatherMe(T& x, MPI_Datatype dataType)
*/
void GatherUsefulVariables(unsigned long long int& accumulatedMemory, bool& isFusion)
{
/*
MPI_Barrier(MPI_COMM_WORLD);
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, myrank, nprocs);
GatherMe<long long int>(accumulatedMemoryLLI, MPI_LONG_LONG_INT, myrank, nprocs);
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;
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