From 1963695d6e1cb152a02c68aa5eb8a3bdf3ee2b41 Mon Sep 17 00:00:00 2001 From: Laurent Belcour Date: Tue, 26 Mar 2013 14:00:17 +0100 Subject: [PATCH] Changing the name of the function, it is only returning the total memory on the system. Updated the computation of the memory cost. --- sources/core/plugins_manager.cpp | 4 ++-- sources/core/plugins_manager.h | 4 ++-- .../rational_fitter_parallel/rational_fitter.cpp | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sources/core/plugins_manager.cpp b/sources/core/plugins_manager.cpp index 9a72022..36320ce 100644 --- a/sources/core/plugins_manager.cpp +++ b/sources/core/plugins_manager.cpp @@ -162,7 +162,7 @@ fitter* plugins_manager::get_fitter(const std::string& n) const // \todo implement the Darwin (MACOS) version. #ifdef WIN32 #include -size_t plugins_manager::get_available_memory() +size_t plugins_manager::get_system_memory() { MEMORYSTATUSEX status; status.dwLength = sizeof(status); @@ -171,7 +171,7 @@ size_t plugins_manager::get_available_memory() } #else #include -size_t plugins_manager::get_available_memory() +size_t plugins_manager::get_system_memory() { long pages = sysconf(_SC_PHYS_PAGES); long page_size = sysconf(_SC_PAGE_SIZE); diff --git a/sources/core/plugins_manager.h b/sources/core/plugins_manager.h index 5f9ea69..4903ad4 100644 --- a/sources/core/plugins_manager.h +++ b/sources/core/plugins_manager.h @@ -32,10 +32,10 @@ class plugins_manager data* get_data(const std::string& n) const ; fitter* get_fitter(const std::string& n) const ; - //! \brief Provide a measure of how much free memory is left on the system. + //! \brief Provide a measure of how much memory there is on the system. //! \details It permits to know is one can allocate more memory for a fitting //! procedure for example. - static size_t get_available_memory() ; + static size_t get_system_memory() ; private: //data diff --git a/sources/plugins/rational_fitter_parallel/rational_fitter.cpp b/sources/plugins/rational_fitter_parallel/rational_fitter.cpp index e8a2c12..4a6930a 100644 --- a/sources/plugins/rational_fitter_parallel/rational_fitter.cpp +++ b/sources/plugins/rational_fitter_parallel/rational_fitter.cpp @@ -61,21 +61,21 @@ bool rational_fitter_parallel::fit_data(const data* dat, function* fit) // Allocate enough processor to run fully in parallel, but account for // the fact that each thread will require its own memory. - size_t need_memory = (i+1) * d->size() * 2 * sizeof(double); - size_t avai_memory = plugins_manager::get_available_memory(); - int nb_cores = avai_memory / need_memory ; + size_t need_memory = ((3*i+1)*d->size()*2 + 2*i + 2*d->dimY()*d->size()) * sizeof(double); + size_t avai_memory = plugins_manager::get_system_memory(); + int nb_cores = (60 * avai_memory) / (100 * need_memory) ; nb_cores = std::min(nb_cores, omp_get_num_procs()); if(nb_cores == 0) { std::cerr << "<> not enough memory to perform the fit" << std::endl ; -#ifndef DEBUG - std::cout << "<> " << need_memory / 1024 << "MB required / " - << avai_memory / 1024 << "MB available" << std::endl; +#ifdef DEBUG + std::cout << "<> " << need_memory / (1024*1024) << "MB required / " + << avai_memory / (1024*1024) << "MB available" << std::endl; #endif return false; } -#ifndef DEBUG +#ifdef DEBUG std::cout << "<> will use " << nb_cores << " threads to compute the quadratic programs" << std::endl ; #endif omp_set_num_threads(nb_cores) ; -- GitLab