1
1
openmpi/opal/util/num_procs.c
George Bosilca ebbc37584f Add Windows support for finding the number of available processors, and
return the same value if there is no registered paffinity module.

This commit was SVN r13509.
2007-02-06 16:53:13 +00:00

59 строки
1.3 KiB
C

/*
* Copyright (c) 2007 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include <unistd.h>
#include "opal/constants.h"
#include "opal/util/num_procs.h"
#if defined(HAVE_SYS_SYSCTL_H)
#include <sys/sysctl.h>
#endif
/*
* Simple wrapper to get the number of processors on the local host
*/
int opal_get_num_processors(int *num_procs)
{
#ifdef __WINDOWS__
SYSTEM_INFO sys_info;
GetSystemInfo( &sys_info );
*num_procs = sys_info.dwNumberOfProcessors;
return OPAL_SUCCESS;
#else
/* POSIX environments */
#if defined(__APPLE__)
/* OSX has a special function for this */
size_t size = sizeof(*num_procs) ;
if (0 == sysctlbyname( "hw.ncpu", num_procs, &size, NULL, 0)) {
return OPAL_SUCCESS;
}
#elif OPAL_HAVE__SC_NPROCESSORS_ONLN
/* Other POSIX'es can use sysconf() */
int count = sysconf(_SC_NPROCESSORS_ONLN);
if (-1 != count) {
*num_procs = count;
return OPAL_SUCCESS;
}
#endif
/* Default case if we don't know how to get the processor number or if
something fails. */
return OPAL_ERR_NOT_FOUND;
#endif
}