From: <hug...@li...> - 2011-12-01 16:43:58
|
branch: details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgrepo/h/hu/hugin/hugin/rev/6a085a22a136 changeset: 5684:6a085a22a136 user: tmodes date: Thu Dec 01 17:43:46 2011 +0100 description: Cpfind: automatic limit number of thread depending on image size and memory diffstat: src/hugin_cpfind/cpfind/PanoDetector.cpp | 38 +++++++++++++++++++++++++++++++- src/hugin_cpfind/cpfind/Utils.cpp | 23 ++++++++++++++++++- src/hugin_cpfind/cpfind/Utils.h | 3 +- 3 files changed, 61 insertions(+), 3 deletions(-) diffs (106 lines): diff -r d7a9fcd482ce -r 6a085a22a136 src/hugin_cpfind/cpfind/PanoDetector.cpp --- a/src/hugin_cpfind/cpfind/PanoDetector.cpp Thu Dec 01 17:38:34 2011 +0100 +++ b/src/hugin_cpfind/cpfind/PanoDetector.cpp Thu Dec 01 17:43:46 2011 +0100 @@ -423,7 +423,6 @@ { // init the random time generator srandom((unsigned int)time(NULL)); - PoolExecutor aExecutor(_cores); // Load the input project file if(!loadProject()) @@ -444,6 +443,43 @@ return; }; + //checking, if memory allows running desired number of threads + unsigned long maxImageSize=0; + bool withRemap=false; + for (ImgDataIt_t aB = _filesData.begin(); aB != _filesData.end(); ++aB) + { + maxImageSize=std::max<unsigned long>(aB->second._detectWidth*aB->second._detectHeight,maxImageSize); + if(aB->second._needsremap) + { + withRemap=true; + }; + }; + unsigned long maxCores; + //determinded factors by testing of some projects + //the memory usage seems to be very high + //if the memory usage could be decreased these numbers can be decreased + if(withRemap) + { + maxCores=utils::getTotalMemory()/(maxImageSize*75); + } + else + { + maxCores=utils::getTotalMemory()/(maxImageSize*50); + }; + if(maxCores<1) + { + maxCores=1; + } + if(maxCores<_cores) + { + if(getVerbose()>0) + { + std::cout << "\nThe available memory does not allow running " << _cores << " threads parallel.\n" + << "Running cpfind with " << maxCores << " threads.\n"; + }; + setCores(maxCores); + }; + PoolExecutor aExecutor(_cores); svmModel=NULL; if(_celeste) { diff -r d7a9fcd482ce -r 6a085a22a136 src/hugin_cpfind/cpfind/Utils.cpp --- a/src/hugin_cpfind/cpfind/Utils.cpp Thu Dec 01 17:38:34 2011 +0100 +++ b/src/hugin_cpfind/cpfind/Utils.cpp Thu Dec 01 17:43:46 2011 +0100 @@ -22,7 +22,11 @@ #if defined(HW_NCPU) || defined(__APPLE__) #include <sys/sysctl.h> #endif - +#ifdef _WINDOWS +#include <Windows.h> +#else +#include <unistd.h> +#endif int utils::getCPUCount() { @@ -49,3 +53,20 @@ return 1; #endif } + +#ifdef _WINDOWS +unsigned long long utils::getTotalMemory() +{ + MEMORYSTATUSEX status; + status.dwLength = sizeof(status); + GlobalMemoryStatusEx(&status); + return status.ullTotalPhys; +}; +#else +unsigned long long utils::getTotalMemory() +{ + long pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + return pages * page_size; +} +#endif diff -r d7a9fcd482ce -r 6a085a22a136 src/hugin_cpfind/cpfind/Utils.h --- a/src/hugin_cpfind/cpfind/Utils.h Thu Dec 01 17:38:34 2011 +0100 +++ b/src/hugin_cpfind/cpfind/Utils.h Thu Dec 01 17:43:46 2011 +0100 @@ -73,8 +73,9 @@ #endif } +/** returns the total memory in byte */ +unsigned long long getTotalMemory(); -//} } #endif // __utils_h |