Dear List Sorry if this question seems very basic. Is there a function to pro grammatically find number of processors in my system _ I want to pass this as a parameter to snow in some serial code to parallel code functions Regards Ajay Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri
Prof Brian Ripley
2010-Oct-03 19:55 UTC
[R] Programmaticly finding number of processors by R code
Without knowing your OS, there is no way anyone can tell you. And you probably want to know 'cores' rather than CPUs. And for some specific OSes, you will find answers in the archives. Beware that this is not a well-defined question: are these physical or virtual cores?, and having them in the system and being allowed to use them are different questions. Package 'multicore' is one that attempts to do this in its function detectCores (see the source code). And on Sparc Solaris it is pretty useless as it gives virtual CPUs, 8x the number of real CPUs. On Sun, 3 Oct 2010, Ajay Ohri wrote:> Dear List > > Sorry if this question seems very basic. > > Is there a function to pro grammatically find number of processors in > my system _ I want to pass this as a parameter to snow in some serial > code to parallel code functions > > Regards > > Ajay > > > > Websites- > http://decisionstats.com > http://dudeofdata.com > > > Linkedin- www.linkedin.com/in/ajayohri > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Peter Langfelder
2010-Oct-03 22:17 UTC
[R] Programmaticly finding number of processors by R code
If no-one replies with a better way, here's a way: under POSIX-compliant systems, you can write a small C function and wrap it in an R function. The C program would be something like #include <unistd.h> void nProcessors(int & n) { #ifdef _SC_NPROCESSORS_ONLN long nProcessorsOnline = sysconf(_SC_NPROCESSORS_ONLN); #else long nProcessorsOnline = 2; // This is my guess - most computers today have at least 2 cores #endif n = (int) nProcessorsOnline; } You need to compile the function into a dynamic library ("shared object" on linux) and load the dynamic library with dyn.load before using it. The R wrapper would be a function along the lines of nProcessors = function() { n = 0; res = .C("nProcessors", n = as.integer(n)); res$n } I haven't actually tested the R function so please take this with a grain of salt, but I do use the C function in my own C code. You may also want to read this thread about potential pitfalls and limitations, plus another (simpler) way that would work on linux: http://forum.soft32.com/linux2/CPUs-machine-ftopict13343.html AFAIK, this will not work on Windows because Windows is not POSIX compliant, but I'm not sure. Peter On Sun, Oct 3, 2010 at 10:03 AM, Ajay Ohri <ohri2007 at gmail.com> wrote:> Dear List > > Sorry if this question seems very basic. > > Is there a function to pro grammatically find number of processors in > my system _ I want to pass this as a parameter to snow in some serial > code to parallel code functions > > Regards > > Ajay >
Henrique Dallazuanna
2010-Oct-03 22:26 UTC
[R] Programmaticly finding number of processors by R code
In windows try this: Sys.getenv('NUMBER_OF_PROCESSORS') On Sun, Oct 3, 2010 at 2:03 PM, Ajay Ohri <ohri2007@gmail.com> wrote:> Dear List > > Sorry if this question seems very basic. > > Is there a function to pro grammatically find number of processors in > my system _ I want to pass this as a parameter to snow in some serial > code to parallel code functions > > Regards > > Ajay > > > > Websites- > http://decisionstats.com > http://dudeofdata.com > > > Linkedin- www.linkedin.com/in/ajayohri > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Abhijit Dasgupta, PhD
2010-Oct-04 04:45 UTC
[R] Programmaticly finding number of processors by R code
If you have installed multicore (for unix/mac), you can find the number of cores by /*multicore:::detectCores()*/ On 10/3/10 1:03 PM, Ajay Ohri wrote:> Dear List > > Sorry if this question seems very basic. > > Is there a function to pro grammatically find number of processors in > my system _ I want to pass this as a parameter to snow in some serial > code to parallel code functions > > Regards > > Ajay > > > > Websites- > http://decisionstats.com > http://dudeofdata.com > > > Linkedin- www.linkedin.com/in/ajayohri > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Abhijit Dasgupta, PhD Director and Principal Statistician ARAASTAT Ph: 301.385.3067 E: adasgupta@araastat.com W: http://www.araastat.com [[alternative HTML version deleted]]