Commit 1963695d authored by Laurent Belcour's avatar Laurent Belcour

Changing the name of the function, it is only returning the total memory on the

system. Updated the computation of the memory cost.
parent 1ec36b2a
......@@ -162,7 +162,7 @@ fitter* plugins_manager::get_fitter(const std::string& n) const
// \todo implement the Darwin (MACOS) version.
#ifdef WIN32
#include <windows.h>
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 <unistd.h>
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);
......
......@@ -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
......
......@@ -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<int>(nb_cores, omp_get_num_procs());
if(nb_cores == 0)
{
std::cerr << "<<ERROR>> not enough memory to perform the fit" << std::endl ;
#ifndef DEBUG
std::cout << "<<DEBUG>> " << need_memory / 1024 << "MB required / "
<< avai_memory / 1024 << "MB available" << std::endl;
#ifdef DEBUG
std::cout << "<<DEBUG>> " << need_memory / (1024*1024) << "MB required / "
<< avai_memory / (1024*1024) << "MB available" << std::endl;
#endif
return false;
}
#ifndef DEBUG
#ifdef DEBUG
std::cout << "<<DEBUG>> will use " << nb_cores << " threads to compute the quadratic programs" << std::endl ;
#endif
omp_set_num_threads(nb_cores) ;
......
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