1
1
Add new function opal_get_num_processors() that will return the number
of processors on the local host.  Does the Right thing in POSIX
environments (to include a special case for OS X), and will shortly do
the Right Thing for Windows (this commit includes a change to
configure, so I wanted to get that in before the US workday -- the
Windows code can some shortly because it won't involve configury
changes).

This commit was SVN r13506.

The following Trac tickets were found above:
  Ticket 853 --> https://svn.open-mpi.org/trac/ompi/ticket/853
Этот коммит содержится в:
Jeff Squyres 2007-02-06 12:03:56 +00:00
родитель c91fcd7fbd
Коммит 0732c555de
5 изменённых файлов: 115 добавлений и 3 удалений

Просмотреть файл

@ -583,7 +583,7 @@ AC_CHECK_HEADERS([alloca.h aio.h arpa/inet.h dirent.h \
sys/resource.h sys/select.h sys/socket.h sys/sockio.h \
stdarg.h sys/stat.h sys/statvfs.h sys/time.h sys/tree.h \
sys/types.h sys/uio.h sys/utsname.h sys/wait.h syslog.h \
time.h termios.h ulimit.h unistd.h util.h utmp.h malloc.h])
time.h termios.h ulimit.h unistd.h util.h utmp.h malloc.h sys/sysctl.h])
# Needed to work around Darwin requiring sys/socket.h for
# net/if.h
@ -713,7 +713,7 @@ OMPI_CHECK_FUNC_LIB([dirname], [gen])
# Darwin doesn't need -lm, as it's a symlink to libSystem.dylib
OMPI_CHECK_FUNC_LIB([ceil], [m])
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf openpty isatty htonl ntohl htons ntohs getpwuid fork waitpid execve pipe ptsname setsid mmap mallopt tcgetpgrp posix_memalign strsignal])
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf openpty isatty htonl ntohl htons ntohs getpwuid fork waitpid execve pipe ptsname setsid mmap mallopt tcgetpgrp posix_memalign strsignal sysconf])
#
# Make sure we can copy va_lists (need check declared, not linkable)
@ -809,6 +809,18 @@ if test "$MPI_OFFSET_DATATYPE" = "not found"; then
fi
AC_DEFINE_UNQUOTED(OMPI_OFFSET_DATATYPE, $MPI_OFFSET_DATATYPE, [MPI datatype corresponding to MPI_Offset])
# Do we have _SC_NPROCESSORS_ONLN? (only going to pass if we also have
# <unistd.h> and sysconf(), which is ok) OS X 10.4 has <unistd.h> and
# sysconf(), but does not have _SC_NPROCESSORS_ONLN. Doh!
AC_MSG_CHECKING([for _SC_NPROCESSORS_ONLN])
AC_TRY_COMPILE([#include <unistd.h>],
[(void)sysconf(_SC_NPROCESSORS_ONLN);],
[MSG=yes VALUE=1], [MSG=no VALUE=0])
AC_DEFINE_UNQUOTED(OPAL_HAVE__SC_NPROCESSORS_ONLN, $VALUE,
[Whether we have the _SC_NPROCESSORS_ONLN])
AC_MSG_RESULT([$MSG])
# all: endian
AC_C_BIGENDIAN

Просмотреть файл

@ -35,6 +35,7 @@
#include "opal/threads/threads.h"
#include "opal/util/show_help.h"
#include "opal/util/stacktrace.h"
#include "opal/util/num_procs.h"
#include "opal/runtime/opal.h"
#include "opal/event/event.h"
@ -679,7 +680,7 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
* first, get the number of processors - if we can't then
* we can't do anything but set conservative values
*/
if (OPAL_SUCCESS == opal_paffinity_base_get_num_processors(&num_processors)) {
if (OPAL_SUCCESS == opal_get_num_processors(&num_processors)) {
/* got the num_processors - compare that to the number of
* local procs in this job to decide if we are oversubscribed
*/

Просмотреть файл

@ -9,6 +9,7 @@
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
@ -39,6 +40,7 @@ headers = \
keyval_parse.h \
malloc.h \
numtostr.h \
num_procs.h \
opal_environ.h \
os_dirpath.h \
os_path.h \
@ -68,6 +70,7 @@ libopalutil_la_SOURCES = \
keyval_parse.c \
malloc.c \
numtostr.c \
num_procs.c \
opal_environ.c \
os_dirpath.c \
os_path.c \

54
opal/util/num_procs.c Обычный файл
Просмотреть файл

@ -0,0 +1,54 @@
/*
* 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__
/* Need to get the Right code for Windows... */
return OPAL_ERR_NOT_IMPLEMENTED;
#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
}

42
opal/util/num_procs.h Обычный файл
Просмотреть файл

@ -0,0 +1,42 @@
/*
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/**
* @file
*
* This function is a simple wrapper to have an OS-independent
* mechanism to get the number of processors on a local host.
*/
#ifndef OPAL_NUM_PROCS_H
#define OPAL_NUM_PROCS_H
#include "opal_config.h"
#if defined(c_plusplus) || defined(__cplusplus)
extern "C" {
#endif
/**
* Provide a portable method for getting the number of processors on
* the local machine. In POSIX environments, this is a simple wrapper
* around sysconf().
*
* @retval OPAL_SUCCESS If successful, indicating that num_procs
* has a meaningful value.
* @retval OPAL_ERR_NOT_IMPLEMENTED on platforms that are not yet
* supported.
*/
int opal_get_num_processors(int *num_procs);
#if defined(c_plusplus) || defined(__cplusplus)
}
#endif
#endif