public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Rupert Wood" <me@rupey.net>
To: "'Cong'" <vo.chi.cong@is.titech.ac.jp>
Cc: "'Bharathi S'" <bharathi@lantana.tenet.res.in>, <gcc-help@gcc.gnu.org>
Subject: RE: how to get the number of CPUs?
Date: Thu, 04 Jul 2002 05:52:00 -0000	[thread overview]
Message-ID: <616BE6A276E3714788D2AC35C40CD18D5EC4E6@whale.softwire.co.uk> (raw)
In-Reply-To: <616BE6A276E3714788D2AC35C40CD18D6C01F7@whale.softwire.co.uk>

Bharathi S. wrote:

> On Thu, 4 Jul 2002, Cong wrote:
> > number of CPUs on each of them. So I want to get the number of CPUs
>   cpu info is avilable in /proc/cpuinfo file
>   if processor is 0 then No. of CPU is 1
>   Explore /proc dir you will more idea :)

Or the sysconf solution - for Solaris, at least, but this ought to be
portable:

    #include <stdio.h>
    #include <unistd.h>

    int main(void)
    {
        long nProcessorsConfigured = sysconf(_SC_NPROCESSORS_CONF);
        long nProcessorsOnline     = sysconf(_SC_NPROCESSORS_ONLN);

        if (nProcessorsConfigured != -1)
        {
            printf("Processors configured :
%ld\n",nProcessorsConfigured);
        }
        else
        {
            printf("Unable to read configured processor count.\n");
        }

        if (nProcessorsOnline != -1)
        {
            printf("Processors online     : %ld\n",nProcessorsOnline);
        }
        else
        {
            printf("Unable to read online processor count.\n");
        }

        return 0;
    }

Try 'man sysconf' to get a list of supported sysconf arguments and their
descriptions on your platform.

Rup.

       reply	other threads:[~2002-07-04 12:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <616BE6A276E3714788D2AC35C40CD18D6C01F7@whale.softwire.co.uk>
2002-07-04  5:52 ` Rupert Wood [this message]
2002-07-06 21:24   ` Cong
2002-07-13  8:00     ` Nix
2002-07-04 13:11 Dockeen
     [not found] <1025766825.11142.ezmlm@gcc.gnu.org>
2002-07-04  4:45 ` Cong
2002-07-04  5:30   ` Bharathi S

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=616BE6A276E3714788D2AC35C40CD18D5EC4E6@whale.softwire.co.uk \
    --to=me@rupey.net \
    --cc=bharathi@lantana.tenet.res.in \
    --cc=gcc-help@gcc.gnu.org \
    --cc=vo.chi.cong@is.titech.ac.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).