autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: number of processors


From: Philip Willoughby
Subject: Re: number of processors
Date: Fri, 30 Aug 2002 21:33:48 +0100 (BST)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yesterday, Philipp Gortan wrote:

>thanks for all interesting answers. Well, using the sysconf() function
>looks like the smoothest way to do the job, even though it's not as
>easily nested into autoconf as my dirty hack... how would you add the c
>code to the program? can is be easily compiled while configure is
>running und its output be used, e.g. via AC_TRY_RUN()?

I'll post a macro to do it to here and ac-archive sometime this weekend
(possibly tonight).  Please could you all try this code on your platforms
and see what happens, and in the event of it failing to work get back to me
with a fix for your platform:

- --BEGIN--

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>


int main() {
  long nprocs = -1;
  long nprocs_max = -1;
#ifdef _WIN32
#ifndef _SC_NPROCESSORS_ONLN
SYSTEM_INFO info;
GetSystemInfo(&info);
#define sysconf(a) info.dwNumberOfProcessors
#define _SC_NPROCESSORS_ONLN
#endif
#endif
#ifdef _SC_NPROCESSORS_ONLN
  nprocs = sysconf(_SC_NPROCESSORS_ONLN);
  if (nprocs < 1)
  {
    fprintf(stderr, "Could not determine number of CPUs online:\n%s\n", 
strerror (errno));
    exit (EXIT_FAILURE);
  }
  nprocs_max = sysconf(_SC_NPROCESSORS_CONF);
  if (nprocs_max < 1)
  {
    fprintf(stderr, "Could not determine number of CPUs configured:\n%s\n", 
strerror (errno));
    exit (EXIT_FAILURE);
  }
  printf ("%ld of %ld processors online\n",nprocs, nprocs_max);
  exit (EXIT_SUCCESS);
#else
  fprintf(stderr, "Could not determine number of CPUs");
  exit (EXIT_FAILURE);
#endif
}

- --END--

Don't contact me if it fails on Windows since I haven't yet tested it, but
I will be doing so in about 5 minutes time.

I don't expect it to work on:
z/OS
OS/400
Minix -- Single CPU only anyway \
Plan9                           |- Who cares?
Old AT&T derived unices         /

Regards,

Philip Willoughby

Systems Programmer, Department of Computing, Imperial College, London, UK
- -- 
echo address@hidden | tr "bizndfohces" "pwgd9ociaku"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9b9azTEXlrOaAVckRAlU4AKCSvC0OfqxE+lzn0RiwT9/TA1nNfgCgngVV
j9UoW+3RfBKG3Cg0PJlbguI=
=G04/
-----END PGP SIGNATURE-----





reply via email to

[Prev in Thread] Current Thread [Next in Thread]