diff --git a/Modules/Applications/AppDomainTransform/app/otbDomainTransform.cxx b/Modules/Applications/AppDomainTransform/app/otbDomainTransform.cxx index 41ee75c1b2c68f6ae924b4df3c3503e5c08e98eb..3e791c67826b93a072c48eb1a1b91b6721eb41e4 100644 --- a/Modules/Applications/AppDomainTransform/app/otbDomainTransform.cxx +++ b/Modules/Applications/AppDomainTransform/app/otbDomainTransform.cxx @@ -27,7 +27,6 @@ #include <itkInverseFFTImageFilter.h> #include <itkUnaryFunctorImageFilter.h> #include <itkFFTShiftImageFilter.h> -#include <itkFFTWGlobalConfiguration.h> #include "otbComplexToVectorImageCastFilter.h" @@ -80,25 +79,17 @@ private: ~DomainTransform() ITK_OVERRIDE { - } - - void CleanupFFTWThreads() - { - std::cout << "Start cleanup threads" << std::endl; // This is a trick to make sure fftw will cleanup its threads when application // shared lib is released. #if defined(ITK_USE_FFTWF) - std::cout << "ITK_USE_FFTWF" << std::endl; fftwf_cleanup_threads(); fftwf_cleanup(); #endif #if defined(ITK_USE_FFTWD) - std::cout << "ITK_USE_FFTWD" << std::endl; fftw_cleanup_threads(); fftw_cleanup(); #endif - std::cout << "End cleanup threads" << std::endl; - } + } void DoInit() ITK_OVERRIDE { @@ -261,10 +252,9 @@ private: // fft ttransform bool shift = IsParameterEnabled( "mode.fft.shift"); typedef otb::Image< std::complex<OutputPixelType> > ComplexOutputImageType; - + if (dir == 0 ) { - otbAppLogINFO( << "Forward FFT" ); //forward fft typedef otb::Image<InputPixelType> TInputImage; typedef TInputImage::Pointer TInputImagePointer; @@ -278,7 +268,7 @@ private: FFTFilter::Pointer fwdFilter = FFTFilter::New(); fwdFilter->SetInput( inImage ); - + //typedef VectorImage for output of UnaryFunctorImageFilter typedef otb::VectorImage<OutputPixelType> TOutputImage; @@ -286,7 +276,7 @@ private: ComplexOutputImageType, TOutputImage > ComplexToVectorImageCastFilter; ComplexToVectorImageCastFilter::Pointer unaryFunctorImageFilter = ComplexToVectorImageCastFilter::New(); - + if( shift) { otbAppLogINFO( << "Applying Shift image filter" ); @@ -314,7 +304,6 @@ private: } else { - otbAppLogINFO( << "Inverse FFT" ); //inverse fft typedef otb::VectorImage<InputPixelType> TInputImage; typedef TInputImage::Pointer TInputImagePointer; @@ -327,7 +316,7 @@ private: std::complex<InputPixelType>, 2 > TComplexImage; //typedef TOutputImage for InverseFFTImageFilter output typedef otb::Image< OutputPixelType > TOutputImage; - + // a unary functor to convert vectorimage to complex image typedef itk::UnaryFunctorImageFilter <TInputImage, @@ -341,7 +330,6 @@ private: if( shift) { - otbAppLogINFO( << "Applying Shift image filter" ); typedef itk::FFTShiftImageFilter< TInputImage, TInputImage > FFTShiftFilterType; @@ -373,9 +361,6 @@ private: SetParameterOutputImage<TOutputImage>("out", invFilter->GetOutput()); } } - - // at the end, cleanup FFTW Threads - CleanupFFTWThreads(); } template<otb::Wavelet::Wavelet TWaveletOperator> diff --git a/Modules/Applications/AppDomainTransform/test/CMakeLists.txt b/Modules/Applications/AppDomainTransform/test/CMakeLists.txt index f5bb2c2e30d2f8db030057dc8c08ec0ca86a2516..e397c71378b543164a511cef1b67c313f7f95bb8 100644 --- a/Modules/Applications/AppDomainTransform/test/CMakeLists.txt +++ b/Modules/Applications/AppDomainTransform/test/CMakeLists.txt @@ -26,29 +26,13 @@ otb_test_application(NAME apTvDomainTransform_fft_shift_fwd -dir fwd -out ${TEMP}/apTvDomainTransform_fft_shift_fwd.tif ) - -otb_test_application(NAME apTvDomainTransform_fft_fwd - APP DomainTransform - OPTIONS -in ${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif - -mode fft - -dir fwd - -out ${TEMP}/apTvDomainTransform_fft_fwd.tif - ) - -otb_test_application(NAME apTvDomainTransform_fft_shift_inv - APP DomainTransform - OPTIONS -in ${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif - -mode fft - -mode.fft.shift true - -dir inv - -out ${TEMP}/apTvDomainTransform_fft_shift_inv.tif - ) + otb_test_application(NAME apTvDomainTransform_fft_inv APP DomainTransform OPTIONS -in ${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif -mode fft -dir inv - -out ${TEMP}/apTvDomainTransform_fft_inv.tif + -out ${TEMP}/apTvDomainTransform_fft_shift_inv.tif ) diff --git a/Modules/IO/TestKernel/include/otbTestMain.h b/Modules/IO/TestKernel/include/otbTestMain.h index c30763f41a1c802a9c9801afc2fc196ef6523e89..42f7e894aa790d7855cbe7a58d1660e5959e039e 100644 --- a/Modules/IO/TestKernel/include/otbTestMain.h +++ b/Modules/IO/TestKernel/include/otbTestMain.h @@ -424,7 +424,6 @@ 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; diff --git a/Modules/MPI/MPIConfig/include/otbMPIConfig.h b/Modules/MPI/MPIConfig/include/otbMPIConfig.h index c5bd1ab1e80b0703fb0f851dcd05ebb5986d443a..3b53299fdd8c0ddbe215b97c9d1ca3a622543060 100644 --- a/Modules/MPI/MPIConfig/include/otbMPIConfig.h +++ b/Modules/MPI/MPIConfig/include/otbMPIConfig.h @@ -53,9 +53,6 @@ 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); @@ -88,8 +85,6 @@ 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; }; diff --git a/Modules/MPI/MPIConfig/src/otbMPIConfig.cxx b/Modules/MPI/MPIConfig/src/otbMPIConfig.cxx index 6d53747f4b8aa07b972649da813f9053ab9dd73a..c582dc322fd9a5e5866e67562b568f8d94e9b538 100644 --- a/Modules/MPI/MPIConfig/src/otbMPIConfig.cxx +++ b/Modules/MPI/MPIConfig/src/otbMPIConfig.cxx @@ -77,94 +77,71 @@ MPIConfig::Pointer MPIConfig::Instance() /** CreateInitialize MPI environment */ MPIConfig::MPIConfig() - : m_MyRank(0), + : m_MyRank(-1), m_NbProcs(0), m_abortOnException(true), - m_initialized(false), - m_terminated(false) + m_initialized(false) { } /** Shuts down the MPI environment. */ MPIConfig::~MPIConfig() { - terminate(); + 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,()); + } + } + } } /** Initialize MPI environment */ -void MPIConfig::Init(int &argc, char **&argv, bool abortOnException) { - if( !m_terminated ) - { - std::cout << "MPI Initialization : " << this << std::endl; - std::flush(std::cout); - // 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) { + // 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); - } -} - -/** Shuts down the MPI environment. */ -void MPIConfig::terminate() -{ - if( m_initialized && !m_terminated ) - { - std::cout << "Terminate : " << this << std::endl; - std::flush(std::cout); - if( std::uncaught_exception() && m_abortOnException ) - { - std::cout << "Abord" << std::endl; - abort( EXIT_FAILURE ); - } - else - { - std::cout << "Start Finalize MPI" << std::endl; - std::flush( std::cout ); - int finalized; - OTB_MPI_CHECK_RESULT( MPI_Finalized, ( &finalized )); - if( !finalized ) - { - std::cout << "Start 2nd End Finalize MPI" << std::endl; - //OTB_MPI_CHECK_RESULT( MPI_Finalize, ( )); - std::cout << "End 2nd Finalize MPI" << std::endl; - } - std::cout << "End Finalize MPI" << std::endl; - std::flush( std::cout ); - } - m_terminated = true; - } + m_NbProcs = static_cast<unsigned int>(inbprocs); } void MPIConfig::abort(int errCode) diff --git a/Modules/Wrappers/CommandLine/src/otbApplicationLauncherCommandLine.cxx b/Modules/Wrappers/CommandLine/src/otbApplicationLauncherCommandLine.cxx index 3d66679172f27299e91ea1d3fdd47f2ed42d5deb..05d439d7fa689d3b8cfca4d9879760d2cb3d8372 100644 --- a/Modules/Wrappers/CommandLine/src/otbApplicationLauncherCommandLine.cxx +++ b/Modules/Wrappers/CommandLine/src/otbApplicationLauncherCommandLine.cxx @@ -303,13 +303,19 @@ int main(int argc, char* argv[]) LauncherType::Pointer launcher = LauncherType::New(); //if (launcher->Load(exp) == true) - bool sucess = launcher->Load(vexp) && launcher->ExecuteAndWriteOutput(); + if (launcher->Load(vexp) == true) + { + if (launcher->ExecuteAndWriteOutput() == false) + { + return EXIT_FAILURE; + } + } + else + { + return EXIT_FAILURE; + } - // shutdown MPI after application finished - #ifdef OTB_USE_MPI - otb::MPIConfig::Instance()->terminate(); - #endif - return sucess ? EXIT_SUCCESS : EXIT_FAILURE; + return EXIT_SUCCESS; } const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key)