- Main Page
- Related Pages
- Classes
- Files

- File List

# hardware.h

    00001 #ifndef OPENMM_HARDWARE_H_
    00002 #define OPENMM_HARDWARE_H_
    00003
    00004 /* -------------------------------------------------------------------------- *
    00005  *                                   OpenMM                                   *
    00006  * -------------------------------------------------------------------------- *
    00007  * This is part of the OpenMM molecular simulation toolkit originating from   *
    00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
    00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
    00010  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
    00011  *                                                                            *
    00012  * Portions copyright (c) 2013 Stanford University and the Authors.           *
    00013  * Authors: Peter Eastman                                                     *
    00014  * Contributors:                                                              *
    00015  *                                                                            *
    00016  * Permission is hereby granted, free of charge, to any person obtaining a    *
    00017  * copy of this software and associated documentation files (the "Software"), *
    00018  * to deal in the Software without restriction, including without limitation  *
    00019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
    00020  * and/or sell copies of the Software, and to permit persons to whom the      *
    00021  * Software is furnished to do so, subject to the following conditions:       *
    00022  *                                                                            *
    00023  * The above copyright notice and this permission notice shall be included in *
    00024  * all copies or substantial portions of the Software.                        *
    00025  *                                                                            *
    00026  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
    00027  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
    00028  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
    00029  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
    00030  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
    00031  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
    00032  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
    00033  * -------------------------------------------------------------------------- */
    00034
    00042 #ifdef __APPLE__
    00043    #include <sys/sysctl.h>
    00044    #include <dlfcn.h>
    00045 #else
    00046    #ifdef WIN32
    00047       #define NOMINMAX
    00048       #include <windows.h>
    00049       #include <intrin.h>
    00050    #else
    00051       #ifdef __ANDROID__
    00052         #include <cpu-features.h>
    00053       #else
    00054         #include <unistd.h>
    00055       #endif
    00056    #endif
    00057 #endif
    00058
    00059 static int getNumProcessors() {
    00060 #ifdef __APPLE__
    00061     int ncpu;
    00062     size_t len = 4;
    00063     if (sysctlbyname("hw.logicalcpu", &ncpu, &len, NULL, 0) == 0)
    00064        return ncpu;
    00065     else
    00066        return 1;
    00067 #else
    00068 #ifdef WIN32
    00069     SYSTEM_INFO siSysInfo;
    00070     int ncpu;
    00071     GetSystemInfo(&siSysInfo);
    00072     ncpu = siSysInfo.dwNumberOfProcessors;
    00073     if (ncpu < 1)
    00074         ncpu = 1;
    00075     return ncpu;
    00076 #else
    00077     #ifdef __ANDROID__
    00078         return android_getCpuCount();
    00079     #else
    00080       long nProcessorsOnline = sysconf(_SC_NPROCESSORS_ONLN);
    00081       if (nProcessorsOnline == -1)
    00082           return 1;
    00083       else
    00084           return (int) nProcessorsOnline;
    00085     #endif
    00086 #endif
    00087 #endif
    00088 }
    00089
    00093 #ifdef WIN32
    00094 #define cpuid __cpuid
    00095 #else
    00096 #if !defined(__ANDROID__) && !defined(__PNACL__)
    00097     static void cpuid(int cpuInfo[4], int infoType){
    00098     #ifdef __LP64__
    00099         __asm__ __volatile__ (
    00100             "cpuid":
    00101             "=a" (cpuInfo[0]),
    00102             "=b" (cpuInfo[1]),
    00103             "=c" (cpuInfo[2]),
    00104             "=d" (cpuInfo[3]) :
    00105             "a" (infoType)
    00106         );
    00107     #else
    00108         __asm__ __volatile__ (
    00109             "pushl %%ebx\n"
    00110             "cpuid\n"
    00111             "movl %%ebx, %1\n"
    00112             "popl %%ebx\n" :
    00113             "=a" (cpuInfo[0]),
    00114             "=r" (cpuInfo[1]),
    00115             "=c" (cpuInfo[2]),
    00116             "=d" (cpuInfo[3]) :
    00117             "a" (infoType)
    00118         );
    00119     #endif
    00120     }
    00121     #endif
    00122 #endif
    00123
    00124 #endif // OPENMM_HARDWARE_H_