NCEPLIBS-sp  2.3.3
ncpus.F
Go to the documentation of this file.
1 C> @file
2 C> Set number of cpus.
3 C> @author IREDELL @date 94-08-19
4 
5 C> Set number of cpus. Designating the number of processors over which
6 C> to parallelize.
7 C>
8 C> PROGRAM HISTORY LOG:
9 C> - 94-08-19 IREDELL
10 C> - 98-11-09 VUONG ADD DOC>BLOCK AND REMOVE CRAY REFERENCES
11 C> - 1998-12-18 IREDELL IBM SMP VERSION
12 C> - 2010-11-16 SLOVACEK LINUX MUST HAVE DIFFERENT CALL
13 C> - 2012-11-01 MIRVIS Multi- threading on LINUX-IBM/TIDE
14 C>
15 C> @param[out] NCPUS INTEGER NUMBER OF CPUS
16 C>
17 C> SUBPROGRAMS CALLED:
18 C> - num_parthds() XLF intrinsic to return number of threads
19 C>
20  FUNCTION ncpus()
21  INTEGER nthreads, tid, omp_get_num_threads,omp_get_thread_num
22 C Obtain thread number
23 #ifdef openmp
24 #if defined linux || defined apple
25 !$OMP PARALLEL PRIVATE(TID)
26  tid = omp_get_thread_num()
27 ! PRINT *, '...............thread # ', TID
28  if (tid. eq. 0) then
29  ncpus=omp_get_num_threads()
30 ! PRINT *, 'totaly #------------------- of threads = ',NCPUS
31  endif
32 !$OMP END PARALLEL
33 #else
34  ncpus=num_parthds()
35 #endif
36 #else
37  tid = 0
38  ncpus = 1
39 #endif
40  RETURN
41  END
ncpus
function ncpus()
Set number of cpus.
Definition: ncpus.F:21