From: richter Date: Wed, 23 Feb 2000 16:55:42 +0000 (+0000) Subject: the number of cpus is detected on linux and sun X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4433d7a7c46bae6b47f93d99af09c6351c06fd9e;p=dealii-svn.git the number of cpus is detected on linux and sun git-svn-id: https://svn.dealii.org/trunk@2486 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/source/multithread_info.cc b/deal.II/base/source/multithread_info.cc new file mode 100644 index 0000000000..604279df43 --- /dev/null +++ b/deal.II/base/source/multithread_info.cc @@ -0,0 +1,89 @@ +//---------------------------- multithread_info.cc ---------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- multithread_info.cc ---------------- + +#include + +#if defined(__linux__) + +#include +#include +#endif + +#if defined(__sun__) +#include +#endif + +#ifdef DEAL_II_USE_MT + +#if defined(__linux__) + +unsigned int MultithreadInfo::get_n_cpus() +{ + ifstream cpuinfo; + string search; + unsigned int nCPU = 0; + + cpuinfo.open("/proc/cpuinfo"); + + AssertThrow(cpuinfo,ExcProcNotPresent()); + + while((cpuinfo)) + { + cpuinfo >> search; + if (search.find("processor")!=string::npos) + nCPU++; + } + cpuinfo.close(); + + return nCPU; +} + +#elif defined(__sun__) + +unsigned int MultithreadInfo::get_n_cpus() +{ + return sysconf(_SC_NPROCESSORS_ONLN); +} + +#else + +#warning Detection of Processors not supported on this OS + +unsigned int MultithreadInfo::get_n_cpus() +{ + return 1; +} + +#endif + + // not in multithreadmode +#else + +unsigned int MultithreadInfo::get_n_cpus() +{ + return 1; +} + +#endif + +MultithreadInfo multithread_info; + +MultithreadInfo::MultithreadInfo () : + n_cpus (get_n_cpus()), + n_default_threads (n_cpus) +{}; + + + + +