Re: [sage-devel] Re: platform independent way of getting the number of processors

1 view
Skip to first unread message

William Stein

unread,
Mar 29, 2009, 3:37:42 PM3/29/09
to sage-...@googlegroups.com, spd...@googlegroups.com
On Sun, Mar 29, 2009 at 11:34 AM, Peter Jeremy
<peter...@optushome.com.au> wrote:
> On 2009-Mar-28 14:53:46 -0700, Ondrej Certik <ond...@certik.cz> wrote:
>>I am trying to figure out the best way to automatically determine the
>>number of processors and used that information to speed up Sage build.
>
> Note that this should be able to be over-ridden by the operator -
> just because a system has (say) 8 cores available doesn't mean that
> the sage build should use them all.

Just for the record this is a discussion about "Simple Python
Distribution", not Sage. What Ondrej is doing doesn't a priori have
anything to do with how Sage is built (though I of course hope it
will). I've cc'd this to the spd-dev list since the discussion would
also make sense there:

http://groups.google.com/group/spd-dev/about

and there are no discussions there yet.

>>If Python is not available, then I can use this simple C program:
>>
>>http://github.com/certik/sysconf/blob/master/ncpus.c
>>
>>but I suspect this will not work on Mac or Windows.
>
> sysconf() is part of POSIX so it should work in any POSIX environment.
> Microsoft made a big claim about Windows being POSIX compliant so it
> should work there - but may need to link against special libraries.
> It should work on OS-X (though I can't test it).

Microsoft Windows only implements POSIX.1. According to wikipedia:
"Because only the first version of POSIX (POSIX.1) is implemented, a
POSIX application cannot create a thread or window, nor can it use RPC
or socket. Instead of implementing the later versions of POSIX,
Microsoft offers Windows Services for UNIX."
http://en.wikipedia.org/wiki/Microsoft_POSIX_subsystem

I donly know if sysconf is in POSIX.1 or not.

>
>>2) try: cat /proc/cpuinfo | grep processor | wc -l
>
> That is far less portable than sysconf() because it _only_ works
> on Linux, whereas sysconf() should work on nearly all Unix systems
> (and some others).
>
> --
> Peter Jeremy
>

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

William Stein

unread,
Mar 29, 2009, 4:03:22 PM3/29/09
to sage-w...@googlegroups.com, spd-dev
Dear Sage Windows guys,

Does the following work on Windows (with MSVC) or not?


---------- Forwarded message ----------
From: Roman Pearce <rpea...@gmail.com>
Date: Sun, Mar 29, 2009 at 12:51 PM
Subject: [sage-devel] Re: platform independent way of getting the
number of processors
To: sage-devel <sage-...@googlegroups.com>



On Mar 29, 12:49 am, Ondrej Certik <ond...@certik.cz> wrote:
> I just tried the following code on several linuxes (Debian, Ubuntu,
> Gentoo, Red Hat, OpenSUSE) and on OS X 10.5 Intel and it seems to just
> work everywhere:
>
> #include "unistd.h"
> #include "stdio.h"
>
> int main()
> {
>     int ncpus;
>     ncpus = sysconf(_SC_NPROCESSORS_ONLN);
>     printf("%d", ncpus);
>     return 0;
>
> }

This is the best way.  I am using sysconf on POSIX systems now.
Reply all
Reply to author
Forward
0 new messages