config/mingw32/proc.c

Go to the documentation of this file.
00001 /* Copyright (C) 2007, 2009 Free Software Foundation, Inc.
00002    Contributed by Danny Smith <dannysmith@users.sourceforge.net>
00003 
00004    This file is part of the GNU OpenMP Library (libgomp).
00005 
00006    Libgomp is free software; you can redistribute it and/or modify it
00007    under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 3, or (at your option)
00009    any later version.
00010 
00011    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
00012    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00014    more details.
00015 
00016    Under Section 7 of GPL version 3, you are granted additional
00017    permissions described in the GCC Runtime Library Exception, version
00018    3.1, as published by the Free Software Foundation.
00019 
00020    You should have received a copy of the GNU General Public License and
00021    a copy of the GCC Runtime Library Exception along with this program;
00022    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023    <http://www.gnu.org/licenses/>.  */
00024 
00025 /* This file contains system specific routines related to counting
00026    online processors and dynamic load balancing.  It is expected that
00027    a system may well want to write special versions of each of these.
00028 
00029    The following implementation uses win32 API routines.  */
00030 
00031 #include "libgomp.h"
00032 #include <windows.h>
00033 
00034 /* Count the CPU's currently available to this process.  */
00035 static unsigned int
00036 count_avail_process_cpus ()
00037 {
00038   DWORD_PTR process_cpus;
00039   DWORD_PTR system_cpus;
00040 
00041   if (GetProcessAffinityMask (GetCurrentProcess (),
00042                   &process_cpus, &system_cpus))
00043     {
00044       unsigned int count;
00045       for (count = 0; process_cpus != 0; process_cpus >>= 1)  
00046     if (process_cpus & 1)
00047       count++;
00048       return count;
00049     }
00050   return 1;
00051 }
00052 
00053 /* At startup, determine the default number of threads.  It would seem
00054    this should be related to the number of cpus available to the process.  */
00055 
00056 void
00057 gomp_init_num_threads (void)
00058 {
00059   gomp_global_icv.nthreads_var = count_avail_process_cpus ();
00060 }
00061 
00062 /* When OMP_DYNAMIC is set, at thread launch determine the number of
00063    threads we should spawn for this team.  FIXME:  How do we adjust for
00064    load average on MS Windows?  */
00065 
00066 unsigned
00067 gomp_dynamic_max_threads (void)
00068 {
00069   unsigned int n_onln = count_avail_process_cpus ();
00070   unsigned int nthreads_var = gomp_icv (false)->nthreads_var;
00071   return n_onln > nthreads_var ? nthreads_var : n_onln;
00072 }
00073 
00074 int
00075 omp_get_num_procs (void)
00076 {
00077   return count_avail_process_cpus ();
00078 }
00079 
00080 ialias (omp_get_num_procs)

Generated on Fri Apr 5 05:38:09 2013 for Libgomp by  doxygen 1.4.7