|
a/src/utils/cpuconf.cpp |
|
b/src/utils/cpuconf.cpp |
|
... |
|
... |
12 |
* You should have received a copy of the GNU General Public License
|
12 |
* You should have received a copy of the GNU General Public License
|
13 |
* along with this program; if not, write to the
|
13 |
* along with this program; if not, write to the
|
14 |
* Free Software Foundation, Inc.,
|
14 |
* Free Software Foundation, Inc.,
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
16 |
*/
|
16 |
*/
|
17 |
|
|
|
18 |
#ifndef TEST_CPUCONF
|
17 |
#ifndef TEST_CPUCONF
|
19 |
|
18 |
|
20 |
#include "autoconfig.h"
|
19 |
#include "autoconfig.h"
|
|
|
20 |
#include "cpuconf.h"
|
|
|
21 |
|
|
|
22 |
#if defined(__gnu_linux__)
|
21 |
|
23 |
|
22 |
#include <stdlib.h>
|
24 |
#include <stdlib.h>
|
23 |
|
|
|
24 |
#include "cpuconf.h"
|
|
|
25 |
#include "execmd.h"
|
25 |
#include "execmd.h"
|
26 |
#include "smallut.h"
|
26 |
#include "smallut.h"
|
27 |
|
27 |
|
28 |
using std::string;
|
28 |
using std::string;
|
29 |
using std::vector;
|
29 |
using std::vector;
|
30 |
|
30 |
|
31 |
#if defined(__gnu_linux__)
|
31 |
// It seems that we could use sysconf as on macosx actually
|
32 |
bool getCpuConf(CpuConf& conf)
|
32 |
bool getCpuConf(CpuConf& conf)
|
33 |
{
|
33 |
{
|
34 |
vector<string> cmdv = create_vector<string>("sh")("-c")
|
34 |
vector<string> cmdv = create_vector<string>("sh")("-c")
|
35 |
("egrep ^processor /proc/cpuinfo | wc -l");
|
35 |
("egrep ^processor /proc/cpuinfo | wc -l");
|
36 |
|
36 |
|
|
... |
|
... |
54 |
conf.ncpus = atoi(result.c_str());
|
54 |
conf.ncpus = atoi(result.c_str());
|
55 |
if (conf.ncpus < 1 || conf.ncpus > 100)
|
55 |
if (conf.ncpus < 1 || conf.ncpus > 100)
|
56 |
conf.ncpus = 1;
|
56 |
conf.ncpus = 1;
|
57 |
return true;
|
57 |
return true;
|
58 |
}
|
58 |
}
|
59 |
//#elif defined(__APPLE__)
|
|
|
60 |
|
59 |
|
|
|
60 |
#elif 0 && defined(_WIN32)
|
|
|
61 |
// On windows, indexing is actually twice slower with threads enabled +
|
|
|
62 |
// there is a bug and the process does not exit at the end of indexing.
|
|
|
63 |
// Until these are solved, pretend there is only 1 cpu
|
|
|
64 |
#include <thread>
|
|
|
65 |
bool getCpuConf(CpuConf& cpus)
|
|
|
66 |
{
|
|
|
67 |
#if 0
|
|
|
68 |
// Native way
|
|
|
69 |
SYSTEM_INFO sysinfo;
|
|
|
70 |
GetSystemInfo( &sysinfo );
|
|
|
71 |
cpus.ncpus = sysinfo.dwNumberOfProcessors;
|
|
|
72 |
#else
|
|
|
73 |
// c++11
|
|
|
74 |
cpus.ncpus = std::thread::hardware_concurrency();
|
|
|
75 |
#endif
|
|
|
76 |
return true;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
#elif defined(__APPLE__)
|
|
|
80 |
|
|
|
81 |
#include <unistd.h>
|
|
|
82 |
bool getCpuConf(CpuConf& cpus)
|
|
|
83 |
{
|
|
|
84 |
cpus.ncpus = sysconf( _SC_NPROCESSORS_ONLN );
|
|
|
85 |
return true;
|
|
|
86 |
}
|
|
|
87 |
|
61 |
#else // Any other system
|
88 |
#else // Any other system
|
62 |
|
89 |
|
63 |
// Generic, pretend there is one
|
90 |
// Generic, pretend there is one
|
64 |
bool getCpuConf(CpuConf& cpus)
|
91 |
bool getCpuConf(CpuConf& cpus)
|
65 |
{
|
92 |
{
|