Commit f8d5877c authored by Guillaume Pasero's avatar Guillaume Pasero

Merge branch 'fft-debug' into develop

parents f7409759 46ee96b6
......@@ -27,6 +27,7 @@
#include <itkInverseFFTImageFilter.h>
#include <itkUnaryFunctorImageFilter.h>
#include <itkFFTShiftImageFilter.h>
#include <itkFFTWGlobalConfiguration.h>
#include "otbComplexToVectorImageCastFilter.h"
......@@ -79,6 +80,10 @@ private:
~DomainTransform() ITK_OVERRIDE
{
}
void CleanupFFTWThreads()
{
// This is a trick to make sure fftw will cleanup its threads when application
// shared lib is released.
#if defined(ITK_USE_FFTWF)
......@@ -89,7 +94,7 @@ private:
fftw_cleanup_threads();
fftw_cleanup();
#endif
}
}
void DoInit() ITK_OVERRIDE
{
......@@ -364,6 +369,9 @@ private:
SetParameterOutputImage<TOutputImage>("out", invFilter->GetOutput());
}
}
// at the end, cleanup FFTW Threads
CleanupFFTWThreads();
}
template<otb::Wavelet::Wavelet TWaveletOperator>
......
......@@ -424,6 +424,7 @@ int main(int ac, char* av[])
std::cout << "------------- End control baseline tests -------------" << std::endl;
#ifdef OTB_USE_MPI
otb::MPIConfig::Instance()->terminate();
}
#endif
return result;
......
......@@ -53,6 +53,9 @@ public:
/** Initialize MPI Processus */
void Init(int& argc, char** &argv, bool abortOnException = true);
/** Shuts down the MPI environment. */
void terminate();
/** Abort all MPI processus. */
void abort(int errCode);
......@@ -85,6 +88,8 @@ private:
bool m_abortOnException;
// Boolean to test if the MPI environment is initialized
bool m_initialized;
// Boolean to test if the MPI environment is terminated
bool m_terminated;
static Pointer m_Singleton;
};
......
......@@ -80,68 +80,80 @@ MPIConfig::MPIConfig()
: m_MyRank(-1),
m_NbProcs(0),
m_abortOnException(true),
m_initialized(false)
m_initialized(false),
m_terminated(false)
{
}
/** Shuts down the MPI environment. */
MPIConfig::~MPIConfig()
{
if (m_initialized)
{
if (std::uncaught_exception() && m_abortOnException)
{
abort(EXIT_FAILURE);
}
else
{
int finalized;
OTB_MPI_CHECK_RESULT(MPI_Finalized,(&finalized));
if (!finalized)
{
OTB_MPI_CHECK_RESULT(MPI_Finalize,());
}
}
}
terminate();
}
/** Initialize MPI environment */
void MPIConfig::Init(int& argc, char** &argv, bool abortOnException) {
// Abort on exception
m_abortOnException = abortOnException;
// Initialize
int initialized;
OTB_MPI_CHECK_RESULT(MPI_Initialized,(&initialized));
m_initialized = (initialized == 1);
if (!m_initialized) {
OTB_MPI_CHECK_RESULT(MPI_Init, (&argc, &argv));
m_initialized = true;
}
// Get MPI rank
int irank = 0;
OTB_MPI_CHECK_RESULT(MPI_Comm_rank, (MPI_COMM_WORLD , &irank));
void MPIConfig::Init(int &argc, char **&argv, bool abortOnException) {
if( !m_terminated )
{
// Abort on exception
m_abortOnException = abortOnException;
// Initialize
int initialized;
OTB_MPI_CHECK_RESULT( MPI_Initialized, ( &initialized ));
m_initialized = ( initialized == 1 );
if( !m_initialized )
{
OTB_MPI_CHECK_RESULT( MPI_Init, ( &argc, &argv ));
m_initialized = true;
}
// Get MPI rank
int irank = 0;
OTB_MPI_CHECK_RESULT( MPI_Comm_rank, ( MPI_COMM_WORLD, &irank ));
if(irank<0)
{
logError("Negative MPI rank");
abort(EXIT_FAILURE);
}
if( irank < 0 )
{
logError( "Negative MPI rank" );
abort( EXIT_FAILURE );
}
m_MyRank = static_cast<unsigned int>(irank);
m_MyRank = static_cast<unsigned int>(irank);
// Get MPI NbProocs
// Get MPI NbProocs
int inbprocs=0;
int inbprocs = 0;
OTB_MPI_CHECK_RESULT(MPI_Comm_size, (MPI_COMM_WORLD , &inbprocs));
OTB_MPI_CHECK_RESULT( MPI_Comm_size, ( MPI_COMM_WORLD, &inbprocs ));
if(inbprocs<1)
{
logError("Negative or null number of processes");
abort(EXIT_FAILURE);
}
if( inbprocs < 1 )
{
logError( "Negative or null number of processes" );
abort( EXIT_FAILURE );
}
m_NbProcs = static_cast<unsigned int>(inbprocs);
m_NbProcs = static_cast<unsigned int>(inbprocs);
}
}
/** Shuts down the MPI environment. */
void MPIConfig::terminate()
{
if( m_initialized && !m_terminated )
{
if( std::uncaught_exception() && m_abortOnException )
{
abort( EXIT_FAILURE );
}
else
{
int finalized;
OTB_MPI_CHECK_RESULT( MPI_Finalized, ( &finalized ));
if( !finalized )
{
OTB_MPI_CHECK_RESULT( MPI_Finalize, ( ));
}
}
m_terminated = true;
}
}
void MPIConfig::abort(int errCode)
......
......@@ -303,19 +303,13 @@ int main(int argc, char* argv[])
LauncherType::Pointer launcher = LauncherType::New();
//if (launcher->Load(exp) == true)
if (launcher->Load(vexp) == true)
{
if (launcher->ExecuteAndWriteOutput() == false)
{
return EXIT_FAILURE;
}
}
else
{
return EXIT_FAILURE;
}
bool sucess = launcher->Load(vexp) && launcher->ExecuteAndWriteOutput();
return EXIT_SUCCESS;
// shutdown MPI after application finished
#ifdef OTB_USE_MPI
otb::MPIConfig::Instance()->terminate();
#endif
return sucess ? EXIT_SUCCESS : EXIT_FAILURE;
}
const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key)
......
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