Mercurial > hg > CbC > CbC_gcc
comparison libgomp/config/mingw32/proc.c @ 0:a06113de4d67
first commit
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2009 14:47:48 +0900 |
parents | |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a06113de4d67 |
---|---|
1 /* Copyright (C) 2007, 2009 Free Software Foundation, Inc. | |
2 Contributed by Danny Smith <dannysmith@users.sourceforge.net> | |
3 | |
4 This file is part of the GNU OpenMP Library (libgomp). | |
5 | |
6 Libgomp is free software; you can redistribute it and/or modify it | |
7 under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 3, or (at your option) | |
9 any later version. | |
10 | |
11 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 more details. | |
15 | |
16 Under Section 7 of GPL version 3, you are granted additional | |
17 permissions described in the GCC Runtime Library Exception, version | |
18 3.1, as published by the Free Software Foundation. | |
19 | |
20 You should have received a copy of the GNU General Public License and | |
21 a copy of the GCC Runtime Library Exception along with this program; | |
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 <http://www.gnu.org/licenses/>. */ | |
24 | |
25 /* This file contains system specific routines related to counting | |
26 online processors and dynamic load balancing. It is expected that | |
27 a system may well want to write special versions of each of these. | |
28 | |
29 The following implementation uses win32 API routines. */ | |
30 | |
31 #include "libgomp.h" | |
32 #include <windows.h> | |
33 | |
34 /* Count the CPU's currently available to this process. */ | |
35 static unsigned int | |
36 count_avail_process_cpus () | |
37 { | |
38 DWORD_PTR process_cpus; | |
39 DWORD_PTR system_cpus; | |
40 | |
41 if (GetProcessAffinityMask (GetCurrentProcess (), | |
42 &process_cpus, &system_cpus)) | |
43 { | |
44 unsigned int count; | |
45 for (count = 0; process_cpus != 0; process_cpus >>= 1) | |
46 if (process_cpus & 1) | |
47 count++; | |
48 return count; | |
49 } | |
50 return 1; | |
51 } | |
52 | |
53 /* At startup, determine the default number of threads. It would seem | |
54 this should be related to the number of cpus available to the process. */ | |
55 | |
56 void | |
57 gomp_init_num_threads (void) | |
58 { | |
59 gomp_global_icv.nthreads_var = count_avail_process_cpus (); | |
60 } | |
61 | |
62 /* When OMP_DYNAMIC is set, at thread launch determine the number of | |
63 threads we should spawn for this team. FIXME: How do we adjust for | |
64 load average on MS Windows? */ | |
65 | |
66 unsigned | |
67 gomp_dynamic_max_threads (void) | |
68 { | |
69 unsigned int n_onln = count_avail_process_cpus (); | |
70 unsigned int nthreads_var = gomp_icv (false)->nthreads_var; | |
71 return n_onln > nthreads_var ? nthreads_var : n_onln; | |
72 } | |
73 | |
74 int | |
75 omp_get_num_procs (void) | |
76 { | |
77 return count_avail_process_cpus (); | |
78 } | |
79 | |
80 ialias (omp_get_num_procs) |