]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
the number of cpus is detected on linux and sun
authorrichter <richter@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 23 Feb 2000 16:55:42 +0000 (16:55 +0000)
committerrichter <richter@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 23 Feb 2000 16:55:42 +0000 (16:55 +0000)
git-svn-id: https://svn.dealii.org/trunk@2486 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/multithread_info.cc [new file with mode: 0644]

diff --git a/deal.II/base/source/multithread_info.cc b/deal.II/base/source/multithread_info.cc
new file mode 100644 (file)
index 0000000..604279d
--- /dev/null
@@ -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 <base/multithread_info.h>
+
+#if defined(__linux__)
+
+#include <fstream.h>
+#include <string>
+#endif
+
+#if defined(__sun__)
+#include <unistd.h>
+#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)
+{};
+
+
+
+
+

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.